]> git.ipfire.org Git - thirdparty/dracut.git/commitdiff
Add infrastructure for dracut module dependency checking.
authorVictor Lowther <victor.lowther@gmail.com>
Sun, 24 May 2009 05:29:44 +0000 (22:29 -0700)
committerHarald Hoyer <harald@redhat.com>
Mon, 25 May 2009 15:49:39 +0000 (17:49 +0200)
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.

dracut
dracut-functions
modules.d/00test/check [deleted file]
modules.d/00test/copy-root.sh [deleted file]
modules.d/00test/create-root.sh [deleted file]
modules.d/00test/halt.sh [deleted file]
modules.d/90crypt/check
modules.d/90lvm/check
modules.d/90mdraid/check

diff --git a/dracut b/dracut
index 9ec3280622cad2ea120836dd670b55659b956409..3d7930b73c388189a87b80b0c13a51bfc33289ea 100755 (executable)
--- 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"
-
-:
index 179ad1a1d06c79f6674a03e87659b67cb15503d1..ac22fcd635ee86ebac090577b0f017fdfb020cac 100755 (executable)
@@ -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 (executable)
index afe8ade..0000000
+++ /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 (executable)
index fe9f57a..0000000
+++ /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 (executable)
index b6f4912..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/bin/sh
-sfdisk -C 640 -H 2 -S 32 -L /dev/sda <<EOF
-,213
-,213
-,213
-;
-EOF
-mdadm --create /dev/md0 --run --auto=yes --level=5 --raid-devices=3 /dev/sda1 /dev/sda2 /dev/sda3
-echo -n test >keyfile
-cryptsetup -q luksFormat /dev/md0 /keyfile
-echo "The passphrase is test"
-cryptsetup luksOpen /dev/md0 dracut_crypt_test </keyfile
-lvm pvcreate -ff  -y /dev/mapper/dracut_crypt_test
-lvm vgcreate dracut /dev/mapper/dracut_crypt_test
-lvm lvcreate -l 100%FREE -n root dracut
-udevadm settle --timeout=4
-[ -b /dev/dracut/root ] || emergency_shell
-mke2fs /dev/dracut/root
-e2mkdir /dev/dracut/root:/proc
diff --git a/modules.d/00test/halt.sh b/modules.d/00test/halt.sh
deleted file mode 100755 (executable)
index 5d51e8b..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-#!/bin/sh
-umount "$NEWROOT"
-lvm lvchange -a n /dev/dracut/root
-cryptsetup luksClose /dev/mapper/dracut_crypt_test
-poweroff -f
\ No newline at end of file
index 7ab1acb3ee836574722aab8db7d784b66f8c0142..4189eaa7aeec7f6cb748732a9deb79b102291a33 100755 (executable)
@@ -1,8 +1,6 @@
 #!/bin/sh
 
-[[ $dracutfunctions ]] && . $dracutfunctions
-
-find_binary cryptsetup >/dev/null || exit 1
+which cryptsetup >/dev/null 2>&1 || exit 1
 
 if [ "$1" = "-h" ]; then
     blkid | grep -q crypt_LUKS || exit 1
index dc433d94566142b7fb78e19eac0fc6ec043c68b2..3b2a4c3e8186bd71dd5d26d6f6e461031e08a360 100755 (executable)
@@ -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
index d809fb42b5fff59efc2f50f398d972657ba8b061..b5330359415062d641107f70fc9c6e43e429bf9a 100755 (executable)
@@ -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