Use balloc to extend Ifile.
[unix-history] / usr / src / sys / ufs / lfs / lfs_alloc.c
index 24f5321..c3f7c9b 100644 (file)
@@ -4,7 +4,7 @@
  *
  * %sccs.include.redist.c%
  *
  *
  * %sccs.include.redist.c%
  *
- *     @(#)lfs_alloc.c 7.49 (Berkeley) %G%
+ *     @(#)lfs_alloc.c 7.56 (Berkeley) %G%
  */
 
 #include <sys/param.h>
  */
 
 #include <sys/param.h>
@@ -45,11 +45,8 @@ lfs_valloc(ap)
        daddr_t blkno;
        ino_t new_ino;
        u_long i, max;
        daddr_t blkno;
        ino_t new_ino;
        u_long i, max;
-       int error;
+       int bb, error;
 
 
-#ifdef VERBOSE
-       printf("lfs_valloc\n");
-#endif
        /* Get the head of the freelist. */
        fs = VTOI(ap->a_pvp)->i_lfs;
        new_ino = fs->lfs_free;
        /* Get the head of the freelist. */
        fs = VTOI(ap->a_pvp)->i_lfs;
        new_ino = fs->lfs_free;
@@ -72,20 +69,15 @@ lfs_valloc(ap)
                vp = fs->lfs_ivnode;
                ip = VTOI(vp);
                blkno = lblkno(fs, ip->i_size);
                vp = fs->lfs_ivnode;
                ip = VTOI(vp);
                blkno = lblkno(fs, ip->i_size);
-printf("Extending ifile: blkno = %d\n", blkno);
-               bp = getblk(vp, blkno, fs->lfs_bsize);
-               if (!bp) {
-                       uprintf("\n%s: no inodes left\n", fs->lfs_fsmnt);
-                       log(LOG_ERR, "uid %d on %s: out of inodes\n",
-                           ap->a_cred->cr_uid, fs->lfs_fsmnt);
-                       return (ENOSPC);
-               }
+               lfs_balloc(vp, fs->lfs_bsize, blkno, &bp);
+               ip->i_size += fs->lfs_bsize;
+               vnode_pager_setsize(vp, (u_long)ip->i_size);
+               vnode_pager_uncache(vp);
+
                i = (blkno - fs->lfs_segtabsz - fs->lfs_cleansz) *
                    fs->lfs_ifpb;
                i = (blkno - fs->lfs_segtabsz - fs->lfs_cleansz) *
                    fs->lfs_ifpb;
-printf("Extending ifile: first inum = %d\n", i);
                fs->lfs_free = i;
                max = i + fs->lfs_ifpb;
                fs->lfs_free = i;
                max = i + fs->lfs_ifpb;
-printf("Extending ifile: max inum = %d\n", max);
                for (ifp = (struct ifile *)bp->b_un.b_words; i < max; ++ifp) {
                        ifp->if_version = 1;
                        ifp->if_daddr = LFS_UNUSED_DADDR;
                for (ifp = (struct ifile *)bp->b_un.b_words; i < max; ++ifp) {
                        ifp->if_version = 1;
                        ifp->if_daddr = LFS_UNUSED_DADDR;
@@ -93,26 +85,19 @@ printf("Extending ifile: max inum = %d\n", max);
                }
                ifp--;
                ifp->if_nextfree = LFS_UNUSED_INUM;
                }
                ifp--;
                ifp->if_nextfree = LFS_UNUSED_INUM;
-
-               ip->i_blocks += btodb(fs->lfs_bsize);
-               fs->lfs_bfree -= btodb(fs->lfs_bsize);
-               ip->i_size += fs->lfs_bsize;
-printf("Extending ifile: blocks = %d size = %d\n", ip->i_blocks, ip->i_size);
-               vnode_pager_setsize(vp, (u_long)ip->i_size);
-               vnode_pager_uncache(vp);
-               LFS_UBWRITE(bp);
+               if (error = VOP_BWRITE(bp))
+                       return (error);
        }
 
        /* Create a vnode to associate with the inode. */
        if (error = lfs_vcreate(ap->a_pvp->v_mount, new_ino, &vp))
                return (error);
        }
 
        /* Create a vnode to associate with the inode. */
        if (error = lfs_vcreate(ap->a_pvp->v_mount, new_ino, &vp))
                return (error);
-       *ap->a_vpp = vp;
-       vp->v_flag |= VDIROP;
-       ip = VTOI(vp);
-       VREF(ip->i_devvp);
 
 
+
+       ip = VTOI(vp);
        /* Zero out the direct and indirect block addresses. */
        /* Zero out the direct and indirect block addresses. */
-       bzero(ip->i_db, (NDADDR + NIADDR) * sizeof(daddr_t));
+       bzero(&ip->i_din, sizeof(struct dinode));
+       ip->i_din.di_inumber = new_ino;
 
        /* Set a new generation number for this inode. */
        if (++nextgennumber < (u_long)time.tv_sec)
 
        /* Set a new generation number for this inode. */
        if (++nextgennumber < (u_long)time.tv_sec)
@@ -122,6 +107,16 @@ printf("Extending ifile: blocks = %d size = %d\n", ip->i_blocks, ip->i_size);
        /* Insert into the inode hash table. */
        ufs_ihashins(ip);
 
        /* Insert into the inode hash table. */
        ufs_ihashins(ip);
 
+       if (error = ufs_vinit(vp->v_mount, lfs_specop_p, LFS_FIFOOPS, &vp)) {
+               vput(vp);
+               *ap->a_vpp = NULL;
+               return (error);
+       }
+
+       *ap->a_vpp = vp;
+       vp->v_flag |= VDIROP;
+       VREF(ip->i_devvp);
+
        /* Set superblock modified bit and increment file count. */
        fs->lfs_fmod = 1;
        ++fs->lfs_nfiles;
        /* Set superblock modified bit and increment file count. */
        fs->lfs_fmod = 1;
        ++fs->lfs_nfiles;
@@ -140,9 +135,6 @@ lfs_vcreate(mp, ino, vpp)
        struct ufsmount *ump;
        int error, i;
 
        struct ufsmount *ump;
        int error, i;
 
-#ifdef VERBOSE
-       printf("lfs_vcreate: ino %d\n", ino);
-#endif
        /* Create the vnode. */
        if (error = getnewvnode(VT_LFS, mp, lfs_vnodeop_p, vpp)) {
                *vpp = NULL;
        /* Create the vnode. */
        if (error = getnewvnode(VT_LFS, mp, lfs_vnodeop_p, vpp)) {
                *vpp = NULL;
@@ -157,9 +149,11 @@ lfs_vcreate(mp, ino, vpp)
        (*vpp)->v_data = ip;
        ip->i_vnode = *vpp;
        ip->i_devvp = ump->um_devvp;
        (*vpp)->v_data = ip;
        ip->i_vnode = *vpp;
        ip->i_devvp = ump->um_devvp;
-       ip->i_flag = 0;
+       ip->i_flag = IMOD;
        ip->i_dev = ump->um_dev;
        ip->i_dev = ump->um_dev;
-       ip->i_number = ip->i_din.di_inum = ino;
+       ip->i_number = ip->i_din.di_inumber = ino;
+ip->i_din.di_spare[0] = 0xdeadbeef;
+ip->i_din.di_spare[1] = 0xdeadbeef;
        ip->i_lfs = ump->um_lfs;
 #ifdef QUOTA
        for (i = 0; i < MAXQUOTAS; i++)
        ip->i_lfs = ump->um_lfs;
 #ifdef QUOTA
        for (i = 0; i < MAXQUOTAS; i++)
@@ -170,6 +164,7 @@ lfs_vcreate(mp, ino, vpp)
        ip->i_mode = 0;
        ip->i_size = 0;
        ip->i_blocks = 0;
        ip->i_mode = 0;
        ip->i_size = 0;
        ip->i_blocks = 0;
+       ++ump->um_lfs->lfs_uinodes;
        return (0);
 }
 
        return (0);
 }
 
@@ -190,15 +185,16 @@ lfs_vfree(ap)
        struct lfs *fs;
        daddr_t old_iaddr;
        ino_t ino;
        struct lfs *fs;
        daddr_t old_iaddr;
        ino_t ino;
+       int error;
 
 
-       ip = VTOI(ap->a_pvp);
-#ifdef VERBOSE
-       printf("lfs_vfree: free %d\n", ip->i_number);
-#endif
        /* Get the inode number and file system. */
        /* Get the inode number and file system. */
+       ip = VTOI(ap->a_pvp);
        fs = ip->i_lfs;
        ino = ip->i_number;
        fs = ip->i_lfs;
        ino = ip->i_number;
-
+       if (ip->i_flag & IMOD) {
+               --fs->lfs_uinodes;
+               ip->i_flag &= ~(IMOD | IACC | IUPD | ICHG);
+       }
        /*
         * Set the ifile's inode entry to unused, increment its version number
         * and link it into the free chain.
        /*
         * Set the ifile's inode entry to unused, increment its version number
         * and link it into the free chain.
@@ -209,7 +205,7 @@ lfs_vfree(ap)
        ++ifp->if_version;
        ifp->if_nextfree = fs->lfs_free;
        fs->lfs_free = ino;
        ++ifp->if_version;
        ifp->if_nextfree = fs->lfs_free;
        fs->lfs_free = ino;
-       LFS_UBWRITE(bp);
+       (void) VOP_BWRITE(bp);
 
        if (old_iaddr != LFS_UNUSED_DADDR) {
                LFS_SEGENTRY(sup, fs, datosn(fs, old_iaddr), bp);
 
        if (old_iaddr != LFS_UNUSED_DADDR) {
                LFS_SEGENTRY(sup, fs, datosn(fs, old_iaddr), bp);
@@ -219,7 +215,7 @@ lfs_vfree(ap)
                            datosn(fs, old_iaddr));
 #endif
                sup->su_nbytes -= sizeof(struct dinode);
                            datosn(fs, old_iaddr));
 #endif
                sup->su_nbytes -= sizeof(struct dinode);
-               LFS_UBWRITE(bp);
+               (void) VOP_BWRITE(bp);
        }
 
        /* Set superblock modified bit and decrement file count. */
        }
 
        /* Set superblock modified bit and decrement file count. */