Blame SOURCES/0066-dracut-lib-wait_for_dev-prevent-systemd-daemon-reloa.patch

a56a5e
From db110a036a13e5c99e073128ec8aa7b1fdc7e992 Mon Sep 17 00:00:00 2001
966cef
From: Harald Hoyer <harald@redhat.com>
966cef
Date: Wed, 18 Dec 2013 12:28:51 +0100
966cef
Subject: [PATCH] dracut-lib/wait_for_dev(): prevent systemd daemon-reload
966cef
966cef
prevent a systemd daemon-reload, if it is not necessary to do.
966cef
---
966cef
 modules.d/98systemd/dracut-cmdline.sh   |  2 --
966cef
 modules.d/98systemd/module-setup.sh     |  2 ++
966cef
 modules.d/98systemd/rootfs-generator.sh | 30 ++++++++++++++++++++++++++++++
966cef
 modules.d/99base/dracut-lib.sh          | 30 ++++++++++++++++++++++++------
966cef
 4 files changed, 56 insertions(+), 8 deletions(-)
966cef
 create mode 100755 modules.d/98systemd/rootfs-generator.sh
966cef
966cef
diff --git a/modules.d/98systemd/dracut-cmdline.sh b/modules.d/98systemd/dracut-cmdline.sh
966cef
index 50b8d6c..36406d9 100755
966cef
--- a/modules.d/98systemd/dracut-cmdline.sh
966cef
+++ b/modules.d/98systemd/dracut-cmdline.sh
966cef
@@ -66,8 +66,6 @@ case "$root" in
966cef
         rootok=1 ;;
966cef
 esac
966cef
 
966cef
-[ "${root%%:*}" = "block" ] && wait_for_dev "${root#block:}"
966cef
-
966cef
 [ -z "$root" ] && die "No or empty root= argument"
966cef
 [ -z "$rootok" ] && die "Don't know how to handle 'root=$root'"
966cef
 
966cef
diff --git a/modules.d/98systemd/module-setup.sh b/modules.d/98systemd/module-setup.sh
966cef
index a5ac2a5..7b3dfa4 100755
966cef
--- a/modules.d/98systemd/module-setup.sh
966cef
+++ b/modules.d/98systemd/module-setup.sh
966cef
@@ -178,6 +178,8 @@ install() {
966cef
     inst_script "$moddir/dracut-mount.sh" /bin/dracut-mount
966cef
     inst_script "$moddir/dracut-pre-pivot.sh" /bin/dracut-pre-pivot
966cef
 
966cef
+    inst_script "$moddir/rootfs-generator.sh" /lib/systemd/system-generators/dracut-rootfs-generator
966cef
+
966cef
     inst_rules 99-systemd.rules
966cef
 
966cef
     for i in \
966cef
diff --git a/modules.d/98systemd/rootfs-generator.sh b/modules.d/98systemd/rootfs-generator.sh
966cef
new file mode 100755
966cef
index 0000000..3770c6b
966cef
--- /dev/null
966cef
+++ b/modules.d/98systemd/rootfs-generator.sh
966cef
@@ -0,0 +1,30 @@
966cef
+#!/bin/sh
966cef
+# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
966cef
+# ex: ts=8 sw=4 sts=4 et filetype=sh
966cef
+
966cef
+type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
966cef
+root=$(getarg root=)
966cef
+case "$root" in
966cef
+    block:LABEL=*|LABEL=*)
966cef
+        root="${root#block:}"
966cef
+        root="$(echo $root | sed 's,/,\\x2f,g')"
966cef
+        root="block:/dev/disk/by-label/${root#LABEL=}"
966cef
+        rootok=1 ;;
966cef
+    block:UUID=*|UUID=*)
966cef
+        root="${root#block:}"
966cef
+        root="block:/dev/disk/by-uuid/${root#UUID=}"
966cef
+        rootok=1 ;;
966cef
+    block:PARTUUID=*|PARTUUID=*)
966cef
+        root="${root#block:}"
966cef
+        root="block:/dev/disk/by-partuuid/${root#PARTUUID=}"
966cef
+        rootok=1 ;;
966cef
+    block:PARTLABEL=*|PARTLABEL=*)
966cef
+        root="${root#block:}"
966cef
+        root="block:/dev/disk/by-partlabel/${root#PARTLABEL=}"
966cef
+        rootok=1 ;;
966cef
+    /dev/*)
966cef
+        root="block:${root}"
966cef
+        rootok=1 ;;
966cef
+esac
966cef
+
966cef
+[ "${root%%:*}" = "block" ] && wait_for_dev -n "${root#block:}"
966cef
diff --git a/modules.d/99base/dracut-lib.sh b/modules.d/99base/dracut-lib.sh
966cef
index 7249c58..a3476ab 100755
966cef
--- a/modules.d/99base/dracut-lib.sh
966cef
+++ b/modules.d/99base/dracut-lib.sh
966cef
@@ -846,7 +846,18 @@ dev_unit_name()
966cef
 wait_for_dev()
966cef
 {
966cef
     local _name
966cef
+    local _needreload
966cef
+    local _noreload
966cef
+
966cef
+    if [ "$1" = "-n" ]; then
966cef
+        _noreload=1
966cef
+        shift
966cef
+    fi
966cef
+
966cef
     _name="$(str_replace "$1" '/' '\x2f')"
966cef
+
966cef
+    [ -e "${PREFIX}$hookdir/initqueue/finished/devexists-${_name}.sh" ] && return 0
966cef
+
966cef
     printf '[ -e "%s" ]\n' $1 \
966cef
         >> "${PREFIX}$hookdir/initqueue/finished/devexists-${_name}.sh"
966cef
     {
966cef
@@ -859,14 +870,21 @@ wait_for_dev()
966cef
         if ! [ -L ${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device ]; then
966cef
             [ -d ${PREFIX}/etc/systemd/system/initrd.target.wants ] || mkdir -p ${PREFIX}/etc/systemd/system/initrd.target.wants
966cef
             ln -s ../${_name}.device ${PREFIX}/etc/systemd/system/initrd.target.wants/${_name}.device
966cef
+            _needreload=1
966cef
         fi
966cef
 
966cef
-        mkdir -p ${PREFIX}/etc/systemd/system/${_name}.device.d
966cef
-        {
966cef
-            echo "[Unit]"
966cef
-            echo "JobTimeoutSec=3600"
966cef
-        } > ${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf
966cef
-        [ -z "$PREFIX" ] && /sbin/initqueue --onetime --unique --name daemon-reload systemctl daemon-reload
966cef
+        if ! [ -f ${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf ]; then
966cef
+            mkdir -p ${PREFIX}/etc/systemd/system/${_name}.device.d
966cef
+            {
966cef
+                echo "[Unit]"
966cef
+                echo "JobTimeoutSec=3600"
966cef
+            } > ${PREFIX}/etc/systemd/system/${_name}.device.d/timeout.conf
966cef
+            _needreload=1
966cef
+        fi
966cef
+
966cef
+        if [ -z "$PREFIX" ] && [ "$_needreload" = 1 ] && [ -z "$_noreload" ]; then
966cef
+            /sbin/initqueue --onetime --unique --name daemon-reload systemctl daemon-reload
966cef
+        fi
966cef
     fi
966cef
 }
966cef