Blame SOURCES/0561-rootfs-generator-rebase-to-upstream-version.patch

18971c
From e42ab58a70ae646d09c319c125154e970e25a994 Mon Sep 17 00:00:00 2001
18971c
From: Lukas Nykryn <lnykryn@redhat.com>
18971c
Date: Thu, 25 Apr 2019 10:11:58 +0200
18971c
Subject: [PATCH] rootfs-generator: rebase to upstream version
18971c
18971c
Resolves: #1640866
18971c
---
18971c
 modules.d/98systemd/rootfs-generator.sh | 87 ++++++++++++++++++++-----
18971c
 1 file changed, 70 insertions(+), 17 deletions(-)
18971c
18971c
diff --git a/modules.d/98systemd/rootfs-generator.sh b/modules.d/98systemd/rootfs-generator.sh
18971c
index a7bffdfd..4ae693bb 100755
18971c
--- a/modules.d/98systemd/rootfs-generator.sh
18971c
+++ b/modules.d/98systemd/rootfs-generator.sh
18971c
@@ -1,6 +1,4 @@
18971c
 #!/bin/sh
18971c
-# -*- mode: shell-script; indent-tabs-mode: nil; sh-basic-offset: 4; -*-
18971c
-# ex: ts=8 sw=4 sts=4 et filetype=sh
18971c
 
18971c
 type getarg >/dev/null 2>&1 || . /lib/dracut-lib.sh
18971c
 
18971c
@@ -10,32 +8,81 @@ generator_wait_for_dev()
18971c
     local _timeout
18971c
 
18971c
     _name="$(str_replace "$1" '/' '\x2f')"
18971c
+    _timeout=$(getarg rd.timeout)
18971c
+    _timeout=${_timeout:-0}
18971c
 
18971c
-    [ -e "$hookdir/initqueue/finished/devexists-${_name}.sh" ] && return 0
18971c
+    if ! [ -e "$hookdir/initqueue/finished/devexists-${_name}.sh" ]; then
18971c
 
18971c
-    printf '[ -e "%s" ]\n' $1 \
18971c
-        >> "$hookdir/initqueue/finished/devexists-${_name}.sh"
18971c
-    {
18971c
-        printf '[ -e "%s" ] || ' $1
18971c
-        printf 'warn "\"%s\" does not exist"\n' $1
18971c
-    } >> "$hookdir/emergency/80-${_name}.sh"
18971c
+        printf '[ -e "%s" ]\n' $1 \
18971c
+            >> "$hookdir/initqueue/finished/devexists-${_name}.sh"
18971c
+        {
18971c
+            printf '[ -e "%s" ] || ' $1
18971c
+            printf 'warn "\"%s\" does not exist"\n' $1
18971c
+        } >> "$hookdir/emergency/80-${_name}.sh"
18971c
+    fi
18971c
 
18971c
     _name=$(dev_unit_name "$1")
18971c
-    if ! [ -L /run/systemd/generator/initrd.target.wants/${_name}.device ]; then
18971c
-        [ -d /run/systemd/generator/initrd.target.wants ] || mkdir -p /run/systemd/generator/initrd.target.wants
18971c
-        ln -s ../${_name}.device /run/systemd/generator/initrd.target.wants/${_name}.device
18971c
+    if ! [ -L "$GENERATOR_DIR"/initrd.target.wants/${_name}.device ]; then
18971c
+        [ -d "$GENERATOR_DIR"/initrd.target.wants ] || mkdir -p "$GENERATOR_DIR"/initrd.target.wants
18971c
+        ln -s ../${_name}.device "$GENERATOR_DIR"/initrd.target.wants/${_name}.device
18971c
     fi
18971c
 
18971c
-    if ! [ -f /run/systemd/generator/${_name}.device.d/timeout.conf ]; then
18971c
-        _timeout=$(getarg rd.device.timeout || printf "0")
18971c
-        mkdir -p /run/systemd/generator/${_name}.device.d
18971c
+    if ! [ -f "$GENERATOR_DIR"/${_name}.device.d/timeout.conf ]; then
18971c
+        mkdir -p "$GENERATOR_DIR"/${_name}.device.d
18971c
         {
18971c
             echo "[Unit]"
18971c
             echo "JobTimeoutSec=$_timeout"
18971c
-        } > /run/systemd/generator/${_name}.device.d/timeout.conf
18971c
+            echo "JobRunningTimeoutSec=$_timeout"
18971c
+        } > "$GENERATOR_DIR"/${_name}.device.d/timeout.conf
18971c
+    fi
18971c
+}
18971c
+
18971c
+generator_mount_rootfs()
18971c
+{
18971c
+    local _type=$2
18971c
+    local _flags=$3
18971c
+    local _name
18971c
+
18971c
+    [ -z "$1" ] && return 0
18971c
+
18971c
+    _name=$(dev_unit_name "$1")
18971c
+    [ -d "$GENERATOR_DIR" ] || mkdir -p "$GENERATOR_DIR"
18971c
+    if ! [ -f "$GENERATOR_DIR"/sysroot.mount ]; then
18971c
+        {
18971c
+            echo "[Unit]"
18971c
+            echo "Before=initrd-root-fs.target"
18971c
+            echo "Requires=systemd-fsck@${_name}.service"
18971c
+            echo "After=systemd-fsck@${_name}.service"
18971c
+            echo "[Mount]"
18971c
+            echo "Where=/sysroot"
18971c
+            echo "What=$1"
18971c
+            echo "Options=${_flags}"
18971c
+            echo "Type=${_type}"
18971c
+        } > "$GENERATOR_DIR"/sysroot.mount
18971c
+    fi
18971c
+    if ! [ -L "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount ]; then
18971c
+        [ -d "$GENERATOR_DIR"/initrd-root-fs.target.requires ] || mkdir -p "$GENERATOR_DIR"/initrd-root-fs.target.requires
18971c
+        ln -s ../sysroot.mount "$GENERATOR_DIR"/initrd-root-fs.target.requires/sysroot.mount
18971c
     fi
18971c
 }
18971c
 
18971c
+generator_fsck_after_pre_mount()
18971c
+{
18971c
+    local _name
18971c
+
18971c
+    [ -z "$1" ] && return 0
18971c
+
18971c
+    _name=$(dev_unit_name "$1")
18971c
+    [ -d /run/systemd/generator/systemd-fsck@${_name}.service.d ] || mkdir -p /run/systemd/generator/systemd-fsck@${_name}.service.d
18971c
+    if ! [ -f /run/systemd/generator/systemd-fsck@${_name}.service.d/after-pre-mount.conf ]; then
18971c
+        {
18971c
+            echo "[Unit]"
18971c
+            echo "After=dracut-pre-mount.service"
18971c
+        } > /run/systemd/generator/systemd-fsck@${_name}.service.d/after-pre-mount.conf
18971c
+    fi
18971c
+
18971c
+}
18971c
+
18971c
 root=$(getarg root=)
18971c
 case "$root" in
18971c
     block:LABEL=*|LABEL=*)
18971c
@@ -62,6 +109,12 @@ case "$root" in
18971c
         rootok=1 ;;
18971c
 esac
18971c
 
18971c
-[ "${root%%:*}" = "block" ] && generator_wait_for_dev "${root#block:}"
18971c
+GENERATOR_DIR="$1"
18971c
+
18971c
+if [ "$rootok" = "1"  ]; then
18971c
+   generator_wait_for_dev "${root#block:}" "$RDRETRY"
18971c
+   generator_fsck_after_pre_mount "${root#block:}"
18971c
+   strstr "$(cat /proc/cmdline)" 'root=' || generator_mount_rootfs "${root#block:}" "$(getarg rootfstype=)" "$(getarg rootflags=)"
18971c
+fi
18971c
 
18971c
 exit 0