]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Split kernel module loading into smaller chunks.
authorVictor Lowther <victor.lowther@gmail.com>
Sat, 15 Aug 2009 19:17:19 +0000 (14:17 -0500)
committerVictor Lowther <victor.lowther@gmail.com>
Sun, 16 Aug 2009 20:28:45 +0000 (15:28 -0500)
This prepares to more tightly integrate dracut-gencmdline with the
rest of the dracut scripts

dracut
dracut-functions
dracut-gencmdline
modules.d/90kernel-modules/installkernel

diff --git a/dracut b/dracut
index 6d4fccbbe49270516cb6cdd95469a4dcc9911c9a..7e5f2d41ea080e700979c296077b83fe627f9050 100755 (executable)
--- a/dracut
+++ b/dracut
@@ -113,6 +113,8 @@ PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:$PATH
 [[ $dracutbasedir ]] || dracutbasedir=/usr/share/dracut
 [[ $fw_dir ]] || fw_dir=/lib/firmware
 [[ $do_strip ]] || do_strip=yes
+# eliminate IFS hackery when messing with fw_dir
+fw_dir=${fw_dir//:/ }
 
 [[ $allowlocal && -f "$(dirname $0)/dracut-functions" ]] && dsrc="$(dirname $0)" || dsrc=$dracutbasedir
 
index 79982ce120f38b8e3f7fac6f4573438145678f39..c57174cd1dd9e58ed5ea7a446a7917e7542bfe37 100755 (executable)
@@ -31,7 +31,7 @@ if ! [[ $dracutlogfile ]]; then
        dracutlogfile=/tmp/dracut.log
     [[ -w $dracutlogfile ]] || dracutlogfile=/tmp/dracut.log
     >"$dracutlogfile"
-fi
+ fi
 
 dwarning() {
     echo "W: $@" >&2
@@ -275,7 +275,43 @@ check_modules() {
     done
 }
 
-# install kernel modules, and handle installing all their dependencies as well.
+# Install a single kernel module along with any firmware it may require.
+# $1 = full path to kernel module to install
+install_kmod_with_fw() {
+    local modname=${1##*/} fwdir found
+    modname=${modname%.ko}
+    inst_simple "$1" "/lib/modules/$kernel/${1##*/lib/modules/$kernel/}"
+    for fw in $(modinfo -k $kernel -F firmware $1 2>/dev/null); do
+       found=''
+       for fwdir in $fw_dir; do
+           if [[ -d $fwdir && -f $fwdir/$fw ]]; then
+               inst_simple "$fwdir/$fw" "/lib/firmware/$fw"
+               found=yes
+           fi
+       done
+       if [[ $found != yes ]]; then
+           dwarning "Possible missing firmware ${fw} for module ${mod}.ko"
+       fi
+    done
+}
+
+# Do something with all the dependencies of a kernel module.
+# Note that kernel modules depend on themselves using the technique we use
+# $1 = function to call for each dependency we find 
+#      It will be passed the full path to the found kernel module 
+# $2 = module to get dependencies for
+# rest of args = arguments to modprobe
+for_each_kmod_dep() {
+    local func=$1 kmod=$2 cmd modpapth options
+    shift 2
+    modprobe "$@" --ignore-install --show-depends $kmod 2>/dev/null | \
+       while read cmd modpath options; do
+           [[ $cmd = insmod ]] || continue
+           $func $modpath
+    done
+}
+
+# install kernel modules along with all their dependencies.
 instmods() {
     [[ $no_kernel = yes ]] && return
     local mod mpargs modpath modname cmd
@@ -308,31 +344,8 @@ instmods() {
                }
                # ok, load the module, all its dependencies, and any firmware
                # it may require
-                modprobe $mpargs --ignore-install --set-version $kernel -d ${srcmods%%/lib/modules/*}/ \
-                   --show-depends $mod 2>/dev/null | \
-                   while read cmd modpath options; do
-                   [[ $cmd = insmod ]] || continue
-                   modname=${modpath##*/}
-                   modname=${modname%.ko}
-                   if [[ ${mod/-/_} != ${modname/-/_} ]]; then
-                       dinfo "Installing dependencies for $mod ($modpath)"
-                       instmods $mpargs $modname
-                   fi
-                   inst_simple "$modpath" "/lib/modules/$kernel/${modpath##*/lib/modules/$kernel/}"
-                   for fw in $(modinfo -k $kernel -F firmware $modpath 2>/dev/null); do
-                       unset found
-                       IFS=: 
-                       for fwdir in $fw_dir; do                    
-                           if [ -d "$fwdir" -a -f $fwdir/$fw ]; then
-                               inst_simple "$fwdir/$fw" "/lib/firmware/$fw"
-                               found=yes
-                           fi
-                       done
-                       if [[ $found != yes ]]; then
-                           dwarning "Possible missing firmware ${fw} for module ${mod}.ko"
-                       fi
-                   done
-               done
+               for_each_kmod_dep install_kmod_with_fw $mod \
+                   --set-version $kernel -d ${srcmods%%/lib/modules/*}/
                ;;
        esac      
        shift
index 29011997cf63c939ce299b14cf78b7101c8c7496..bab102f45b15071c6d1383c47e13838911e88f29 100755 (executable)
@@ -41,18 +41,11 @@ moduledep() {
     [ -n "$deps" ] && vecho ": $deps" || vecho
 }
 
-if [ $UID != 0 ]; then
-    error "$0 must be run as root."
-    exit 1
-fi
-
 export MALLOC_PERTURB_=204
 
 PATH=/sbin:/usr/sbin:/bin:/usr/bin:$PATH
 export PATH
 
-. /etc/rc.d/init.d/functions
-
 # Set the umask. For iscsi, the initrd can contain plaintext
 # password (chap secret), so only allow read by owner.
 umask 077
index 94e3ba90378000374eb5dd3a87ec6564fcb17648..f9a1ab45ca486dec1ea4a2ffc2d147bb24206415 100755 (executable)
@@ -1,5 +1,5 @@
 #!/bin/bash
-if [ -z "$drivers" ]; then
+if [[ -z $drivers ]]; then
   drivers="sd_mod =fs"
   # Include block controller drivers
   blockfuncs='ata_scsi_ioctl|scsi_add_host|blk_init_queue|register_mtd_blktrans|scsi_esp_register|register_virtio_device'