From owner-p4-projects@FreeBSD.ORG Wed Jul 29 13:14:09 2009 Return-Path: Delivered-To: p4-projects@freebsd.org Received: by hub.freebsd.org (Postfix, from userid 32767) id 2A7CD1065672; Wed, 29 Jul 2009 13:14:09 +0000 (UTC) Delivered-To: perforce@FreeBSD.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id C6B6F106566C for ; Wed, 29 Jul 2009 13:14:08 +0000 (UTC) (envelope-from truncs@FreeBSD.org) Received: from repoman.freebsd.org (repoman.freebsd.org [IPv6:2001:4f8:fff6::29]) by mx1.freebsd.org (Postfix) with ESMTP id B3BF68FC17 for ; Wed, 29 Jul 2009 13:14:08 +0000 (UTC) (envelope-from truncs@FreeBSD.org) Received: from repoman.freebsd.org (localhost [127.0.0.1]) by repoman.freebsd.org (8.14.3/8.14.3) with ESMTP id n6TDE8sR070649 for ; Wed, 29 Jul 2009 13:14:08 GMT (envelope-from truncs@FreeBSD.org) Received: (from perforce@localhost) by repoman.freebsd.org (8.14.3/8.14.3/Submit) id n6TDE8Gm070647 for perforce@freebsd.org; Wed, 29 Jul 2009 13:14:08 GMT (envelope-from truncs@FreeBSD.org) Date: Wed, 29 Jul 2009 13:14:08 GMT Message-Id: <200907291314.n6TDE8Gm070647@repoman.freebsd.org> X-Authentication-Warning: repoman.freebsd.org: perforce set sender to truncs@FreeBSD.org using -f From: Aditya Sarawgi To: Perforce Change Reviews Cc: Subject: PERFORCE change 166731 for review X-BeenThere: p4-projects@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: p4 projects tree changes List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 29 Jul 2009 13:14:10 -0000 http://perforce.freebsd.org/chv.cgi?CH=166731 Change 166731 by truncs@aditya on 2009/07/29 13:13:28 Rearranging functions to make it consistent with NetBSD's src. Suggested by: Pedro Giffuni Affected files ... .. //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_alloc.c#34 edit .. //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_vfsops.c#16 edit Differences ... ==== //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_alloc.c#34 (text+ko) ==== @@ -393,6 +393,31 @@ } /* + * Find a cylinder to place a directory. + * + * The policy implemented by this algorithm is to select from + * among those cylinder groups with above the average number of + * free inodes, the one with the smallest number of directories. + */ +static u_long +ext2_dirpref(struct m_ext2fs *fs) +{ + int cg, maxspace, mincg, avgifree; + avgifree = fs->e2fs->e2fs_ficount / fs->e2fs_gcount; + maxspace = 0; + mincg = -1; + for (cg = 0; cg < fs->e2fs_gcount; cg++) { + if ( fs->e2fs_gd[cg].ext2bgd_nifree >= avgifree) { + if (mincg == -1 || fs->e2fs_gd[cg].ext2bgd_nbfree > maxspace) { + mincg = cg; + maxspace = fs->e2fs_gd[cg].ext2bgd_nbfree; + } + } + } + return mincg; +} + +/* * Select the desired position for the next block in a file. * * we try to mimic what Remy does in inode_getblk/block_getblk @@ -439,143 +464,6 @@ } /* - * Free a block or fragment. - * - * pass on to the Linux code - */ -void -ext2_blkfree(ip, bno, size) - struct inode *ip; - int32_t bno; - long size; -{ - struct m_ext2fs *fs; - struct buf *bp; - int cg, error; - char *bbp; - - fs = ip->i_e2fs; - cg = dtog(fs, bno); - if ((u_int)bno >= fs->e2fs->e2fs_bcount) { - printf("bad block %lld, ino %llu\n", (long long)bno, - (unsigned long long)ip->i_number); - ext2_fserr(fs, ip->i_uid, "bad block"); - return; - } - error = bread(ip->i_devvp, - fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_b_bitmap), - (int)fs->e2fs_bsize, NOCRED, &bp); - if (error) { - brelse(bp); - return; - } - bbp = (char *)bp->b_data; - bno = dtogd(fs, bno); - if (isclr(bbp, bno)) { - printf("block = %lld, fs = %s\n", - (long long)bno, fs->e2fs_fsmnt); - panic("blkfree: freeing free block"); - } - clrbit(bbp, bno); - fs->e2fs->e2fs_fbcount++; - fs->e2fs_gd[cg].ext2bgd_nbfree++; - fs->e2fs_fmod = 1; - bdwrite(bp); -} - -/* - * Free an inode. - * - * the maintenance of the actual bitmaps is again up to the linux code - */ -int -ext2_vfree(pvp, ino, mode) - struct vnode *pvp; - ino_t ino; - int mode; -{ - struct m_ext2fs *fs; - struct inode *pip; - struct buf *bp; - int error, cg; - char * ibp; -/* mode_t save_i_mode; */ - - pip = VTOI(pvp); - fs = pip->i_e2fs; - if ((u_int)ino > fs->e2fs_ipg * fs->e2fs_gcount) - panic("ext2_vfree: range: devvp = %p, ino = %d, fs = %s", - pip->i_devvp, ino, fs->e2fs_fsmnt); - - cg = ino_to_cg(fs, ino); - error = bread(pip->i_devvp, - fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_i_bitmap), - (int)fs->e2fs_bsize, NOCRED, &bp); - if (error) { - brelse(bp); - return (0); - } - ibp = (char *)bp->b_data; - ino = (ino - 1) % fs->e2fs->e2fs_ipg; - if (isclr(ibp, ino)) { - printf("ino = %llu, fs = %s\n", - (unsigned long long)ino, fs->e2fs_fsmnt); - if (fs->e2fs_ronly == 0) - panic("ifree: freeing free inode"); - } - clrbit(ibp, ino); - fs->e2fs->e2fs_ficount++; - fs->e2fs_gd[cg].ext2bgd_nifree++; - if ((mode & IFMT) == IFDIR) { - fs->e2fs_gd[cg].ext2bgd_ndirs--; - } - fs->e2fs_fmod = 1; - bdwrite(bp); - return (0); -} - -/* - * Fserr prints the name of a file system with an error diagnostic. - * - * The form of the error message is: - * fs: error message - */ -static void -ext2_fserr(fs, uid, cp) - struct m_ext2fs *fs; - u_int uid; - char *cp; -{ - - log(LOG_ERR, "uid %d on %s: %s\n", uid, fs->e2fs_fsmnt, cp); -} - -/* - * Find a cylinder to place a directory. - * - * The policy implemented by this algorithm is to select from - * among those cylinder groups with above the average number of - * free inodes, the one with the smallest number of directories. - */ -static u_long -ext2_dirpref(struct m_ext2fs *fs) -{ - int cg, maxspace, mincg, avgifree; - avgifree = fs->e2fs->e2fs_ficount / fs->e2fs_gcount; - maxspace = 0; - mincg = -1; - for (cg = 0; cg < fs->e2fs_gcount; cg++) { - if ( fs->e2fs_gd[cg].ext2bgd_nifree >= avgifree) { - if (mincg == -1 || fs->e2fs_gd[cg].ext2bgd_nbfree > maxspace) { - mincg = cg; - maxspace = fs->e2fs_gd[cg].ext2bgd_nbfree; - } - } - } - return mincg; -} - -/* * Implement the cylinder overflow algorithm. * * The policy implemented by this algorithm is: @@ -708,6 +596,7 @@ bdwrite(bp); return (cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bno); } + /* * Determine whether an inode can be allocated. * @@ -781,6 +670,102 @@ } /* + * Free a block or fragment. + * + * pass on to the Linux code + */ +void +ext2_blkfree(ip, bno, size) + struct inode *ip; + int32_t bno; + long size; +{ + struct m_ext2fs *fs; + struct buf *bp; + int cg, error; + char *bbp; + + fs = ip->i_e2fs; + cg = dtog(fs, bno); + if ((u_int)bno >= fs->e2fs->e2fs_bcount) { + printf("bad block %lld, ino %llu\n", (long long)bno, + (unsigned long long)ip->i_number); + ext2_fserr(fs, ip->i_uid, "bad block"); + return; + } + error = bread(ip->i_devvp, + fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_b_bitmap), + (int)fs->e2fs_bsize, NOCRED, &bp); + if (error) { + brelse(bp); + return; + } + bbp = (char *)bp->b_data; + bno = dtogd(fs, bno); + if (isclr(bbp, bno)) { + printf("block = %lld, fs = %s\n", + (long long)bno, fs->e2fs_fsmnt); + panic("blkfree: freeing free block"); + } + clrbit(bbp, bno); + fs->e2fs->e2fs_fbcount++; + fs->e2fs_gd[cg].ext2bgd_nbfree++; + fs->e2fs_fmod = 1; + bdwrite(bp); +} + +/* + * Free an inode. + * + * the maintenance of the actual bitmaps is again up to the linux code + */ +int +ext2_vfree(pvp, ino, mode) + struct vnode *pvp; + ino_t ino; + int mode; +{ + struct m_ext2fs *fs; + struct inode *pip; + struct buf *bp; + int error, cg; + char * ibp; +/* mode_t save_i_mode; */ + + pip = VTOI(pvp); + fs = pip->i_e2fs; + if ((u_int)ino > fs->e2fs_ipg * fs->e2fs_gcount) + panic("ext2_vfree: range: devvp = %p, ino = %d, fs = %s", + pip->i_devvp, ino, fs->e2fs_fsmnt); + + cg = ino_to_cg(fs, ino); + error = bread(pip->i_devvp, + fsbtodb(fs, fs->e2fs_gd[cg].ext2bgd_i_bitmap), + (int)fs->e2fs_bsize, NOCRED, &bp); + if (error) { + brelse(bp); + return (0); + } + ibp = (char *)bp->b_data; + ino = (ino - 1) % fs->e2fs->e2fs_ipg; + if (isclr(ibp, ino)) { + printf("ino = %llu, fs = %s\n", + (unsigned long long)ino, fs->e2fs_fsmnt); + if (fs->e2fs_ronly == 0) + panic("ifree: freeing free inode"); + } + clrbit(ibp, ino); + fs->e2fs->e2fs_ficount++; + fs->e2fs_gd[cg].ext2bgd_nifree++; + if ((mode & IFMT) == IFDIR) { + fs->e2fs_gd[cg].ext2bgd_ndirs--; + } + fs->e2fs_fmod = 1; + bdwrite(bp); + return (0); +} + +/* * Find a block in the specified cylinder group. * * It is a panic if a request is made to find a block if none are @@ -825,6 +810,22 @@ /* NOTREACHED */ } +/* + * Fserr prints the name of a file system with an error diagnostic. + * + * The form of the error message is: + * fs: error message + */ +static void +ext2_fserr(fs, uid, cp) + struct m_ext2fs *fs; + u_int uid; + char *cp; +{ + + log(LOG_ERR, "uid %d on %s: %s\n", uid, fs->e2fs_fsmnt, cp); +} + int cg_has_sb(int i) { @@ -839,5 +840,3 @@ return 1; return 0; } - - ==== //depot/projects/soc2009/soc_ext2fs/src/sys/gnu/fs/ext2fs/ext2_vfsops.c#16 (text+ko) ====