X-Git-Url: https://git.subgeniuskitty.com/unix-history/.git/blobdiff_plain/ea67b335f253aa21ac70a85a8ca0427b66a604dc..fd88f5c5678c80ff5e338adc372d28a52ad20530:/usr/src/sys/ufs/lfs/lfs_alloc.c diff --git a/usr/src/sys/ufs/lfs/lfs_alloc.c b/usr/src/sys/ufs/lfs/lfs_alloc.c index e36faf07ed..837d2ea496 100644 --- a/usr/src/sys/ufs/lfs/lfs_alloc.c +++ b/usr/src/sys/ufs/lfs/lfs_alloc.c @@ -1,10 +1,36 @@ /* - * Copyright (c) 1991 Regents of the University of California. - * All rights reserved. + * Copyright (c) 1991, 1993, 1995 + * The Regents of the University of California. All rights reserved. * - * %sccs.include.redist.c% + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by the University of + * California, Berkeley and its contributors. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. * - * @(#)lfs_alloc.c 7.43 (Berkeley) %G% + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)lfs_alloc.c 8.7 (Berkeley) 5/14/95 */ #include @@ -20,6 +46,7 @@ #include #include #include +#include #include #include @@ -29,26 +56,26 @@ extern u_long nextgennumber; /* Allocate a new inode. */ /* ARGSUSED */ int -lfs_valloc(pvp, notused, cred, vpp) - struct vnode *pvp, **vpp; - int notused; - struct ucred *cred; +lfs_valloc(ap) + struct vop_valloc_args /* { + struct vnode *a_pvp; + int a_mode; + struct ucred *a_cred; + struct vnode **a_vpp; + } */ *ap; { struct lfs *fs; struct buf *bp; struct ifile *ifp; struct inode *ip; struct vnode *vp; - daddr_t blkno; + ufs_daddr_t blkno; ino_t new_ino; u_long i, max; int error; -#ifdef VERBOSE - printf("lfs_valloc\n"); -#endif /* Get the head of the freelist. */ - fs = VTOI(pvp)->i_lfs; + fs = VTOI(ap->a_pvp)->i_lfs; new_ino = fs->lfs_free; #ifdef ALLOCPRINT printf("lfs_ialloc: allocate inode %d\n", new_ino); @@ -69,45 +96,35 @@ lfs_valloc(pvp, notused, cred, vpp) 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", - cred->cr_uid, fs->lfs_fsmnt); - return (ENOSPC); - } + lfs_balloc(vp, 0, 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; -printf("Extending ifile: first inum = %d\n", i); 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) { + for (ifp = (struct ifile *)bp->b_data; i < max; ++ifp) { ifp->if_version = 1; ifp->if_daddr = LFS_UNUSED_DADDR; ifp->if_nextfree = ++i; } ifp--; ifp->if_nextfree = LFS_UNUSED_INUM; - - ++ip->i_blocks; /* XXX This may not be right. */ - 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(pvp->v_mount, new_ino, &vp)) + if (error = lfs_vcreate(ap->a_pvp->v_mount, new_ino, &vp)) return (error); - *vpp = vp; - ip = VTOI(vp); - VREF(ip->i_devvp); + + ip = VTOI(vp); /* 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) @@ -117,6 +134,16 @@ printf("Extending ifile: blocks = %d size = %d\n", ip->i_blocks, ip->i_size); /* 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; @@ -130,16 +157,13 @@ lfs_vcreate(mp, ino, vpp) ino_t ino; struct vnode **vpp; { - extern struct vnodeops lfs_vnodeops; + extern int (**lfs_vnodeop_p)(); struct inode *ip; 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_vnodeops, vpp)) { + if (error = getnewvnode(VT_LFS, mp, lfs_vnodeop_p, vpp)) { *vpp = NULL; return (error); } @@ -149,12 +173,13 @@ lfs_vcreate(mp, ino, vpp) /* Initialize the inode. */ MALLOC(ip, struct inode *, sizeof(struct inode), M_LFSNODE, M_WAITOK); + lockinit(&ip->i_lock, PINOD, "lfsinode", 0, 0); (*vpp)->v_data = ip; ip->i_vnode = *vpp; ip->i_devvp = ump->um_devvp; - ip->i_flag = 0; + ip->i_flag = IN_MODIFIED; 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_lfs = ump->um_lfs; #ifdef QUOTA for (i = 0; i < MAXQUOTAS; i++) @@ -164,33 +189,38 @@ lfs_vcreate(mp, ino, vpp) ip->i_diroff = 0; ip->i_mode = 0; ip->i_size = 0; + ip->i_blocks = 0; + ++ump->um_lfs->lfs_uinodes; return (0); } /* Free an inode. */ /* ARGUSED */ -void -lfs_vfree(vp, notused1, notused2) - struct vnode *vp; - ino_t notused1; - int notused2; +int +lfs_vfree(ap) + struct vop_vfree_args /* { + struct vnode *a_pvp; + ino_t a_ino; + int a_mode; + } */ *ap; { SEGUSE *sup; struct buf *bp; struct ifile *ifp; struct inode *ip; struct lfs *fs; - daddr_t old_iaddr; + ufs_daddr_t old_iaddr; ino_t ino; - ip = VTOI(vp); -#ifdef VERBOSE - printf("lfs_vfree: free %d\n", ip->i_number); -#endif /* Get the inode number and file system. */ + ip = VTOI(ap->a_pvp); fs = ip->i_lfs; ino = ip->i_number; - + if (ip->i_flag & IN_MODIFIED) { + --fs->lfs_uinodes; + ip->i_flag &= + ~(IN_ACCESS | IN_CHANGE | IN_MODIFIED | IN_UPDATE); + } /* * Set the ifile's inode entry to unused, increment its version number * and link it into the free chain. @@ -201,7 +231,7 @@ lfs_vfree(vp, notused1, notused2) ++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); @@ -211,10 +241,11 @@ lfs_vfree(vp, notused1, notused2) 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. */ fs->lfs_fmod = 1; --fs->lfs_nfiles; + return (0); }