Blame 0073-dracut-lib-wait_for_dev-prevent-systemd-daemon-reloa.patch

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