Make-initrd development discussion
 help / color / mirror / Atom feed
From: Alexey Gladkov <gladkov.alexey@gmail.com>
To: make-initrd@lists.altlinux.org
Subject: [make-initrd] [PATCH] runtime: Freeze rootdelay countdown while paused
Date: Wed, 21 Oct 2026 12:10:27 +0200
Message-ID: <20261021101032.278166-1-gladkov.alexey@gmail.com> (raw)
In-Reply-To: <5471301a-a86f-4d22-b606-689eff804df8@gmail.com>

The rootdelay service tracks device discovery timeouts against an
absolute deadline timestamp. When rootdelay_pause is invoked (e.g.,
during fsck filesystem checks), the deadline was left unchanged while
boottime continued to advance. When unpaused, the time spent waiting on
the blocking operation was counted against the rootdelay allowance,
often causing the timeout to expire immediately.

Fix this by recording the timestamp when pausing and shifting the
deadline forward by the elapsed pause duration upon unpause. Atomic
mkdir and directory renaming are used to eliminate time-of-check to
time-of-use races between concurrent callers. If the timer is reset
while paused, advance the recorded pause start timestamp to prevent
adding duplicate time.

Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
---

Ты имеешь в виду что-то типа вот такого поведения ?

---

 features/runtime/data/bin/initrd-sh-functions | 59 ++++++++++++++++---
 features/runtime/data/sbin/rootdelayd         |  4 +-
 2 files changed, 54 insertions(+), 9 deletions(-)

diff --git a/features/runtime/data/bin/initrd-sh-functions b/features/runtime/data/bin/initrd-sh-functions
index a69eabee..be8d7182 100644
--- a/features/runtime/data/bin/initrd-sh-functions
+++ b/features/runtime/data/bin/initrd-sh-functions
@@ -126,17 +126,57 @@ write_atomic()
 	fi
 }
 
-_rootdelay_pause=/.initrd/rootdelay/pause
-_rootdelay_timestamp=/.initrd/rootdelay/deadline
+current_seconds()
+{
+	local __v=
+	__v="$("${TIMESTAMP:-timestamp}" boottime raw 2>/dev/null)" ||:
+	__v="${__v%.*}"
+	eval "$1=\"\$__v\""
+}
+
+_rootdelay_pause="${_rootdelay_pause:-/.initrd/rootdelay/pause}"
+_rootdelay_timestamp="${_rootdelay_timestamp:-/.initrd/rootdelay/deadline}"
 
 rootdelay_pause()
 {
-	mkdir -p "$_rootdelay_pause"
+	local now
+
+	mkdir -p -- "${_rootdelay_pause%/*}"
+	if ! mkdir "$_rootdelay_pause" 2>/dev/null; then
+		return 0
+	fi
+
+	current_seconds now
+	write_atomic "$_rootdelay_pause/start" printf '%s\n' "$now"
 }
 
 rootdelay_unpause()
 {
-	rm -rf "$_rootdelay_pause"
+	local pause_dir="$_rootdelay_pause.$$.$BASHPID"
+	local pause_start now paused_duration deadline
+
+	if ! mv "$_rootdelay_pause" "$pause_dir" 2>/dev/null; then
+		return 0
+	fi
+
+	if [ -f "$pause_dir/start" ]; then
+		readline pause_start "$pause_dir/start"
+
+		if [ -n "$pause_start" ] && [ -f "$_rootdelay_timestamp" ]; then
+			current_seconds now
+			paused_duration=$(( $now - $pause_start ))
+
+			if [ "$paused_duration" -gt 0 ]; then
+				readline deadline "$_rootdelay_timestamp"
+
+				if [ -n "$deadline" ] && [ "$deadline" -gt 0 ]; then
+					rootdelay_set_deadline "$(( $deadline + $paused_duration ))"
+				fi
+			fi
+		fi
+	fi
+
+	rm -rf "$pause_dir"
 }
 
 rootdelay_paused()
@@ -153,11 +193,16 @@ rootdelay_set_deadline()
 rootdelay_reset_timer()
 {
 	local now="${1-}"
+
 	if [ -z "$now" ]; then
-		now="$(timestamp boottime raw)"
-		now="${now%.*}"
+		current_seconds now
+	fi
+
+	rootdelay_set_deadline "$(( $now + ${ROOTDELAY:-0} ))"
+
+	if [ -f "$_rootdelay_pause/start" ]; then
+		write_atomic "$_rootdelay_pause/start" printf '%s\n' "$now"
 	fi
-	rootdelay_set_deadline "$(( $now + $ROOTDELAY ))"
 }
 
 initrd_features=/.initrd/features
diff --git a/features/runtime/data/sbin/rootdelayd b/features/runtime/data/sbin/rootdelayd
index 5fa21f07..4b11e5a4 100755
--- a/features/runtime/data/sbin/rootdelayd
+++ b/features/runtime/data/sbin/rootdelayd
@@ -71,9 +71,9 @@ while :; do
 		continue
 	fi
 
+	current_seconds now
+
 	first_iter=
-	now="$(timestamp boottime raw)"
-	now="${now%.*}"
 	consmsg="/.initrd/rootdelay/message"
 
 	if [ ! -f "$_rootdelay_timestamp" ]; then
-- 
2.56.0



  reply	other threads:[~2026-10-21 10:10 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-12 22:42 [make-initrd] Параметр rdshell Leonid Krivoshein
2026-10-14 10:04 ` Egor Shestakov
2026-10-14 16:01   ` Leonid Krivoshein
2026-10-15 14:48     ` [make-initrd] [RFC PATCH] runtime: fix a suspended boot after rdshell Egor Shestakov
2026-10-16 10:20       ` Alexey Gladkov
2026-10-16 13:39         ` Egor Shestakov
2026-10-16 14:09           ` Alexey Gladkov
2026-10-16 14:13             ` Egor Shestakov
2026-10-16 14:11           ` Egor Shestakov
2026-10-19 10:22   ` [make-initrd] Параметр rdshell Alexey Gladkov
2026-10-19 12:51     ` [make-initrd] kmscon (was: Параметр rdshell) Egor Shestakov
2026-10-19 13:38       ` Alexey Gladkov
2026-10-19 15:09         ` Egor Shestakov
2026-10-19 16:14           ` Alexey Gladkov
2026-10-16 12:06 ` [make-initrd] [PATCH 0/2] runtime: Fix console locking Alexey Gladkov
2026-10-16 12:06   ` [make-initrd] [PATCH 1/2] runtime: Fix a lock leak in rootdelayd Alexey Gladkov
2026-10-16 12:06   ` [make-initrd] [PATCH 2/2] runtime: Fix console lock shadowing by /dev mount Alexey Gladkov
2026-10-16 20:02     ` Leonid Krivoshein
2026-10-17  9:45       ` Alexey Gladkov
2026-10-17 16:19         ` Leonid Krivoshein
2026-10-17 16:41           ` Alexey Gladkov
2026-10-19  9:57 ` [make-initrd] [PATCH v2 00/11] Improve support for atomic actions Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 01/11] runtime: Fix a lock leak in rootdelayd Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 02/11] runtime: Fix console lock shadowing by /dev mount Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 03/11] runtime: Avoid leaking lock descriptor 90 to child processes Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 04/11] runtime: Replace /.initrd/initenv locking with atomic file update Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 05/11] runtime: Centralize file and console locking helpers Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 06/11] create-rootfs: Require bash 4.1 or newer for initramfs Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 07/11] network: Share DHCP hook lock between IPv4 and IPv6 on the same interface Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 08/11] luks: Serialize /etc/luks.keys updates and avoid duplicate entries Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 09/11] runtime: Synchronize concurrent /etc/fstab access with shared and exclusive locks Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 10/11] runtime: Update rootdelay deadline and failure message atomically Alexey Gladkov
2026-10-19  9:57   ` [make-initrd] [PATCH v2 11/11] runtime: Centralize atomic file replacement in write_atomic helper Alexey Gladkov
2026-10-19 19:30   ` [make-initrd] [PATCH v2 00/11] Improve support for atomic actions Leonid Krivoshein
2026-10-20 14:59     ` Alexey Gladkov
2026-10-20 19:04       ` Leonid Krivoshein
2026-10-20 19:23         ` [make-initrd] Уточнение по rootdelay_unpause() Leonid Krivoshein
2026-10-21 10:10           ` Alexey Gladkov [this message]
2026-10-21  7:18         ` [make-initrd] [PATCH v2 00/11] Improve support for atomic actions Alexey Gladkov
2026-10-21  8:50           ` Leonid Krivoshein
2026-10-21 10:18             ` Alexey Gladkov

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261021101032.278166-1-gladkov.alexey@gmail.com \
    --to=gladkov.alexey@gmail.com \
    --cc=make-initrd@lists.altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Make-initrd development discussion

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/make-initrd/0 make-initrd/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 make-initrd make-initrd/ http://lore.altlinux.org/make-initrd \
		make-initrd@lists.altlinux.org make-initrd@lists.altlinux.ru make-initrd@lists.altlinux.com
	public-inbox-index make-initrd

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.make-initrd


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git