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

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