BSD 4_4_Lite2 release
[unix-history] / usr / src / sys / ufs / lfs / lfs_syscalls.c
index 666595e..c6034e2 100644 (file)
@@ -30,7 +30,7 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- *     @(#)lfs_syscalls.c      8.5 (Berkeley) 4/20/94
+ *     @(#)lfs_syscalls.c      8.10 (Berkeley) 5/14/95
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -64,6 +64,10 @@ if (sp->sum_bytes_left < (s)) {              \
 }
 struct buf *lfs_fakebuf __P((struct vnode *, int, size_t, caddr_t));
 
 }
 struct buf *lfs_fakebuf __P((struct vnode *, int, size_t, caddr_t));
 
+int debug_cleaner = 0;
+int clean_vnlocked = 0;
+int clean_inlocked = 0;
+
 /*
  * lfs_markv:
  *
 /*
  * lfs_markv:
  *
@@ -99,7 +103,7 @@ lfs_markv(p, uap, retval)
        fsid_t fsid;
        void *start;
        ino_t lastino;
        fsid_t fsid;
        void *start;
        ino_t lastino;
-       daddr_t b_daddr, v_daddr;
+       ufs_daddr_t b_daddr, v_daddr;
        u_long bsize;
        int cnt, error;
 
        u_long bsize;
        int cnt, error;
 
@@ -108,7 +112,7 @@ lfs_markv(p, uap, retval)
 
        if (error = copyin(uap->fsidp, &fsid, sizeof(fsid_t)))
                return (error);
 
        if (error = copyin(uap->fsidp, &fsid, sizeof(fsid_t)))
                return (error);
-       if ((mntp = getvfs(&fsid)) == NULL)
+       if ((mntp = vfs_getvfs(&fsid)) == NULL)
                return (EINVAL);
 
        cnt = uap->blkcnt;
                return (EINVAL);
 
        cnt = uap->blkcnt;
@@ -135,7 +139,7 @@ lfs_markv(p, uap, retval)
                                if (sp->fip->fi_nblocks == 0) {
                                        DEC_FINFO(sp);
                                        sp->sum_bytes_left +=
                                if (sp->fip->fi_nblocks == 0) {
                                        DEC_FINFO(sp);
                                        sp->sum_bytes_left +=
-                                           sizeof(FINFO) - sizeof(daddr_t);
+                                           sizeof(FINFO) - sizeof(ufs_daddr_t);
                                } else {
                                        lfs_updatemeta(sp);
                                        BUMP_FIP(sp);
                                } else {
                                        lfs_updatemeta(sp);
                                        BUMP_FIP(sp);
@@ -147,7 +151,7 @@ lfs_markv(p, uap, retval)
 
                        /* Start a new file */
                        CHECK_SEG(sizeof(FINFO));
 
                        /* Start a new file */
                        CHECK_SEG(sizeof(FINFO));
-                       sp->sum_bytes_left -= sizeof(FINFO) - sizeof(daddr_t);
+                       sp->sum_bytes_left -= sizeof(FINFO) - sizeof(ufs_daddr_t);
                        INC_FINFO(sp);
                        sp->start_lbp = &sp->fip->fi_blocks[0];
                        sp->vp = NULL;
                        INC_FINFO(sp);
                        sp->start_lbp = &sp->fip->fi_blocks[0];
                        sp->vp = NULL;
@@ -172,6 +176,7 @@ lfs_markv(p, uap, retval)
 #ifdef DIAGNOSTIC
                                printf("lfs_markv: VFS_VGET failed (%d)\n",
                                    blkp->bi_inode);
 #ifdef DIAGNOSTIC
                                printf("lfs_markv: VFS_VGET failed (%d)\n",
                                    blkp->bi_inode);
+                               panic("lfs_markv VFS_VGET FAILED");
 #endif
                                lastino = LFS_UNUSED_INUM;
                                v_daddr = LFS_UNUSED_DADDR;
 #endif
                                lastino = LFS_UNUSED_INUM;
                                v_daddr = LFS_UNUSED_DADDR;
@@ -202,7 +207,7 @@ lfs_markv(p, uap, retval)
                        bp = getblk(vp, blkp->bi_lbn, bsize, 0, 0);
                        if (!(bp->b_flags & (B_DELWRI | B_DONE | B_CACHE)) &&
                            (error = copyin(blkp->bi_bp, bp->b_data,
                        bp = getblk(vp, blkp->bi_lbn, bsize, 0, 0);
                        if (!(bp->b_flags & (B_DELWRI | B_DONE | B_CACHE)) &&
                            (error = copyin(blkp->bi_bp, bp->b_data,
-                           bsize)))
+                           blkp->bi_size)))
                                goto err2;
                        if (error = VOP_BWRITE(bp))
                                goto err2;
                                goto err2;
                        if (error = VOP_BWRITE(bp))
                                goto err2;
@@ -213,7 +218,7 @@ lfs_markv(p, uap, retval)
                if (sp->fip->fi_nblocks == 0) {
                        DEC_FINFO(sp);
                        sp->sum_bytes_left +=
                if (sp->fip->fi_nblocks == 0) {
                        DEC_FINFO(sp);
                        sp->sum_bytes_left +=
-                           sizeof(FINFO) - sizeof(daddr_t);
+                           sizeof(FINFO) - sizeof(ufs_daddr_t);
                } else
                        lfs_updatemeta(sp);
 
                } else
                        lfs_updatemeta(sp);
 
@@ -267,10 +272,11 @@ lfs_bmapv(p, uap, retval)
 {
        BLOCK_INFO *blkp;
        struct mount *mntp;
 {
        BLOCK_INFO *blkp;
        struct mount *mntp;
+       struct ufsmount *ump;
        struct vnode *vp;
        fsid_t fsid;
        void *start;
        struct vnode *vp;
        fsid_t fsid;
        void *start;
-       daddr_t daddr;
+       ufs_daddr_t daddr;
        int cnt, error, step;
 
        if (error = suser(p->p_ucred, &p->p_acflag))
        int cnt, error, step;
 
        if (error = suser(p->p_ucred, &p->p_acflag))
@@ -278,7 +284,7 @@ lfs_bmapv(p, uap, retval)
 
        if (error = copyin(uap->fsidp, &fsid, sizeof(fsid_t)))
                return (error);
 
        if (error = copyin(uap->fsidp, &fsid, sizeof(fsid_t)))
                return (error);
-       if ((mntp = getvfs(&fsid)) == NULL)
+       if ((mntp = vfs_getvfs(&fsid)) == NULL)
                return (EINVAL);
 
        cnt = uap->blkcnt;
                return (EINVAL);
 
        cnt = uap->blkcnt;
@@ -291,10 +297,18 @@ lfs_bmapv(p, uap, retval)
        for (step = cnt; step--; ++blkp) {
                if (blkp->bi_lbn == LFS_UNUSED_LBN)
                        continue;
        for (step = cnt; step--; ++blkp) {
                if (blkp->bi_lbn == LFS_UNUSED_LBN)
                        continue;
-               /* Could be a deadlock ? */
-               if (VFS_VGET(mntp, blkp->bi_inode, &vp))
+               /*
+                * A regular call to VFS_VGET could deadlock
+                * here.  Instead, we try an unlocked access.
+                */
+               ump = VFSTOUFS(mntp);
+               if ((vp =
+                   ufs_ihashlookup(ump->um_dev, blkp->bi_inode)) != NULL) {
+                       if (VOP_BMAP(vp, blkp->bi_lbn, NULL, &daddr, NULL))
+                               daddr = LFS_UNUSED_DADDR;
+               } else if (VFS_VGET(mntp, blkp->bi_inode, &vp))
                        daddr = LFS_UNUSED_DADDR;
                        daddr = LFS_UNUSED_DADDR;
-               else {
+               else  {
                        if (VOP_BMAP(vp, blkp->bi_lbn, NULL, &daddr, NULL))
                                daddr = LFS_UNUSED_DADDR;
                        vput(vp);
                        if (VOP_BMAP(vp, blkp->bi_lbn, NULL, &daddr, NULL))
                                daddr = LFS_UNUSED_DADDR;
                        vput(vp);
@@ -337,7 +351,7 @@ lfs_segclean(p, uap, retval)
 
        if (error = copyin(uap->fsidp, &fsid, sizeof(fsid_t)))
                return (error);
 
        if (error = copyin(uap->fsidp, &fsid, sizeof(fsid_t)))
                return (error);
-       if ((mntp = getvfs(&fsid)) == NULL)
+       if ((mntp = vfs_getvfs(&fsid)) == NULL)
                return (EINVAL);
 
        fs = VFSTOUFS(mntp)->um_lfs;
                return (EINVAL);
 
        fs = VFSTOUFS(mntp)->um_lfs;
@@ -402,14 +416,14 @@ lfs_segwait(p, uap, retval)
        if (fsid == (fsid_t)-1)
                addr = &lfs_allclean_wakeup;
        else {
        if (fsid == (fsid_t)-1)
                addr = &lfs_allclean_wakeup;
        else {
-               if ((mntp = getvfs(&fsid)) == NULL)
+               if ((mntp = vfs_getvfs(&fsid)) == NULL)
                        return (EINVAL);
                addr = &VFSTOUFS(mntp)->um_lfs->lfs_nextseg;
        }
 #else
        if (error = copyin(uap->fsidp, &fsid, sizeof(fsid_t)))
                return (error);
                        return (EINVAL);
                addr = &VFSTOUFS(mntp)->um_lfs->lfs_nextseg;
        }
 #else
        if (error = copyin(uap->fsidp, &fsid, sizeof(fsid_t)))
                return (error);
-       if ((mntp = getvfs(&fsid)) == NULL)
+       if ((mntp = vfs_getvfs(&fsid)) == NULL)
                addr = &lfs_allclean_wakeup;
        else
                addr = &VFSTOUFS(mntp)->um_lfs->lfs_nextseg;
                addr = &lfs_allclean_wakeup;
        else
                addr = &VFSTOUFS(mntp)->um_lfs->lfs_nextseg;
@@ -441,7 +455,7 @@ int
 lfs_fastvget(mp, ino, daddr, vpp, dinp)
        struct mount *mp;
        ino_t ino;
 lfs_fastvget(mp, ino, daddr, vpp, dinp)
        struct mount *mp;
        ino_t ino;
-       daddr_t daddr;
+       ufs_daddr_t daddr;
        struct vnode **vpp;
        struct dinode *dinp;
 {
        struct vnode **vpp;
        struct dinode *dinp;
 {
@@ -462,14 +476,12 @@ lfs_fastvget(mp, ino, daddr, vpp, dinp)
        if ((*vpp = ufs_ihashlookup(dev, ino)) != NULL) {
                lfs_vref(*vpp);
                if ((*vpp)->v_flag & VXLOCK)
        if ((*vpp = ufs_ihashlookup(dev, ino)) != NULL) {
                lfs_vref(*vpp);
                if ((*vpp)->v_flag & VXLOCK)
-                       printf ("Cleaned vnode VXLOCKED\n");
+                       clean_vnlocked++;
                ip = VTOI(*vpp);
                ip = VTOI(*vpp);
-               if (ip->i_flags & IN_LOCKED)
-                       printf("cleaned vnode locked\n");
-               if (!(ip->i_flag & IN_MODIFIED)) {
+               if (lockstatus(&ip->i_lock))
+                       clean_inlocked++;
+               if (!(ip->i_flag & IN_MODIFIED))
                        ++ump->um_lfs->lfs_uinodes;
                        ++ump->um_lfs->lfs_uinodes;
-                       ip->i_flag |= IN_MODIFIED;
-               }
                ip->i_flag |= IN_MODIFIED;
                return (0);
        }
                ip->i_flag |= IN_MODIFIED;
                return (0);
        }
@@ -522,9 +534,6 @@ lfs_fastvget(mp, ino, daddr, vpp, dinp)
                brelse(bp);
        }
 
                brelse(bp);
        }
 
-       /* Inode was just read from user space or disk, make sure it's locked */
-       ip->i_flag |= IN_LOCKED;
-
        /*
         * Initialize the vnode from the inode, check for aliases.  In all
         * cases re-init ip, the underlying vnode/inode may have changed.
        /*
         * Initialize the vnode from the inode, check for aliases.  In all
         * cases re-init ip, the underlying vnode/inode may have changed.