Blame 0031-instmods-get-filenames-from-stdin-if-no-args-use-it.patch

Harald Hoyer 55891e
From 881eda695ed552474b9d1e5befe084d7bfab3d50 Mon Sep 17 00:00:00 2001
Harald Hoyer 55891e
From: John Reiser <jreiser@BitWagon.com>
Harald Hoyer 55891e
Date: Mon, 29 Aug 2011 13:40:21 -0700
Harald Hoyer 55891e
Subject: [PATCH] instmods: get filenames from stdin if no args; use it
Harald Hoyer 55891e
Harald Hoyer 55891e
Use bash  "[[ string =~ pattern ]]"  instead of "egrep -q".
Harald Hoyer 55891e
Replace control-dominated serial fondling
Harald Hoyer 55891e
	for var in $(proc1); do proc2 var; done
Harald Hoyer 55891e
with data-dominated parallel pipeline
Harald Hoyer 55891e
	proc1  |  while read var; do proc2 var; done
Harald Hoyer 55891e
Together this is a large savings.
Harald Hoyer 55891e
Harald Hoyer 55891e
[harald@redhat.com: fixed network kernel module filter]
Harald Hoyer 55891e
---
Harald Hoyer 55891e
 dracut-functions                           |   57 ++++++++++++++++++++--------
Harald Hoyer 55891e
 modules.d/40network/module-setup.sh        |   19 +++++++--
Harald Hoyer 55891e
 modules.d/90kernel-modules/module-setup.sh |   11 +++++-
Harald Hoyer 55891e
 modules.d/90multipath/module-setup.sh      |   15 +++++--
Harald Hoyer 55891e
 modules.d/95iscsi/module-setup.sh          |   12 ++++-
Harald Hoyer 55891e
 5 files changed, 84 insertions(+), 30 deletions(-)
Harald Hoyer 55891e
Harald Hoyer 55891e
diff --git a/dracut-functions b/dracut-functions
Harald Hoyer 55891e
index 4d3317c..556d309 100755
Harald Hoyer 55891e
--- a/dracut-functions
Harald Hoyer 55891e
+++ b/dracut-functions
Harald Hoyer 55891e
@@ -863,49 +863,63 @@ filter_kernel_modules_by_path () (
Harald Hoyer 55891e
         esac
Harald Hoyer 55891e
     done
Harald Hoyer 55891e
 )
Harald Hoyer 55891e
+find_kernel_modules_by_path () (
Harald Hoyer 55891e
+    if ! [[ $hostonly ]]; then
Harald Hoyer 55891e
+        find "$srcmods/kernel/$1" "$srcmods/extra" "$srcmods/weak-updates" \
Harald Hoyer 55891e
+          -name "*.ko" -o -name "*.ko.gz" 2>/dev/null
Harald Hoyer 55891e
+    else
Harald Hoyer 55891e
+        cut -d " " -f 1 
Harald Hoyer 55891e
+        | xargs modinfo -F filename -k $kernel 2>/dev/null
Harald Hoyer 55891e
+    fi
Harald Hoyer 55891e
+)
Harald Hoyer 55891e
 
Harald Hoyer 55891e
 filter_kernel_modules () {
Harald Hoyer 55891e
     filter_kernel_modules_by_path  drivers  "$1"
Harald Hoyer 55891e
 }
Harald Hoyer 55891e
 
Harald Hoyer 55891e
+find_kernel_modules () {
Harald Hoyer 55891e
+    find_kernel_modules_by_path  drivers
Harald Hoyer 55891e
+}
Harald Hoyer 55891e
+
Harald Hoyer 55891e
 # install kernel modules along with all their dependencies.
Harald Hoyer 55891e
 instmods() {
Harald Hoyer 55891e
     [[ $no_kernel = yes ]] && return
Harald Hoyer 55891e
-    local _mod _mpargs _moddirname
Harald Hoyer 55891e
-    local _ret=0
Harald Hoyer 55891e
-    while (($# > 0)); do
Harald Hoyer 55891e
-        _mod=${1%.ko*}
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+    function inst1mod() {
Harald Hoyer 55891e
+        local _mod="$1"
Harald Hoyer 55891e
         case $_mod in
Harald Hoyer 55891e
             =*)
Harald Hoyer 55891e
                 # This introduces 2 incompatible meanings for =* arguments
Harald Hoyer 55891e
                 # to instmods.  We need to decide which one to keep.
Harald Hoyer 55891e
                 if [[ $_mod = =ata && -f $srcmods/modules.block ]]; then
Harald Hoyer 55891e
-                    instmods $_mpargs \
Harald Hoyer 55891e
-                        $(egrep 'ata|ahci' "${srcmods}/modules.block")
Harald Hoyer 55891e
+                    ( echo -n "$_mpargs"; egrep 'ata|ahci' "${srcmods}/modules.block" ) \
Harald Hoyer 55891e
+                    | instmods
Harald Hoyer 55891e
                 elif [ -f $srcmods/modules.${_mod#=} ]; then
Harald Hoyer 55891e
-                    instmods $_mpargs $(cat ${srcmods}/modules.${_mod#=} )
Harald Hoyer 55891e
+                    ( echo -n "$_mpargs"; cat "${srcmods}/modules.${_mod#=}" ) \
Harald Hoyer 55891e
+                    | instmods
Harald Hoyer 55891e
                 else
Harald Hoyer 55891e
-                    instmods $_mpargs $(find "$srcmods" -path "*/${_mod#=}/*")
Harald Hoyer 55891e
+                    ( echo -n "$_mpargs"; find "$srcmods" -path "*/${_mod#=}/*" ) \
Harald Hoyer 55891e
+                    | instmods
Harald Hoyer 55891e
                 fi
Harald Hoyer 55891e
                 ;;
Harald Hoyer 55891e
-            --*)
Harald Hoyer 55891e
-                _mpargs+=" $_mod";;
Harald Hoyer 55891e
-            i2o_scsi) shift; continue;; # Do not load this diagnostic-only module
Harald Hoyer 55891e
+            --*) _mpargs+="${_mod##*/}"$'\n' ;;  # one _mod per line; lops '--'
Harald Hoyer 55891e
+            i2o_scsi) return ;; # Do not load this diagnostic-only module
Harald Hoyer 55891e
             *)  _mod=${_mod##*/}
Harald Hoyer 55891e
+
Harald Hoyer 55891e
                 # if we are already installed, skip this module and go on
Harald Hoyer 55891e
                 # to the next one.
Harald Hoyer 55891e
-                [[ -f $initdir/$1 ]] && { shift; continue; }
Harald Hoyer 55891e
+                [[ -f $initdir/$1 ]] && return
Harald Hoyer 55891e
+
Harald Hoyer 55891e
                 # If we are building a host-specific initramfs and this
Harald Hoyer 55891e
                 # module is not already loaded, move on to the next one.
Harald Hoyer 55891e
                 [[ $hostonly ]] && ! grep -qe "\<${_mod//-/_}\>" /proc/modules \
Harald Hoyer 55891e
-                    && ! echo $add_drivers | grep -qe "\<${_mod}\>" && {
Harald Hoyer 55891e
-                        shift; continue
Harald Hoyer 55891e
-                    }
Harald Hoyer 55891e
+                    && ! echo $add_drivers | grep -qe "\<${_mod}\>" \
Harald Hoyer 55891e
+                    && return
Harald Hoyer 55891e
 
Harald Hoyer 55891e
                 # We use '-d' option in modprobe only if modules prefix path
Harald Hoyer 55891e
                 # differs from default '/'.  This allows us to use Dracut with
Harald Hoyer 55891e
                 # old version of modprobe which doesn't have '-d' option.
Harald Hoyer 55891e
-                _moddirname=${srcmods%%/lib/modules/*}
Harald Hoyer 55891e
+                local _moddirname=${srcmods%%/lib/modules/*}
Harald Hoyer 55891e
                 [[ -n ${_moddirname} ]] && _moddirname="-d ${_moddirname}/"
Harald Hoyer 55891e
 
Harald Hoyer 55891e
                 # ok, load the module, all its dependencies, and any firmware
Harald Hoyer 55891e
@@ -915,6 +929,17 @@ instmods() {
Harald Hoyer 55891e
                 ((_ret+=$?))
Harald Hoyer 55891e
                 ;;
Harald Hoyer 55891e
         esac
Harald Hoyer 55891e
+    }
Harald Hoyer 55891e
+
Harald Hoyer 55891e
+    local _mpargs _ret=0
Harald Hoyer 55891e
+    if (($# == 0)); then  # filenames from stdin
Harald Hoyer 55891e
+        local _mod
Harald Hoyer 55891e
+        while read _mod; do
Harald Hoyer 55891e
+            inst1mod "${_mod%.ko*}"
Harald Hoyer 55891e
+        done
Harald Hoyer 55891e
+    fi
Harald Hoyer 55891e
+    while (($# > 0)); do  # filenames as args
Harald Hoyer 55891e
+        inst1mod ${1%.ko*}
Harald Hoyer 55891e
         shift
Harald Hoyer 55891e
     done
Harald Hoyer 55891e
     return $_ret
Harald Hoyer 55891e
diff --git a/modules.d/40network/module-setup.sh b/modules.d/40network/module-setup.sh
Harald Hoyer 55891e
index 39366b6..cb81269 100755
Harald Hoyer 55891e
--- a/modules.d/40network/module-setup.sh
Harald Hoyer 55891e
+++ b/modules.d/40network/module-setup.sh
Harald Hoyer 55891e
@@ -24,15 +24,24 @@ depends() {
Harald Hoyer 55891e
 installkernel() {
Harald Hoyer 55891e
     # Include wired net drivers, excluding wireless
Harald Hoyer 55891e
 
Harald Hoyer 55891e
-    net_module_test() {
Harald Hoyer 55891e
+    net_module_filter() {
Harald Hoyer 55891e
         local _net_drivers='eth_type_trans|register_virtio_device'
Harald Hoyer 55891e
         local _unwanted_drivers='/(wireless|isdn|uwb)/'
Harald Hoyer 55891e
-        egrep -q $_net_drivers "$1" && \
Harald Hoyer 55891e
-            egrep -qv 'iw_handler_get_spy' "$1" && \
Harald Hoyer 55891e
-            [[ ! $1 =~ $_unwanted_drivers ]]
Harald Hoyer 55891e
+        local _fname
Harald Hoyer 55891e
+        while read _fname; do
Harald Hoyer 55891e
+            local _fcont
Harald Hoyer 55891e
+            case "$_fname" in
Harald Hoyer 55891e
+                *.ko)    _fcont="$(<        $_fname)" ;;
Harald Hoyer 55891e
+                *.ko.gz) _fcont="$(gzip -dc $_fname)" ;;
Harald Hoyer 55891e
+            esac
Harald Hoyer 55891e
+            [[   $_fcont =~ $_net_drivers
Harald Hoyer 55891e
+            && ! $_fcont =~ iw_handler_get_spy \
Harald Hoyer 55891e
+            && ! $_fname =~ $_unwanted_drivers ]] \
Harald Hoyer 55891e
+            && echo "$_fname"
Harald Hoyer 55891e
+        done
Harald Hoyer 55891e
     }
Harald Hoyer 55891e
 
Harald Hoyer 55891e
-    instmods $(filter_kernel_modules_by_path drivers/net net_module_test)
Harald Hoyer 55891e
+    find_kernel_modules_by_path drivers/net | net_module_filter | instmods
Harald Hoyer 55891e
 
Harald Hoyer 55891e
     instmods ecb arc4
Harald Hoyer 55891e
     # bridge modules
Harald Hoyer 55891e
diff --git a/modules.d/90kernel-modules/module-setup.sh b/modules.d/90kernel-modules/module-setup.sh
Harald Hoyer 55891e
index 245ec0b..9fc4248 100755
Harald Hoyer 55891e
--- a/modules.d/90kernel-modules/module-setup.sh
Harald Hoyer 55891e
+++ b/modules.d/90kernel-modules/module-setup.sh
Harald Hoyer 55891e
@@ -9,6 +9,15 @@ installkernel() {
Harald Hoyer 55891e
 
Harald Hoyer 55891e
             egrep -q "$blockfuncs" "$1"
Harald Hoyer 55891e
         }
Harald Hoyer 55891e
+        block_module_filter() {
Harald Hoyer 55891e
+            local _blockfuncs='ahci_init_controller|ata_scsi_ioctl|scsi_add_host|blk_init_queue|register_mtd_blktrans|scsi_esp_register|register_virtio_device'
Harald Hoyer 55891e
+            local _f
Harald Hoyer 55891e
+            while read _f; do case "$_f" in
Harald Hoyer 55891e
+                *.ko)    [[ $(<         $_f) =~ $_blockfuncs ]] && echo "$_f" ;;
Harald Hoyer 55891e
+                *.ko.gz) [[ $(gzip -dc <$_f) =~ $_blockfuncs ]] && echo "$_f" ;;
Harald Hoyer 55891e
+                esac
Harald Hoyer 55891e
+            done
Harald Hoyer 55891e
+        }
Harald Hoyer 55891e
         hostonly='' instmods sr_mod sd_mod scsi_dh scsi_dh_rdac scsi_dh_emc
Harald Hoyer 55891e
         hostonly='' instmods pcmcia firewire-ohci
Harald Hoyer 55891e
         hostonly='' instmods usb_storage sdhci sdhci-pci
Harald Hoyer 55891e
@@ -18,7 +27,7 @@ installkernel() {
Harald Hoyer 55891e
         # install unix socket support
Harald Hoyer 55891e
         hostonly='' instmods unix
Harald Hoyer 55891e
         instmods "=drivers/pcmcia" =ide "=drivers/usb/storage"
Harald Hoyer 55891e
-        instmods $(filter_kernel_modules block_module_test)
Harald Hoyer 55891e
+        find_kernel_modules  |  block_module_filter  |  instmods
Harald Hoyer 55891e
         # if not on hostonly mode, install all known filesystems,
Harald Hoyer 55891e
         # if the required list is not set via the filesystems variable
Harald Hoyer 55891e
         if ! [[ $hostonly ]]; then
Harald Hoyer 55891e
diff --git a/modules.d/90multipath/module-setup.sh b/modules.d/90multipath/module-setup.sh
Harald Hoyer 55891e
index e9a47fc..f68b58d 100755
Harald Hoyer 55891e
--- a/modules.d/90multipath/module-setup.sh
Harald Hoyer 55891e
+++ b/modules.d/90multipath/module-setup.sh
Harald Hoyer 55891e
@@ -33,13 +33,18 @@ depends() {
Harald Hoyer 55891e
 }
Harald Hoyer 55891e
 
Harald Hoyer 55891e
 installkernel() {
Harald Hoyer 55891e
-    mp_mod_test() {
Harald Hoyer 55891e
-        local mpfuncs='scsi_register_device_handler|dm_dirty_log_type_register|dm_register_path_selector|dm_register_target'
Harald Hoyer 55891e
-        egrep -q "$mpfuncs" "$1"
Harald Hoyer 55891e
+    mp_mod_filter() {
Harald Hoyer 55891e
+        local _mpfuncs='scsi_register_device_handler|dm_dirty_log_type_register|dm_register_path_selector|dm_register_target'
Harald Hoyer 55891e
+        local _f
Harald Hoyer 55891e
+        while read _f; do case "$_f" in
Harald Hoyer 55891e
+            *.ko)    [[ $(<         $_f) =~ $_mpfuncs ]] && echo "$_f" ;;
Harald Hoyer 55891e
+            *.ko.gz) [[ $(gzip -dc <$_f) =~ $_mpfuncs ]] && echo "$_f" ;;
Harald Hoyer 55891e
+            esac
Harald Hoyer 55891e
+        done
Harald Hoyer 55891e
     }
Harald Hoyer 55891e
 
Harald Hoyer 55891e
-    instmods $(filter_kernel_modules_by_path drivers/scsi mp_mod_test)
Harald Hoyer 55891e
-    instmods $(filter_kernel_modules_by_path drivers/md mp_mod_test)
Harald Hoyer 55891e
+    ( find_kernel_modules_by_path drivers/scsi;
Harald Hoyer 55891e
+      find_kernel_modules_by_path drivers/md )  |  mp_mod_filter  |  instmods
Harald Hoyer 55891e
 }
Harald Hoyer 55891e
 
Harald Hoyer 55891e
 install() {
Harald Hoyer 55891e
diff --git a/modules.d/95iscsi/module-setup.sh b/modules.d/95iscsi/module-setup.sh
Harald Hoyer 55891e
index 3db40ea..b7771ab 100755
Harald Hoyer 55891e
--- a/modules.d/95iscsi/module-setup.sh
Harald Hoyer 55891e
+++ b/modules.d/95iscsi/module-setup.sh
Harald Hoyer 55891e
@@ -42,11 +42,17 @@ depends() {
Harald Hoyer 55891e
 
Harald Hoyer 55891e
 installkernel() {
Harald Hoyer 55891e
     instmods iscsi_tcp iscsi_ibft crc32c
Harald Hoyer 55891e
-    iscsi_module_test() {
Harald Hoyer 55891e
+    iscsi_module_filter() {
Harald Hoyer 55891e
         local _iscsifuncs='iscsi_register_transport'
Harald Hoyer 55891e
-        fgrep -q "$_iscsifuncs" "$1"
Harald Hoyer 55891e
+        local _f
Harald Hoyer 55891e
+        while read _f; do case "$_f" in
Harald Hoyer 55891e
+            *.ko)    [[ $(<         $_f) =~ $_iscsifuncs ]] && echo "$_f" ;;
Harald Hoyer 55891e
+            *.ko.gz) [[ $(gzip -dc <$_f) =~ $_iscsifuncs ]] && echo "$_f" ;;
Harald Hoyer 55891e
+            esac
Harald Hoyer 55891e
+        done
Harald Hoyer 55891e
     }
Harald Hoyer 55891e
-    instmods $(filter_kernel_modules_by_path drivers/scsi iscsi_module_test)
Harald Hoyer 55891e
+    find_kernel_modules_by_path drivers/scsi \
Harald Hoyer 55891e
+    | iscsi_module_filter  |  instmods
Harald Hoyer 55891e
 }
Harald Hoyer 55891e
 
Harald Hoyer 55891e
 install() {