Source-Changes-HG archive

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

[src/trunk]: src/sbin/newfs_lfs Enable the creation of lfs64 volumes.



details:   https://anonhg.NetBSD.org/src/rev/4fc92896583f
branches:  trunk
changeset: 341029:4fc92896583f
user:      dholland <dholland%NetBSD.org@localhost>
date:      Thu Oct 15 06:24:33 2015 +0000

description:
Enable the creation of lfs64 volumes.

To create an lfs64 volume, use -w 64. You can also force a 32-bit
volume with -w 32, but this will fail on devices thta are too large.

lfs64 is the default for devices > 1TB. (1TB rather than 2TB because
daddr_t is signed and negative block numbers can cause interesting
complications.)

For now print a warning that the lfs64 format isn't finalized, because
it isn't. For now any lfs64 use should be limited to test data,
benchmarking, and so forth.

diffstat:

 sbin/newfs_lfs/extern.h    |   4 +-
 sbin/newfs_lfs/make_lfs.c  |  17 +++++++---
 sbin/newfs_lfs/newfs.c     |  72 ++++++++++++++++++++++++++++++++++++++++++---
 sbin/newfs_lfs/newfs_lfs.8 |  14 +++++++-
 4 files changed, 91 insertions(+), 16 deletions(-)

diffs (253 lines):

diff -r 4dbe37ecb96f -r 4fc92896583f sbin/newfs_lfs/extern.h
--- a/sbin/newfs_lfs/extern.h   Thu Oct 15 06:24:21 2015 +0000
+++ b/sbin/newfs_lfs/extern.h   Thu Oct 15 06:24:33 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: extern.h,v 1.13 2015/08/02 18:18:09 dholland Exp $     */
+/*     $NetBSD: extern.h,v 1.14 2015/10/15 06:24:33 dholland Exp $     */
 
 /*-
  * Copyright (c) 1991, 1993
@@ -38,7 +38,7 @@
      __attribute__((__format__(__printf__,1,2)));
 u_int  lfs_log2(u_int);
 int    make_lfs(int, uint, struct dkwedge_info *, int,
-    int, int, int, int, int, int, daddr_t, int, int, u_int32_t);
+    int, int, int, int, int, int, daddr_t, int, int, u_int32_t, int);
 
 extern char    *progname;
 extern char    *special;
diff -r 4dbe37ecb96f -r 4fc92896583f sbin/newfs_lfs/make_lfs.c
--- a/sbin/newfs_lfs/make_lfs.c Thu Oct 15 06:24:21 2015 +0000
+++ b/sbin/newfs_lfs/make_lfs.c Thu Oct 15 06:24:33 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: make_lfs.c,v 1.58 2015/10/10 22:34:19 dholland Exp $   */
+/*     $NetBSD: make_lfs.c,v 1.59 2015/10/15 06:24:33 dholland 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.58 2015/10/10 22:34:19 dholland Exp $");
+__RCSID("$NetBSD: make_lfs.c,v 1.59 2015/10/15 06:24:33 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -389,7 +389,7 @@
 make_lfs(int devfd, uint secsize, struct dkwedge_info *dkw, int minfree,
         int block_size, int frag_size, int seg_size, int minfreeseg,
         int resvseg, int version, daddr_t start, int ibsize, int interleave,
-        u_int32_t roll_id)
+        u_int32_t roll_id, int bitwidth)
 {
        union lfs_dinode *dip;  /* Pointer to a disk inode */
        CLEANERINFO *cip;       /* Segment cleaner information table */
@@ -418,9 +418,11 @@
        int dmeta, labelskew;
        u_int64_t tsepb, tnseg;
        time_t stamp;
-       bool is64 = false; /* XXX notyet */
+       bool is64;
        bool dobyteswap = false; /* XXX notyet */
 
+       is64 = (bitwidth == 64);
+
        /*
         * Initialize buffer cache.  Use a ballpark guess of the length of
         * the segment table for the number of hash chains.
@@ -639,10 +641,15 @@
         * Now that we've determined what we're going to do, announce it
         * to the user.
         */
-        printf("Creating a version %d LFS", lfs_sb_getversion(fs));
+        printf("Creating a version %d LFS%d", lfs_sb_getversion(fs), bitwidth);
         if (lfs_sb_getversion(fs) > 1)
                 printf(" with roll-forward ident 0x%x", lfs_sb_getident(fs));
         printf("\n");   
+       if (bitwidth == 64) {
+               printf("WARNING: The LFS64 on-disk format is not final.\n");
+               printf("WARNING: 64-bit volumes should be used only for "
+                      "testing.\n");
+       }
         fssize = (double)lfs_sb_getnseg(fs);
         fssize *= (double)ssize;
         fssize /= 1048576.0;
diff -r 4dbe37ecb96f -r 4fc92896583f sbin/newfs_lfs/newfs.c
--- a/sbin/newfs_lfs/newfs.c    Thu Oct 15 06:24:21 2015 +0000
+++ b/sbin/newfs_lfs/newfs.c    Thu Oct 15 06:24:33 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: newfs.c,v 1.29 2013/06/18 18:18:58 christos Exp $      */
+/*     $NetBSD: newfs.c,v 1.30 2015/10/15 06:24:33 dholland Exp $      */
 
 /*-
  * Copyright (c) 1989, 1992, 1993
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)newfs.c    8.5 (Berkeley) 5/24/95";
 #else
-__RCSID("$NetBSD: newfs.c,v 1.29 2013/06/18 18:18:58 christos Exp $");
+__RCSID("$NetBSD: newfs.c,v 1.30 2015/10/15 06:24:33 dholland Exp $");
 #endif
 #endif /* not lint */
 
@@ -104,6 +104,7 @@
 extern long    dev_bsize;              /* device block size */
 
 static int64_t strsuftoi64(const char *, const char *, int64_t, int64_t, int *);
+static int strtoint(const char *, const char *, int, int);
 static void usage(void);
 
 /* CHUNKSIZE should be larger than MAXPHYS */
@@ -166,7 +167,7 @@
        struct disk_geom geo;
        struct dkwedge_info dkw;
        struct stat st;
-       int debug, force, fsi, fso, lfs_segsize, maxpartitions;
+       int debug, force, fsi, fso, lfs_segsize, maxpartitions, bitwidth;
        uint secsize = 0;
        daddr_t start;
        const char *opstring;
@@ -184,9 +185,9 @@
        if (maxpartitions > 26)
                fatal("insane maxpartitions value %d", maxpartitions);
 
-       opstring = "AB:b:DFf:I:i:LM:m:NO:R:r:S:s:v:";
+       opstring = "AB:b:DFf:I:i:LM:m:NO:R:r:S:s:v:w:";
 
-       debug = force = lfs_segsize = start = 0;
+       start = debug = force = lfs_segsize = bitwidth = 0;
        while ((ch = getopt(argc, argv, opstring)) != -1)
                switch(ch) {
                case 'A':       /* Adaptively configure segment size */
@@ -249,6 +250,9 @@
                case 'v':
                        version = strsuftoi64("file system version", optarg, 1, LFS_VERSION, NULL);
                        break;
+               case 'w':
+                       bitwidth = strtoint("bit width", optarg, 32, 64);
+                       break;
                case '?':
                default:
                        usage();
@@ -259,6 +263,14 @@
        if (argc != 2 && argc != 1)
                usage();
 
+       if (bitwidth != 32 && bitwidth != 64 && bitwidth != 0) {
+               errx(1, "bit width %d is not sensible; please use 32 or 64",
+                    bitwidth);
+       }
+       if (bitwidth == 64 && version < 2) {
+               errx(1, "Cannot make a 64-bit version 1 volume");
+       }
+
        /*
         * If the -N flag isn't specified, open the output file.  If no path
         * prefix, try /dev/r%s and then /dev/%s.
@@ -343,6 +355,30 @@
                if (fssize != 0 && fssize < dkw.dkw_size)
                        dkw.dkw_size = fssize;
 
+       /*
+        * default to 64-bit for large volumes; note that we test for
+        * 2^31 sectors and not 2^32, because block numbers (daddr_t)
+        * are signed and negative values can/will cause interesting
+        * complications.
+        */
+       if (bitwidth == 0) {
+               if (dkw.dkw_size > 0x7fffffff) {
+                       bitwidth = 64;
+               } else {
+                       bitwidth = 32;
+               }
+       }
+
+       if (dkw.dkw_size > 0x7fffffff && bitwidth == 32) {
+               if (dkw.dkw_size >= 0xfffffffe) {
+                       /* block numbers -1 and -2 are magic; must not exist */
+                       errx(1, "This volume is too large for a 32-bit LFS.");
+               }
+               /* User does this at own risk */
+               warnx("Using negative block numbers; not recommended. "
+                     "You should probably use -w 64.");
+       }
+
        /* Try autoconfiguring segment size, if asked to */
        if (lfs_segsize == -1) {
                if (!S_ISCHR(st.st_mode)) {
@@ -355,7 +391,8 @@
 
        /* If we're making a LFS, we break out here */
        r = make_lfs(fso, secsize, &dkw, minfree, bsize, fsize, lfs_segsize,
-           minfreeseg, resvseg, version, start, ibsize, interleave, roll_id);
+           minfreeseg, resvseg, version, start, ibsize, interleave, roll_id,
+           bitwidth);
        if (debug)
                bufstats();
        exit(r);
@@ -406,6 +443,29 @@
        return result;
 }
 
+static int
+strtoint(const char *desc, const char *arg, int min, int max)
+{
+       long result;
+       char *s;
+
+       errno = 0;
+       result = strtol(arg, &s, 10);
+       if (errno || *s != '\0') {
+               errx(1, "%s `%s' is not a valid number.", desc, arg);
+       }
+#if LONG_MAX > INT_MAX
+       if (result > INT_MAX || result < INT_MIN) {
+               errx(1, "%s `%s' is out of range.", desc, arg);
+       }
+#endif
+       if (result < min || result > max) {
+               errx(1, "%s `%s' is out of range.", desc, arg);
+       }
+
+       return (int)result;
+}
+
 void
 usage()
 {
diff -r 4dbe37ecb96f -r 4fc92896583f sbin/newfs_lfs/newfs_lfs.8
--- a/sbin/newfs_lfs/newfs_lfs.8        Thu Oct 15 06:24:21 2015 +0000
+++ b/sbin/newfs_lfs/newfs_lfs.8        Thu Oct 15 06:24:33 2015 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: newfs_lfs.8,v 1.23 2014/01/04 15:35:10 wiz Exp $
+.\"    $NetBSD: newfs_lfs.8,v 1.24 2015/10/15 06:24:33 dholland Exp $
 .\"
 .\" Copyright (c) 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -29,7 +29,7 @@
 .\"
 .\"     @(#)newlfs.8   8.1 (Berkeley) 6/19/93
 .\"
-.Dd July 12, 2001
+.Dd October 13, 2015
 .Dt NEWFS_LFS 8
 .Os
 .Sh NAME
@@ -140,7 +140,15 @@
 Make a filesystem with the specified disk layout version.
 Valid options are 1 or 2 (the default).
 .Em Note ,
-however, that LFS version 1 is deprecated.
+however, that LFS version 1 is deprecated, and 64-bit volumes may not
+be version 1.
+.It Fl w Ar bitwidth
+Create a filesystem using the specified bit width: 32 or 64.
+32-bit LFS volumes are limited to 2TB in size; 64-bit LFS volumes are
+not, but incur additional overhead from having larger metadata
+structures.
+The default is 32-bit for volumes less than 1 TB, and 64-bit for
+larger volumes.
 .El
 .Sh SEE ALSO
 .Xr disktab 5 ,



Home | Main Index | Thread Index | Old Index