Blame SOURCES/0549-Introduce-tri-state-hostonly-mode.patch

18971c
From ecd196732f36064aad675e18bf77b2b678673d63 Mon Sep 17 00:00:00 2001
18971c
From: Kairui Song <kasong@redhat.com>
18971c
Date: Wed, 4 Jul 2018 17:21:37 +0800
18971c
Subject: [PATCH] Introduce tri-state hostonly mode
18971c
18971c
Add a new option --hostonly-mode which accept an <mode> parameter, so we have a tri-state hostonly mode:
18971c
18971c
    * generic: by passing "--no-hostonly" or not passing anything.
18971c
               "--hostonly-mode" has no effect in such case.
18971c
    * sloppy: by passing "--hostonly --hostonly-mode sloppy". This
18971c
              is also the default mode when only "--hostonly" is given.
18971c
    * strict: by passing "--hostonly --hostonly-mode strict".
18971c
18971c
Sloppy mode is the original hostonly mode, the new introduced strict
18971c
mode will allow modules to ignore more drivers or do some extra job to
18971c
save memory and disk space, while making the image less portable.
18971c
18971c
Also introduced a helper function "optional_hostonly" to make it
18971c
easier for modules to leverage new hostonly mode.
18971c
18971c
To force install modules only in sloppy hostonly mode, use the form:
18971c
18971c
hostonly="$(optional_hostonly)" instmods <modules>
18971c
18971c
Signed-off-by: Kairui Song <kasong@redhat.com>
18971c
18971c
Cherry-picked from: a695250ec7db21359689e50733c6581a8d211215
18971c
Resolves: #1599592
18971c
---
18971c
 dracut-functions.sh | 11 +++++++++++
18971c
 dracut.sh           | 34 ++++++++++++++++++++++++++++++++++
18971c
 2 files changed, 45 insertions(+)
18971c
18971c
diff --git a/dracut-functions.sh b/dracut-functions.sh
18971c
index b7568bd9..4387168a 100755
18971c
--- a/dracut-functions.sh
18971c
+++ b/dracut-functions.sh
18971c
@@ -1770,3 +1770,14 @@ lvm_internal_dev() {
18971c
     [[ ${DM_LV_LAYER} ]] || [[ ! -L /dev/${DM_VG_NAME}/${DM_LV_NAME} ]]
18971c
 }
18971c
 
18971c
+# Use with form hostonly="$(optional_hostonly)" inst_xxxx <args>
18971c
+# If hosotnly mode is set to "strict", hostonly restrictions will still
18971c
+# be applied, else will ignore hostonly mode and try to install all
18971c
+# given modules.
18971c
+optional_hostonly() {
18971c
+    if [[ $hostonly_mode = "strict" ]]; then
18971c
+        printf -- "$hostonly"
18971c
+    else
18971c
+        printf ""
18971c
+    fi
18971c
+}
18971c
diff --git a/dracut.sh b/dracut.sh
18971c
index 4f324439..52835872 100755
18971c
--- a/dracut.sh
18971c
+++ b/dracut.sh
18971c
@@ -141,6 +141,21 @@ Creates initial ramdisk images for preloading modules
18971c
   -H, --hostonly        Host-Only mode: Install only what is needed for
18971c
                         booting the local host instead of a generic host.
18971c
   -N, --no-hostonly     Disables Host-Only mode
18971c
+  --hostonly-mode <mode>
18971c
+                        Specify the hostonly mode to use. <mode> could be
18971c
+                        one of "sloppy" or "strict". "sloppy" mode is used
18971c
+                        by default.
18971c
+                        In "sloppy" hostonly mode, extra drivers and modules
18971c
+                        will be installed, so minor hardware change won't make
18971c
+                        the image unbootable (eg. changed keyboard), and the
18971c
+                        image is still portable among similar hosts.
18971c
+                        With "strict" mode enabled, anything not necessary
18971c
+                        for booting the local host in its current state will
18971c
+                        not be included, and modules may do some extra job
18971c
+                        to save more space. Minor change of hardware or
18971c
+                        environment could make the image unbootable.
18971c
+                        DO NOT use "strict" mode unless you know what you
18971c
+                        are doing.
18971c
   --hostonly-cmdline    Store kernel command line arguments needed
18971c
                         in the initramfs
18971c
   --no-hostonly-cmdline Do not store kernel command line arguments needed
18971c
@@ -364,6 +379,7 @@ rearrange_params()
18971c
         --long host-only \
18971c
         --long no-hostonly \
18971c
         --long no-host-only \
18971c
+        --long hostonly-mode: \
18971c
         --long hostonly-cmdline \
18971c
         --long no-hostonly-cmdline \
18971c
         --long no-hostonly-default-device \
18971c
@@ -548,6 +564,8 @@ while :; do
18971c
                        hostonly_l="yes" ;;
18971c
         -N|--no-hostonly|--no-host-only)
18971c
                        hostonly_l="no" ;;
18971c
+        --hostonly-mode)
18971c
+                       hostonly_mode_l="$2";           PARMS_TO_STORE+=" '$2'"; shift;;
18971c
         --hostonly-cmdline)
18971c
                        hostonly_cmdline_l="yes" ;;
18971c
         --hostonly-i18n)
18971c
@@ -803,6 +821,7 @@ stdloglvl=$((stdloglvl + verbosity_mod_l))
18971c
 [[ $prefix = "/" ]] && unset prefix
18971c
 [[ $hostonly_l ]] && hostonly=$hostonly_l
18971c
 [[ $hostonly_cmdline_l ]] && hostonly_cmdline=$hostonly_cmdline_l
18971c
+[[ $hostonly_mode_l ]] && hostonly_mode=$hostonly_mode_l
18971c
 [[ $i18n_install_all_l ]] && i18n_install_all=$i18n_install_all_l
18971c
 [[ $persistent_policy_l ]] && persistent_policy=$persistent_policy_l
18971c
 [[ $use_fstab_l ]] && use_fstab=$use_fstab_l
18971c
@@ -840,6 +859,21 @@ fi
18971c
 [[ $hostonly = yes ]] && hostonly="-h"
18971c
 [[ $hostonly != "-h" ]] && unset hostonly
18971c
 
18971c
+case $hostonly_mode in
18971c
+    '')
18971c
+        [[ $hostonly ]] && hostonly_mode="sloppy" ;;
18971c
+    sloppy|strict)
18971c
+        if [[ ! $hostonly ]]; then
18971c
+            unset hostonly_mode
18971c
+        fi
18971c
+        ;;
18971c
+    *)
18971c
+        printf "%s\n" "dracut: Invalid hostonly mode '$hostonly_mode'." >&2
18971c
+        exit 1
18971c
+esac
18971c
+
18971c
+
18971c
+
18971c
 readonly TMPDIR="$tmpdir"
18971c
 readonly DRACUT_TMPDIR="$(mktemp -p "$TMPDIR/" -d -t dracut.XXXXXX)"
18971c
 [ -d "$DRACUT_TMPDIR" ] || {