Skip to content

Commit

Permalink
feat(dracut): support parallel execution with --parallel
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
mwilck authored and johannbg committed Jun 17, 2022
1 parent d9812fc commit 6d92326
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 35 deletions.
99 changes: 64 additions & 35 deletions dracut.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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: \
Expand Down Expand Up @@ -447,6 +450,7 @@ rearrange_params() {
--long keep \
--long printsize \
--long regenerate-all \
--long parallel \
--long noimageifnotneeded \
--long early-microcode \
--long no-early-microcode \
Expand Down Expand Up @@ -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" ;;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions man/dracut.8.asc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions man/dracut.conf.5.asc
Original file line number Diff line number Diff line change
Expand Up @@ -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_::
Expand Down

0 comments on commit 6d92326

Please sign in to comment.