Date: Mon, 10 May 2010 04:27:33 GMT From: Zheng Liu <lz@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 178024 for review Message-ID: <201005100427.o4A4RX3J018818@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://p4web.freebsd.org/@@178024?ac=10 Change 178024 by lz@gnehzuil-freebsd on 2010/05/10 04:26:50 Improved the code style. Affected files ... .. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#6 edit .. //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_rsv_win.h#4 edit Differences ... ==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_alloc.c#6 (text+ko) ==== @@ -61,13 +61,14 @@ static daddr_t ext2_nodealloccg(struct inode *, int, daddr_t, int); static daddr_t ext2_mapsearch(struct m_ext2fs *, char *, daddr_t); -static void ext2_rsv_win_remove(struct m_ext2fs *, struct ext2_rsv_win *); +/* For reservation window */ +static void ext2_add_rsv_win(struct m_ext2fs *, struct ext2_rsv_win *); +static int ext2_alloc_new_rsv(struct inode *, struct m_ext2fs *, int, int32_t, int); +static daddr_t ext2_alloccg_rsv(struct inode *, int, daddr_t, int); +static u_long ext2_mapsearch_rsv(struct m_ext2fs *, char *, daddr_t); static int ext2_in_rsv(struct ext2_rsv_win *, int32_t); -static daddr_t ext2_alloccg_rsv(struct inode *, int, daddr_t, int); -static int ext2_alloc_new_rsv(struct inode *, struct m_ext2fs *, int, int32_t, int); +static void ext2_remove_rsv_win(struct m_ext2fs *, struct ext2_rsv_win *); static int ext2_search_rsv_win(struct inode *, struct m_ext2fs *, int, int32_t, int); -static u_long ext2_bmap_search_free_block(struct m_ext2fs *, char *, daddr_t); -static void ext2_rsv_win_add(struct m_ext2fs *, struct ext2_rsv_win *); RB_GENERATE(ext2_rsv_win_tree, ext2_rsv_win, rw_link, ext2_rsv_win_cmp); @@ -127,14 +128,14 @@ mtx_lock_spin(&ip->i_e2fs->e2fs_rsv_win_lock); if (rwp->rw_end != EXT2_RWI_NOT_ALLOCATED) - ext2_rsv_win_remove(ip->i_e2fs, rwp); + ext2_remove_rsv_win(ip->i_e2fs, rwp); mtx_unlock_spin(&ip->i_e2fs->e2fs_rsv_win_lock); } /* * Add a ext2_rsv_win struct to RB tree. */ -static void ext2_rsv_win_add(struct m_ext2fs *sbp, struct ext2_rsv_win *rwp) +static void ext2_add_rsv_win(struct m_ext2fs *sbp, struct ext2_rsv_win *rwp) { RB_INSERT(ext2_rsv_win_tree, &sbp->e2fs_tree, rwp); } @@ -143,7 +144,7 @@ * Remove a ext2_rsv_win structure from RB tree. */ static void -ext2_rsv_win_remove(struct m_ext2fs *sbp, struct ext2_rsv_win *rwp) +ext2_remove_rsv_win(struct m_ext2fs *sbp, struct ext2_rsv_win *rwp) { rwp->rw_start = EXT2_RWI_NOT_ALLOCATED; rwp->rw_end = EXT2_RWI_NOT_ALLOCATED; @@ -164,103 +165,6 @@ } /* - * Determine whether a block can be allocated. - * - * Check to see if a block of the appropriate size is available, - * and if it is, allocate it. - */ -static daddr_t -ext2_alloccg_rsv(struct inode *ip, int cg, daddr_t bpref, int size) -{ - struct m_ext2fs *fs; - struct buf *bp; - struct ext2mount *ump; - int error, bno; - char *bbp; - - fs = ip->i_e2fs; - ump = ip->i_ump; - if (fs->e2fs_gd[cg].ext2bgd_nbfree == 0) - return (0); - EXT2_UNLOCK(ump); - error = bread(ip->i_devvp, fsbtodb(fs, - fs->e2fs_gd[cg].ext2bgd_b_bitmap), - (int)fs->e2fs_bsize, NOCRED, &bp); - if (error) { - brelse(bp); - EXT2_LOCK(ump); - return (0); - } - bbp = (char *)bp->b_data; - - if (dtog(fs, bpref) != cg) - bpref = 0; - if (bpref != 0) { - bpref = dtogd(fs, bpref); - /* - * if the requested block is available, use it - */ - if (isclr(bbp, bpref)) { - bno = bpref; - goto gotit; - } - } - - brelse(bp); - EXT2_LOCK(ump); - return (0); - -gotit: - setbit(bbp, (daddr_t)bno); - EXT2_LOCK(ump); - fs->e2fs->e2fs_fbcount--; - fs->e2fs_gd[cg].ext2bgd_nbfree--; - fs->e2fs_fmod = 1; - EXT2_UNLOCK(ump); - bdwrite(bp); - return (cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bno); -} - -/* - * Search a free block from bpref. - */ -static u_long ext2_bmap_search_free_block(struct m_ext2fs *sbp, char *bbp, daddr_t bpref) -{ - daddr_t bno; - int start, len, loc, i, map; - - /* - * find the fragment by searching through the free block - * map for an appropriate bit pattern - */ - if (bpref) - start = dtogd(sbp, bpref) / NBBY; - else - start = 0; - len = howmany(sbp->e2fs->e2fs_fpg, NBBY) - start; - loc = skpc(0xff, len, &bbp[start]); - if (loc == 0) { - len = start + 1; - start = 0; - loc = skpc(0xff, len, &bbp[start]); - if (loc == 0) { - printf("start = %d, len = %d, fs = %s\n", - start, len, sbp->e2fs_fsmnt); - panic("ext2fs_alloccg: map corrupted"); - /* NOTREACHED */ - } - } - i = start + len - loc; - map = bbp[i]; - bno = i * NBBY; - for (i = 1; i < (1 << NBBY); i <<= 1, bno++) { - if ((map & i) == 0) - return 1; - } - return 0; -} - -/* * Find a reservation window which includes bpref. */ static int @@ -293,13 +197,13 @@ * else we need to traverse tree to find a space. */ if (RB_EMPTY(&sbp->e2fs_tree)) { - if (!ext2_bmap_search_free_block(sbp, bbp, bpref)) + if (!ext2_mapsearch_rsv(sbp, bbp, bpref)) goto failed; rwp = &ip->i_rsv_winp->rwi_entry; rwp->rw_start = bpref; rwp->rw_end = bpref + rwp->rw_goal_size - 1; - ext2_rsv_win_add(sbp, rwp); + ext2_add_rsv_win(sbp, rwp); goto success; } else { @@ -342,13 +246,13 @@ break; } - if (!ext2_bmap_search_free_block(sbp, bbp, bpref)) + if (!ext2_mapsearch_rsv(sbp, bbp, bpref)) goto failed; rwp = &ip->i_rsv_winp->rwi_entry; rwp->rw_start = bpref; rwp->rw_end = bpref + rwp->rw_goal_size - 1; - ext2_rsv_win_add(sbp, rwp); + ext2_add_rsv_win(sbp, rwp); goto success; } @@ -377,7 +281,7 @@ /* delete old reservation window */ if (rwp->rw_end != EXT2_RWI_NOT_ALLOCATED) { mtx_lock_spin(&sbp->e2fs_rsv_win_lock); - ext2_rsv_win_remove(sbp, &ip->i_rsv_winp->rwi_entry); + ext2_remove_rsv_win(sbp, &ip->i_rsv_winp->rwi_entry); mtx_unlock_spin(&sbp->e2fs_rsv_win_lock); } @@ -385,13 +289,15 @@ if (ext2_search_rsv_win(ip, sbp, cg, bpref, size)) return 1; - /* XXX: force to allocate a new reservation window in next group */ + /* TODO: force to allocate a new reservation window in next group */ return 0; } /* * Allocate a block using reservation window in ext2 file system. + * + * NOTE: This function will replace the ext2_alloc() function. */ int ext2_alloc_rsv(struct inode *ip, int32_t lbn, int32_t bpref, @@ -1019,6 +925,66 @@ * * Check to see if a block of the appropriate size is available, * and if it is, allocate it. + * + * NOTE: This function will replace the ext2_alloccg() function. + */ +static daddr_t +ext2_alloccg_rsv(struct inode *ip, int cg, daddr_t bpref, int size) +{ + struct m_ext2fs *fs; + struct buf *bp; + struct ext2mount *ump; + int error, bno; + char *bbp; + + fs = ip->i_e2fs; + ump = ip->i_ump; + if (fs->e2fs_gd[cg].ext2bgd_nbfree == 0) + return (0); + EXT2_UNLOCK(ump); + error = bread(ip->i_devvp, fsbtodb(fs, + fs->e2fs_gd[cg].ext2bgd_b_bitmap), + (int)fs->e2fs_bsize, NOCRED, &bp); + if (error) { + brelse(bp); + EXT2_LOCK(ump); + return (0); + } + bbp = (char *)bp->b_data; + + if (dtog(fs, bpref) != cg) + bpref = 0; + if (bpref != 0) { + bpref = dtogd(fs, bpref); + /* + * if the requested block is available, use it + */ + if (isclr(bbp, bpref)) { + bno = bpref; + goto gotit; + } + } + + brelse(bp); + EXT2_LOCK(ump); + return (0); + +gotit: + setbit(bbp, (daddr_t)bno); + EXT2_LOCK(ump); + fs->e2fs->e2fs_fbcount--; + fs->e2fs_gd[cg].ext2bgd_nbfree--; + fs->e2fs_fmod = 1; + EXT2_UNLOCK(ump); + bdwrite(bp); + return (cg * fs->e2fs->e2fs_fpg + fs->e2fs->e2fs_first_dblock + bno); +} + +/* + * Determine whether a block can be allocated. + * + * Check to see if a block of the appropriate size is available, + * and if it is, allocate it. */ static daddr_t ext2_alloccg(struct inode *ip, int cg, daddr_t bpref, int size) @@ -1288,6 +1254,47 @@ } /* + * Search a free block from bpref. + * + * NOTE: This function will replace the ext2_mapsearch() function. + */ +static u_long ext2_mapsearch_rsv(struct m_ext2fs *sbp, char *bbp, daddr_t bpref) +{ + daddr_t bno; + int start, len, loc, i, map; + + /* + * find the fragment by searching through the free block + * map for an appropriate bit pattern + */ + if (bpref) + start = dtogd(sbp, bpref) / NBBY; + else + start = 0; + len = howmany(sbp->e2fs->e2fs_fpg, NBBY) - start; + loc = skpc(0xff, len, &bbp[start]); + if (loc == 0) { + len = start + 1; + start = 0; + loc = skpc(0xff, len, &bbp[start]); + if (loc == 0) { + printf("start = %d, len = %d, fs = %s\n", + start, len, sbp->e2fs_fsmnt); + panic("ext2fs_alloccg: map corrupted"); + /* NOTREACHED */ + } + } + i = start + len - loc; + map = bbp[i]; + bno = i * NBBY; + for (i = 1; i < (1 << NBBY); i <<= 1, bno++) { + if ((map & i) == 0) + return 1; + } + 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 ==== //depot/projects/soc2010/extfs/src/sys/fs/ext2fs/ext2_rsv_win.h#4 (text+ko) ==== @@ -74,7 +74,7 @@ #endif }; -/* ext2_allo.c */ +/* ext2_alloc.c */ struct inode; void ext2_init_rsv_win_info(struct inode *ip); void ext2_discard_rsv_win(struct inode *ip);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201005100427.o4A4RX3J018818>