Split kernel module loading into smaller chunks.

This prepares to more tightly integrate dracut-gencmdline with the
rest of the dracut scripts
master
Victor Lowther 2009-08-15 14:17:19 -05:00
parent 0c1a8ebc37
commit ddfd1d10a0
4 changed files with 43 additions and 35 deletions

2
dracut
View File

@ -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


View File

@ -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

View File

@ -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

View File

@ -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'