[make-initrd] [PATCH v6 08/22] bootchain-waitdev: introduces an optional waitdev_timeout

Leonid Krivoshein klark.devel at gmail.com
Sun Oct 24 20:21:06 MSK 2021


"waitdev_timeout" describes a common timeout for all "waitdev" steps
in the "bootchain". Defining a timeout allows to use a fallback if
the specified devices are not ready yet. By default is not set, which
makes to wait forever.

Signed-off-by: Leonid Krivoshein <klark.devel at gmail.com>
---
 features/bootchain-waitdev/README.md           |  3 +++
 .../etc/initrd/cmdline.d/bootchain-waitdev     |  1 +
 .../data/lib/bootchain/waitdev                 | 18 ++++++++++++++++++
 .../data/lib/initrd/pre/bootchain/300-waitdev  |  3 +++
 4 files changed, 25 insertions(+)

diff --git a/features/bootchain-waitdev/README.md b/features/bootchain-waitdev/README.md
index 126a904..d6bae63 100644
--- a/features/bootchain-waitdev/README.md
+++ b/features/bootchain-waitdev/README.md
@@ -13,6 +13,9 @@ feature. It allows to wait a specified block or character special devices.
    the same as `root=`, but with optional `CDROM:` prefix. This parameter can be
    specified more than once depending on how many times a corresponding element
    is mentioned in the `bootchain`.
+- `waitdev_timeout` describes a common timeout for all `waitdev` steps in the
+  `bootchain`. Defining a timeout allows to use a fallback if the specified
+  devices are not ready yet. By default is not set, which makes to wait forever.
 
 ## Example
 
diff --git a/features/bootchain-waitdev/data/etc/initrd/cmdline.d/bootchain-waitdev b/features/bootchain-waitdev/data/etc/initrd/cmdline.d/bootchain-waitdev
index 3544c25..6929a86 100644
--- a/features/bootchain-waitdev/data/etc/initrd/cmdline.d/bootchain-waitdev
+++ b/features/bootchain-waitdev/data/etc/initrd/cmdline.d/bootchain-waitdev
@@ -1 +1,2 @@
 register_array string WAITDEV
+register_parameter number WAITDEV_TIMEOUT
diff --git a/features/bootchain-waitdev/data/lib/bootchain/waitdev b/features/bootchain-waitdev/data/lib/bootchain/waitdev
index 60464d9..fa99c45 100755
--- a/features/bootchain-waitdev/data/lib/bootchain/waitdev
+++ b/features/bootchain-waitdev/data/lib/bootchain/waitdev
@@ -3,6 +3,14 @@
 . bootchain-sh-functions
 
 check_parameter WAITDEV
+
+timeout=
+timecnt=/.initrd/bootchain/waitdev/TIMECNT
+
+[ ! -s "$timecnt" ] ||
+	read -r timeout < "$timecnt" ||:
+[ "$timeout" != 0 ] ||
+	exit 0
 devspec="$(get_parameter WAITDEV)"
 
 while [ -n "$devspec" ]; do
@@ -25,4 +33,14 @@ while [ -n "$devspec" ]; do
 	fi
 
 	sleep 1
+	[ -n "$timeout" ] ||
+		continue
+	timeout=$(($timeout - 1))
+
+	if [ "$timeout" = 0 ]; then
+		message "device waiting timeout exceedded"
+		break
+	fi
 done
+
+[ -z "$timeout" ] || printf '%s\n' "$timeout" > "$timecnt"
diff --git a/features/bootchain-waitdev/data/lib/initrd/pre/bootchain/300-waitdev b/features/bootchain-waitdev/data/lib/initrd/pre/bootchain/300-waitdev
index 3642722..5e0f040 100755
--- a/features/bootchain-waitdev/data/lib/initrd/pre/bootchain/300-waitdev
+++ b/features/bootchain-waitdev/data/lib/initrd/pre/bootchain/300-waitdev
@@ -5,6 +5,9 @@
 dir=/.initrd/bootchain/waitdev
 mkdir -p -- "$dir"
 
+[ -z "${WAITDEV_TIMEOUT-}" ] ||
+	printf '%s\n' "$WAITDEV_TIMEOUT" >"$dir"/TIMECNT
+
 i=0
 while [ "$i" -lt "${WAITDEV:-0}" ]; do
 	touch "$dir/$i"
-- 
2.24.1



More information about the Make-initrd mailing list