]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
dracut-functions.sh: extend module_is_host_only()
authorHarald Hoyer <harald@redhat.com>
Wed, 11 Sep 2013 07:57:52 +0000 (09:57 +0200)
committerHarald Hoyer <harald@redhat.com>
Wed, 11 Sep 2013 10:53:50 +0000 (12:53 +0200)
If the currently running kernel is not present in the installer root,
fall back to modalias checking.

dracut-functions.sh
dracut.sh

index 1d39a6d38f0f4e1bc4a5d7802df3d33e79772a8f..cf33af56af365dbce7bbd76c024d55f0de125dde 100755 (executable)
@@ -1473,23 +1473,41 @@ dracut_kernel_post() {
     [[ $DRACUT_KERNEL_LAZY_HASHDIR ]] && rm -fr -- "$DRACUT_KERNEL_LAZY_HASHDIR"
 }
 
+[[ "$kernel_current" ]] || export kernel_current=$(uname -r)
+
 module_is_host_only() {
     local _mod=$1
+    local _modenc a i
     _mod=${_mod##*/}
     _mod=${_mod%.ko}
+    _modenc=${_mod//-/_}
 
     [[ " $add_drivers " == *\ ${_mod}\ * ]] && return 0
 
     # check if module is loaded
-    for i in /sys/module/${_mod//-/_}; do
-        [[ -d $i ]] && return 0
-    done
+    [[ ${host_modules["$_modenc"]} ]] && return 0
+
+    [[ "$kernel_current" ]] || export kernel_current=$(uname -r)
+
+    if [[ "$kernel_current" != "$kernel" ]]; then
+        # check if module is loadable on the current kernel
+        # this covers the case, where a new module is introduced
+        # or a module was renamed
+        # or a module changed from builtin to a module
+        if [[ -d /lib/modules/$kernel_current ]]; then
+            # if the modinfo can be parsed, but the module
+            # is not loaded, then we can safely return 1
+            modinfo -F filename "$_mod" &>/dev/null && return 1
+        fi
 
-    # check if module is loadable on the current kernel
-    # this covers the case, where a new module is introduced
-    # or a module was renamed
-    # or a module changed from builtin to a module
-    modinfo -F filename "$_mod" &>/dev/null || return 0
+        # Finally check all modalias, if we install for a kernel
+        # different from the current one
+        for a in $(modinfo -k $kernel -F alias $_mod 2>/dev/null); do
+            for i in "${!host_modalias[@]}"; do
+                [[ $i == $a ]]  && return 0
+            done
+        done
+    fi
 
     return 1
 }
index fcc489e43103b0bcac4bca56474dacda275c48ba..1442a824ab1ff24195ba4253405c7f40a1ddb57c 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -919,6 +919,23 @@ if [[ $hostonly ]]; then
     fi
 fi
 
+# record all host modaliases
+declare -A host_modalias
+find  /sys/devices/ -name modalias -print > "$initdir/.modalias"
+ while read m; do
+    host_modalias["$(<"$m")"]=1
+done < "$initdir/.modalias"
+rm -f -- "$initdir/.modalias"
+
+# check /proc/modules
+declare -A host_modules
+while read m rest; do
+    host_modules["$m"]=1
+done </proc/modules
+
+unset m
+unset rest
+
 _get_fs_type() {
     [[ $1 ]] || return
     if [[ -b /dev/block/$1 ]] && ID_FS_TYPE=$(get_fs_env "/dev/block/$1"); then
@@ -989,7 +1006,8 @@ export initdir dracutbasedir dracutmodules \
     stdloglvl sysloglvl fileloglvl kmsgloglvl logfile \
     debug host_fs_types host_devs sshkey add_fstab \
     DRACUT_VERSION udevdir prefix filesystems drivers \
-    systemdutildir systemdsystemunitdir systemdsystemconfdir
+    systemdutildir systemdsystemunitdir systemdsystemconfdir \
+    host_modalias host_modules
 
 mods_to_load=""
 # check all our modules to see if they should be sourced.