diff options
author | Jeff Roberson <jeff@FreeBSD.org> | 2010-04-24 07:05:35 +0000 |
---|---|---|
committer | Jeff Roberson <jeff@FreeBSD.org> | 2010-04-24 07:05:35 +0000 |
commit | 113db2dddb719510679d71ff41679afe30c8b3d1 (patch) | |
tree | e551aa2ab43f7f11c3646b241ebf3f582988d375 /lib/libufs/cgroup.c | |
parent | 07b9cc2f468471a723504ac789201a84f6dcd38a (diff) | |
download | src-113db2dddb719510679d71ff41679afe30c8b3d1.tar.gz src-113db2dddb719510679d71ff41679afe30c8b3d1.zip |
- Merge soft-updates journaling from projects/suj/head into head. This
brings in support for an optional intent log which eliminates the need
for background fsck on unclean shutdown.
Sponsored by: iXsystems, Yahoo!, and Juniper.
With help from: McKusick and Peter Holm
Notes
Notes:
svn path=/head/; revision=207141
Diffstat (limited to 'lib/libufs/cgroup.c')
-rw-r--r-- | lib/libufs/cgroup.c | 140 |
1 files changed, 138 insertions, 2 deletions
diff --git a/lib/libufs/cgroup.c b/lib/libufs/cgroup.c index 28e5ea87a430..b0cb4a7d63db 100644 --- a/lib/libufs/cgroup.c +++ b/lib/libufs/cgroup.c @@ -40,11 +40,143 @@ __FBSDID("$FreeBSD$"); #include <errno.h> #include <fcntl.h> #include <stdio.h> +#include <stdlib.h> #include <string.h> #include <unistd.h> #include <libufs.h> +ufs2_daddr_t +cgballoc(struct uufsd *disk) +{ + u_int8_t *blksfree; + struct cg *cgp; + struct fs *fs; + long bno; + + fs = &disk->d_fs; + cgp = &disk->d_cg; + blksfree = cg_blksfree(cgp); + for (bno = 0; bno < fs->fs_fpg / fs->fs_frag; bno++) + if (ffs_isblock(fs, blksfree, bno)) + goto gotit; + return (0); +gotit: + fs->fs_cs(fs, cgp->cg_cgx).cs_nbfree--; + ffs_clrblock(fs, blksfree, (long)bno); + ffs_clusteracct(fs, cgp, bno, -1); + cgp->cg_cs.cs_nbfree--; + fs->fs_cstotal.cs_nbfree--; + fs->fs_fmod = 1; + return (cgbase(fs, cgp->cg_cgx) + blkstofrags(fs, bno)); +} + +int +cgbfree(struct uufsd *disk, ufs2_daddr_t bno, long size) +{ + u_int8_t *blksfree; + struct fs *fs; + struct cg *cgp; + ufs1_daddr_t fragno, cgbno; + int i, cg, blk, frags, bbase; + + fs = &disk->d_fs; + cg = dtog(fs, bno); + if (cgread1(disk, cg) != 1) + return (-1); + cgp = &disk->d_cg; + cgbno = dtogd(fs, bno); + blksfree = cg_blksfree(cgp); + if (size == fs->fs_bsize) { + fragno = fragstoblks(fs, cgbno); + ffs_setblock(fs, blksfree, fragno); + ffs_clusteracct(fs, cgp, fragno, 1); + cgp->cg_cs.cs_nbfree++; + fs->fs_cstotal.cs_nbfree++; + fs->fs_cs(fs, cg).cs_nbfree++; + } else { + bbase = cgbno - fragnum(fs, cgbno); + /* + * decrement the counts associated with the old frags + */ + blk = blkmap(fs, blksfree, bbase); + ffs_fragacct(fs, blk, cgp->cg_frsum, -1); + /* + * deallocate the fragment + */ + frags = numfrags(fs, size); + for (i = 0; i < frags; i++) + setbit(blksfree, cgbno + i); + cgp->cg_cs.cs_nffree += i; + fs->fs_cstotal.cs_nffree += i; + fs->fs_cs(fs, cg).cs_nffree += i; + /* + * add back in counts associated with the new frags + */ + blk = blkmap(fs, blksfree, bbase); + ffs_fragacct(fs, blk, cgp->cg_frsum, 1); + /* + * if a complete block has been reassembled, account for it + */ + fragno = fragstoblks(fs, bbase); + if (ffs_isblock(fs, blksfree, fragno)) { + cgp->cg_cs.cs_nffree -= fs->fs_frag; + fs->fs_cstotal.cs_nffree -= fs->fs_frag; + fs->fs_cs(fs, cg).cs_nffree -= fs->fs_frag; + ffs_clusteracct(fs, cgp, fragno, 1); + cgp->cg_cs.cs_nbfree++; + fs->fs_cstotal.cs_nbfree++; + fs->fs_cs(fs, cg).cs_nbfree++; + } + } + return cgwrite(disk); +} + +ino_t +cgialloc(struct uufsd *disk) +{ + struct ufs2_dinode *dp2; + u_int8_t *inosused; + struct cg *cgp; + struct fs *fs; + ino_t ino; + int i; + + fs = &disk->d_fs; + cgp = &disk->d_cg; + inosused = cg_inosused(cgp); + for (ino = 0; ino < fs->fs_ipg / NBBY; ino++) + if (isclr(inosused, ino)) + goto gotit; + return (0); +gotit: + if (fs->fs_magic == FS_UFS2_MAGIC && + ino + INOPB(fs) > cgp->cg_initediblk && + cgp->cg_initediblk < cgp->cg_niblk) { + char block[MAXBSIZE]; + bzero(block, (int)fs->fs_bsize); + dp2 = (struct ufs2_dinode *)█ + for (i = 0; i < INOPB(fs); i++) { + dp2->di_gen = arc4random() / 2 + 1; + dp2++; + } + if (bwrite(disk, ino_to_fsba(fs, + cgp->cg_cgx * fs->fs_ipg + cgp->cg_initediblk), + block, fs->fs_bsize)) + return (0); + cgp->cg_initediblk += INOPB(fs); + } + + setbit(inosused, ino); + cgp->cg_irotor = ino; + cgp->cg_cs.cs_nifree--; + fs->fs_cstotal.cs_nifree--; + fs->fs_cs(fs, cgp->cg_cgx).cs_nifree--; + fs->fs_fmod = 1; + + return (ino + (cgp->cg_cgx * fs->fs_ipg)); +} + int cgread(struct uufsd *disk) { @@ -55,14 +187,12 @@ int cgread1(struct uufsd *disk, int c) { struct fs *fs; - off_t ccg; fs = &disk->d_fs; if ((unsigned)c >= fs->fs_ncg) { return (0); } - ccg = fsbtodb(fs, cgtod(fs, c)) * disk->d_bsize; if (bread(disk, fsbtodb(fs, cgtod(fs, c)), disk->d_cgunion.d_buf, fs->fs_bsize) == -1) { ERROR(disk, "unable to read cylinder group"); @@ -73,6 +203,12 @@ cgread1(struct uufsd *disk, int c) } int +cgwrite(struct uufsd *disk) +{ + return (cgwrite1(disk, disk->d_lcg)); +} + +int cgwrite1(struct uufsd *disk, int c) { struct fs *fs; |