Source-Changes-HG archive

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

[src/trunk]: src Various minor LFS improvements:



details:   https://anonhg.NetBSD.org/src/rev/6e89afa2627b
branches:  trunk
changeset: 574263:6e89afa2627b
user:      perseant <perseant%NetBSD.org@localhost>
date:      Sat Feb 26 05:45:54 2005 +0000

description:
Various minor LFS improvements:

* Extend the lfs library from fsck_lfs(8) so that it can be used with a
  not-yet-existent LFS.  Make newfs_lfs(8) use this library, so it can
  create LFSs whose Ifile is larger than one segment.
* Make newfs_lfs(8) use strsuftoi64() for its arguments, a la newfs(8).
* Make fsck_lfs(8) respect the "file system is clean" flag.
* Don't let fsck_lfs(8) think it has dirty blocks when invoked with the
  -n flag.

diffstat:

 regress/sys/fs/lfs/newfs_fsck/Makefile   |     6 +-
 regress/sys/fs/lfs/newfs_fsck/mkfs_mount |     8 +-
 regress/sys/fs/lfs/newfs_fsck/smallfiles |    24 +-
 sbin/fsck_lfs/bufcache.c                 |    31 +-
 sbin/fsck_lfs/bufcache.h                 |     3 +-
 sbin/fsck_lfs/lfs.c                      |   138 ++-
 sbin/fsck_lfs/lfs.h                      |     4 +-
 sbin/fsck_lfs/pass0.c                    |     7 +-
 sbin/fsck_lfs/pass3.c                    |     4 +-
 sbin/fsck_lfs/segwrite.c                 |     7 +-
 sbin/fsck_lfs/setup.c                    |     6 +-
 sbin/fsck_lfs/utilities.c                |     5 +-
 sbin/newfs_lfs/Makefile                  |     9 +-
 sbin/newfs_lfs/lfs.c                     |  1037 ------------------------------
 sbin/newfs_lfs/make_lfs.c                |   853 ++++++++++++++++++++++++
 sbin/newfs_lfs/newfs.c                   |    94 +-
 16 files changed, 1074 insertions(+), 1162 deletions(-)

diffs (truncated from 2673 to 300 lines):

diff -r 5a527cc0ec0e -r 6e89afa2627b regress/sys/fs/lfs/newfs_fsck/Makefile
--- a/regress/sys/fs/lfs/newfs_fsck/Makefile    Sat Feb 26 05:43:04 2005 +0000
+++ b/regress/sys/fs/lfs/newfs_fsck/Makefile    Sat Feb 26 05:45:54 2005 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.3 2003/02/03 07:45:05 perseant Exp $
+#      $NetBSD: Makefile,v 1.4 2005/02/26 05:45:54 perseant Exp $
 
 NOMAN= # defined
 
@@ -35,6 +35,7 @@
        cd ${TMPMP} && : > foo && ln foo bar && mv foo bar
        sync
        rm -f bar
+       ${MAKE} TMPMP=${TMPMP} VND=${VND} MPART=${MPART} fsck
 
 # Trivial newfs & fsck test
 test_mkfs_mount:
@@ -45,11 +46,12 @@
 #
 fsck:
        umount ${TMPMP}
-       fsck_lfs -n ${CVND}${MPART}
+       fsck_lfs -f -n ${CVND}${MPART}
        mount ${BVND}${MPART} ${TMPMP}
 
 clean:
        -umount ${TMPMP}
+       sleep 2
        vnconfig -u ${BVND}${RPART}
        rmdir ${TMPMP}
        rm -f ${TMPIM}
diff -r 5a527cc0ec0e -r 6e89afa2627b regress/sys/fs/lfs/newfs_fsck/mkfs_mount
--- a/regress/sys/fs/lfs/newfs_fsck/mkfs_mount  Sat Feb 26 05:43:04 2005 +0000
+++ b/regress/sys/fs/lfs/newfs_fsck/mkfs_mount  Sat Feb 26 05:45:54 2005 +0000
@@ -8,7 +8,7 @@
 CVND=/dev/r${VND}
 if [ "x$NEWFS_LFS_FLAGS" = "x" ]
 then
-       NEWFS_LFS_FLAGS="-B 131072 -b 4096 -f 512 -M 2"
+       NEWFS_LFS_FLAGS="-B 131072 -b 4096 -f 4096 -M 6"
 fi
 
 echo "***  Creating a dummy directory tree at ${TMPMP} mounted on ${TMPIM}."
@@ -16,7 +16,9 @@
 vnconfig -v ${BVND}${RPART} ${TMPIM}
 disklabel -f ${SRCDIR}/disktab -rw ${VND} floppy288
 newfs_lfs ${NEWFS_LFS_FLAGS} ${CVND}${MPART}
+
 echo "***  Checking that fs made by newfs_lfs could be understood by fsck_lfs"
-fsck_lfs -n ${CVND}${MPART} || exit 1
+fsck_lfs -f -n ${CVND}${MPART} || exit 1
+
 mkdir ${TMPMP}
-mount -t lfs ${BVND}${MPART} ${TMPMP}
+mount -t lfs -o-N1 ${BVND}${MPART} ${TMPMP}
diff -r 5a527cc0ec0e -r 6e89afa2627b regress/sys/fs/lfs/newfs_fsck/smallfiles
--- a/regress/sys/fs/lfs/newfs_fsck/smallfiles  Sat Feb 26 05:43:04 2005 +0000
+++ b/regress/sys/fs/lfs/newfs_fsck/smallfiles  Sat Feb 26 05:45:54 2005 +0000
@@ -1,31 +1,31 @@
 #!/bin/sh
 
 #
-# Create a bunch of small files at once, then delete most of them.
-# This forces live blocks in nearly empty segments.
+# Create a bunch of small files at once, then delete half of them.
+# The file size is less than the segment size.
+# This forces live blocks in half-empty segments.
 # If the filesystem is small enough, the cleaner will have to run in
 # order for this to complete.
 #
 # Argument is directory in which to run.
 #
-for i in 0 1 2 3 4 5
+echo -n "making small files: "
+for i in 0 1 2 3 4 5 6 7 8 9 a b c d e f
 do
+       echo -n "$i "
        for j in 0 1
        do
-                       # Quarter megabyte files, two at a time
-                       # for a maximum of six at once
-                       # (enough to force cleaning on a 2.88 disk)
-                       dd if=/dev/zero of=$1/f$i$j bs=512 count=512 &
+               dd if=/dev/zero of=$1/f$i$j bs=65536 count=1 >/dev/null 2>&1
        done
-       wait
        sync
        rm -f $1/f*1
-       df -k $1
-       ls -l $1
 done
+echo "done."
 
 echo "Sleeping for 10 seconds...."
 sleep 10
 
-echo "Trying with another half meg"
-dd if=/dev/zero of=$1/f61 bs=512 count=1024
+echo "Trying with another half meg; expect 'no space on device'"
+dd if=/dev/zero of=$1/f61 bs=512 count=1024 >/dev/null || true
+sync
+df -h $1
diff -r 5a527cc0ec0e -r 6e89afa2627b sbin/fsck_lfs/bufcache.c
--- a/sbin/fsck_lfs/bufcache.c  Sat Feb 26 05:43:04 2005 +0000
+++ b/sbin/fsck_lfs/bufcache.c  Sat Feb 26 05:45:54 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: bufcache.c,v 1.2 2003/03/31 19:56:59 perseant Exp $ */
+/* $NetBSD: bufcache.c,v 1.3 2005/02/26 05:45:54 perseant Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -174,6 +174,9 @@
 getblk(struct uvnode * vp, daddr_t lbn, int size)
 {
        struct ubuf *bp;
+#ifdef DEBUG
+       static int warned;
+#endif
 
        /*
         * First check the buffer cache lists.
@@ -199,7 +202,7 @@
                if (bp == NULL) {
                        bp = TAILQ_FIRST(&bufqueues[BQ_LRU]);
                        if (bp)
-                               TAILQ_REMOVE(&bufqueues[BQ_AGE], bp,
+                               TAILQ_REMOVE(&bufqueues[BQ_LRU], bp,
                                    b_freelist);
                }
                if (bp) {
@@ -209,8 +212,11 @@
                }
 #ifdef DEBUG
                else {
-                       warnx("no free buffers, allocating more than %d",
-                           maxbufs);
+                       if (!warned)
+                               warnx("allocating more than %d buffers",
+                                       maxbufs);
+                       ++warned;
+                       break;
                }
 #endif
        }
@@ -315,3 +321,20 @@
                LIST_INSERT_HEAD(&vp->v_cleanblkhd, bp, b_vnbufs);
        }
 }
+
+#ifdef DEBUG
+void
+dump_free_lists(void)
+{
+       struct ubuf *bp;
+       int i;
+
+       for (i = 0; i <= BQ_LOCKED; i++) {
+               printf("==> free list %d:\n", i);
+               TAILQ_FOREACH(bp, &bufqueues[i], b_freelist) {
+                       printf("vp %p lbn %" PRId64 " flags %lx\n",
+                               bp->b_vp, bp->b_lblkno, bp->b_flags);
+               }
+       }
+}
+#endif
diff -r 5a527cc0ec0e -r 6e89afa2627b sbin/fsck_lfs/bufcache.h
--- a/sbin/fsck_lfs/bufcache.h  Sat Feb 26 05:43:04 2005 +0000
+++ b/sbin/fsck_lfs/bufcache.h  Sat Feb 26 05:45:54 2005 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: bufcache.h,v 1.2 2003/08/07 10:04:22 agc Exp $ */
+/*     $NetBSD: bufcache.h,v 1.3 2005/02/26 05:45:54 perseant Exp $    */
 
 /*-
  * Copyright (c) 1999, 2000 The NetBSD Foundation, Inc.
@@ -119,3 +119,4 @@
 void brelse(struct ubuf *);
 int bread(struct uvnode *, daddr_t, int, struct ucred *, struct ubuf **);
 void reassignbuf(struct ubuf *, struct uvnode *);
+void dump_free_lists(void);
diff -r 5a527cc0ec0e -r 6e89afa2627b sbin/fsck_lfs/lfs.c
--- a/sbin/fsck_lfs/lfs.c       Sat Feb 26 05:43:04 2005 +0000
+++ b/sbin/fsck_lfs/lfs.c       Sat Feb 26 05:45:54 2005 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: lfs.c,v 1.7 2003/08/07 10:04:23 agc Exp $ */
+/* $NetBSD: lfs.c,v 1.8 2005/02/26 05:45:54 perseant Exp $ */
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -101,6 +101,7 @@
 
 extern u_int32_t cksum(void *, size_t);
 extern u_int32_t lfs_sb_cksum(struct dlfs *);
+extern void pwarn(const char *, ...);
 
 extern struct uvnodelst vnodelist;
 extern struct uvnodelst getvnodelist;
@@ -372,17 +373,19 @@
        ip->i_flag = 0;
 
        /* Load inode block and find inode */
-       bread(fs->lfs_unlockvp, fsbtodb(fs, daddr), fs->lfs_ibsize, NULL, &bp);
-       bp->b_flags |= B_AGE;
-       dip = lfs_ifind(fs, ino, bp);
-       if (dip == NULL) {
+       if (daddr > 0) {
+               bread(fs->lfs_unlockvp, fsbtodb(fs, daddr), fs->lfs_ibsize, NULL, &bp);
+               bp->b_flags |= B_AGE;
+               dip = lfs_ifind(fs, ino, bp);
+               if (dip == NULL) {
+                       brelse(bp);
+                       free(ip);
+                       free(vp);
+                       return NULL;
+               }
+               memcpy(ip->i_din.ffs1_din, dip, sizeof(*dip));
                brelse(bp);
-               free(ip);
-               free(vp);
-               return NULL;
        }
-       memcpy(ip->i_din.ffs1_din, dip, sizeof(*dip));
-       brelse(bp);
        ip->i_number = ino;
        /* ip->i_devvp = fs->lfs_unlockvp; */
        ip->i_lfs = fs;
@@ -449,7 +452,7 @@
 
 /* Initialize LFS library; load superblocks and choose which to use. */
 struct lfs *
-lfs_init(int devfd, daddr_t sblkno, daddr_t idaddr, int debug)
+lfs_init(int devfd, daddr_t sblkno, daddr_t idaddr, int dummy_read, int debug)
 {
        struct uvnode *devvp;
        struct ubuf *bp;
@@ -470,55 +473,64 @@
        LIST_INIT(&devvp->v_dirtyblkhd);
 
        tryalt = 0;
-       if (sblkno == 0) {
-               sblkno = btodb(LFS_LABELPAD);
-               tryalt = 1;
-       } else if (debug) {
-               printf("No -b flag given, not attempting to verify checkpoint\n");
-       }
-       error = bread(devvp, sblkno, LFS_SBPAD, NOCRED, &bp);
-       fs = (struct lfs *) malloc(sizeof(*fs));
-       memset(fs, 0, sizeof(*fs));
-       fs->lfs_dlfs = *((struct dlfs *) bp->b_data);
-       fs->lfs_unlockvp = devvp;
-       bp->b_flags |= B_INVAL;
-       brelse(bp);
-
-       if (tryalt) {
-               error = bread(devvp, fsbtodb(fs, fs->lfs_sboffs[1]),
-                   LFS_SBPAD, NOCRED, &bp);
-               altfs = (struct lfs *) malloc(sizeof(*altfs));
-               memset(altfs, 0, sizeof(*altfs));
-               altfs->lfs_dlfs = *((struct dlfs *) bp->b_data);
-               altfs->lfs_unlockvp = devvp;
+       if (dummy_read) {
+               if (sblkno == 0)
+                       sblkno = btodb(LFS_LABELPAD);
+               fs = (struct lfs *) malloc(sizeof(*fs));
+               memset(fs, 0, sizeof(*fs));
+               fs->lfs_unlockvp = devvp;
+       } else {
+               if (sblkno == 0) {
+                       sblkno = btodb(LFS_LABELPAD);
+                       tryalt = 1;
+               } else if (debug) {
+                       printf("No -b flag given, not attempting to verify checkpoint\n");
+               }
+               error = bread(devvp, sblkno, LFS_SBPAD, NOCRED, &bp);
+               fs = (struct lfs *) malloc(sizeof(*fs));
+               memset(fs, 0, sizeof(*fs));
+               fs->lfs_dlfs = *((struct dlfs *) bp->b_data);
+               fs->lfs_unlockvp = devvp;
                bp->b_flags |= B_INVAL;
                brelse(bp);
-
-               if (check_sb(fs)) {
-                       if (debug)
-                               printf("Primary superblock is no good, using first alternate\n");
-                       free(fs);
-                       fs = altfs;
-               } else {
-                       /* If both superblocks check out, try verification */
-                       if (check_sb(altfs)) {
+       
+               if (tryalt) {
+                       error = bread(devvp, fsbtodb(fs, fs->lfs_sboffs[1]),
+                       LFS_SBPAD, NOCRED, &bp);
+                       altfs = (struct lfs *) malloc(sizeof(*altfs));
+                       memset(altfs, 0, sizeof(*altfs));
+                       altfs->lfs_dlfs = *((struct dlfs *) bp->b_data);
+                       altfs->lfs_unlockvp = devvp;
+                       bp->b_flags |= B_INVAL;
+                       brelse(bp);
+       
+                       if (check_sb(fs) || fs->lfs_idaddr <= 0) {



Home | Main Index | Thread Index | Old Index