Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src Three changes in a single commit.



details:   https://anonhg.NetBSD.org/src/rev/db5ef585c47d
branches:  trunk
changeset: 752142:db5ef585c47d
user:      mlelstv <mlelstv%NetBSD.org@localhost>
date:      Tue Feb 16 23:20:30 2010 +0000

description:
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.

diffstat:

 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(-)

diffs (truncated from 1218 to 300 lines):

diff -r 7e20ba8e239e -r db5ef585c47d sbin/fsck_lfs/dir.c
--- a/sbin/fsck_lfs/dir.c       Tue Feb 16 23:13:13 2010 +0000
+++ b/sbin/fsck_lfs/dir.c       Tue Feb 16 23:20:30 2010 +0000
@@ -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 @@
            (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 -r 7e20ba8e239e -r db5ef585c47d sbin/fsck_lfs/inode.c
--- a/sbin/fsck_lfs/inode.c     Tue Feb 16 23:13:13 2010 +0000
+++ b/sbin/fsck_lfs/inode.c     Tue Feb 16 23:20:30 2010 +0000
@@ -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 @@
                        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 -r 7e20ba8e239e -r db5ef585c47d sbin/fsck_lfs/kernelops.h
--- a/sbin/fsck_lfs/kernelops.h Tue Feb 16 23:13:13 2010 +0000
+++ b/sbin/fsck_lfs/kernelops.h Tue Feb 16 23:20:30 2010 +0000
@@ -19,4 +19,6 @@
 };
 extern const struct kernelops kops;
 
+extern long dev_bsize;
+
 #endif /* _LFS_KERNEL_OPS_H_ */
diff -r 7e20ba8e239e -r db5ef585c47d sbin/fsck_lfs/lfs.c
--- a/sbin/fsck_lfs/lfs.c       Tue Feb 16 23:13:13 2010 +0000
+++ b/sbin/fsck_lfs/lfs.c       Tue Feb 16 23:20:30 2010 +0000
@@ -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 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 @@
 
        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 @@
        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 @@
        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 @@
                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 @@
         * 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 @@
        /*
         * 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 @@
 {
        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 @@
                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 -r 7e20ba8e239e -r db5ef585c47d sbin/fsck_lfs/pass1.c
--- a/sbin/fsck_lfs/pass1.c     Tue Feb 16 23:13:13 2010 +0000
+++ b/sbin/fsck_lfs/pass1.c     Tue Feb 16 23:20:30 2010 +0000
@@ -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 @@
        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 @@
        } 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 -r 7e20ba8e239e -r db5ef585c47d sbin/fsck_lfs/pass4.c
--- a/sbin/fsck_lfs/pass4.c     Tue Feb 16 23:13:13 2010 +0000
+++ b/sbin/fsck_lfs/pass4.c     Tue Feb 16 23:20:30 2010 +0000
@@ -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 @@
        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 -r 7e20ba8e239e -r db5ef585c47d sbin/fsck_lfs/pass6.c
--- a/sbin/fsck_lfs/pass6.c     Tue Feb 16 23:13:13 2010 +0000
+++ b/sbin/fsck_lfs/pass6.c     Tue Feb 16 23:20:30 2010 +0000
@@ -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 @@
        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 @@
        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 @@
 
                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 @@
        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 @@
 



Home | Main Index | Thread Index | Old Index