installer - Add hammer2 support to the installer
authorMatthew Dillon <dillon@apollo.backplane.com>
Tue, 12 Sep 2017 00:57:56 +0000 (17:57 -0700)
committerMatthew Dillon <dillon@apollo.backplane.com>
Tue, 12 Sep 2017 00:57:56 +0000 (17:57 -0700)
* hammer2 can now be selected as a filesystem in the installer.

* Note that we still for /boot to use UFS.  The boot loader *CAN*
  access a hammer2 /boot, but the small size of the filesystem makes
  it too easy to fill up when doing installkernel or installworld.

* Also fix a minor bug in the installer.  when issuing a 'dumpon device'
  be sure to first issue a 'dumpon off' to avoid dumpon complaints about
  a dump device already being specified.

share/installer/cmdnames.conf
usr.sbin/installer/dfuibe_installer/Makefile
usr.sbin/installer/dfuibe_installer/flow.c
usr.sbin/installer/dfuibe_installer/flow.h
usr.sbin/installer/dfuibe_installer/fn.h
usr.sbin/installer/dfuibe_installer/fn_configure.c
usr.sbin/installer/dfuibe_installer/fn_install.c
usr.sbin/installer/dfuibe_installer/fn_subpart_hammer.c
usr.sbin/installer/libinstaller/diskutil.c
usr.sbin/installer/libinstaller/diskutil.h

index 47cc05f..4d377a1 100644 (file)
@@ -30,15 +30,18 @@ DUMPON=sbin/dumpon
 FDISK=sbin/fdisk
 GPT=sbin/gpt
 HAMMER=sbin/hammer
+HAMMER2=sbin/hammer2
 IFCONFIG=sbin/ifconfig
 MOUNT=sbin/mount
 MOUNTD=sbin/mountd
 MOUNT_HAMMER=sbin/mount_hammer
+MOUNT_HAMMER2=sbin/mount_hammer2
 MOUNT_MSDOS=sbin/mount_msdos
 MOUNT_NULL=sbin/mount_null
 MOUNT_TMPFS=sbin/mount_tmpfs
 NEWFS=sbin/newfs
 NEWFS_HAMMER=sbin/newfs_hammer
+NEWFS_HAMMER2=sbin/newfs_hammer2
 NEWFS_MSDOS=sbin/newfs_msdos
 NFSD=sbin/nfsd
 ROUTE=sbin/route
index 16e70a0..2b1603f 100644 (file)
@@ -4,7 +4,8 @@
 PROG=  dfuibe_installer
 NOMAN=
 SRCS=  flow.c fn_diagnostic.c fn_install.c fn_zonetab.c \
-       fn_configure.c fn_disk.c fn_subpart_hammer.c fn_subpart_ufs.c main.c
+       fn_configure.c fn_disk.c main.c \
+       fn_subpart_hammer.c fn_subpart_ufs.c
 
 CFLAGS+=-I${.CURDIR}/..
 
index 51fbbed..9ef91b1 100644 (file)
@@ -393,7 +393,7 @@ state_configure_menu(struct i_fn_args *a)
 
        if (during_install == 0) {
                switch (dfui_be_present_dialog(a->c, _("Select file system"),
-                   _("HAMMER|UFS|Return to Welcome Menu"),
+                   _("HAMMER|HAMMER2|UFS|Return to Welcome Menu"),
                    _("Please select the file system installed on the disk.\n\n")))
                {
                case 1:
@@ -401,10 +401,14 @@ state_configure_menu(struct i_fn_args *a)
                        use_hammer = 1;
                        break;
                case 2:
+                       /* HAMMER2 */
+                       use_hammer = 2;
+                       break;
+               case 3:
                        /* UFS */
                        use_hammer = 0;
                        break;
-               case 3:
+               case 4:
                        state = state_welcome;
                        return;
                        /* NOTREACHED */
@@ -1021,9 +1025,12 @@ state_ask_fs(struct i_fn_args *a)
        use_hammer = 0;
 
        switch (dfui_be_present_dialog(a->c, _("Select file system"),
-           _("Use HAMMER|Use UFS|Return to Select Disk"),
+           _("Use HAMMER|Use HAMMER2|Use UFS|Return to Select Disk"),
            _("Please select the file system you want to use with %s.\n\n"
-             "HAMMER is the new %s file system.  UFS is the traditional BSD file system."),
+             "HAMMER is the primary %s file system.  "
+             "HAMMER2 is the bleeding edge %s file system.  "
+             "UFS is the traditional BSD file system."),
+           OPERATING_SYSTEM_NAME,
            OPERATING_SYSTEM_NAME,
            OPERATING_SYSTEM_NAME))
        {
@@ -1032,9 +1039,13 @@ state_ask_fs(struct i_fn_args *a)
                use_hammer = 1;
                break;
        case 2:
-               /* UFS */
+               /* HAMMER2 */
+               use_hammer = 2;
                break;
        case 3:
+               /* UFS */
+               break;
+       case 4:
                state = state_select_disk;
                return;
                /* NOTREACHED */
@@ -1212,10 +1223,17 @@ state_create_subpartitions(struct i_fn_args *a)
        /*
         * Create subpartitions and filesystems
         */
-       if (use_hammer)
-               fn_create_subpartitions_hammer(a);
-       else
+       switch(use_hammer) {
+       case 1:
+               fn_create_subpartitions_hammer(FS_HAMMER, a);
+               break;
+       case 2:
+               fn_create_subpartitions_hammer(FS_HAMMER2, a);
+               break;
+       default:
                fn_create_subpartitions_ufs(a);
+               break;
+       }
 
        if (a->result) {
                state = state_install_os;
index 9b5a13a..f297cac 100644 (file)
@@ -49,7 +49,7 @@
 #define BUILD_MAX      20480   /* suggested */
 
 struct i_fn_args;
-int use_hammer;
+int use_hammer;                        /* 0=UFS 1=HAMMER 2=HAMMER2 */
 int use_uefi;
 int during_install;
 /*** PROTOTYPES ***/
index 82870ee..042294e 100644 (file)
@@ -97,7 +97,7 @@ void           fn_create_cdboot_floppy(struct i_fn_args *);
 int             format_slice(struct i_fn_args *);
 
 void            fn_create_subpartitions_ufs(struct i_fn_args *);
-void            fn_create_subpartitions_hammer(struct i_fn_args *);
+void            fn_create_subpartitions_hammer(int which, struct i_fn_args *);
 void            fn_install_os(struct i_fn_args *);
 
 /* Global variables */
index b6c5461..406af7f 100644 (file)
@@ -1345,21 +1345,6 @@ mount_target_system(struct i_fn_args *a)
         *
         * XXX NEEDS TO BE REWRITTEN XXX
         */
-#if 0
-       if (use_hammer == 0) {
-               command_add(cmds, "%s%s /dev/%s %s%s",
-                   a->os_root, cmd_name(a, "MOUNT"),
-                   subpartition_get_device_name(d_subpart),
-                   a->os_root, a->cfg_root);
-               cmd = command_add(cmds,
-                   "%s%s -f %st2;"
-                   "%s%s \"^[^#]\" %s%s/etc/crypttab >%st2",
-                   a->os_root, cmd_name(a, "RM"), a->tmp,
-                   a->os_root, cmd_name(a, "GREP"),
-                   a->os_root, a->cfg_root, a->tmp);
-               command_set_failure_mode(cmd, COMMAND_FAILURE_IGNORE);
-       } else
-#endif
        {
                command_add(cmds, "%s%s /dev/%s %sboot",
                    a->os_root, cmd_name(a, "MOUNT"),
@@ -1385,7 +1370,24 @@ mount_target_system(struct i_fn_args *a)
         */
        {
                struct stat sb = { .st_size = 0 };
-               const char *fsname = use_hammer ? "hammer" : "ufs";
+               const char *fsname;
+               const char *mountid;
+
+               switch (use_hammer) {
+               case 1:
+                       fsname = "hammer";
+                       mountid = "MOUNT_HAMMER";
+                       break;
+               case 2:
+                       fsname = "hammer2";
+                       mountid = "MOUNT_HAMMER2";
+                       break;
+               case 0:
+               default:
+                       fsname = "ufs";
+                       mountid = "MOUNT";
+                       break;
+               }
 
                stat("/tmp/t2", &sb);
                if (sb.st_size > 0) {
@@ -1407,8 +1409,7 @@ mount_target_system(struct i_fn_args *a)
                        command_add(cmds,
                            "%s%s %s %s%s",
                            a->os_root,
-                            (use_hammer ? cmd_name(a, "MOUNT_HAMMER") :
-                                          cmd_name(a, "MOUNT")),
+                           cmd_name(a, mountid),
                            subpartition_get_mapper_name(d_subpart, 1),
                            a->os_root, a->cfg_root);
                } else {
@@ -1417,8 +1418,7 @@ mount_target_system(struct i_fn_args *a)
                            "%s%s -F%s: '{print $2;}' |"
                            "%s%s 's/\"//'` %s%s",
                            a->os_root,
-                            (use_hammer ? cmd_name(a, "MOUNT_HAMMER") :
-                                          cmd_name(a, "MOUNT")),
+                           cmd_name(a, mountid),
                            a->os_root, cmd_name(a, "GREP"),
                            a->os_root,
                            a->os_root, cmd_name(a, "AWK"),
index 00db8de..b0b83fe 100644 (file)
@@ -236,7 +236,8 @@ fn_install_os(struct i_fn_args *a)
                                    a->os_root, cmd_name(a, "MKDIR"),
                                    a->os_root,
                                    subpartition_get_mountpoint(sp));
-                       if (use_hammer == 1) {
+                       switch(use_hammer) {
+                       case 1:
                                command_add(cmds, "%s%s /dev/%s %smnt%s",
                                    a->os_root, cmd_name(a, "MOUNT_HAMMER"),
                                    (subpartition_is_encrypted(sp) ?
@@ -244,7 +245,18 @@ fn_install_os(struct i_fn_args *a)
                                        subpartition_get_device_name(sp)),
                                    a->os_root,
                                    subpartition_get_mountpoint(sp));
-                       } else {
+                               break;
+                       case 2:
+                               command_add(cmds, "%s%s /dev/%s %smnt%s",
+                                   a->os_root, cmd_name(a, "MOUNT_HAMMER2"),
+                                   (subpartition_is_encrypted(sp) ?
+                                       subpartition_get_mapper_name(sp, 0) :
+                                       subpartition_get_device_name(sp)),
+                                   a->os_root,
+                                   subpartition_get_mountpoint(sp));
+                               break;
+                       case 0:
+                       default:
                                command_add(cmds, "%s%s /dev/%s %smnt%s",
                                    a->os_root, cmd_name(a, "MOUNT"),
                                    (subpartition_is_encrypted(sp) ?
@@ -252,6 +264,7 @@ fn_install_os(struct i_fn_args *a)
                                        subpartition_get_device_name(sp)),
                                    a->os_root,
                                    subpartition_get_mountpoint(sp));
+                               break;
                        }
                }
        }
@@ -265,6 +278,8 @@ fn_install_os(struct i_fn_args *a)
                        /*
                         * Set this subpartition as the dump device.
                         */
+                       command_add(cmds, "%s%s off",
+                           a->os_root, cmd_name(a, "DUMPON"));
                        command_add(cmds, "%s%s -v /dev/%s",
                            a->os_root, cmd_name(a, "DUMPON"),
                            subpartition_is_encrypted(sp) ?
@@ -585,6 +600,8 @@ fn_install_os(struct i_fn_args *a)
                         */
                        if (strcmp(subpartition_get_mountpoint(sp), "/boot") == 0)
                                fsname = "ufs";
+                       else if (use_hammer == 2)
+                               fsname = "hammer2";
                        else if (use_hammer)
                                fsname = "hammer";
                        else
index 236185a..d9ae422 100644 (file)
 
 /*
  * fn_subpart_hammer.c
- * Installer Function : Create HAMMER Subpartitions.
+ * Installer Function : Create HAMMER or HAMMER2 Subpartitions.
  */
 
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <ctype.h>
+#include <assert.h>
 
 #ifdef ENABLE_NLS
 #include <libintl.h>
@@ -66,7 +67,7 @@
 #include "flow.h"
 #include "pathnames.h"
 
-static int     create_subpartitions(struct i_fn_args *);
+static int     create_subpartitions(int which, struct i_fn_args *);
 static long    default_capacity(struct storage *, const char *);
 static int     check_capacity(struct i_fn_args *);
 static int     check_subpartition_selections(struct dfui_response *,
@@ -78,7 +79,7 @@ static void   populate_create_subpartitions_form(struct dfui_form *,
 static int     warn_subpartition_selections(struct i_fn_args *);
 static int     warn_encrypted_boot(struct i_fn_args *);
 static struct dfui_form *make_create_subpartitions_form(struct i_fn_args *);
-static int     show_create_subpartitions_form(struct dfui_form *,
+static int     show_create_subpartitions_form(int which, struct dfui_form *,
                        struct i_fn_args *);
 static char    *construct_lname(const char *mtpt);
 
@@ -91,12 +92,25 @@ static int expert = 0;
  * create them.
  */
 static int
-create_subpartitions(struct i_fn_args *a)
+create_subpartitions(int which, struct i_fn_args *a)
 {
        struct subpartition *sp;
        struct commands *cmds;
        int result = 0;
        int num_partitions;
+       const char *whichfs;
+
+       switch(which) {
+       case FS_HAMMER:
+               whichfs = "HAMMER";
+               break;
+       case FS_HAMMER2:
+               whichfs = "HAMMER2";
+               break;
+       default:
+               whichfs = NULL;
+               assert(0);
+       }
 
        cmds = commands_new();
        if (!is_file("%sinstall.disklabel.%s",
@@ -182,12 +196,12 @@ create_subpartitions(struct i_fn_args *a)
                            a->tmp);
                } else {
                        command_add(cmds,
-                           "%s%s '  %c:\t%s\t*\tHAMMER' "
+                           "%s%s '  %c:\t%s\t*\t%s' "
                            ">>%sinstall.disklabel",
                            a->os_root, cmd_name(a, "ECHO"),
                            subpartition_get_letter(sp),
                            capacity_to_string(subpartition_get_capacity(sp)),
-                           a->tmp);
+                           whichfs, a->tmp);
                }
        }
        temp_file_add(a, "install.disklabel");
@@ -257,14 +271,24 @@ create_subpartitions(struct i_fn_args *a)
                                    subpartition_get_device_name(sp),
                                    subpartition_get_mapper_name(sp, -1));
                        }
-                       ham_name = construct_lname(subpartition_get_mountpoint(sp));
-                       command_add(cmds, "%s%s -f -L %s /dev/%s",
-                           a->os_root, cmd_name(a, "NEWFS_HAMMER"),
-                           ham_name,
-                           (subpartition_is_encrypted(sp) ?
-                               subpartition_get_mapper_name(sp, 0) :
-                               subpartition_get_device_name(sp)));
-                       free(ham_name);
+
+                       if (which == FS_HAMMER) {
+                               ham_name = construct_lname(
+                                             subpartition_get_mountpoint(sp));
+                               command_add(cmds, "%s%s -f -L %s /dev/%s",
+                                   a->os_root, cmd_name(a, "NEWFS_HAMMER"),
+                                   ham_name,
+                                   (subpartition_is_encrypted(sp) ?
+                                       subpartition_get_mapper_name(sp, 0) :
+                                       subpartition_get_device_name(sp)));
+                               free(ham_name);
+                       } else {
+                               command_add(cmds, "%s%s -f /dev/%s",
+                                   a->os_root, cmd_name(a, "NEWFS_HAMMER2"),
+                                   (subpartition_is_encrypted(sp) ?
+                                       subpartition_get_mapper_name(sp, 0) :
+                                       subpartition_get_device_name(sp)));
+                       }
                }
        }
 
@@ -424,7 +448,9 @@ check_capacity(struct i_fn_args *a)
                          "You may have to run 'hammer prune-everything' and "
                          "'hammer reblock'\n"
                          "manually or often via a cron job, even if using a "
-                         "nohistory mount."));
+                         "nohistory mount.\n"
+                         "For HAMMER2 you may have to run 'hammer2 bulkfree' "
+                         "manually or often via a cron job.\n"));
        } else {
                good = 1;
        }
@@ -749,7 +775,8 @@ make_create_subpartitions_form(struct i_fn_args *a)
  *      1 = success, function is over
  */
 static int
-show_create_subpartitions_form(struct dfui_form *f, struct i_fn_args *a)
+show_create_subpartitions_form(int which, struct dfui_form *f,
+                              struct i_fn_args *a)
 {
        struct dfui_dataset *ds;
        struct dfui_response *r;
@@ -776,7 +803,7 @@ show_create_subpartitions_form(struct dfui_form *f, struct i_fn_args *a)
                                save_subpartition_selections(r, a);
                                if (!warn_subpartition_selections(a) &&
                                    !warn_encrypted_boot(a)) {
-                                       if (!create_subpartitions(a)) {
+                                       if (!create_subpartitions(which, a)) {
                                                inform(a->c, _("The subpartitions you chose were "
                                                        "not correctly created, and the "
                                                        "primary partition may "
@@ -807,7 +834,7 @@ show_create_subpartitions_form(struct dfui_form *f, struct i_fn_args *a)
  * want on the disk, how large each should be, and where it should be mounted.
  */
 void
-fn_create_subpartitions_hammer(struct i_fn_args *a)
+fn_create_subpartitions_hammer(int which, struct i_fn_args *a)
 {
        struct dfui_form *f;
        unsigned long capacity;
@@ -815,7 +842,7 @@ fn_create_subpartitions_hammer(struct i_fn_args *a)
 
        a->result = 0;
        capacity = disk_get_capacity(storage_get_selected_disk(a->s));
-       if (capacity < HAMMER_MIN) {
+       if (which == FS_HAMMER && capacity < HAMMER_MIN) {
                inform(a->c, _("The selected %dM disk is smaller than the "
                    "required %dM for the HAMMER filesystem."),
                    (int)capacity,
@@ -824,7 +851,7 @@ fn_create_subpartitions_hammer(struct i_fn_args *a)
        }
        while (!done) {
                f = make_create_subpartitions_form(a);
-               switch (show_create_subpartitions_form(f, a)) {
+               switch (show_create_subpartitions_form(which, f, a)) {
                case -1:
                        done = 0;
                        break;
index 0ad699f..5bf1101 100644 (file)
@@ -508,8 +508,8 @@ slices_free(struct slice *head)
 }
 
 struct subpartition *
-subpartition_new_hammer(struct slice *s, const char *mountpoint, long capacity,
-    int encrypted)
+subpartition_new_hammer(struct slice *s, const char *mountpoint,
+                       long capacity, int encrypted)
 {
        struct subpartition *sp;
        struct subpartition *last = s->subpartition_tail;
@@ -570,6 +570,69 @@ subpartition_new_hammer(struct slice *s, const char *mountpoint, long capacity,
        return(sp);
 }
 
+struct subpartition *
+subpartition_new_hammer2(struct slice *s, const char *mountpoint,
+                        long capacity, int encrypted)
+{
+       struct subpartition *sp;
+       struct subpartition *last = s->subpartition_tail;
+
+       AURA_MALLOC(sp, subpartition);
+
+       sp->parent = s;
+
+       if (last == NULL) {
+               sp->letter = 'a';
+       } else if (last->letter == 'b') {
+               sp->letter = 'd';
+       } else {
+               sp->letter = (char)(last->letter + 1);
+       }
+       if (sp->letter == 'b' && strcmp(mountpoint, "swap") != 0)
+               sp->letter = 'd';
+
+       sp->mountpoint = aura_strdup(mountpoint);
+       sp->capacity = capacity;
+       sp->encrypted = encrypted;
+       sp->type = FS_HAMMER2;
+
+       /*
+        * We need this here, because a UFS /boot needs valid values
+        */
+       if (sp->capacity < 1024)
+               sp->fsize = 1024;
+       else
+               sp->fsize = 2048;
+
+       if (sp->capacity < 1024)
+               sp->bsize = 8192;
+       else
+               sp->bsize = 16384;
+
+       sp->is_swap = 0;
+#if 0
+       sp->pfs = 0;
+#endif
+       if (strcasecmp(mountpoint, "swap") == 0)
+               sp->is_swap = 1;
+#if 0
+       if (strcmp(mountpoint, "/") != 0 && strcmp(mountpoint, "/boot") != 0 &&
+           strcmp(mountpoint, "swap") != 0)
+               sp->pfs = 1;
+#endif
+
+       sp->next = NULL;
+       if (s->subpartition_head == NULL)
+               s->subpartition_head = sp;
+       else
+               s->subpartition_tail->next = sp;
+
+       sp->prev = s->subpartition_tail;
+       s->subpartition_tail = sp;
+
+       return(sp);
+}
+
 /*
  * NOTE: arguments to this function are not checked for sanity.
  *
index cdaa7d1..d26ab94 100644 (file)
@@ -50,8 +50,9 @@ struct disk;
 struct slice;
 struct subpartition;
 
-#define FS_HAMMER      0
-#define FS_UFS         1
+#define FS_UFS         0
+#define FS_HAMMER      1
+#define FS_HAMMER2     2
 
 #ifdef NEEDS_DISKUTIL_STRUCTURE_DEFINITIONS
 
@@ -161,6 +162,8 @@ struct subpartition *slice_subpartition_first(const struct slice *);
 
 struct subpartition    *subpartition_new_hammer(struct slice *, const char *,
                                                 long, int);
+struct subpartition    *subpartition_new_hammer2(struct slice *, const char *,
+                                                long, int);
 struct subpartition    *subpartition_new_ufs(struct slice *, const char *,
                                              long, int, int, long, long, int);
 int                     subpartition_count(const struct slice *);