mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Ismael Luceno <ismael@iodev.co.uk>
To: linux-kernel@vger.kernel.org
Cc: Ismael Luceno <ismael@iodev.co.uk>,
	Ismael Luceno <iluceno@suse.de>,
	Alexander Viro <viro@zeniv.linux.org.uk>,
	Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>,
	linux-fsdevel@vger.kernel.org (open list:FILESYSTEMS (VFS and
	infrastructure))
Subject: [PATCH 3/8] init: let filesystems ask whether they are mounting the root device
Date: Mon, 16 Nov 2026 23:43:19 +0100	[thread overview]
Message-ID: <20261116224316.11237-13-ismael@iodev.co.uk> (raw)
In-Reply-To: <20261116224316.11237-10-ismael@iodev.co.uk>

A filesystem that wants to treat the root mount differently from any
other mount has no way to tell which one it is being asked for, and no
way to find out how long the user is willing to wait for it.  Expose
both.

root_wait becomes a global so a filesystem can read the value the user
gave rootwait=, and is_root_dev() reports whether a device is the one
the root filesystem is being mounted from.  mount_root() is the only
thing that mounts from /dev/root, and that name exists for the root
mount alone, so a filesystem handed that device is being asked to be
the root filesystem.

No behaviour changes.  This is here so a filesystem can act on the
root mount, which btrfs does next.

Signed-off-by: Ismael Luceno <ismael@iodev.co.uk>
Signed-off-by: Ismael Luceno <iluceno@suse.de>
---
 include/linux/root_dev.h | 14 ++++++++++++++
 init/do_mounts.c         | 18 +++++++++++++++++-
 2 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/include/linux/root_dev.h b/include/linux/root_dev.h
index 847c9a06101b..b5a0181d1967 100644
--- a/include/linux/root_dev.h
+++ b/include/linux/root_dev.h
@@ -15,4 +15,18 @@ #define _ROOT_DEV_H_
 
 extern dev_t ROOT_DEV;
 
+/*
+ * Milliseconds to wait for the root device, from the rootwait= parameter.
+ * Negative means wait indefinitely, zero means do not wait.
+ */
+extern int root_wait;
+
+/*
+ * True if @dev is the device the root filesystem is being mounted from, or
+ * was mounted from.  The root mount names the device /dev/root, which is
+ * created for it alone, so a filesystem can tell the root mount from any
+ * other it is asked to do.
+ */
+bool is_root_dev(dev_t dev);
+
 #endif
diff --git a/init/do_mounts.c b/init/do_mounts.c
index febcc37f9128..f1dcb18201eb 100644
--- a/init/do_mounts.c
+++ b/init/do_mounts.c
@@ -30,9 +30,9 @@
 
 int root_mountflags = MS_RDONLY | MS_SILENT;
 static char __initdata saved_root_name[64];
-static int root_wait;
 
 dev_t ROOT_DEV;
+int root_wait;
 
 static int __init readonly(char *str)
 {
@@ -372,10 +372,26 @@ #define CIFSROOT_RETRY_MAX	5
 		pr_emerg("Failed to create /dev/root: %d\n", err);
 	mount_root_generic("/dev/root", root_device_name, root_mountflags);
 }
+
+/*
+ * Was the filesystem on @dev mounted as the root filesystem?  mount_root()
+ * above is the only thing that mounts from /dev/root, and that name is given
+ * to the root mount alone, so a filesystem being handed that device is being
+ * asked to be the root filesystem.
+ */
+bool is_root_dev(dev_t dev)
+{
+	return dev && dev == ROOT_DEV;
+}
 #else
 static inline void mount_block_root(char *root_device_name)
 {
 }
+
+static inline bool is_root_dev(dev_t dev)
+{
+	return false;
+}
 #endif /* CONFIG_BLOCK */
 
 void __init mount_root(char *root_device_name)

  parent reply	other threads:[~2026-11-16 22:43 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-16 22:43 [PATCH 0/8] btrfs: assemble a multi-device root filesystem without an initrd Ismael Luceno
2026-11-16 22:43 ` [PATCH 1/8] btrfs: add config options for the root device scan Ismael Luceno
2026-11-16 22:43 ` [PATCH 2/8] init: mount devtmpfs before the root filesystem Ismael Luceno
2026-11-16 22:43 ` Ismael Luceno [this message]
2026-11-16 22:43 ` [PATCH 4/8] btrfs: add a helper to scan all block devices Ismael Luceno
2026-11-16 22:43 ` [PATCH 5/8] btrfs: wait for the root filesystem to have all its devices Ismael Luceno
2026-11-16 22:43 ` [PATCH 6/8] Documentation: btrfs: document waiting for the root filesystem devices Ismael Luceno
2026-11-16 22:43 ` [PATCH 7/8] init: let a filesystem resolve a root device by UUID or label Ismael Luceno
2026-11-16 22:43 ` [PATCH 8/8] btrfs: resolve root=UUID= and root=LABEL= Ismael Luceno
2026-11-16 23:41 ` [PATCH 0/8] btrfs: assemble a multi-device root filesystem without an initrd Qu Wenruo

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=20261116224316.11237-13-ismael@iodev.co.uk \
    --to=ismael@iodev.co.uk \
    --cc=brauner@kernel.org \
    --cc=iluceno@suse.de \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®