vBulletin Search Engine Optimization
| |||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| re many functions read cylinder group and duplicate the code. here factor it out into a separate function used from everywhere. also cuts some bytes off (; cu -- paranoic mickey (my swapper has changed but, the page has remained) Index: ffs_alloc.c ================================================== ================= RCS file: /cvs/src/sys/ufs/ffs/ffs_alloc.c,v retrieving revision 1.78 diff -u -r1.78 ffs_alloc.c --- ffs_alloc.c 22 Jun 2007 13:59:12 -0000 1.78 +++ ffs_alloc.c 29 Jul 2007 17:29:57 -0000 @@ -69,6 +69,7 @@ } while (0) daddr_t ffs_alloccg(struct inode *, int, daddr_t, int); +struct buf *ffs_cgread(struct fs *, struct inode *, int); daddr_t ffs_alloccgblk(struct inode *, struct buf *, daddr_t); daddr_t ffs_clusteralloc(struct inode *, int, daddr_t, int); ino_t ffs_dirpref(struct inode *); @@ -1177,6 +1178,25 @@ return (0); } +struct buf * +ffs_cgread(struct fs *fs, struct inode *ip, int cg) +{ + struct buf *bp; + + if (bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), + (int)fs->fs_cgsize, NOCRED, &bp)) { + brelse(bp); + return (NULL); + } + + if (!cg_chkmagic((struct cg *)bp->b_data)) { + brelse(bp); + return (NULL); + } + + return bp; +} + /* * Determine whether a fragment can be extended. * @@ -1190,8 +1210,7 @@ struct cg *cgp; struct buf *bp; long bno; - int frags, bbase; - int i, error; + int i, frags, bbase; fs = ip->i_fs; if (fs->fs_cs(fs, cg).cs_nffree < numfrags(fs, nsize - osize)) @@ -1202,18 +1221,11 @@ /* cannot extend across a block boundary */ return (0); } - error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), - (int)fs->fs_cgsize, NOCRED, &bp); - if (error) { - brelse(bp); - return (0); - } - cgp = (struct cg *)bp->b_data; - if (!cg_chkmagic(cgp)) { - brelse(bp); + + if (!(bp = ffs_cgread(fs, ip, cg))) return (0); - } + cgp = (struct cg *)bp->b_data; cgp->cg_ffs2_time = cgp->cg_time = time_second; bno = dtogd(fs, bprev); @@ -1261,21 +1273,17 @@ struct cg *cgp; struct buf *bp; daddr_t bno, blkno; - int error, i, frags, allocsiz; + int i, frags, allocsiz; fs = ip->i_fs; if (fs->fs_cs(fs, cg).cs_nbfree == 0 && size == fs->fs_bsize) return (0); - /* read cylinder group block */ - error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), - (int)fs->fs_cgsize, NOCRED, &bp); - if (error) { - brelse(bp); + + if (!(bp = ffs_cgread(fs, ip, cg))) return (0); - } + cgp = (struct cg *)bp->b_data; - if (!cg_chkmagic(cgp) || - (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize)) { + if (cgp->cg_cs.cs_nbfree == 0 && size == fs->fs_bsize) { brelse(bp); return (0); } @@ -1424,12 +1432,12 @@ fs = ip->i_fs; if (fs->fs_maxcluster[cg] < len) return (0); - if (bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), (int)fs->fs_cgsize, - NOCRED, &bp)) - goto fail; + + if (!(bp = ffs_cgread(fs, ip, cg))) + return (0); + cgp = (struct cg *)bp->b_data; - if (!cg_chkmagic(cgp)) - goto fail; + /* * Check to see if a cluster of the needed size (or bigger) is * available in this cylinder group. @@ -1523,7 +1531,7 @@ struct fs *fs; struct cg *cgp; struct buf *bp; - int error, start, len, loc, map, i; + int start, len, loc, map, i; #ifdef FFS2 struct buf *ibp = NULL; struct ufs2_dinode *dp2; @@ -1538,15 +1546,11 @@ if (fs->fs_cs(fs, cg).cs_nifree == 0) return (0); - error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), - (int)fs->fs_cgsize, NOCRED, &bp); - if (error) { - brelse(bp); + if (!(bp = ffs_cgread(fs, ip, cg))) return (0); - } cgp = (struct cg *)bp->b_data; - if (!cg_chkmagic(cgp) || cgp->cg_cs.cs_nifree == 0) { + if (cgp->cg_cs.cs_nifree == 0) { brelse(bp); return (0); } @@ -1691,7 +1695,7 @@ struct cg *cgp; struct buf *bp; daddr_t blkno; - int i, error, cg, blk, frags, bbase; + int i, cg, blk, frags, bbase; fs = ip->i_fs; if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0 || @@ -1706,18 +1710,10 @@ ffs_fserr(fs, DIP(ip, uid), "bad block"); return; } - error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), - (int)fs->fs_cgsize, NOCRED, &bp); - if (error) { - brelse(bp); + if (!(bp = ffs_cgread(fs, ip, cg))) return; - } - cgp = (struct cg *)bp->b_data; - if (!cg_chkmagic(cgp)) { - brelse(bp); - return; - } + cgp = (struct cg *)bp->b_data; cgp->cg_ffs2_time = cgp->cg_time = time_second; bno = dtogd(fs, bno); @@ -1814,25 +1810,18 @@ struct fs *fs; struct cg *cgp; struct buf *bp; - int error, cg; + int cg; fs = pip->i_fs; if ((u_int)ino >= fs->fs_ipg * fs->fs_ncg) panic("ffs_freefile: range: dev = 0x%x, ino = %d, fs = %s", pip->i_dev, ino, fs->fs_fsmnt); + cg = ino_to_cg(fs, ino); - error = bread(pip->i_devvp, fsbtodb(fs, cgtod(fs, cg)), - (int)fs->fs_cgsize, NOCRED, &bp); - if (error) { - brelse(bp); - return (error); - } - cgp = (struct cg *)bp->b_data; - if (!cg_chkmagic(cgp)) { - brelse(bp); + if (!(bp = ffs_cgread(fs, pip, cg))) return (0); - } + cgp = (struct cg *)bp->b_data; cgp->cg_ffs2_time = cgp->cg_time = time_second; ino %= fs->fs_ipg; @@ -1869,7 +1858,7 @@ struct fs *fs; struct cg *cgp; struct buf *bp; - int i, error, frags, free; + int i, frags, free; fs = ip->i_fs; if ((u_int)size > fs->fs_bsize || fragoff(fs, size) != 0) { @@ -1879,19 +1868,11 @@ } if ((u_int)bno >= fs->fs_size) panic("ffs_checkblk: bad block %d", bno); - error = bread(ip->i_devvp, fsbtodb(fs, cgtod(fs, dtog(fs, bno))), - (int)fs->fs_cgsize, NOCRED, &bp); - if (error) { - brelse(bp); - return (0); - } - cgp = (struct cg *)bp->b_data; - if (!cg_chkmagic(cgp)) { - brelse(bp); + if (!(bp = ffs_cgread(fs, ip, dtog(fs, bno)))) return (0); - } + cgp = (struct cg *)bp->b_data; bno = dtogd(fs, bno); if (size == fs->fs_bsize) { free = ffs_isblock(fs, cg_blksfree(cgp), fragstoblks(fs, bno)); |