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

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