From: Harald Hoyer Date: Wed, 11 Sep 2013 07:57:52 +0000 (+0200) Subject: dracut-functions.sh: extend module_is_host_only() X-Git-Tag: 033~2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3c4315fa1368f1ee12dfa8abb5dd7c3556da79f8;p=thirdparty%2Fdracut.git dracut-functions.sh: extend module_is_host_only() If the currently running kernel is not present in the installer root, fall back to modalias checking. --- diff --git a/dracut-functions.sh b/dracut-functions.sh index 1d39a6d38..cf33af56a 100755 --- a/dracut-functions.sh +++ b/dracut-functions.sh @@ -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 } diff --git a/dracut.sh b/dracut.sh index fcc489e43..1442a824a 100755 --- 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