hammer2 - buildworld components, boot2 and loader support
authorMatthew Dillon <dillon@apollo.backplane.com>
Fri, 18 Aug 2017 07:53:40 +0000 (00:53 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Fri, 18 Aug 2017 07:53:40 +0000 (00:53 -0700)
* Compile hammer2 components unconditionally in buildworld now.
  Leave conditionals commented out for the moment, they will be
  removed entirely later on.

* Finish revamping the boot code to properly handle H2 DIRENTs.
  The boot code can now boot from a HAMMER2 'a' partition if desired.
  UFS is no longer required.

* Change newfs_hammer2, mount_hammer2, and the hammer2 vfs to supply
  a default super-root label if none specified.  Supply "@BOOT" when
  mounting from the 'a' partition, "@ROOT" when mounting from the 'd'
  partition, and "@DATA" when mounting from any other partition.

  mount_hammer2 no longer defaults to using @LOCAL for the label when
  none is specified.  Instead we want hammer2 mounts that fail to supply
  a label to behave in a manner that is more likely to be expected by
  the superuser.

* Do not yet include hammer2 in X86_64_GENERIC.  At the moment it must
  be supplied in /boot/loader.conf if the user wishes to boot from it.

lib/Makefile
lib/libstand/hammer2.c
sbin/Makefile
sbin/mount_hammer2/mount_hammer2.c
sbin/newfs_hammer2/newfs_hammer2.c
sys/vfs/Makefile
sys/vfs/hammer2/hammer2_vfsops.c

index 3976ebd..2c01f63 100644 (file)
@@ -110,9 +110,9 @@ SUBDIR:=    libc ${SUBDIR:Nlibc}
 .endif
 
 .if !defined(NO_CRYPT)
-.  if defined(WANT_HAMMER2)
+#.  if defined(WANT_HAMMER2)
 _libdmsg=      libdmsg
-.  endif
+#.  endif
 
 SUBDIR+=       libldns \
                libtcplay
index fb2885c..c11226b 100644 (file)
@@ -284,14 +284,14 @@ h2lookup(struct hammer2_fs *hfs, hammer2_blockref_t *base,
        int dev_boff;
        int dev_bsize;
 
-       bref_ret->type = 0;
-
        if (base == NULL) {
                saved_base.data_off = (hammer2_off_t)-1;
                return(0);
        }
-       if (base->data_off == (hammer2_off_t)-1)
+       if (base->data_off == (hammer2_off_t)-1) {
+               bref_ret->type = 0;
                return(-1);
+       }
 
        /*
         * Calculate the number of blockrefs to scan
@@ -329,6 +329,7 @@ again:
                        if (blocksize(base) && h2read(hfs, &media,
                                                      blocksize(base),
                                                      blockoff(base))) {
+                               bref_ret->type = 0;
                                return(-1);
                        }
                        saved_base = *base;
@@ -380,6 +381,7 @@ again:
                /*
                 * Return 0
                 */
+               bref_ret->type = 0;
                rc = 0;
                break;
        case HAMMER2_BREF_TYPE_INDIRECT:
@@ -495,6 +497,8 @@ h2resolve(struct hammer2_fs *hfs, const char *path,
                                                 bres.embed.dirent.inum,
                                                 bres.embed.dirent.inum,
                                                 &bres, (void **)&ino);
+                               if (inop)
+                                       *inop = ino;
                                goto found;
                                break;  /* NOT REACHED */
                        case HAMMER2_BREF_TYPE_INODE:
index 0ccc54c..8d4d0fb 100644 (file)
@@ -120,12 +120,12 @@ SUBDIR+=cryptdisks \
 
 # include hammer2 utilities (requires LibreSSL)
 #
-.  if defined(WANT_HAMMER2)
+#.  if defined(WANT_HAMMER2)
 _mount_hammer2= mount_hammer2
 _newfs_hammer2=        newfs_hammer2
 _hammer2=      hammer2
 .  endif
-.endif
+#.endif
 
 # maximum parallelism
 #
index 58e216c..bf908de 100644 (file)
@@ -124,11 +124,31 @@ main(int ac, char *av[])
        devpath = strdup(av[0]);
        mountpt = av[1];
 
+       if (devpath[0] == 0) {
+               fprintf(stderr, "mount_hammer2: empty device path\n");
+               exit(1);
+       }
+
        /*
-        * Automatically add @LOCAL if no label specified.
+        * Automatically add @BOOT, @ROOT, or @DATA if no label specified,
+        * based on the slice.
         */
        if (strchr(devpath, '@') == NULL) {
-               asprintf(&devpath, "%s@LOCAL", devpath);
+               char slice;
+
+               slice = devpath[strlen(devpath)-1];
+
+               switch(slice) {
+               case 'a':
+                       asprintf(&devpath, "%s@BOOT", devpath);
+                       break;
+               case 'd':
+                       asprintf(&devpath, "%s@ROOT", devpath);
+                       break;
+               default:
+                       asprintf(&devpath, "%s@DATA", devpath);
+                       break;
+               }
        }
 
        /*
@@ -142,7 +162,7 @@ main(int ac, char *av[])
        info.cluster_fd = cluster_connect(devpath);
        if (info.cluster_fd < 0) {
                fprintf(stderr,
-                       "hammer2_mount: cluster_connect(%s) failed\n",
+                       "mount_hammer2: cluster_connect(%s) failed\n",
                        devpath);
                exit(1);
        }
@@ -228,12 +248,12 @@ usage(const char *ctl, ...)
        va_list va;
 
        va_start(va, ctl);
-       fprintf(stderr, "hammer2_mount: ");
+       fprintf(stderr, "mount_hammer2: ");
        vfprintf(stderr, ctl, va);
        va_end(va);
        fprintf(stderr, "\n");
-       fprintf(stderr, " hammer2_mount -u [-o opts] mountpt\n");
-       fprintf(stderr, " hammer2_mount [-o opts] dev@LABEL mountpt\n");
+       fprintf(stderr, " mount_hammer2 -u [-o opts] mountpt\n");
+       fprintf(stderr, " mount_hammer2 [-o opts] dev@LABEL mountpt\n");
        fprintf(stderr, "\n");
        fprintf(stderr, "options:\n"
                        " <standard_mount_opts>\n"
index 5d2c150..81a519a 100644 (file)
@@ -149,8 +149,8 @@ main(int ac, char **av)
                        }
                        Label[NLabels++] = optarg;
                        if (strlen(Label[NLabels-1]) > HAMMER2_INODE_MAXNAME) {
-                               errx(1, "Root directory label too long "
-                                       "(64 chars max)\n");
+                               errx(1, "Volume label '%s' is too long "
+                                       "(64 chars max)\n", optarg);
                        }
                        break;
                case 'b':
@@ -216,9 +216,7 @@ main(int ac, char **av)
        /*
         * Adjust Label[] and NLabels.
         */
-       if (defaultlabels == 0) {
-               NLabels = 1;
-       } else {
+       if (defaultlabels) {
                char c = av[0][strlen(av[0]) - 1];
                if (c == 'a')
                        Label[NLabels++] = "BOOT";
index 9438062..e49311c 100644 (file)
@@ -5,9 +5,9 @@ SUBDIR=fifofs msdosfs nfs procfs puffs \
        hpfs ntfs smbfs isofs mfs udf \
        nullfs hammer tmpfs autofs
 
-.if defined(WANT_HAMMER2)
+#.if defined(WANT_HAMMER2)
 SUBDIR+= hammer2
-.endif
+#.endif
 
 # empty to allow concurrent building
 #
index 959427d..74e887e 100644 (file)
@@ -891,15 +891,35 @@ hammer2_vfs_mount(struct mount *mp, char *path, caddr_t data,
        }
 
        /*
-        * Extract device and label, automatically mount @LOCAL if no
-        * label specified.
+        * Extract device and label, automatically mount @BOOT, @ROOT, or @DATA
+        * if no label specified, based on the partition id.  Error out if no
+        * partition id.  This is strictly a convenience to match the
+        * default label created by newfs_hammer2, our preference is
+        * that a label always be specified.
         */
        dev = devstr;
        label = strchr(devstr, '@');
        if (label && ((label + 1) - dev) > done)
                return (EINVAL);
+       if (label && label == devstr)
+               return (EINVAL);
        if (label == NULL || label[1] == 0) {
-               label = "LOCAL";        /* not modified after this point */
+               char slice;
+
+               if (label == NULL)
+                       label = devstr + strlen(devstr);
+               slice = label[-1];
+               switch(slice) {
+               case 'a':
+                       label = "BOOT";
+                       break;
+               case 'd':
+                       label = "ROOT";
+                       break;
+               default:
+                       label = "DATA";
+                       break;
+               }
        } else {
                *label = '\0';
                label++;