]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
feat(dracut): support parallel execution with --parallel
authorMartin Wilck <mwilck@suse.com>
Thu, 9 Jun 2022 11:32:17 +0000 (13:32 +0200)
committerJóhann B. Guðmundsson <johannbg@gmail.com>
Fri, 17 Jun 2022 16:47:44 +0000 (16:47 +0000)
Add an option --parallel which can currently be used with
--regenerate-all. With --regenerate-all --parallel, dracut will be
run in parallel for all kernels found.

Also introduce a config file equivalent setting: parallel="yes".
Making this work requires moving the code block that handles --regenerate-all
behind the code block for reading the config files.

Signed-off-by: Martin Wilck <mwilck@suse.com>
dracut.sh
man/dracut.8.asc
man/dracut.conf.5.asc

index 0b7199661a0a5aa5fd40491d90567ea00ab07c06..a1ea1bc32443726ebb5d1c542bf6063ca30b1043 100755 (executable)
--- a/dracut.sh
+++ b/dracut.sh
@@ -273,6 +273,9 @@ Creates initial ramdisk images for preloading modules
   --kernel-image [FILE] Location of the kernel image.
   --regenerate-all      Regenerate all initramfs images at the default location
                          for the kernel versions found on the system.
+  -p, --parallel        Use parallel processing if possible (currently only
+                        supported --regenerate-all)
+                        images simultaneously.
   --version             Display version.
 
 If [LIST] has multiple arguments, then you have to put these in quotes.
@@ -368,7 +371,7 @@ rearrange_params() {
     TEMP=$(
         unset POSIXLY_CORRECT
         getopt \
-            -o "a:m:o:d:I:k:c:r:L:fvqlHhMN" \
+            -o "a:m:o:d:I:k:c:r:L:fvqlHhMNp" \
             --long kver: \
             --long add: \
             --long force-add: \
@@ -447,6 +450,7 @@ rearrange_params() {
             --long keep \
             --long printsize \
             --long regenerate-all \
+            --long parallel \
             --long noimageifnotneeded \
             --long early-microcode \
             --long no-early-microcode \
@@ -813,7 +817,8 @@ while :; do
             ;;
         --keep) keep="yes" ;;
         --printsize) printsize="yes" ;;
-        --regenerate-all) regenerate_all="yes" ;;
+        --regenerate-all) regenerate_all_l="yes" ;;
+        -p | --parallel) parallel_l="yes" ;;
         --noimageifnotneeded) noimageifnotneeded="yes" ;;
         --reproducible) reproducible_l="yes" ;;
         --no-reproducible) reproducible_l="no" ;;
@@ -870,37 +875,6 @@ done
 
 [[ $sysroot_l ]] && dracutsysrootdir="$sysroot_l"
 
-if [[ $regenerate_all == "yes" ]]; then
-    ret=0
-    if [[ $kernel ]]; then
-        printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
-        exit 1
-    fi
-
-    if [[ $outfile ]]; then
-        printf -- "--regenerate-all cannot be called with a image file\n" >&2
-        exit 1
-    fi
-
-    ((len = ${#dracut_args[@]}))
-    for ((i = 0; i < len; i++)); do
-        [[ ${dracut_args[$i]} == "--regenerate-all" ]] \
-            && unset dracut_args["$i"]
-    done
-
-    cd "$dracutsysrootdir"/lib/modules || exit 1
-    for i in *; do
-        [[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
-        "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
-        ((ret += $?))
-    done
-    exit "$ret"
-fi
-
-if ! [[ $kernel ]]; then
-    kernel=$(uname -r)
-fi
-
 export LC_ALL=C
 export LANG=C
 unset LC_MESSAGES
@@ -961,6 +935,62 @@ for f in $(dropindirs_sort ".conf" "$confdir" "$dracutbasedir/dracut.conf.d"); d
     [[ -e $f ]] && . "$f"
 done
 
+# regenerate_all shouldn't be set in conf files
+regenerate_all=$regenerate_all_l
+if [[ $parallel_l == "yes" ]]; then
+    parallel=yes
+fi
+
+if [[ $regenerate_all == "yes" ]]; then
+    ret=0
+    if [[ $kernel ]]; then
+        printf -- "--regenerate-all cannot be called with a kernel version\n" >&2
+        exit 1
+    fi
+
+    if [[ $outfile ]]; then
+        printf -- "--regenerate-all cannot be called with a image file\n" >&2
+        exit 1
+    fi
+
+    ((len = ${#dracut_args[@]}))
+    for ((i = 0; i < len; i++)); do
+        case ${dracut_args[$i]} in
+            --regenerate-all | --parallel)
+                unset dracut_args["$i"]
+                ;;
+        esac
+    done
+
+    cd "$dracutsysrootdir"/lib/modules || exit 1
+    if [[ $parallel != "yes" ]]; then
+        for i in *; do
+            [[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
+            "$dracut_cmd" --kver="$i" "${dracut_args[@]}"
+            ((ret += $?))
+        done
+    else
+        for i in *; do
+            [[ -f $i/modules.dep ]] || [[ -f $i/modules.dep.bin ]] || continue
+            "$dracut_cmd" --kver="$i" "${dracut_args[@]}" &
+        done
+        while true; do
+            wait -n
+            wst=$?
+            if [[ $wst == 127 ]]; then
+                break
+            else
+                ((ret += wst))
+            fi
+        done
+    fi
+    exit "$ret"
+fi
+
+if ! [[ $kernel ]]; then
+    kernel=$(uname -r)
+fi
+
 DRACUT_PATH=${DRACUT_PATH:-/sbin /bin /usr/sbin /usr/bin}
 
 for i in $DRACUT_PATH; do
@@ -1332,8 +1362,7 @@ dinfo "Executing: $dracut_cmd ${dracut_args[*]}"
 [[ $do_list == yes ]] && {
     for mod in "$dracutbasedir"/modules.d/*; do
         [[ -d $mod ]] || continue
-        [[ -e $mod/install || -e $mod/installkernel || -e \
-        $mod/module-setup.sh ]] || continue
+        [[ -e $mod/install || -e $mod/installkernel || -e $mod/module-setup.sh ]] || continue
         printf "%s\n" "${mod##*/??}"
     done
     exit 0
index 83b46938b64ace90306283f6fcb363f0347663ba..bfb86f5de14f837af074490afdac9d4bd9375c22 100644 (file)
@@ -558,6 +558,11 @@ will not be able to boot. Equivalent to "--compress=zstd -15 -q -T0".
     Regenerate all initramfs images at the default location with the kernel
     versions found on the system. Additional parameters are passed through.
 
+**-p, --parallel**::
+    Try to execute tasks in parallel. Currently only supported with
+    **--regenerate-all** (build initramfs images for all kernel
+    versions simultaneously).
+
 **--noimageifnotneeded**::
     Do not create an image in host-only mode, if no kernel driver is needed
 and no /etc/cmdline/*.conf will be generated into the initramfs.
index 5b1bf4660337fd8c2dfec6509a916de2d771e191..96c801292f9b86d6a428f8ff435e415c2d65e9d5 100644 (file)
@@ -308,6 +308,10 @@ Logging levels:
     parameters, with initramfs source files, **tmpdir** staging area and
     destination all on the same copy-on-write capable filesystem.
 
+*parallel=*"__{yes|no}__"::
+   If set to _yes_, try to execute tasks in parallel (currently only supported
+   for _--regenerate-all_).
+
 Files
 -----
 _/etc/dracut.conf_::