From: Victor Lowther Date: Sun, 24 May 2009 05:29:44 +0000 (-0700) Subject: Add infrastructure for dracut module dependency checking. X-Git-Tag: 0.1~181 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0c2e3d122195ad6e247c3bf85c677019f98dc7c8;p=thirdparty%2Fdracut.git Add infrastructure for dracut module dependency checking. This also eliminates --skip-missing. Check scripts should now check to ensure that any files and settings they will copy from the host system actually exist when called without arguments. The check scripts are also updated to not try to source dracut-functions which(1) is a perfectly good way of checking if a command is on the path. --- diff --git a/dracut b/dracut index 9ec328062..3d7930b73 100755 --- a/dracut +++ b/dracut @@ -37,8 +37,6 @@ Creates initial ramdisk images for preloading modules Target directory in the final initramfs. -I, --install [LIST] Install the space separated list of files into the initramfs. - --skip-missing Do not quit on missing module dependencies but skip - these. " } @@ -56,7 +54,6 @@ while (($# > 0)); do -H|--hostonly) hostonly="-h" ;; -i|--include) include_src="$2"; include_target="$3"; shift 2;; -I|--install) install_items="$2"; shift;; - --skip-missing) skipmissing="yes" ;; *) break ;; esac shift @@ -89,16 +86,13 @@ export dracutfunctions case $dracutmodules in ""|auto) dracutmodules="all" - skipmissing="yes" ;; hostonly) dracutmodules="all" - skipmissing="yes" hostonly="-h" ;; esac - [[ $2 ]] && kernel=$2 || kernel=$(uname -r) [[ $1 ]] && outfile=$(readlink -f $1) || outfile="/boot/initrd-$kernel.img" @@ -122,31 +116,13 @@ for d in bin sbin usr/bin usr/sbin usr/lib etc proc sys sysroot dev/pts var/run; mkdir -p "$initdir/$d"; done -# these bits are fugly, and need some cleanup. -# Actually documenting how dracut modules work these days would be good. -skip_missing() { - # $1 = location of module - [[ $skipmissing ]] || return 0 - [[ -x $1/check ]] || return 0 - "$1/check" $hostonly -} - -can_source_module() { - # $1 = location of module - mod=${1##*/}; mod=${mod#[0-9][0-9]}; - if [[ $dracutmodules != all ]]; then - strstr "$dracutmodules " "$mod " || return 1 - fi - strstr "$omit_dracutmodules " "$mod " && return 1 - skip_missing "$1" -} - -# source all our modules -for moddir in "$dsrc/modules.d"/*; do - [[ -d $moddir || -L $moddir ]] || continue - can_source_module "$moddir" || continue - dinfo "Using module: $moddir" - [[ -x $moddir/install ]] && . "$moddir/install" +# check all our modules to see if they should be sourced +check_modules + +#source our modules. +for moddir in "$dsrc/modules.d"/[0-9][0-9]*; do + mod=${moddir##*/}; mod=${mod#[0-9][0-9]} + strstr "$mods_to_load" "$mod" && . "$moddir/install" done unset moddir @@ -176,5 +152,3 @@ unset item ( cd "$initdir"; find . |cpio -H newc -o |gzip -9 > "$outfile"; ) [[ "$beverbose" = "yes" ]] && ls -lh "$outfile" - -: diff --git a/dracut-functions b/dracut-functions index 179ad1a1d..ac22fcd63 100755 --- a/dracut-functions +++ b/dracut-functions @@ -201,6 +201,57 @@ dracut_install() { done } +memoize() { + local cmd=memoize_$@ ret + cmd=${cmd//[^[:alnum:]]/_} + [[ ${!cmd} ]] && return ${!cmd} + "$@" + ret=$? + eval "$cmd=$ret" + return $ret +} + +check_module_deps() { + local moddir dep + # turn a module name into a directory, if we can. + moddir=$(echo ${dsrc}/modules.d/??${1}) + [[ -d $moddir && -x $moddir/install ]] || return 1 + # if we do not have a check script, we are unconditionally included + if [[ -x $moddir/check ]]; then + memoize "$moddir/check" || return 1 + for dep in $("$moddir/check" -d); do + memoize check_module_deps "$dep" && continue + dwarning "Dependency $mod failed." + return 1 + done + fi + mods_to_load+=" $1 " +} + +should_source_module() { + local dep + [[ -x $1/install ]] || return 1 + [[ -x $1/check ]] || return 0 + "$1/check" $hostonly || return 1 + for dep in $("$1/check" -d); do + memoize check_module_deps "$dep" && continue + dwarning "Cannot load $mod, dependencies failed." + return 1 + done +} + +check_modules() { + for moddir in "$dsrc/modules.d"/[0-9][0-9]*; do + local mod=${moddir##*/}; mod=${mod#[0-9][0-9]} + [[ -d $moddir ]] || continue + [[ $dracutmodules != all ]] && ! strstr "$dracutmodules" "$mod" && \ + continue + strstr "$omit_dracutmodules" "$mod" && continue + should_source_module "$moddir" || continue + mods_to_load+=" $mod " + done +} + # install modules, and handle installing all their dependencies as well. instmods() { local mod mpargs modpath modname cmd diff --git a/modules.d/00test/check b/modules.d/00test/check deleted file mode 100755 index afe8ade3e..000000000 --- a/modules.d/00test/check +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/bash -exit 1 diff --git a/modules.d/00test/copy-root.sh b/modules.d/00test/copy-root.sh deleted file mode 100755 index fe9f57ae9..000000000 --- a/modules.d/00test/copy-root.sh +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/sh -cp -a -t "$NEWROOT" /source/* \ No newline at end of file diff --git a/modules.d/00test/create-root.sh b/modules.d/00test/create-root.sh deleted file mode 100755 index b6f491269..000000000 --- a/modules.d/00test/create-root.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/sh -sfdisk -C 640 -H 2 -S 32 -L /dev/sda <keyfile -cryptsetup -q luksFormat /dev/md0 /keyfile -echo "The passphrase is test" -cryptsetup luksOpen /dev/md0 dracut_crypt_test /dev/null || exit 1 +which cryptsetup >/dev/null 2>&1 || exit 1 if [ "$1" = "-h" ]; then blkid | grep -q crypt_LUKS || exit 1 diff --git a/modules.d/90lvm/check b/modules.d/90lvm/check index dc433d945..3b2a4c3e8 100755 --- a/modules.d/90lvm/check +++ b/modules.d/90lvm/check @@ -1,8 +1,5 @@ #!/bin/sh - -[[ $dracutfunctions ]] && . $dracutfunctions - -find_binary lvm >/dev/null || exit 1 +which lvm >/dev/null 2>&1 || exit 1 if [ "$1" = "-h" ]; then blkid | grep -q lvm2pv || exit 1 diff --git a/modules.d/90mdraid/check b/modules.d/90mdraid/check index d809fb42b..b53303594 100755 --- a/modules.d/90mdraid/check +++ b/modules.d/90mdraid/check @@ -1,8 +1,5 @@ #!/bin/sh - -[[ $dracutfunctions ]] && . $dracutfunctions - -find_binary mdadm >/dev/null || exit 1 +which mdadm >/dev/null 2>&1 || exit 1 if [ "$1" = "-h" ]; then blkid | grep -q linux_raid || exit 1