From 9687cd2753d34cd91571932ad50ae1ba2378a7cb Mon Sep 17 00:00:00 2001 From: Sascha Wildner Date: Thu, 23 Sep 2010 11:43:06 +0200 Subject: [PATCH] installer: Utilize dumpon(8) and swapoff(8) to turn off dump and swap. 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 | 2 + usr.sbin/installer/dfuibe_installer/flow.c | 59 ++----------------- .../installer/dfuibe_installer/fn_install.c | 6 ++ usr.sbin/installer/libinstaller/diskutil.c | 17 ++++++ usr.sbin/installer/libinstaller/diskutil.h | 1 + 5 files changed, 32 insertions(+), 53 deletions(-) diff --git a/share/installer/cmdnames.conf b/share/installer/cmdnames.conf index 58f2a04058..76c8656134 100644 --- a/share/installer/cmdnames.conf +++ b/share/installer/cmdnames.conf @@ -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 diff --git a/usr.sbin/installer/dfuibe_installer/flow.c b/usr.sbin/installer/dfuibe_installer/flow.c index e1c9be4290..44cd4d49a7 100644 --- a/usr.sbin/installer/dfuibe_installer/flow.c +++ b/usr.sbin/installer/dfuibe_installer/flow.c @@ -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(); } } diff --git a/usr.sbin/installer/dfuibe_installer/fn_install.c b/usr.sbin/installer/dfuibe_installer/fn_install.c index ad37126eeb..08067b5049 100644 --- a/usr.sbin/installer/dfuibe_installer/fn_install.c +++ b/usr.sbin/installer/dfuibe_installer/fn_install.c @@ -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.")); } diff --git a/usr.sbin/installer/libinstaller/diskutil.c b/usr.sbin/installer/libinstaller/diskutil.c index 64f5fac57c..4f381483d1 100644 --- a/usr.sbin/installer/libinstaller/diskutil.c +++ b/usr.sbin/installer/libinstaller/diskutil.c @@ -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); +} diff --git a/usr.sbin/installer/libinstaller/diskutil.h b/usr.sbin/installer/libinstaller/diskutil.h index 1a86decf9f..4b972be938 100644 --- a/usr.sbin/installer/libinstaller/diskutil.h +++ b/usr.sbin/installer/libinstaller/diskutil.h @@ -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 *); -- 2.41.0