From 797487255274497f443b61a5d8c401a3103b43ad Mon Sep 17 00:00:00 2001 From: mlelstv Date: Tue, 16 Feb 2010 23:20:30 +0000 Subject: [PATCH] Three changes in a single commit. - drop the notion of frags (LFS fragments) vs fsb (FFS fragments) The code uses a complicated unity function that just makes the code difficult to understand. - support larger sector sizes. Fix disk address computations to use DEV_BSIZE in the kernel as required by device drivers and to use sector sizes in userland. - Fix several locking bugs in lfs_bio.c and lfs_subr.c. --- sbin/fsck_lfs/dir.c | 4 ++-- sbin/fsck_lfs/inode.c | 4 ++-- sbin/fsck_lfs/kernelops.h | 2 ++ sbin/fsck_lfs/lfs.c | 39 ++++++++++++++++++++---------------- sbin/fsck_lfs/pass1.c | 6 +++--- sbin/fsck_lfs/pass4.c | 4 ++-- sbin/fsck_lfs/pass6.c | 21 +++++++++---------- sbin/fsck_lfs/segwrite.c | 23 +++++++++++---------- sbin/fsck_lfs/segwrite.h | 4 ++-- sbin/fsck_lfs/setup.c | 23 +++------------------ sbin/fsck_lfs/vars.c | 4 +--- sbin/fsck_lfs/vnode.c | 6 +++--- sbin/newfs_lfs/make_lfs.c | 10 +++++----- sbin/newfs_lfs/newfs.c | 11 +++++++--- sys/ufs/lfs/lfs.h | 33 +++++++++++++++--------------- sys/ufs/lfs/lfs_balloc.c | 40 ++++++++++++++++++------------------- sys/ufs/lfs/lfs_bio.c | 39 +++++++++++++++++++----------------- sys/ufs/lfs/lfs_inode.c | 5 +++-- sys/ufs/lfs/lfs_segment.c | 12 +++++------ sys/ufs/lfs/lfs_subr.c | 10 ++++++---- sys/ufs/lfs/lfs_syscalls.c | 6 +++--- sys/ufs/lfs/lfs_vfsops.c | 41 +++++++++++++++----------------------- 22 files changed, 168 insertions(+), 179 deletions(-) diff --git a/sbin/fsck_lfs/dir.c b/sbin/fsck_lfs/dir.c index b1eb77e632af..9867a5100892 100644 --- a/sbin/fsck_lfs/dir.c +++ b/sbin/fsck_lfs/dir.c @@ -1,4 +1,4 @@ -/* $NetBSD: dir.c,v 1.24 2008/05/16 09:21:59 hannken Exp $ */ +/* $NetBSD: dir.c,v 1.25 2010/02/16 23:20:30 mlelstv Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -144,7 +144,7 @@ dirscan(struct inodesc *idesc) (idesc->id_filesize & (DIRBLKSIZ - 1)) != 0) idesc->id_filesize = roundup(idesc->id_filesize, DIRBLKSIZ); blksiz = idesc->id_numfrags * fs->lfs_fsize; - if (chkrange(idesc->id_blkno, fragstofsb(fs, idesc->id_numfrags))) { + if (chkrange(idesc->id_blkno, idesc->id_numfrags)) { idesc->id_filesize -= blksiz; return (SKIP); } diff --git a/sbin/fsck_lfs/inode.c b/sbin/fsck_lfs/inode.c index b6f3c44b8b01..8b0f75e59249 100644 --- a/sbin/fsck_lfs/inode.c +++ b/sbin/fsck_lfs/inode.c @@ -1,4 +1,4 @@ -/* $NetBSD: inode.c,v 1.41 2010/02/04 23:55:43 christos Exp $ */ +/* $NetBSD: inode.c,v 1.42 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1997, 1998 The NetBSD Foundation, Inc. @@ -242,7 +242,7 @@ iblock(struct inodesc *idesc, long ilevel, u_int64_t isize) return (n); } else func = dirscan; - if (chkrange(idesc->id_blkno, fragstofsb(fs, idesc->id_numfrags))) + if (chkrange(idesc->id_blkno, idesc->id_numfrags)) return (SKIP); devvp = fs->lfs_devvp; diff --git a/sbin/fsck_lfs/kernelops.h b/sbin/fsck_lfs/kernelops.h index 781feb500b81..fc9c7b71c6bd 100644 --- a/sbin/fsck_lfs/kernelops.h +++ b/sbin/fsck_lfs/kernelops.h @@ -19,4 +19,6 @@ struct kernelops { }; extern const struct kernelops kops; +extern long dev_bsize; + #endif /* _LFS_KERNEL_OPS_H_ */ diff --git a/sbin/fsck_lfs/lfs.c b/sbin/fsck_lfs/lfs.c index 0ad9f002d1e3..63d973a1c67e 100644 --- a/sbin/fsck_lfs/lfs.c +++ b/sbin/fsck_lfs/lfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfs.c,v 1.31 2009/08/06 00:51:55 pooka Exp $ */ +/* $NetBSD: lfs.c,v 1.32 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. * All rights reserved. @@ -102,6 +102,8 @@ extern struct uvnodelst vnodelist; extern struct uvnodelst getvnodelist[VNODE_HASH_MAX]; extern int nvnodes; +long dev_bsize; + static int lfs_fragextend(struct uvnode *, int, int, daddr_t, struct ubuf **); @@ -119,12 +121,12 @@ lfs_vop_strategy(struct ubuf * bp) if (bp->b_flags & B_READ) { count = kops.ko_pread(bp->b_vp->v_fd, bp->b_data, bp->b_bcount, - dbtob(bp->b_blkno)); + bp->b_blkno * dev_bsize); if (count == bp->b_bcount) bp->b_flags |= B_DONE; } else { count = kops.ko_pwrite(bp->b_vp->v_fd, bp->b_data, bp->b_bcount, - dbtob(bp->b_blkno)); + bp->b_blkno * dev_bsize); if (count == 0) { perror("pwrite"); return -1; @@ -467,22 +469,27 @@ lfs_init(int devfd, daddr_t sblkno, daddr_t idaddr, int dummy_read, int debug) tryalt = 0; if (dummy_read) { if (sblkno == 0) - sblkno = btodb(LFS_LABELPAD); + sblkno = LFS_LABELPAD / dev_bsize; fs = ecalloc(1, sizeof(*fs)); fs->lfs_devvp = devvp; } else { if (sblkno == 0) { - sblkno = btodb(LFS_LABELPAD); + sblkno = LFS_LABELPAD / dev_bsize; tryalt = 1; } else if (debug) { printf("No -b flag given, not attempting to verify checkpoint\n"); } + + dev_bsize = DEV_BSIZE; + error = bread(devvp, sblkno, LFS_SBPAD, NOCRED, 0, &bp); fs = ecalloc(1, sizeof(*fs)); fs->lfs_dlfs = *((struct dlfs *) bp->b_data); fs->lfs_devvp = devvp; bp->b_flags |= B_INVAL; brelse(bp, 0); + + dev_bsize = fs->lfs_fsize >> fs->lfs_fsbtodb; if (tryalt) { error = bread(devvp, fsbtodb(fs, fs->lfs_sboffs[1]), @@ -977,7 +984,7 @@ lfs_balloc(struct uvnode *vp, off_t startoffset, int iosize, struct ubuf **bpp) struct lfs *fs; struct indir indirs[NIADDR+2], *idp; daddr_t lbn, lastblock; - int bb, bcount; + int bcount; int error, frags, i, nsize, osize, num; ip = VTOI(vp); @@ -1035,13 +1042,12 @@ lfs_balloc(struct uvnode *vp, off_t startoffset, int iosize, struct ubuf **bpp) if (lblktosize(fs, lbn) >= ip->i_ffs1_size) { /* Brand new block or fragment */ frags = numfrags(fs, nsize); - bb = fragstofsb(fs, frags); if (bpp) { *bpp = bp = getblk(vp, lbn, nsize); bp->b_blkno = UNWRITTEN; } - ip->i_lfs_effnblks += bb; - fs->lfs_bfree -= bb; + ip->i_lfs_effnblks += frags; + fs->lfs_bfree -= frags; ip->i_ffs1_db[lbn] = UNWRITTEN; } else { if (nsize <= osize) { @@ -1072,14 +1078,14 @@ lfs_balloc(struct uvnode *vp, off_t startoffset, int iosize, struct ubuf **bpp) * Do byte accounting all at once, so we can gracefully fail *before* * we start assigning blocks. */ - bb = fsbtodb(fs, 1); /* bb = VFSTOUFS(vp->v_mount)->um_seqinc; */ + frags = fsbtodb(fs, 1); /* frags = VFSTOUFS(vp->v_mount)->um_seqinc; */ bcount = 0; if (daddr == UNASSIGNED) { - bcount = bb; + bcount = frags; } for (i = 1; i < num; ++i) { if (!indirs[i].in_exists) { - bcount += bb; + bcount += frags; } } fs->lfs_bfree -= bcount; @@ -1127,7 +1133,6 @@ lfs_balloc(struct uvnode *vp, off_t startoffset, int iosize, struct ubuf **bpp) /* * Get the existing block from the cache, if requested. */ - frags = fsbtofrags(fs, bb); if (bpp) *bpp = bp = getblk(vp, lbn, blksize(fs, ip, lbn)); @@ -1191,13 +1196,13 @@ lfs_fragextend(struct uvnode *vp, int osize, int nsize, daddr_t lbn, { struct inode *ip; struct lfs *fs; - long bb; + int frags; int error; size_t obufsize; ip = VTOI(vp); fs = ip->i_lfs; - bb = (long)fragstofsb(fs, numfrags(fs, nsize - osize)); + frags = (long)numfrags(fs, nsize - osize); error = 0; /* @@ -1211,8 +1216,8 @@ lfs_fragextend(struct uvnode *vp, int osize, int nsize, daddr_t lbn, goto out; } - fs->lfs_bfree -= bb; - ip->i_lfs_effnblks += bb; + fs->lfs_bfree -= frags; + ip->i_lfs_effnblks += frags; ip->i_flag |= IN_CHANGE | IN_UPDATE; if (bpp) { diff --git a/sbin/fsck_lfs/pass1.c b/sbin/fsck_lfs/pass1.c index 392c35399f5c..bb6c767c9696 100644 --- a/sbin/fsck_lfs/pass1.c +++ b/sbin/fsck_lfs/pass1.c @@ -1,4 +1,4 @@ -/* $NetBSD: pass1.c,v 1.29 2007/10/08 21:39:49 ad Exp $ */ +/* $NetBSD: pass1.c,v 1.30 2010/02/16 23:20:30 mlelstv Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -328,7 +328,7 @@ pass1check(struct inodesc *idesc) struct dups *dlp; struct dups *new; - if ((anyout = chkrange(blkno, fragstofsb(fs, idesc->id_numfrags))) != 0) { + if ((anyout = chkrange(blkno, idesc->id_numfrags)) != 0) { blkerror(idesc->id_number, "BAD", blkno); if (badblk++ >= MAXBAD) { pwarn("EXCESSIVE BAD BLKS I=%llu", @@ -342,7 +342,7 @@ pass1check(struct inodesc *idesc) } else if (!testbmap(blkno)) { seg_table[dtosn(fs, blkno)].su_nbytes += idesc->id_numfrags * fs->lfs_fsize; } - for (ndblks = fragstofsb(fs, idesc->id_numfrags); ndblks > 0; blkno++, ndblks--) { + for (ndblks = idesc->id_numfrags; ndblks > 0; blkno++, ndblks--) { if (anyout && chkrange(blkno, 1)) { res = SKIP; } else if (!testbmap(blkno)) { diff --git a/sbin/fsck_lfs/pass4.c b/sbin/fsck_lfs/pass4.c index 0e7739c644ba..00d0bf7002e7 100644 --- a/sbin/fsck_lfs/pass4.c +++ b/sbin/fsck_lfs/pass4.c @@ -1,4 +1,4 @@ -/* $NetBSD: pass4.c,v 1.16 2006/11/09 19:36:36 christos Exp $ */ +/* $NetBSD: pass4.c,v 1.17 2010/02/16 23:20:30 mlelstv Exp $ */ /* * Copyright (c) 1980, 1986, 1993 @@ -154,7 +154,7 @@ pass4check(struct inodesc * idesc) int sn; sn = dtosn(fs, blkno); - for (ndblks = fragstofsb(fs, idesc->id_numfrags); ndblks > 0; blkno++, ndblks--) { + for (ndblks = idesc->id_numfrags; ndblks > 0; blkno++, ndblks--) { if (chkrange(blkno, 1)) { res = SKIP; } else if (testbmap(blkno) || preen) { diff --git a/sbin/fsck_lfs/pass6.c b/sbin/fsck_lfs/pass6.c index 15bb7cdc9a4c..6c0d770e476a 100644 --- a/sbin/fsck_lfs/pass6.c +++ b/sbin/fsck_lfs/pass6.c @@ -1,4 +1,4 @@ -/* $NetBSD: pass6.c,v 1.22 2008/05/16 09:21:59 hannken Exp $ */ +/* $NetBSD: pass6.c,v 1.23 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -86,7 +86,8 @@ rfw_update_single(struct uvnode *vp, daddr_t lbn, ufs_daddr_t ndaddr, int size) struct inode *ip; daddr_t daddr, ooff; int num, error; - int i, bb, osize = 0, obb = 0; + int i, osize = 0; + int frags, ofrags = 0; u_int32_t oldsn, sn; ip = VTOI(vp); @@ -99,23 +100,23 @@ rfw_update_single(struct uvnode *vp, daddr_t lbn, ufs_daddr_t ndaddr, int size) if (daddr > 0) daddr = dbtofsb(fs, daddr); - bb = fragstofsb(fs, numfrags(fs, size)); + frags = numfrags(fs, size); switch (num) { case 0: ooff = ip->i_ffs1_db[lbn]; if (ooff <= 0) - ip->i_ffs1_blocks += bb; + ip->i_ffs1_blocks += frags; else { /* possible fragment truncation or extension */ - obb = btofsb(fs, ip->i_lfs_fragsize[lbn]); - ip->i_ffs1_blocks += (bb - obb); + ofrags = ip->i_lfs_fragsize[lbn]; + ip->i_ffs1_blocks += (frags - ofrags); } ip->i_ffs1_db[lbn] = ndaddr; break; case 1: ooff = ip->i_ffs1_ib[a[0].in_off]; if (ooff <= 0) - ip->i_ffs1_blocks += bb; + ip->i_ffs1_blocks += frags; ip->i_ffs1_ib[a[0].in_off] = ndaddr; break; default: @@ -126,7 +127,7 @@ rfw_update_single(struct uvnode *vp, daddr_t lbn, ufs_daddr_t ndaddr, int size) ooff = ((ufs_daddr_t *) bp->b_data)[ap->in_off]; if (ooff <= 0) - ip->i_ffs1_blocks += bb; + ip->i_ffs1_blocks += frags; ((ufs_daddr_t *) bp->b_data)[ap->in_off] = ndaddr; (void) VOP_BWRITE(bp); } @@ -188,7 +189,7 @@ rfw_update_single(struct uvnode *vp, daddr_t lbn, ufs_daddr_t ndaddr, int size) if (daddr <= 0) { fs->lfs_bfree -= btofsb(fs, size); } else if (size != osize) { - fs->lfs_bfree -= (bb - obb); + fs->lfs_bfree -= (frags - ofrags); } /* @@ -292,7 +293,7 @@ pass6check(struct inodesc * idesc) /* Check that the blocks do not lie within clean segments. */ anyout = anynew = 0; - for (i = 0; i < fragstofsb(fs, idesc->id_numfrags); i++) { + for (i = 0; i < idesc->id_numfrags; i++) { sn = dtosn(fs, idesc->id_blkno + i); if (sn < 0 || sn >= fs->lfs_nseg || (seg_table[sn].su_flags & SEGUSE_DIRTY) == 0) { diff --git a/sbin/fsck_lfs/segwrite.c b/sbin/fsck_lfs/segwrite.c index bdee92daa7ad..d99a76f470d0 100644 --- a/sbin/fsck_lfs/segwrite.c +++ b/sbin/fsck_lfs/segwrite.c @@ -1,4 +1,4 @@ -/* $NetBSD: segwrite.c,v 1.19 2008/05/16 09:21:59 hannken Exp $ */ +/* $NetBSD: segwrite.c,v 1.20 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. * All rights reserved. @@ -440,7 +440,8 @@ lfs_update_single(struct lfs * fs, struct segment * sp, daddr_t lbn, struct uvnode *vp; daddr_t daddr, ooff; int num, error; - int bb, osize, obb; + int osize; + int frags, ofrags; vp = sp->vp; ip = VTOI(vp); @@ -451,23 +452,23 @@ lfs_update_single(struct lfs * fs, struct segment * sp, daddr_t lbn, if (daddr > 0) daddr = dbtofsb(fs, daddr); - bb = fragstofsb(fs, numfrags(fs, size)); + frags = numfrags(fs, size); switch (num) { case 0: ooff = ip->i_ffs1_db[lbn]; if (ooff == UNWRITTEN) - ip->i_ffs1_blocks += bb; + ip->i_ffs1_blocks += frags; else { /* possible fragment truncation or extension */ - obb = btofsb(fs, ip->i_lfs_fragsize[lbn]); - ip->i_ffs1_blocks += (bb - obb); + ofrags = btofsb(fs, ip->i_lfs_fragsize[lbn]); + ip->i_ffs1_blocks += (frags - ofrags); } ip->i_ffs1_db[lbn] = ndaddr; break; case 1: ooff = ip->i_ffs1_ib[a[0].in_off]; if (ooff == UNWRITTEN) - ip->i_ffs1_blocks += bb; + ip->i_ffs1_blocks += frags; ip->i_ffs1_ib[a[0].in_off] = ndaddr; break; default: @@ -478,7 +479,7 @@ lfs_update_single(struct lfs * fs, struct segment * sp, daddr_t lbn, ooff = ((ufs_daddr_t *) bp->b_data)[ap->in_off]; if (ooff == UNWRITTEN) - ip->i_ffs1_blocks += bb; + ip->i_ffs1_blocks += frags; ((ufs_daddr_t *) bp->b_data)[ap->in_off] = ndaddr; (void) VOP_BWRITE(bp); } @@ -520,7 +521,7 @@ lfs_updatemeta(struct segment * sp) struct uvnode *vp; daddr_t lbn; int i, nblocks, num; - int bb; + int frags; int bytesleft, size; vp = sp->vp; @@ -585,10 +586,10 @@ lfs_updatemeta(struct segment * sp) for (bytesleft = sbp->b_bcount; bytesleft > 0; bytesleft -= fs->lfs_bsize) { size = MIN(bytesleft, fs->lfs_bsize); - bb = fragstofsb(fs, numfrags(fs, size)); + frags = numfrags(fs, size); lbn = *sp->start_lbp++; lfs_update_single(fs, sp, lbn, fs->lfs_offset, size); - fs->lfs_offset += bb; + fs->lfs_offset += frags; } } diff --git a/sbin/fsck_lfs/segwrite.h b/sbin/fsck_lfs/segwrite.h index 5626dd9ffd6d..c35d49c2aac1 100644 --- a/sbin/fsck_lfs/segwrite.h +++ b/sbin/fsck_lfs/segwrite.h @@ -1,4 +1,4 @@ -/* $NetBSD: segwrite.h,v 1.2 2008/04/28 20:23:08 martin Exp $ */ +/* $NetBSD: segwrite.h,v 1.3 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. * All rights reserved. @@ -33,7 +33,7 @@ */ #define LFS_PARTIAL_FITS(fs) \ ((fs)->lfs_fsbpseg - ((fs)->lfs_offset - (fs)->lfs_curseg) > \ - fragstofsb((fs), (fs)->lfs_frag)) + (fs)->lfs_frag) /* op values to lfs_writevnodes */ #define VN_REG 0 diff --git a/sbin/fsck_lfs/setup.c b/sbin/fsck_lfs/setup.c index 21523bc5428c..3116c11fe97b 100644 --- a/sbin/fsck_lfs/setup.c +++ b/sbin/fsck_lfs/setup.c @@ -1,4 +1,4 @@ -/* $NetBSD: setup.c,v 1.36 2008/05/16 09:21:59 hannken Exp $ */ +/* $NetBSD: setup.c,v 1.37 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -68,6 +68,7 @@ #include #include #include +#include #include #include @@ -81,6 +82,7 @@ #include #include #include +#include #include #include #include @@ -94,7 +96,6 @@ #include "fsutil.h" extern u_int32_t cksum(void *, size_t); -static struct disklabel *getdisklabel(const char *, int); static uint64_t calcmaxfilesize(int); ufs_daddr_t *din_table; @@ -163,7 +164,6 @@ int setup(const char *dev) { long bmapsize; - struct disklabel *lp; struct stat statb; int doskipclean; u_int64_t maxfilesize; @@ -215,10 +215,6 @@ setup(const char *dev) printf("%s: ", cdevname()); errexit("BAD SUPER BLOCK OR IFILE INODE NOT FOUND"); } - if ((lp = getdisklabel((char *) NULL, fsreadfd)) != NULL) - dev_bsize = secsize = lp->d_secsize; - else - dev_bsize = secsize = DEV_BSIZE; /* Resize buffer cache now that we have a superblock to guess from. */ bufrehash((fs->lfs_segtabsz + maxino / fs->lfs_ifpb) << 4); @@ -466,16 +462,3 @@ setup(const char *dev) return (0); } -static struct disklabel * -getdisklabel(const char *s, int fd) -{ - static struct disklabel lab; - - if (ioctl(fd, DIOCGDINFO, (char *) &lab) < 0) { - if (s == NULL) - return ((struct disklabel *) NULL); - pwarn("ioctl (GCINFO): %s\n", strerror(errno)); - return NULL; - } - return (&lab); -} diff --git a/sbin/fsck_lfs/vars.c b/sbin/fsck_lfs/vars.c index 1727c1d45a84..aebbd5c5ec63 100644 --- a/sbin/fsck_lfs/vars.c +++ b/sbin/fsck_lfs/vars.c @@ -1,4 +1,4 @@ -/* $NetBSD: vars.c,v 1.13 2008/04/28 20:23:08 martin Exp $ */ +/* $NetBSD: vars.c,v 1.14 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. * All rights reserved. @@ -48,8 +48,6 @@ struct lfs *fs; daddr_t idaddr; /* inode block containing ifile inode */ long numdirs, listmax, inplast; -long dev_bsize; /* computed value of DEV_BSIZE */ -long secsize; /* actual disk sector size */ char nflag; /* assume a no response */ char yflag; /* assume a yes response */ int bflag; /* location of alternate super block */ diff --git a/sbin/fsck_lfs/vnode.c b/sbin/fsck_lfs/vnode.c index 342f2c0e11d5..895a1a68066b 100644 --- a/sbin/fsck_lfs/vnode.c +++ b/sbin/fsck_lfs/vnode.c @@ -1,4 +1,4 @@ -/* $NetBSD: vnode.c,v 1.10 2009/08/06 00:51:55 pooka Exp $ */ +/* $NetBSD: vnode.c,v 1.11 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. * All rights reserved. @@ -75,10 +75,10 @@ raw_vop_strategy(struct ubuf * bp) { if (bp->b_flags & B_READ) { return kops.ko_pread(bp->b_vp->v_fd, bp->b_data, bp->b_bcount, - dbtob(bp->b_blkno)); + bp->b_blkno * dev_bsize); } else { return kops.ko_pwrite(bp->b_vp->v_fd, bp->b_data, bp->b_bcount, - dbtob(bp->b_blkno)); + bp->b_blkno * dev_bsize); } } diff --git a/sbin/newfs_lfs/make_lfs.c b/sbin/newfs_lfs/make_lfs.c index 85f8e2f4f302..2f2cf3efb649 100644 --- a/sbin/newfs_lfs/make_lfs.c +++ b/sbin/newfs_lfs/make_lfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: make_lfs.c,v 1.15 2009/02/22 23:06:23 dholland Exp $ */ +/* $NetBSD: make_lfs.c,v 1.16 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 2003 The NetBSD Foundation, Inc. @@ -62,7 +62,7 @@ #if 0 static char sccsid[] = "@(#)lfs.c 8.5 (Berkeley) 5/24/95"; #else -__RCSID("$NetBSD: make_lfs.c,v 1.15 2009/02/22 23:06:23 dholland Exp $"); +__RCSID("$NetBSD: make_lfs.c,v 1.16 2010/02/16 23:20:30 mlelstv Exp $"); #endif #endif /* not lint */ @@ -232,7 +232,7 @@ make_dinode(ino_t ino, struct ufs1_dinode *dip, int nfrags, struct lfs *fs) nfrags = roundup(nfrags, fs->lfs_frag); dip->di_nlink = 1; - dip->di_blocks = fragstofsb(fs, nfrags); + dip->di_blocks = nfrags; dip->di_size = (nfrags << fs->lfs_ffshift); dip->di_atime = dip->di_mtime = dip->di_ctime = fs->lfs_tstamp; @@ -240,7 +240,7 @@ make_dinode(ino_t ino, struct ufs1_dinode *dip, int nfrags, struct lfs *fs) dip->di_inumber = ino; dip->di_gen = 1; - fsb_per_blk = fragstofsb(fs, blkstofrags(fs, 1)); + fsb_per_blk = blkstofrags(fs, 1); if (NDADDR < nblocks) { /* Count up how many indirect blocks we need, recursively */ @@ -251,7 +251,7 @@ make_dinode(ino_t ino, struct ufs1_dinode *dip, int nfrags, struct lfs *fs) ifibc += bb; --bb; } - dip->di_blocks += fragstofsb(fs, blkstofrags(fs, ifibc)); + dip->di_blocks += blkstofrags(fs, ifibc); } /* Assign the block addresses for the ifile */ diff --git a/sbin/newfs_lfs/newfs.c b/sbin/newfs_lfs/newfs.c index 31b8e4720922..cf409b30c1bb 100644 --- a/sbin/newfs_lfs/newfs.c +++ b/sbin/newfs_lfs/newfs.c @@ -1,4 +1,4 @@ -/* $NetBSD: newfs.c,v 1.24 2008/07/20 01:20:23 lukem Exp $ */ +/* $NetBSD: newfs.c,v 1.25 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1989, 1992, 1993 @@ -39,7 +39,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1992, 1993\ #if 0 static char sccsid[] = "@(#)newfs.c 8.5 (Berkeley) 5/24/95"; #else -__RCSID("$NetBSD: newfs.c,v 1.24 2008/07/20 01:20:23 lukem Exp $"); +__RCSID("$NetBSD: newfs.c,v 1.25 2010/02/16 23:20:30 mlelstv Exp $"); #endif #endif /* not lint */ @@ -103,6 +103,8 @@ int preen = 0; /* Coexistence with fsck_lfs */ char device[MAXPATHLEN]; char *progname, *special; +extern long dev_bsize; /* device block size */ + static int64_t strsuftoi64(const char *, const char *, int64_t, int64_t, int *); static void usage(void); @@ -315,6 +317,9 @@ main(int argc, char **argv) if (secsize == 0) secsize = geo.dg_secsize; + /* Make device block size available to low level routines */ + dev_bsize = secsize; + /* From here on out fssize is in sectors */ if (byte_sized) { fssize /= secsize; @@ -336,7 +341,7 @@ main(int argc, char **argv) warnx("%s is not a character special device, ignoring -A", special); segsize = 0; } else - segsize = auto_segsize(fsi, dbtob(dkw.dkw_size), + segsize = auto_segsize(fsi, dkw.dkw_size / secsize, version); } diff --git a/sys/ufs/lfs/lfs.h b/sys/ufs/lfs/lfs.h index 7f7420ff42b3..687a8f1ff112 100644 --- a/sys/ufs/lfs/lfs.h +++ b/sys/ufs/lfs/lfs.h @@ -1,4 +1,4 @@ -/* $NetBSD: lfs.h,v 1.132 2009/11/05 17:16:36 pooka Exp $ */ +/* $NetBSD: lfs.h,v 1.133 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. @@ -203,7 +203,7 @@ typedef struct lfs_res_blk { locked_queue_bytes -= bp->b_bufsize; \ if (locked_queue_count < LFS_WAIT_BUFS && \ locked_queue_bytes < LFS_WAIT_BYTES) \ - wakeup(&locked_queue_count); \ + cv_broadcast(&locked_queue_cv); \ mutex_exit(&lfs_lock); \ } \ (bp)->b_flags &= ~B_LOCKED; \ @@ -219,7 +219,7 @@ extern u_long bufmem_lowater, bufmem_hiwater; /* XXX */ # define LFS_DEBUG_COUNTLOCKED(m) do { \ if (lfs_debug_log_subsys[DLOG_LLIST]) { \ lfs_countlocked(&locked_queue_count, &locked_queue_bytes, (m)); \ - wakeup(&locked_queue_count); \ + cv_broadcast(&locked_queue_cv); \ } \ } while (0) # else @@ -858,31 +858,30 @@ struct lfs { #define blkoff(fs, loc) ((int)((loc) & (fs)->lfs_bmask)) #define fragoff(fs, loc) /* calculates (loc % fs->lfs_fsize) */ \ ((int)((loc) & (fs)->lfs_ffmask)) + +#if defined (_KERNEL) +#define fsbtodb(fs, b) ((b) << ((fs)->lfs_ffshift - DEV_BSHIFT)) +#define dbtofsb(fs, b) ((b) >> ((fs)->lfs_ffshift - DEV_BSHIFT)) +#else #define fsbtodb(fs, b) ((b) << (fs)->lfs_fsbtodb) #define dbtofsb(fs, b) ((b) >> (fs)->lfs_fsbtodb) -#define fragstodb(fs, b) ((b) << ((fs)->lfs_blktodb - (fs)->lfs_fbshift)) -#define dbtofrags(fs, b) ((b) >> ((fs)->lfs_blktodb - (fs)->lfs_fbshift)) +#endif + #define lblkno(fs, loc) ((loc) >> (fs)->lfs_bshift) #define lblktosize(fs, blk) ((blk) << (fs)->lfs_bshift) -/* Same as above, but named like dbtob(), btodb() */ -#define fsbtob(fs, b) ((b) << ((fs)->lfs_bshift - \ - (fs)->lfs_blktodb + (fs)->lfs_fsbtodb)) -#define btofsb(fs, b) ((b) >> ((fs)->lfs_bshift - \ - (fs)->lfs_blktodb + (fs)->lfs_fsbtodb)) -#define fsbtofrags(fs, b) ((b) >> ((fs)->lfs_blktodb - (fs)->lfs_fbshift - \ - (fs)->lfs_fsbtodb)) -#define fragstofsb(fs, b) ((b) << ((fs)->lfs_blktodb - (fs)->lfs_fbshift - \ - (fs)->lfs_fsbtodb)) -#define btofrags(fs, b) ((b) >> (fs)->lfs_ffshift) + +#define fsbtob(fs, b) ((b) << (fs)->lfs_ffshift) +#define btofsb(fs, b) ((b) >> (fs)->lfs_ffshift) + #define numfrags(fs, loc) /* calculates (loc / fs->lfs_fsize) */ \ ((loc) >> (fs)->lfs_ffshift) #define blkroundup(fs, size) /* calculates roundup(size, fs->lfs_bsize) */ \ ((off_t)(((size) + (fs)->lfs_bmask) & (~(fs)->lfs_bmask))) #define fragroundup(fs, size) /* calculates roundup(size, fs->lfs_fsize) */ \ ((off_t)(((size) + (fs)->lfs_ffmask) & (~(fs)->lfs_ffmask))) -#define fragstoblks(fs, frags) /* calculates (frags / fs->lfs_frag) */ \ +#define fragstoblks(fs, frags)/* calculates (frags / fs->fs_frag) */ \ ((frags) >> (fs)->lfs_fbshift) -#define blkstofrags(fs, blks) /* calculates (blks * fs->lfs_frag) */ \ +#define blkstofrags(fs, blks) /* calculates (blks * fs->fs_frag) */ \ ((blks) << (fs)->lfs_fbshift) #define fragnum(fs, fsb) /* calculates (fsb % fs->lfs_frag) */ \ ((fsb) & ((fs)->lfs_frag - 1)) diff --git a/sys/ufs/lfs/lfs_balloc.c b/sys/ufs/lfs/lfs_balloc.c index 7240c27d926c..7052677b36ae 100644 --- a/sys/ufs/lfs/lfs_balloc.c +++ b/sys/ufs/lfs/lfs_balloc.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_balloc.c,v 1.68 2009/03/18 16:00:24 cegger Exp $ */ +/* $NetBSD: lfs_balloc.c,v 1.69 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.68 2009/03/18 16:00:24 cegger Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_balloc.c,v 1.69 2010/02/16 23:20:30 mlelstv Exp $"); #if defined(_KERNEL_OPT) #include "opt_quota.h" @@ -118,7 +118,7 @@ lfs_balloc(struct vnode *vp, off_t startoffset, int iosize, kauth_cred_t cred, struct lfs *fs; struct indir indirs[NIADDR+2], *idp; daddr_t lbn, lastblock; - int bb, bcount; + int bcount; int error, frags, i, nsize, osize, num; ip = VTOI(vp); @@ -181,8 +181,7 @@ lfs_balloc(struct vnode *vp, off_t startoffset, int iosize, kauth_cred_t cred, if (lblktosize(fs, lbn) >= ip->i_size) { /* Brand new block or fragment */ frags = numfrags(fs, nsize); - bb = fragstofsb(fs, frags); - if (!ISSPACE(fs, bb, cred)) + if (!ISSPACE(fs, frags, cred)) return ENOSPC; if (bpp) { *bpp = bp = getblk(vp, lbn, nsize, 0, 0); @@ -190,9 +189,9 @@ lfs_balloc(struct vnode *vp, off_t startoffset, int iosize, kauth_cred_t cred, if (flags & B_CLRBUF) clrbuf(bp); } - ip->i_lfs_effnblks += bb; + ip->i_lfs_effnblks += frags; mutex_enter(&lfs_lock); - fs->lfs_bfree -= bb; + fs->lfs_bfree -= frags; mutex_exit(&lfs_lock); ip->i_ffs1_db[lbn] = UNWRITTEN; } else { @@ -225,14 +224,14 @@ lfs_balloc(struct vnode *vp, off_t startoffset, int iosize, kauth_cred_t cred, * Do byte accounting all at once, so we can gracefully fail *before* * we start assigning blocks. */ - bb = VFSTOUFS(vp->v_mount)->um_seqinc; + frags = VFSTOUFS(vp->v_mount)->um_seqinc; bcount = 0; if (daddr == UNASSIGNED) { - bcount = bb; + bcount = frags; } for (i = 1; i < num; ++i) { if (!indirs[i].in_exists) { - bcount += bb; + bcount += frags; } } if (ISSPACE(fs, bcount, cred)) { @@ -294,7 +293,6 @@ lfs_balloc(struct vnode *vp, off_t startoffset, int iosize, kauth_cred_t cred, /* * Get the existing block from the cache, if requested. */ - frags = fsbtofrags(fs, bb); if (bpp) *bpp = bp = getblk(vp, lbn, blksize(fs, ip, lbn), 0, 0); @@ -375,14 +373,14 @@ lfs_fragextend(struct vnode *vp, int osize, int nsize, daddr_t lbn, struct buf * { struct inode *ip; struct lfs *fs; - long bb; + long frags; int error; extern long locked_queue_bytes; size_t obufsize; ip = VTOI(vp); fs = ip->i_lfs; - bb = (long)fragstofsb(fs, numfrags(fs, nsize - osize)); + frags = (long)numfrags(fs, nsize - osize); error = 0; ASSERT_NO_SEGLOCK(fs); @@ -399,7 +397,7 @@ lfs_fragextend(struct vnode *vp, int osize, int nsize, daddr_t lbn, struct buf * LFS_DEBUG_COUNTLOCKED("frag"); } - if (!ISSPACE(fs, bb, cred)) { + if (!ISSPACE(fs, frags, cred)) { error = ENOSPC; goto out; } @@ -415,7 +413,7 @@ lfs_fragextend(struct vnode *vp, int osize, int nsize, daddr_t lbn, struct buf * goto out; } #ifdef QUOTA - if ((error = chkdq(ip, bb, cred, 0))) { + if ((error = chkdq(ip, frags, cred, 0))) { if (bpp) brelse(*bpp, 0); goto out; @@ -429,23 +427,23 @@ lfs_fragextend(struct vnode *vp, int osize, int nsize, daddr_t lbn, struct buf * */ if (bpp && ((*bpp)->b_oflags & BO_DELWRI)) { - if (!lfs_fits(fs, bb)) { + if (!lfs_fits(fs, frags)) { if (bpp) brelse(*bpp, 0); #ifdef QUOTA - chkdq(ip, -bb, cred, 0); + chkdq(ip, -frags, cred, 0); #endif rw_exit(&fs->lfs_fraglock); - lfs_availwait(fs, bb); + lfs_availwait(fs, frags); goto top; } - fs->lfs_avail -= bb; + fs->lfs_avail -= frags; } mutex_enter(&lfs_lock); - fs->lfs_bfree -= bb; + fs->lfs_bfree -= frags; mutex_exit(&lfs_lock); - ip->i_lfs_effnblks += bb; + ip->i_lfs_effnblks += frags; ip->i_flag |= IN_CHANGE | IN_UPDATE; if (bpp) { diff --git a/sys/ufs/lfs/lfs_bio.c b/sys/ufs/lfs/lfs_bio.c index 4c11ababab07..08a7e79f2666 100644 --- a/sys/ufs/lfs/lfs_bio.c +++ b/sys/ufs/lfs/lfs_bio.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_bio.c,v 1.116 2010/01/08 11:35:12 pooka Exp $ */ +/* $NetBSD: lfs_bio.c,v 1.117 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.116 2010/01/08 11:35:12 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.117 2010/02/16 23:20:30 mlelstv Exp $"); #include #include @@ -110,12 +110,13 @@ extern int lfs_dostats; int locked_queue_rcount = 0; long locked_queue_rbytes = 0L; -int lfs_fits_buf(struct lfs *, int, int); -int lfs_reservebuf(struct lfs *, struct vnode *vp, struct vnode *vp2, +static int lfs_fits_buf(struct lfs *, int, int); +static int lfs_reservebuf(struct lfs *, struct vnode *vp, struct vnode *vp2, int, int); -int lfs_reserveavail(struct lfs *, struct vnode *vp, struct vnode *vp2, int); +static int lfs_reserveavail(struct lfs *, struct vnode *vp, struct vnode *vp2, + int); -int +static int lfs_fits_buf(struct lfs *fs, int n, int bytes) { int count_fit, bytes_fit; @@ -124,9 +125,9 @@ lfs_fits_buf(struct lfs *fs, int n, int bytes) KASSERT(mutex_owned(&lfs_lock)); count_fit = - (locked_queue_count + locked_queue_rcount + n < LFS_WAIT_BUFS); + (locked_queue_count + locked_queue_rcount + n <= LFS_WAIT_BUFS); bytes_fit = - (locked_queue_bytes + locked_queue_rbytes + bytes < LFS_WAIT_BYTES); + (locked_queue_bytes + locked_queue_rbytes + bytes <= LFS_WAIT_BYTES); #ifdef DEBUG if (!count_fit) { @@ -145,7 +146,7 @@ lfs_fits_buf(struct lfs *fs, int n, int bytes) } /* ARGSUSED */ -int +static int lfs_reservebuf(struct lfs *fs, struct vnode *vp, struct vnode *vp2, int n, int bytes) { @@ -170,6 +171,9 @@ lfs_reservebuf(struct lfs *fs, struct vnode *vp, locked_queue_rcount += n; locked_queue_rbytes += bytes; + if (n < 0) + cv_broadcast(&locked_queue_cv); + mutex_exit(&lfs_lock); KASSERT(locked_queue_rcount >= 0); @@ -194,7 +198,7 @@ lfs_reservebuf(struct lfs *fs, struct vnode *vp, * specific code so that each file systems can have their own vnode locking and * vnode re-using strategies. */ -int +static int lfs_reserveavail(struct lfs *fs, struct vnode *vp, struct vnode *vp2, int fsb) { @@ -330,8 +334,7 @@ lfs_reserve(struct lfs *fs, struct vnode *vp, struct vnode *vp2, int fsb) /* * XXX just a guess. should be more precise. */ - error = lfs_reservebuf(fs, vp, vp2, - fragstoblks(fs, fsb), fsbtob(fs, fsb)); + error = lfs_reservebuf(fs, vp, vp2, fsb, fsbtob(fs, fsb)); if (error) lfs_reserveavail(fs, vp, vp2, -fsb); @@ -374,7 +377,7 @@ lfs_fits(struct lfs *fs, int fsb) ASSERT_NO_SEGLOCK(fs); needed = fsb + btofsb(fs, fs->lfs_sumsize) + ((howmany(fs->lfs_uinodes + 1, INOPB(fs)) + fs->lfs_segtabsz + - 1) << (fs->lfs_blktodb - fs->lfs_fsbtodb)); + 1) << (fs->lfs_bshift - fs->lfs_ffshift)); if (needed >= fs->lfs_avail) { #ifdef DEBUG @@ -484,7 +487,7 @@ lfs_bwrite_ext(struct buf *bp, int flags) * blocks. */ if ((bp->b_flags & B_LOCKED) == 0) { - fsb = fragstofsb(fs, numfrags(fs, bp->b_bcount)); + fsb = numfrags(fs, bp->b_bcount); ip = VTOI(vp); mutex_enter(&lfs_lock); @@ -703,8 +706,8 @@ lfs_check(struct vnode *vp, daddr_t blkno, int flags) wakeup(&lfs_writer_daemon); } - while (locked_queue_count + INOCOUNT(fs) > LFS_WAIT_BUFS || - locked_queue_bytes + INOBYTES(fs) > LFS_WAIT_BYTES || + while (locked_queue_count + INOCOUNT(fs) >= LFS_WAIT_BUFS || + locked_queue_bytes + INOBYTES(fs) >= LFS_WAIT_BYTES || lfs_subsys_pages > LFS_WAIT_PAGES || fs->lfs_dirvcount > LFS_MAX_FSDIROP(fs) || lfs_dirvcount > LFS_MAX_DIROP) { @@ -724,8 +727,8 @@ lfs_check(struct vnode *vp, daddr_t blkno, int flags) * and we weren't asked to checkpoint. Try flushing again * to keep us from blocking indefinitely. */ - if (locked_queue_count + INOCOUNT(fs) > LFS_MAX_BUFS || - locked_queue_bytes + INOBYTES(fs) > LFS_MAX_BYTES) { + if (locked_queue_count + INOCOUNT(fs) >= LFS_MAX_BUFS || + locked_queue_bytes + INOBYTES(fs) >= LFS_MAX_BYTES) { lfs_flush(fs, flags | SEGM_CKP, 0); } } diff --git a/sys/ufs/lfs/lfs_inode.c b/sys/ufs/lfs/lfs_inode.c index b76b1f28a519..ef7fafd1cc03 100644 --- a/sys/ufs/lfs/lfs_inode.c +++ b/sys/ufs/lfs/lfs_inode.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_inode.c,v 1.121 2010/02/07 17:12:40 bouyer Exp $ */ +/* $NetBSD: lfs_inode.c,v 1.122 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.121 2010/02/07 17:12:40 bouyer Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_inode.c,v 1.122 2010/02/16 23:20:30 mlelstv Exp $"); #if defined(_KERNEL_OPT) #include "opt_quota.h" @@ -410,6 +410,7 @@ lfs_truncate(struct vnode *ovp, off_t length, int ioflag, kauth_cred_t cred) oip->i_size = oip->i_ffs1_size = length; uvm_vnp_setsize(ovp, length); + /* * Calculate index into inode's block list of * last direct and indirect blocks (if any) diff --git a/sys/ufs/lfs/lfs_segment.c b/sys/ufs/lfs/lfs_segment.c index 87ec90192aa6..5645b12fd1e2 100644 --- a/sys/ufs/lfs/lfs_segment.c +++ b/sys/ufs/lfs/lfs_segment.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_segment.c,v 1.214 2009/08/07 13:58:38 wiz Exp $ */ +/* $NetBSD: lfs_segment.c,v 1.215 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.214 2009/08/07 13:58:38 wiz Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_segment.c,v 1.215 2010/02/16 23:20:30 mlelstv Exp $"); #ifdef DEBUG # define vndebug(vp, str) do { \ @@ -123,7 +123,7 @@ static void lfs_cluster_callback(struct buf *); */ #define LFS_PARTIAL_FITS(fs) \ ((fs)->lfs_fsbpseg - ((fs)->lfs_offset - (fs)->lfs_curseg) > \ - fragstofsb((fs), (fs)->lfs_frag)) + (fs)->lfs_frag) /* * Figure out whether we should do a checkpoint write or go ahead with @@ -1448,7 +1448,7 @@ lfs_update_single(struct lfs *fs, struct segment *sp, if (daddr > 0) daddr = dbtofsb(fs, daddr); - bb = fragstofsb(fs, numfrags(fs, size)); + bb = numfrags(fs, size); switch (num) { case 0: ooff = ip->i_ffs1_db[lbn]; @@ -1655,7 +1655,7 @@ lfs_updatemeta(struct segment *sp) for (bytesleft = sbp->b_bcount; bytesleft > 0; bytesleft -= fs->lfs_bsize) { size = MIN(bytesleft, fs->lfs_bsize); - bb = fragstofsb(fs, numfrags(fs, size)); + bb = numfrags(fs, size); lbn = *sp->start_lbp++; lfs_update_single(fs, sp, sp->vp, lbn, fs->lfs_offset, size); @@ -2548,7 +2548,7 @@ lfs_cluster_aiodone(struct buf *bp) tbp->b_flags |= B_ASYNC; /* Master buffers have BC_AGE */ if (tbp->b_private == tbp) - tbp->b_flags |= BC_AGE; + tbp->b_cflags |= BC_AGE; } mutex_exit(&bufcache_lock); diff --git a/sys/ufs/lfs/lfs_subr.c b/sys/ufs/lfs/lfs_subr.c index dec3996803a6..be55785894a3 100644 --- a/sys/ufs/lfs/lfs_subr.c +++ b/sys/ufs/lfs/lfs_subr.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_subr.c,v 1.73 2008/04/28 20:24:11 martin Exp $ */ +/* $NetBSD: lfs_subr.c,v 1.74 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc. @@ -60,7 +60,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.73 2008/04/28 20:24:11 martin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_subr.c,v 1.74 2010/02/16 23:20:30 mlelstv Exp $"); #include #include @@ -293,9 +293,9 @@ lfs_seglock(struct lfs *fs, unsigned long flags) if (fs->lfs_seglock) { if (fs->lfs_lockpid == curproc->p_pid && fs->lfs_locklwp == curlwp->l_lid) { - mutex_exit(&lfs_lock); ++fs->lfs_seglock; fs->lfs_sp->seg_flags |= flags; + mutex_exit(&lfs_lock); return 0; } else if (flags & SEGM_PAGEDAEMON) { mutex_exit(&lfs_lock); @@ -503,9 +503,11 @@ lfs_segunlock(struct lfs *fs) * by a superblock completed. */ mutex_enter(&lfs_lock); - while (ckp && sync && fs->lfs_iocount) + while (ckp && sync && fs->lfs_iocount) { (void)mtsleep(&fs->lfs_iocount, PRIBIO + 1, "lfs_iocount", 0, &lfs_lock); + DLOG((DLOG_SEG, "sleeping on iocount %x == %d\n", fs, fs->lfs_iocount)); + } while (sync && sp->seg_iocount) { (void)mtsleep(&sp->seg_iocount, PRIBIO + 1, "seg_iocount", 0, &lfs_lock); diff --git a/sys/ufs/lfs/lfs_syscalls.c b/sys/ufs/lfs/lfs_syscalls.c index 20c9dff9641e..ac089a9e6dfd 100644 --- a/sys/ufs/lfs/lfs_syscalls.c +++ b/sys/ufs/lfs/lfs_syscalls.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_syscalls.c,v 1.135 2009/09/13 05:17:37 tsutsui Exp $ */ +/* $NetBSD: lfs_syscalls.c,v 1.136 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007, 2008 @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.135 2009/09/13 05:17:37 tsutsui Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.136 2010/02/16 23:20:30 mlelstv Exp $"); #ifndef LFS # define LFS /* for prototypes in syscallargs.h */ @@ -247,7 +247,7 @@ lfs_markv(struct proc *p, fsid_t *fsidp, BLOCK_INFO *blkiov, if (fs->lfs_ronly) return EROFS; - maxino = (fragstoblks(fs, fsbtofrags(fs, VTOI(fs->lfs_ivnode)->i_ffs1_blocks)) - + maxino = (fragstoblks(fs, VTOI(fs->lfs_ivnode)->i_ffs1_blocks) - fs->lfs_cleansz - fs->lfs_segtabsz) * fs->lfs_ifpb; cnt = blkcnt; diff --git a/sys/ufs/lfs/lfs_vfsops.c b/sys/ufs/lfs/lfs_vfsops.c index bae36205dd1f..1c65f82e15e7 100644 --- a/sys/ufs/lfs/lfs_vfsops.c +++ b/sys/ufs/lfs/lfs_vfsops.c @@ -1,4 +1,4 @@ -/* $NetBSD: lfs_vfsops.c,v 1.282 2010/01/08 11:35:12 pooka Exp $ */ +/* $NetBSD: lfs_vfsops.c,v 1.283 2010/02/16 23:20:30 mlelstv Exp $ */ /*- * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007 @@ -61,7 +61,7 @@ */ #include -__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.282 2010/01/08 11:35:12 pooka Exp $"); +__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.283 2010/02/16 23:20:30 mlelstv Exp $"); #if defined(_KERNEL_OPT) #include "opt_lfs.h" @@ -708,9 +708,8 @@ lfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) struct ufsmount *ump; struct vnode *vp; struct buf *bp, *abp; - struct partinfo dpart; dev_t dev; - int error, i, ronly, secsize, fsbsize; + int error, i, ronly, fsbsize; kauth_cred_t cred; CLEANERINFO *cip; SEGUSE *sup; @@ -728,17 +727,13 @@ lfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) return (error); ronly = (mp->mnt_flag & MNT_RDONLY) != 0; - if (VOP_IOCTL(devvp, DIOCGPART, &dpart, FREAD, cred) != 0) - secsize = DEV_BSIZE; - else - secsize = dpart.disklab->d_secsize; /* Don't free random space on error. */ bp = NULL; abp = NULL; ump = NULL; - sb_addr = LFS_LABELPAD / secsize; + sb_addr = LFS_LABELPAD / DEV_BSIZE; while (1) { /* Read in the superblock. */ error = bread(devvp, sb_addr, LFS_SBPAD, cred, 0, &bp); @@ -762,24 +757,20 @@ lfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) } if (dfs->dlfs_version == 1) - fsbsize = secsize; + fsbsize = DEV_BSIZE; else { - fsbsize = 1 << (dfs->dlfs_bshift - dfs->dlfs_blktodb + - dfs->dlfs_fsbtodb); + fsbsize = 1 << dfs->dlfs_ffshift; /* * Could be, if the frag size is large enough, that we * don't have the "real" primary superblock. If that's * the case, get the real one, and try again. */ - if (sb_addr != dfs->dlfs_sboffs[0] << - dfs->dlfs_fsbtodb) { + if (sb_addr != (dfs->dlfs_sboffs[0] << (dfs->dlfs_ffshift - DEV_BSHIFT))) { DLOG((DLOG_MOUNT, "lfs_mountfs: sb daddr" " 0x%llx is not right, trying 0x%llx\n", (long long)sb_addr, - (long long)(dfs->dlfs_sboffs[0] << - dfs->dlfs_fsbtodb))); - sb_addr = dfs->dlfs_sboffs[0] << - dfs->dlfs_fsbtodb; + (long long)(dfs->dlfs_sboffs[0] << (dfs->dlfs_ffshift - DEV_BSHIFT)))); + sb_addr = dfs->dlfs_sboffs[0] << (dfs->dlfs_ffshift - DEV_BSHIFT); brelse(bp, 0); continue; } @@ -796,7 +787,7 @@ lfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) if (dfs->dlfs_sboffs[1] && dfs->dlfs_sboffs[1] - LFS_LABELPAD / fsbsize > LFS_SBPAD / fsbsize) { - error = bread(devvp, dfs->dlfs_sboffs[1] * (fsbsize / secsize), + error = bread(devvp, dfs->dlfs_sboffs[1] * (fsbsize / DEV_BSIZE), LFS_SBPAD, cred, 0, &abp); if (error) goto out; @@ -886,7 +877,7 @@ lfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) /* Set up the I/O information */ - fs->lfs_devbsize = secsize; + fs->lfs_devbsize = DEV_BSIZE; fs->lfs_iocount = 0; fs->lfs_diropwait = 0; fs->lfs_activesb = 0; @@ -927,8 +918,8 @@ lfs_mountfs(struct vnode *devvp, struct mount *mp, struct lwp *l) ump->um_mountp = mp; ump->um_dev = dev; ump->um_devvp = devvp; - ump->um_bptrtodb = fs->lfs_fsbtodb; - ump->um_seqinc = fragstofsb(fs, fs->lfs_frag); + ump->um_bptrtodb = fs->lfs_ffshift - DEV_BSHIFT; + ump->um_seqinc = fs->lfs_frag; ump->um_nindir = fs->lfs_nindir; ump->um_lognindir = ffs(fs->lfs_nindir) - 1; for (i = 0; i < MAXQUOTAS; i++) @@ -1184,16 +1175,16 @@ lfs_statvfs(struct mount *mp, struct statvfs *sbp) sbp->f_bsize = fs->lfs_bsize; sbp->f_frsize = fs->lfs_fsize; sbp->f_iosize = fs->lfs_bsize; - sbp->f_blocks = fsbtofrags(fs, LFS_EST_NONMETA(fs) - VTOI(fs->lfs_ivnode)->i_lfs_effnblks); + sbp->f_blocks = LFS_EST_NONMETA(fs) - VTOI(fs->lfs_ivnode)->i_lfs_effnblks; - sbp->f_bfree = fsbtofrags(fs, LFS_EST_BFREE(fs)); + sbp->f_bfree = LFS_EST_BFREE(fs); KASSERT(sbp->f_bfree <= fs->lfs_dsize); #if 0 if (sbp->f_bfree < 0) sbp->f_bfree = 0; #endif - sbp->f_bresvd = fsbtofrags(fs, LFS_EST_RSVD(fs)); + sbp->f_bresvd = LFS_EST_RSVD(fs); if (sbp->f_bfree > sbp->f_bresvd) sbp->f_bavail = sbp->f_bfree - sbp->f_bresvd; else