6edea0
From 90d96c4f6a44d895f8999da8c4721a04612e6379 Mon Sep 17 00:00:00 2001
6edea0
From: Kairui Song <kasong@redhat.com>
6edea0
Date: Tue, 29 Oct 2019 16:29:14 +0800
6edea0
Subject: [PATCH] 90kernel-modules: don't install any block driver if not
6edea0
 needed
6edea0
6edea0
If hostonly mode is in use, and there isn't any block device included
6edea0
as hostonly device, then the initramfs won't need any block driver.
6edea0
6edea0
Eg. for kdump built image, there could be only one nfs mount point,
6edea0
or the initramfs may only execute some network operation then reboot.
6edea0
6edea0
In such case, skip block driver installation to save space and time.
6edea0
6edea0
Signed-off-by: Kairui Song <kasong@redhat.com>
6edea0
(cherry picked from commit f4ad2e5c8964b6c7b50420299a0096bade6a40bd)
6edea0
6edea0
Resolves: #1776659
6edea0
---
6edea0
 modules.d/90kernel-modules/module-setup.sh | 32 +++++++++++++++++++++++-------
6edea0
 1 file changed, 25 insertions(+), 7 deletions(-)
6edea0
6edea0
diff --git a/modules.d/90kernel-modules/module-setup.sh b/modules.d/90kernel-modules/module-setup.sh
6edea0
index 3dfceff0..c91ba10c 100755
6edea0
--- a/modules.d/90kernel-modules/module-setup.sh
6edea0
+++ b/modules.d/90kernel-modules/module-setup.sh
6edea0
@@ -2,6 +2,8 @@
6edea0
 
6edea0
 # called by dracut
6edea0
 installkernel() {
6edea0
+    local _blockfuncs='ahci_platform_get_resources|ata_scsi_ioctl|scsi_add_host|blk_cleanup_queue|register_mtd_blktrans|scsi_esp_register|register_virtio_device|usb_stor_disconnect|mmc_add_host|sdhci_add_host|scsi_add_host_with_dma'
6edea0
+
6edea0
     find_kernel_modules_external () {
6edea0
         local _OLDIFS
6edea0
         local external_pattern="^/"
6edea0
@@ -16,11 +18,25 @@ installkernel() {
6edea0
         done < "$srcmods/modules.dep"
6edea0
         IFS=$_OLDIFS
6edea0
     }
6edea0
-    local _blockfuncs='ahci_platform_get_resources|ata_scsi_ioctl|scsi_add_host|blk_cleanup_queue|register_mtd_blktrans|scsi_esp_register|register_virtio_device|usb_stor_disconnect|mmc_add_host|sdhci_add_host|scsi_add_host_with_dma'
6edea0
+
6edea0
+    is_block_dev() {
6edea0
+        [ -e /sys/dev/block/$1 ] && return 0
6edea0
+        return 1
6edea0
+    }
6edea0
+
6edea0
+    install_block_modules () {
6edea0
+        hostonly='' instmods sr_mod sd_mod scsi_dh ata_piix
6edea0
+        instmods \
6edea0
+            scsi_dh_rdac scsi_dh_emc scsi_dh_alua \
6edea0
+            =ide nvme vmd nfit \
6edea0
+            virtio_blk
6edea0
+
6edea0
+        dracut_instmods -o -s "${_blockfuncs}" "=drivers"
6edea0
+    }
6edea0
 
6edea0
     if [[ -z $drivers ]]; then
6edea0
         hostonly='' instmods \
6edea0
-            sr_mod sd_mod scsi_dh ata_piix hid_generic unix \
6edea0
+            hid_generic unix \
6edea0
             ehci-hcd ehci-pci ehci-platform \
6edea0
             ohci-hcd ohci-pci \
6edea0
             uhci-hcd \
6edea0
@@ -38,10 +54,10 @@ installkernel() {
6edea0
             ${NULL}
6edea0
 
6edea0
         instmods \
6edea0
-            yenta_socket scsi_dh_rdac scsi_dh_emc scsi_dh_alua \
6edea0
+            yenta_socket \
6edea0
             atkbd i8042 usbhid firewire-ohci pcmcia hv-vmbus \
6edea0
-            virtio virtio_blk virtio_ring virtio_pci virtio_scsi \
6edea0
-            "=drivers/pcmcia" =ide nvme vmd nfit
6edea0
+            virtio virtio_ring virtio_pci virtio_scsi \
6edea0
+            "=drivers/pcmcia"
6edea0
 
6edea0
         if [[ "$(uname -m)" == arm* || "$(uname -m)" == aarch64 ]]; then
6edea0
             # arm/aarch64 specific modules
6edea0
@@ -72,10 +88,12 @@ installkernel() {
6edea0
                 ${NULL}
6edea0
         fi
6edea0
 
6edea0
-        dracut_instmods -o -s "${_blockfuncs}" "=drivers"
6edea0
-
6edea0
         find_kernel_modules_external | instmods
6edea0
 
6edea0
+        if ! [[ $hostonly ]] || for_each_host_dev_and_slaves is_block_dev; then
6edea0
+            install_block_modules
6edea0
+        fi
6edea0
+
6edea0
         # if not on hostonly mode, install all known filesystems,
6edea0
         # if the required list is not set via the filesystems variable
6edea0
         if ! [[ $hostonly ]]; then
6edea0