installer: Utilize dumpon(8) and swapoff(8) to turn off dump and swap.
authorSascha Wildner <saw@online.de>
Thu, 23 Sep 2010 09:43:06 +0000 (11:43 +0200)
committerSascha Wildner <saw@online.de>
Thu, 23 Sep 2010 09:43:31 +0000 (11:43 +0200)
Previously, the installer would block further installation attempts
once a swap was mounted. This was very inconvenient, e.g. when trying
to do multiple installs in one session.

It also never issued a 'dumpon off' causing dumping to be enabled
until rebooting. This caused issues upon reboot when a removable disk
(eSATA, for example) was unplugged before the reboot.

Now that we have swapoff(8), fix all these issues by turning off
dumping and swapping once the installation is completed (after
unmounting). Also, do this in a number of other places (where we
previously warned) to make sure it all gets deactivated again should
the user have cancelled a previous installation.

share/installer/cmdnames.conf
usr.sbin/installer/dfuibe_installer/flow.c
usr.sbin/installer/dfuibe_installer/fn_install.c
usr.sbin/installer/libinstaller/diskutil.c
usr.sbin/installer/libinstaller/diskutil.h

index 58f2a04..76c8656 100644 (file)
@@ -41,6 +41,7 @@ NEWFS_HAMMER=sbin/newfs_hammer
 NEWFS_MSDOS=sbin/newfs_msdos
 NFSD=sbin/nfsd
 ROUTE=sbin/route
+SWAPOFF=sbin/swapoff
 SWAPON=sbin/swapon
 UMOUNT=sbin/umount
 
@@ -50,6 +51,7 @@ GREP=usr/bin/grep
 KILLALL=usr/bin/killall
 SED=usr/bin/sed
 TOUCH=usr/bin/touch
+XARGS=usr/bin/xargs
 YES=usr/bin/yes
 
 TFTPD=usr/libexec/tftpd
index e1c9be4..44cd4d4 100644 (file)
@@ -1020,7 +1020,6 @@ state_ask_fs(struct i_fn_args *a)
 void
 state_format_disk(struct i_fn_args *a)
 {
-
        switch (dfui_be_present_dialog(a->c, _("How Much Disk?"),
            _("Use Entire Disk|Use Part of Disk|Return to Select Disk"),
            _("Select how much of this disk you want to use for %s.\n\n%s"),
@@ -1029,24 +1028,10 @@ state_format_disk(struct i_fn_args *a)
        case 1:
                /* Entire Disk */
                if (measure_activated_swap_from_disk(a, storage_get_selected_disk(a->s)) > 0) {
-                       switch(dfui_be_present_dialog(a->c,
-                           _("Swap already active"),
-                           _("Reboot|Return to Select Disk"),
-                           _("Some subpartitions on the primary partition "
-                           "of this disk are already activated as swap. "
-                           "Since there is no way to deactivate swap in "
-                           "%s once it is activated, in order "
-                           "to edit the subpartition layout of this "
-                           "primary partition, you must first reboot."),
-                           OPERATING_SYSTEM_NAME)) {
-                       case 1:
-                               state = state_reboot;
-                               return;
-                       case 2:
+                       if (swapoff_all(a) == NULL) {
+                               inform(a->c, _("Warning: swap could not be turned off."));
                                state = state_select_disk;
                                return;
-                       default:
-                               abort_backend();
                        }
                }
 
@@ -1101,24 +1086,10 @@ state_select_slice(struct i_fn_args *a)
        } else {
                if (measure_activated_swap_from_slice(a, storage_get_selected_disk(a->s),
                    storage_get_selected_slice(a->s)) > 0) {
-                       switch(dfui_be_present_dialog(a->c,
-                           _("Swap already active"),
-                           _("Reboot|Return to Select Primary Partition"),
-                           _("Some subpartitions on the selected primary "
-                           "partition are already activated as swap. "
-                           "Since there is no way to deactivate swap in "
-                           "%s once it is activated, in order "
-                           "to edit the subpartition layout of this "
-                           "primary partition, you must first reboot."),
-                           OPERATING_SYSTEM_NAME)) {
-                       case 1:
-                               state = state_reboot;
-                               return;
-                       case 2:
+                       if (swapoff_all(a) == NULL) {
+                               inform(a->c, _("Warning: swap could not be turned off."));
                                state = state_select_slice;
                                return;
-                       default:
-                               abort_backend();
                        }
                }
 
@@ -1163,33 +1134,15 @@ state_select_slice(struct i_fn_args *a)
 void
 state_create_subpartitions(struct i_fn_args *a)
 {
-       char msg_buf[1][1024];
        struct commands *cmds;
 
        if (measure_activated_swap_from_slice(a, storage_get_selected_disk(a->s),
            storage_get_selected_slice(a->s)) > 0) {
-               snprintf(msg_buf[0], sizeof(msg_buf[0]),
-                   _("Some subpartitions on the selected primary "
-                   "partition are already activated as swap. "
-                   "Since there is no way to deactivate swap in "
-                   "%s once it is activated, in order "
-                   "to edit the subpartition layout of this "
-                   "primary partition, you must first reboot."),
-                   OPERATING_SYSTEM_NAME);
-               switch(dfui_be_present_dialog(a->c, _("Swap already active"),
-                   disk_get_formatted(storage_get_selected_disk(a->s)) ?
-                   _("Reboot|Return to Select Disk") :
-                   _("Reboot|Return to Select Primary Partition"),
-                   msg_buf[0])) {
-               case 1:
-                       state = state_reboot;
-                       return;
-               case 2:
+               if (swapoff_all(a) == NULL) {
+                       inform(a->c, _("Warning: swap could not be turned off."));
                        state = disk_get_formatted(storage_get_selected_disk(a->s)) ?
                            state_select_disk : state_select_slice;
                        return;
-               default:
-                       abort_backend();
                }
        }
 
index ad37126..08067b5 100644 (file)
@@ -675,4 +675,10 @@ fn_install_os(struct i_fn_args *a)
                inform(a->c, _("Warning: subpartitions were not correctly unmounted."));
 
        commands_free(cmds);
+
+       /*
+        * Finally, remove all swap.
+        */
+       if (swapoff_all(a) == NULL)
+               inform(a->c, _("Warning: swap could not be turned off."));
 }
index 64f5fac..4f38148 100644 (file)
@@ -903,3 +903,20 @@ measure_activated_swap_from_disk(const struct i_fn_args *a,
 
        return(swap);
 }
+
+void *
+swapoff_all(const struct i_fn_args *a)
+{
+       FILE *p;
+
+       if ((p = aura_popen("%s%s off; %s%s | %s%s \"^/dev\" | %s%s '{print $1;}' | %s%s %s%s", "r",
+                   a->os_root, cmd_name(a, "DUMPON"),
+                   a->os_root, cmd_name(a, "SWAPINFO"),
+                   a->os_root, cmd_name(a, "GREP"),
+                   a->os_root, cmd_name(a, "AWK"),
+                   a->os_root, cmd_name(a, "XARGS"),
+                   a->os_root, cmd_name(a, "SWAPOFF"))) != NULL)
+               aura_pclose(p);
+
+       return(p);
+}
index 1a86dec..4b972be 100644 (file)
@@ -182,6 +182,7 @@ long                         measure_activated_swap_from_slice(const struct i_fn_args *,
                                const struct disk *, const struct slice *);
 long                    measure_activated_swap_from_disk(const struct i_fn_args *,
                                const struct disk *);
+void                   *swapoff_all(const struct i_fn_args *);
 
 int                     survey_storage(struct i_fn_args *);