121229
From 7ee74e539dba61c3765afe34426b085eff0de027 Mon Sep 17 00:00:00 2001
121229
From: Kairui Song <kasong@redhat.com>
121229
Date: Thu, 21 Feb 2019 13:18:37 +0800
121229
Subject: [PATCH] dracut: let module handling function accept optional path
121229
 option
121229
121229
Let the caller pass in the module path instead of try to find the module
121229
path everytime. This helps optimize the overall runtime.
121229
121229
Test results (3 rounds) on Fedora 30 in KVM VM with 8 CPUs, 2G memory, HDD:
121229
121229
    $ time ./dracut.sh --local --quiet --hostonly --hostonly-cmdline --hostonly-i18n --hostonly-mode 'strict' -o 'plymouth dash resume ifcfg' --mount '/dev/mapper/fedora-root /sysroot xfs defaults' --no-hostonly-default-device -f initramfs.img
121229
    Before the commit:
121229
    real    0m11.782s  |  real    0m11.505s  |  real    0m11.958s
121229
    user    0m9.169s   |  user    0m9.218s   |  user    0m9.327s
121229
    sys     0m10.839s  |  sys     0m10.829s  |  sys     0m10.925s
121229
121229
    After this commit:
121229
    real    0m9.866s  |  real    0m9.580s  |  real    0m9.638s
121229
    user    0m9.048s  |  user    0m9.142s  |  user    0m9.120s
121229
    sys     0m7.411s  |  sys     0m7.775s  |  sys     0m7.745s
121229
121229
Test result of building a ordinary image:
121229
121229
    $ time ./dracut.sh --local --quiet -f initramfs.img
121229
    Before the commit:
121229
    real    0m34.697s  |  real    0m34.371s  |  real    0m35.122s
121229
    user    0m27.608s  |  user    0m27.524s  |  user    0m27.705s
121229
    sys     0m22.341s  |  sys     0m22.032s  |  sys     0m22.246s
121229
121229
    After the commit:
121229
    real    0m31.914s  |  real    0m31.006  |  real    0m31.289ss
121229
    user    0m27.315s  |  user    0m27.324  |  user    0m27.290ss
121229
    sys     0m19.051s  |  sys     0m18.916  |  sys     0m19.022ss
121229
121229
This will have an ~2s speed up.
121229
121229
Signed-off-by: Kairui Song <kasong@redhat.com>
121229
(cherry picked from commit 5916d31b24ad9eb21fd376929a96c459813315a1)
121229
121229
Cherry-picked from: 5916d31b
121229
Resolves: #1734047
121229
---
121229
 dracut-init.sh | 4 ++++
121229
 dracut.sh      | 8 ++++----
121229
 2 files changed, 8 insertions(+), 4 deletions(-)
121229
121229
diff --git a/dracut-init.sh b/dracut-init.sh
121229
index b1ac9966..ab07cabf 100644
121229
--- a/dracut-init.sh
121229
+++ b/dracut-init.sh
121229
@@ -154,6 +154,10 @@ dracut_no_switch_root() {
121229
     >"$initdir/lib/dracut/no-switch-root"
121229
 }
121229
 
121229
+dracut_module_path() {
121229
+    echo ${dracutbasedir}/modules.d/??${1} | { read a b; echo "$a"; }
121229
+}
121229
+
121229
 if ! [[ $DRACUT_INSTALL ]]; then
121229
     DRACUT_INSTALL=$(find_binary dracut-install)
121229
 fi
121229
diff --git a/dracut.sh b/dracut.sh
121229
index 8144a16e..f270af76 100755
121229
--- a/dracut.sh
121229
+++ b/dracut.sh
121229
@@ -1373,7 +1373,7 @@ do_print_cmdline()
121229
     for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
121229
         _d_mod=${moddir##*/}; _d_mod=${_d_mod#[0-9][0-9]}
121229
         [[ ${_mods_to_print[$_d_mod]} ]] || continue
121229
-        module_cmdline "$_d_mod"
121229
+        module_cmdline "$_d_mod" "$moddir"
121229
     done
121229
     unset moddir
121229
 }
121229
@@ -1454,14 +1454,14 @@ for moddir in "$dracutbasedir/modules.d"/[0-9][0-9]*; do
121229
         dinfo "*** Including module: $_d_mod ***"
121229
     fi
121229
     if [[ $kernel_only == yes ]]; then
121229
-        module_installkernel "$_d_mod" || {
121229
+        module_installkernel "$_d_mod" "$moddir" || {
121229
             dfatal "installkernel failed in module $_d_mod"
121229
             exit 1
121229
         }
121229
     else
121229
-        module_install "$_d_mod"
121229
+        module_install "$_d_mod" "$moddir"
121229
         if [[ $no_kernel != yes ]]; then
121229
-            module_installkernel "$_d_mod" || {
121229
+            module_installkernel "$_d_mod" "$moddir" || {
121229
                 dfatal "installkernel failed in module $_d_mod"
121229
                 exit 1
121229
             }
121229