Make-initrd development discussion
 help / color / mirror / Atom feed
From: Leonid Krivoshein <klark.devel@gmail.com>
To: Alexey Gladkov <gladkov.alexey@gmail.com>,
	make-initrd@lists.altlinux.org
Subject: Re: [make-initrd] [PATCH 2/2] runtime: Fix console lock shadowing by /dev mount
Date: Fri, 16 Oct 2026 23:02:36 +0300
Message-ID: <66dae82b-2bd9-4ac2-aa17-d04e3845fbc5@gmail.com> (raw)
In-Reply-To: <355e18e638f4631184c105d566e41029f1e5a1f1.1792152299.git.gladkov.alexey@gmail.com>

Привет!


On 10/16/26 3:06 PM, Alexey Gladkov wrote:
> /etc/rc.d/rc acquires an exclusive lock on /dev/console before starting
> runlevel services. When the mountfs service mounts devtmpfs over /dev,
> the original /dev/console inode on rootfs is shadowed by a new inode on
> devtmpfs. Consequently, rc holds the lock on the shadowed inode while
> processes started after mountfs lock the new /dev/console inode without
> waiting for rc to finish starting services. In particular, with the
> rdshell boot parameter, rootdelayd acquires the console lock and starts
> the emergency shell in the middle of runlevel 3 instead of after all
> services have started.
> 
> Once the console lock is preserved across mountfs, the network-up init
> service deadlocks against its parent /etc/rc.d/rc because network-up
> requests a shared lock on the console while rc already holds an
> exclusive lock for the duration of the runlevel scripts.
> 
> Use a dedicated /.initrd/console.lock file in /.initrd so the lock
> remains on the same inode across /dev mount operations, and drop the
> redundant lock acquisition from the synchronous network-up init script.

Хорошо, что нашлось решение и есть в сообществе люди, умеющие не только 
репортить баги, но и разбирающиеся в них, предлагающие патчи! Я всего-то 
хотел уточнить, поскольку вносил изменения в свою документацию, а тут 
столько всего поменялось. :-)

Но есть вопросы к этим изменениям, см. ниже...


> 
> Fixes: 598a4b241a4f ("Rewrite console locking")
> Reported-by: Leonid Krivoshein <klark.devel@gmail.com>
> Signed-off-by: Alexey Gladkov <gladkov.alexey@gmail.com>
> ---
>   features/fsck/data/lib/uevent/handlers/040-mountdev         | 2 +-
>   features/luks/data/lib/uevent/handlers/085-luks             | 2 +-
>   features/network/data/etc/rc.d/init.d/network-up            | 3 ---
>   features/runtime/data/etc/rc.d/rc                           | 2 +-
>   features/runtime/data/init                                  | 1 +
>   .../runtime/data/lib/uevent/handlers/mount/900-localdev     | 2 +-
>   features/runtime/data/sbin/rootdelayd                       | 6 +++---
>   features/sshfsroot/data/lib/uevent/handlers/040-sshfsroot   | 2 +-
>   features/zfs/data/sbin/ueventd-zfs                          | 2 +-
>   9 files changed, 10 insertions(+), 12 deletions(-)
> 
> diff --git a/features/fsck/data/lib/uevent/handlers/040-mountdev b/features/fsck/data/lib/uevent/handlers/040-mountdev
> index 53208f0d..9e9f06ea 100755
> --- a/features/fsck/data/lib/uevent/handlers/040-mountdev
> +++ b/features/fsck/data/lib/uevent/handlers/040-mountdev
> @@ -56,7 +56,7 @@ handler()
>   }
>   
>   exec 0</dev/console >/dev/console 2>&1
> -fd_lock 90 /dev/console
> +fd_lock 90 /.initrd/console.lock
Получается, здесь сначала выполняется открытие файла консоли, только 
потом её захват. Не лучше ли наоборот или это непринципиально?

Коль блокировка консоли используется внутри make-initrd во многих 
местах, нет ли смысла скрыть её внутреннюю реализацию как раз на случай 
таких изменений? Что-то типа fd_lock_console() / fd_unlock_console().

Насколько безопасно использовать статически заданный дескриптор для этой 
блокировки? Не лучше ли его определять динамически?


>   
>   for e in "$eventdir"/mountdev.*; do
>   	[ -e "$e" ] || break
> diff --git a/features/luks/data/lib/uevent/handlers/085-luks b/features/luks/data/lib/uevent/handlers/085-luks
> index db5a217b..423082ad 100755
> --- a/features/luks/data/lib/uevent/handlers/085-luks
> +++ b/features/luks/data/lib/uevent/handlers/085-luks
> @@ -366,7 +366,7 @@ handler() {
>   }
>   
>   exec 0</dev/console >/dev/console 2>&1
> -fd_lock 90 /dev/console
> +fd_lock 90 /.initrd/console.lock
>   
>   rc=0
>   for e in "$eventdir"/luks.*; do
> diff --git a/features/network/data/etc/rc.d/init.d/network-up b/features/network/data/etc/rc.d/init.d/network-up
> index 9ec3b978..ae1532e0 100755
> --- a/features/network/data/etc/rc.d/init.d/network-up
> +++ b/features/network/data/etc/rc.d/init.d/network-up
> @@ -13,14 +13,11 @@
>   
>   msg="Network up"
>   
> -. shell-locks
>   . network-sh-functions
>   
>   # wait for network modules
>   udevadm settle --timeout=3
>   
> -fd_rlock 90 /dev/console
> -
>   ifaces=' '
>   while :; do
>   	set -- /sys/class/net/*
> diff --git a/features/runtime/data/etc/rc.d/rc b/features/runtime/data/etc/rc.d/rc
> index 02f85ae5..916fa390 100755
> --- a/features/runtime/data/etc/rc.d/rc
> +++ b/features/runtime/data/etc/rc.d/rc
> @@ -22,7 +22,7 @@ rcd="/etc/rc.d/rc$runlevel.d"
>   	exit 0
>   
>   exec </dev/console 2>&1
> -fd_lock 90 /dev/console
> +fd_lock 90 /.initrd/console.lock
>   
>   msg "INIT: Entering runlevel: $runlevel"
>   
> diff --git a/features/runtime/data/init b/features/runtime/data/init
> index 6fd887a4..f4c789a1 100755
> --- a/features/runtime/data/init
> +++ b/features/runtime/data/init
> @@ -11,6 +11,7 @@ export PATH=/sbin:/usr/sbin:/usr/local/sbin:/bin:/usr/bin:/usr/local/bin
>   
>   # Create storage for init environment
>   :> /.initrd/initenv
> +:> /.initrd/console.lock
>   
>   # Check and create the necessary device files
>   [ -d /dev ] ||
> diff --git a/features/runtime/data/lib/uevent/handlers/mount/900-localdev b/features/runtime/data/lib/uevent/handlers/mount/900-localdev
> index ddd33df2..ecc37b36 100755
> --- a/features/runtime/data/lib/uevent/handlers/mount/900-localdev
> +++ b/features/runtime/data/lib/uevent/handlers/mount/900-localdev
> @@ -78,7 +78,7 @@ while [ "$method" = localdev ]; do
>   	all_mounted && sysinit_found ||
>   		break
>   
> -	fd_lock 90 /dev/console
> +	fd_lock 90 /.initrd/console.lock
>   
>   	message "$QUEUE: session=$SESSION: $method ready. acting!"
>   
> diff --git a/features/runtime/data/sbin/rootdelayd b/features/runtime/data/sbin/rootdelayd
> index d61b2ae4..cad6efd6 100755
> --- a/features/runtime/data/sbin/rootdelayd
> +++ b/features/runtime/data/sbin/rootdelayd
> @@ -36,7 +36,7 @@ while :; do
>   	if [ -n "${RDSHELL-}" ]; then
>   		mkdir -p -- "$disabled"
>   
> -		fd_lock 90 /dev/console
> +		fd_lock 90 /.initrd/console.lock
>   		rdshell "Emergency shell" 90<&-
>   		fd_unlock 90
>   
> @@ -76,7 +76,7 @@ while :; do
>   
>   		msg="${msg:-The waiting time expired!}"
>   
> -		fd_lock 90 /dev/console
> +		fd_lock 90 /.initrd/console.lock
>   
>   		# Disallow console access
>   		if [ "${PANIC-}" = "0" ]; then
> @@ -101,7 +101,7 @@ while :; do
>   
>   	if [ -z "${QUIET-}" ] && [ -z "$first_iter" ] && [ $(( $delay % 15 )) -eq 0 ]; then
>   
> -		fd_lock 90 /dev/console
> +		fd_lock 90 /.initrd/console.lock
>   
>   		resume_checked &&
>   			msg="Waiting for root ${ROOT:+($ROOT) }..." ||
> diff --git a/features/sshfsroot/data/lib/uevent/handlers/040-sshfsroot b/features/sshfsroot/data/lib/uevent/handlers/040-sshfsroot
> index 6730a203..dfd140cf 100755
> --- a/features/sshfsroot/data/lib/uevent/handlers/040-sshfsroot
> +++ b/features/sshfsroot/data/lib/uevent/handlers/040-sshfsroot
> @@ -41,7 +41,7 @@ handler() {
>   }
>   
>   exec 0</dev/console >/dev/console 2>&1
> -fd_lock 90 /dev/console
> +fd_lock 90 /.initrd/console.lock
>   
>   rc=0
>   for e in "$eventdir"/sshfsroot.*; do
> diff --git a/features/zfs/data/sbin/ueventd-zfs b/features/zfs/data/sbin/ueventd-zfs
> index 8229eaee..e164d779 100755
> --- a/features/zfs/data/sbin/ueventd-zfs
> +++ b/features/zfs/data/sbin/ueventd-zfs
> @@ -104,7 +104,7 @@ while :; do
>   	fi
>   
>   	if resume_checked; then
> -		fd_lock 90 /dev/console
> +		fd_lock 90 /.initrd/console.lock
>   
>   		findmnt -sno TARGET -t zfs | sort -d -k1,1 |
>   		while read -r mnt; do

-- 
WBR, Leonid Krivoshein.



  reply	other threads:[~2026-10-16 20:02 UTC|newest]

Thread overview: 47+ 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 [this message]
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           ` [make-initrd] [PATCH] runtime: Freeze rootdelay countdown while paused Alexey Gladkov
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
2026-10-21 18:52               ` Leonid Krivoshein
2026-10-21 19:30                 ` Alexey Gladkov
2026-10-21 19:33                   ` Leonid Krivoshein
2026-10-21 19:31                 ` Leonid Krivoshein
2026-10-21 20:03                   ` Alexey Gladkov
2026-10-21 20:48                     ` Leonid Krivoshein

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=66dae82b-2bd9-4ac2-aa17-d04e3845fbc5@gmail.com \
    --to=klark.devel@gmail.com \
    --cc=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