]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
90kernel-modules: install block drivers more strictly
authorKairui Song <kasong@redhat.com>
Tue, 20 Oct 2020 08:44:40 +0000 (16:44 +0800)
committerHarald Hoyer <harald@hoyer.xyz>
Fri, 30 Oct 2020 09:13:37 +0000 (10:13 +0100)
For strict hostonly mode, only install block drivers needed for hostonly
devices.

Signed-off-by: Kairui Song <kasong@redhat.com>
modules.d/90kernel-modules/module-setup.sh

index a45722596cf450a47da0567490e2848767415541..73df29bf5667e132e239d222a83d12664c8343d5 100755 (executable)
@@ -3,6 +3,7 @@
 # called by dracut
 installkernel() {
     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'
+    local _hostonly_drvs
 
     find_kernel_modules_external () {
         local _OLDIFS
@@ -19,13 +20,19 @@ installkernel() {
         IFS=$_OLDIFS
     }
 
-    is_block_dev() {
-        [ -e /sys/dev/block/$1 ] && return 0
+    record_block_dev_drv() {
+        for _mod in $(get_dev_module /dev/block/$1); do
+            [[ " $_hostonly_drvs " != *$_mod* ]] && _hostonly_drvs+=" $_mod"
+        done
+        [[ "$_hostonly_drvs" ]] && return 0
         return 1
     }
 
+    install_block_modules_strict () {
+        hostonly='' instmods $_hostonly_drvs
+    }
+
     install_block_modules () {
-        hostonly='' instmods sg sr_mod sd_mod scsi_dh ata_piix
         instmods \
             scsi_dh_rdac scsi_dh_emc scsi_dh_alua \
             =ide nvme vmd \
@@ -93,8 +100,18 @@ installkernel() {
 
         find_kernel_modules_external | instmods
 
-        if ! [[ $hostonly ]] || for_each_host_dev_and_slaves is_block_dev; then
-            install_block_modules
+        # if not on hostonly mode, or there are hostonly block device
+        # install block drivers
+        if ! [[ $hostonly ]] || \
+            for_each_host_dev_and_slaves_all record_block_dev_drv;
+        then
+            hostonly='' instmods sg sr_mod sd_mod scsi_dh ata_piix
+
+            if [[ "$hostonly_mode" == "strict" ]]; then
+                install_block_modules_strict
+            else
+                install_block_modules
+            fi
         fi
 
         # if not on hostonly mode, install all known filesystems,