Blame 0006-modules-are-now-only-handled-with-sys-modules-and-mo.patch

Harald Hoyer 18c19d
From fe1484f3db0c7fe7fe8e6d5cc1e6e4d8f0b17052 Mon Sep 17 00:00:00 2001
Harald Hoyer 18c19d
From: Harald Hoyer <harald@redhat.com>
Harald Hoyer 18c19d
Date: Wed, 6 Jun 2012 18:20:35 +0200
Harald Hoyer 18c19d
Subject: [PATCH] modules are now only handled with /sys/modules and
Harald Hoyer 18c19d
 modules.dep
Harald Hoyer 18c19d
Harald Hoyer 18c19d
No more "find" and /proc/modules checking. We now rely entirely on
Harald Hoyer 18c19d
depmod and modules.dep
Harald Hoyer 18c19d
---
Harald Hoyer 18c19d
 TODO                                 |    3 +-
Harald Hoyer 18c19d
 dracut-functions.sh                  |   56 +++++++-----------------------
Harald Hoyer 18c19d
 dracut.sh                            |    5 +++
Harald Hoyer 18c19d
 modules.d/50plymouth/module-setup.sh |   62 +++++++++++++++++++++++++---------
Harald Hoyer 18c19d
 4 files changed, 65 insertions(+), 61 deletions(-)
Harald Hoyer 18c19d
Harald Hoyer 18c19d
diff --git a/TODO b/TODO
Harald Hoyer 18c19d
index acbb0a2..095ec97 100644
Harald Hoyer 18c19d
--- a/TODO
Harald Hoyer 18c19d
+++ b/TODO
Harald Hoyer 18c19d
@@ -17,7 +17,8 @@ INITRAMFS TODO
Harald Hoyer 18c19d
 
Harald Hoyer 18c19d
 GENERATOR TODO
Harald Hoyer 18c19d
 
Harald Hoyer 18c19d
-- remove /proc/modules use /sys/module
Harald Hoyer 18c19d
+- add interpreter/plugin-scripts to be sourced at the beginning or end (can use dracut-functions)
Harald Hoyer 18c19d
+- provide "installkernel" and "new-kernel-pkg"
Harald Hoyer 18c19d
 - add mechanism for module specific command line options
Harald Hoyer 18c19d
 - pkg-config integration, to make it easy for other packages to use us.
Harald Hoyer 18c19d
 - add recovery image creator (mkrecovery)
Harald Hoyer 18c19d
diff --git a/dracut-functions.sh b/dracut-functions.sh
Harald Hoyer 18c19d
index 8aba88d..6a72fce 100755
Harald Hoyer 18c19d
--- a/dracut-functions.sh
Harald Hoyer 18c19d
+++ b/dracut-functions.sh
Harald Hoyer 18c19d
@@ -1053,7 +1053,7 @@ install_kmod_with_fw() {
Harald Hoyer 18c19d
             fi
Harald Hoyer 18c19d
         done
Harald Hoyer 18c19d
         if [[ $_found != yes ]]; then
Harald Hoyer 18c19d
-            if ! grep -qe "\<${_modname//-/_}\>" /proc/modules; then
Harald Hoyer 18c19d
+            if ! [[ -d $(echo /sys/module/${_modname//-/_}|{ read a b; echo $a; }) ]]; then
Harald Hoyer 18c19d
                 dinfo "Possible missing firmware \"${_fw}\" for kernel module" \
Harald Hoyer 18c19d
                     "\"${_modname}.ko\""
Harald Hoyer 18c19d
             else
Harald Hoyer 18c19d
@@ -1086,54 +1086,21 @@ for_each_kmod_dep() {
Harald Hoyer 18c19d
     )
Harald Hoyer 18c19d
 }
Harald Hoyer 18c19d
 
Harald Hoyer 18c19d
-# filter kernel modules to install certain modules that meet specific
Harald Hoyer 18c19d
-# requirements.
Harald Hoyer 18c19d
-# $1 = search only in subdirectory of /kernel/$1
Harald Hoyer 18c19d
-# $2 = function to call with module name to filter.
Harald Hoyer 18c19d
-#      This function will be passed the full path to the module to test.
Harald Hoyer 18c19d
-# The behaviour of this function can vary depending on whether $hostonly is set.
Harald Hoyer 18c19d
-# If it is, we will only look at modules that are already in memory.
Harald Hoyer 18c19d
-# If it is not, we will look at all kernel modules
Harald Hoyer 18c19d
-# This function returns the full filenames of modules that match $1
Harald Hoyer 18c19d
-filter_kernel_modules_by_path () (
Harald Hoyer 18c19d
-    local _modname _filtercmd
Harald Hoyer 18c19d
-    if ! [[ $hostonly ]]; then
Harald Hoyer 18c19d
-        _filtercmd='find "$srcmods/kernel/$1" "$srcmods/extra"'
Harald Hoyer 18c19d
-        _filtercmd+=' "$srcmods/weak-updates" -name "*.ko" -o -name "*.ko.gz"'
Harald Hoyer 18c19d
-        _filtercmd+=' -o -name "*.ko.xz"'
Harald Hoyer 18c19d
-        _filtercmd+=' 2>/dev/null'
Harald Hoyer 18c19d
-    else
Harald Hoyer 18c19d
-        _filtercmd='cut -d " " -f 1 
Harald Hoyer 18c19d
-        _filtercmd+='-k $kernel 2>/dev/null'
Harald Hoyer 18c19d
-    fi
Harald Hoyer 18c19d
-    for _modname in $(eval $_filtercmd); do
Harald Hoyer 18c19d
-        case $_modname in
Harald Hoyer 18c19d
-            *.ko) "$2" "$_modname" && echo "$_modname";;
Harald Hoyer 18c19d
-            *.ko.gz) gzip -dc "$_modname" > $initdir/$$.ko
Harald Hoyer 18c19d
-                $2 $initdir/$$.ko && echo "$_modname"
Harald Hoyer 18c19d
-                rm -f $initdir/$$.ko
Harald Hoyer 18c19d
-                ;;
Harald Hoyer 18c19d
-            *.ko.xz) xz -dc "$_modname" > $initdir/$$.ko
Harald Hoyer 18c19d
-                $2 $initdir/$$.ko && echo "$_modname"
Harald Hoyer 18c19d
-                rm -f $initdir/$$.ko
Harald Hoyer 18c19d
-                ;;
Harald Hoyer 18c19d
-        esac
Harald Hoyer 18c19d
-    done
Harald Hoyer 18c19d
-)
Harald Hoyer 18c19d
+
Harald Hoyer 18c19d
 find_kernel_modules_by_path () (
Harald Hoyer 18c19d
     if ! [[ $hostonly ]]; then
Harald Hoyer 18c19d
-        find "$srcmods/kernel/$1" "$srcmods/extra" "$srcmods/weak-updates" \
Harald Hoyer 18c19d
-          -name "*.ko" -o -name "*.ko.gz" -o -name "*.ko.xz" 2>/dev/null
Harald Hoyer 18c19d
+        while read a rest; do
Harald Hoyer 18c19d
+            if [[ "${a##kernel}" != "$a" ]]; then
Harald Hoyer 18c19d
+                [[ "${a##kernel/$1}" != "$a" ]] || continue
Harald Hoyer 18c19d
+            fi
Harald Hoyer 18c19d
+            echo $srcmods/${a%:}
Harald Hoyer 18c19d
+        done < $srcmods/modules.dep
Harald Hoyer 18c19d
     else
Harald Hoyer 18c19d
-        cut -d " " -f 1 
Harald Hoyer 18c19d
+        ( cd /sys/module; echo *; ) \
Harald Hoyer 18c19d
         | xargs modinfo -F filename -k $kernel 2>/dev/null
Harald Hoyer 18c19d
     fi
Harald Hoyer 18c19d
 )
Harald Hoyer 18c19d
 
Harald Hoyer 18c19d
-filter_kernel_modules () {
Harald Hoyer 18c19d
-    filter_kernel_modules_by_path  drivers  "$1"
Harald Hoyer 18c19d
-}
Harald Hoyer 18c19d
-
Harald Hoyer 18c19d
 find_kernel_modules () {
Harald Hoyer 18c19d
     find_kernel_modules_by_path  drivers
Harald Hoyer 18c19d
 }
Harald Hoyer 18c19d
@@ -1180,8 +1147,9 @@ instmods() {
Harald Hoyer 18c19d
                 fi
Harald Hoyer 18c19d
                 # If we are building a host-specific initramfs and this
Harald Hoyer 18c19d
                 # module is not already loaded, move on to the next one.
Harald Hoyer 18c19d
-                [[ $hostonly ]] && ! grep -qe "\<${_mod//-/_}\>" /proc/modules \
Harald Hoyer 18c19d
-                    && ! echo $add_drivers | grep -qe "\<${_mod}\>" \
Harald Hoyer 18c19d
+                [[ $hostonly ]] \
Harald Hoyer 18c19d
+                    && ! [[ -d $(echo /sys/module/${_mod//-/_}|{ read a b; echo $a; }) ]] \
Harald Hoyer 18c19d
+                    && ! [[ "$add_drivers" =~ " ${_mod} " ]] \
Harald Hoyer 18c19d
                     && return
Harald Hoyer 18c19d
 
Harald Hoyer 18c19d
                 # We use '-d' option in modprobe only if modules prefix path
Harald Hoyer 18c19d
diff --git a/dracut.sh b/dracut.sh
Harald Hoyer 18c19d
index 49ea503..78e7ac8 100755
Harald Hoyer 18c19d
--- a/dracut.sh
Harald Hoyer 18c19d
+++ b/dracut.sh
Harald Hoyer 18c19d
@@ -555,6 +555,11 @@ srcmods="/lib/modules/$kernel/"
Harald Hoyer 18c19d
 }
Harald Hoyer 18c19d
 export srcmods
Harald Hoyer 18c19d
 
Harald Hoyer 18c19d
+[[ -f $srcmods/modules.dep ]] || {
Harald Hoyer 18c19d
+    dfatal "$srcmods/modules.dep is missing. Did you run depmod?"
Harald Hoyer 18c19d
+    exit 1
Harald Hoyer 18c19d
+}
Harald Hoyer 18c19d
+
Harald Hoyer 18c19d
 if [[ -f $outfile && ! $force ]]; then
Harald Hoyer 18c19d
     dfatal "Will not override existing initramfs ($outfile) without --force"
Harald Hoyer 18c19d
     exit 1
Harald Hoyer 18c19d
diff --git a/modules.d/50plymouth/module-setup.sh b/modules.d/50plymouth/module-setup.sh
Harald Hoyer 18c19d
index 8a675ec..69f1bc7 100755
Harald Hoyer 18c19d
--- a/modules.d/50plymouth/module-setup.sh
Harald Hoyer 18c19d
+++ b/modules.d/50plymouth/module-setup.sh
Harald Hoyer 18c19d
@@ -14,23 +14,53 @@ depends() {
Harald Hoyer 18c19d
 installkernel() {
Harald Hoyer 18c19d
     local _modname
Harald Hoyer 18c19d
     # Include KMS capable drm drivers
Harald Hoyer 18c19d
-    for _modname in $(find "$srcmods/kernel/drivers/gpu/drm" "$srcmods/extra" \( -name '*.ko' -o -name '*.ko.gz' -o -name '*.ko.xz' \) 2>/dev/null); do
Harald Hoyer 18c19d
-        case $_modname in
Harald Hoyer 18c19d
-            *.ko)      grep -q drm_crtc_init $_modname ;;
Harald Hoyer 18c19d
-            *.ko.gz)  zgrep -q drm_crtc_init $_modname ;;
Harald Hoyer 18c19d
-            *.ko.xz) xzgrep -q drm_crtc_init $_modname ;;
Harald Hoyer 18c19d
-        esac
Harald Hoyer 18c19d
-        if test $? -eq 0; then
Harald Hoyer 18c19d
-            # if the hardware is present, include module even if it is not currently loaded,
Harald Hoyer 18c19d
-            # as we could e.g. be in the installer; nokmsboot boot parameter will disable
Harald Hoyer 18c19d
-            # loading of the driver if needed
Harald Hoyer 18c19d
-            if [[ $hostonly ]] && modinfo -F alias $_modname | sed -e 's,\?,\.,g' -e 's,\*,\.\*,g' \
Harald Hoyer 18c19d
-                                  | grep -qxf - /sys/bus/pci/devices/*/modalias; then
Harald Hoyer 18c19d
-                hostonly='' instmods $_modname
Harald Hoyer 18c19d
-                continue
Harald Hoyer 18c19d
-            fi
Harald Hoyer 18c19d
-            instmods $_modname
Harald Hoyer 18c19d
+
Harald Hoyer 18c19d
+    drm_module_filter() {
Harald Hoyer 18c19d
+        local _drm_drivers='drm_crtc_init'
Harald Hoyer 18c19d
+        local _ret
Harald Hoyer 18c19d
+        # subfunctions inherit following FDs
Harald Hoyer 18c19d
+        local _merge=8 _side2=9
Harald Hoyer 18c19d
+        function nmf1() {
Harald Hoyer 18c19d
+            local _fname _fcont
Harald Hoyer 18c19d
+            while read _fname; do
Harald Hoyer 18c19d
+                case "$_fname" in
Harald Hoyer 18c19d
+                    *.ko)    _fcont="$(<        $_fname)" ;;
Harald Hoyer 18c19d
+                    *.ko.gz) _fcont="$(gzip -dc $_fname)" ;;
Harald Hoyer 18c19d
+                    *.ko.xz) _fcont="$(xz -dc   $_fname)" ;;
Harald Hoyer 18c19d
+                esac
Harald Hoyer 18c19d
+                [[   $_fcont =~ $_drm_drivers
Harald Hoyer 18c19d
+                && ! $_fcont =~ iw_handler_get_spy ]] \
Harald Hoyer 18c19d
+                && echo "$_fname"
Harald Hoyer 18c19d
+            done
Harald Hoyer 18c19d
+        }
Harald Hoyer 18c19d
+        function rotor() {
Harald Hoyer 18c19d
+            local _f1 _f2
Harald Hoyer 18c19d
+            while read _f1; do
Harald Hoyer 18c19d
+                echo "$_f1"
Harald Hoyer 18c19d
+                if read _f2; then
Harald Hoyer 18c19d
+                    echo "$_f2" 1>&${_side2}
Harald Hoyer 18c19d
+                fi
Harald Hoyer 18c19d
+            done | nmf1 1>&${_merge}
Harald Hoyer 18c19d
+        }
Harald Hoyer 18c19d
+        # Use two parallel streams to filter alternating modules.
Harald Hoyer 18c19d
+        set +x
Harald Hoyer 18c19d
+        eval "( ( rotor ) ${_side2}>&1 | nmf1 ) ${_merge}>&1"
Harald Hoyer 18c19d
+        _ret=$?
Harald Hoyer 18c19d
+        [[ $debug ]] && set -x
Harald Hoyer 18c19d
+        return $_ret
Harald Hoyer 18c19d
+    }
Harald Hoyer 18c19d
+
Harald Hoyer 18c19d
+    for _modname in $(find_kernel_modules_by_path drivers/gpu/drm \
Harald Hoyer 18c19d
+        | drm_module_filter) ; do
Harald Hoyer 18c19d
+        # if the hardware is present, include module even if it is not currently loaded,
Harald Hoyer 18c19d
+        # as we could e.g. be in the installer; nokmsboot boot parameter will disable
Harald Hoyer 18c19d
+        # loading of the driver if needed
Harald Hoyer 18c19d
+        if [[ $hostonly ]] && modinfo -F alias $_modname | sed -e 's,\?,\.,g' -e 's,\*,\.\*,g' \
Harald Hoyer 18c19d
+            | grep -qxf - /sys/bus/pci/devices/*/modalias; then
Harald Hoyer 18c19d
+            hostonly='' instmods $_modname
Harald Hoyer 18c19d
+            continue
Harald Hoyer 18c19d
         fi
Harald Hoyer 18c19d
+        instmods $_modname
Harald Hoyer 18c19d
     done
Harald Hoyer 18c19d
 }
Harald Hoyer 18c19d