From: Bhavik Sachdev <b.sachdev1904@gmail.com>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>
Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Aleksa Sarai <cyphar@cyphar.com>,
Bhavik Sachdev <b.sachdev1904@gmail.com>,
Pavel Tikhomirov <ptikhomirov@virtuozzo.com>,
Jan Kara <jack@suse.cz>, John Garry <john.g.garry@oracle.com>,
Arnaldo Carvalho de Melo <acme@redhat.com>,
"Darrick J . Wong" <djwong@kernel.org>,
Namhyung Kim <namhyung@kernel.org>,
Ingo Molnar <mingo@kernel.org>, Andrei Vagin <avagin@gmail.com>,
Alexander Mikhalitsyn <alexander@mihalicyn.com>
Subject: [PATCH 2/4] fs/namespace: add umounted mounts to umount_mnt_ns
Date: Thu, 2 Oct 2025 18:18:38 +0530 [thread overview]
Message-ID: <20251002125422.203598-3-b.sachdev1904@gmail.com> (raw)
In-Reply-To: <20251002125422.203598-1-b.sachdev1904@gmail.com>
From: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
This patch add "unmounted" mounts to umount_mnt_ns instead of mount
namespace being NULL for such mounts. This will allow us to later use
statmount to get mount info about these mounts.
We also introduce proper checks so that "unmounted" mounts are still
detected correctly.
We delete mounts from umount_mnt_ns when no references to them exist.
Signed-off-by: Pavel Tikhomirov <ptikhomirov@virtuozzo.com>
---
fs/d_path.c | 2 +-
fs/mount.h | 10 +++++++++-
fs/namespace.c | 23 ++++++++++++++++++++---
3 files changed, 30 insertions(+), 5 deletions(-)
diff --git a/fs/d_path.c b/fs/d_path.c
index bb365511066b..c6a4118899e1 100644
--- a/fs/d_path.c
+++ b/fs/d_path.c
@@ -119,7 +119,7 @@ static int __prepend_path(const struct dentry *dentry, const struct mount *mnt,
/* Global root */
mnt_ns = READ_ONCE(mnt->mnt_ns);
/* open-coded is_mounted() to use local mnt_ns */
- if (!IS_ERR_OR_NULL(mnt_ns) && !is_anon_ns(mnt_ns))
+ if (!IS_ERR_OR_NULL(mnt_ns) && !is_anon_ns(mnt_ns) && !is_umount_ns(mnt_ns))
return 1; // absolute root
else
return 2; // detached or not attached yet
diff --git a/fs/mount.h b/fs/mount.h
index 97737051a8b9..03f8165939b4 100644
--- a/fs/mount.h
+++ b/fs/mount.h
@@ -122,10 +122,18 @@ static inline int mnt_has_parent(const struct mount *mnt)
return mnt != mnt->mnt_parent;
}
+extern struct mnt_namespace *umount_mnt_ns;
+
+static inline bool is_umount_ns(struct mnt_namespace *ns)
+{
+ return ns == umount_mnt_ns;
+}
+
static inline int is_mounted(struct vfsmount *mnt)
{
+ struct mnt_namespace *ns = READ_ONCE(real_mount(mnt)->mnt_ns);
/* neither detached nor internal? */
- return !IS_ERR_OR_NULL(real_mount(mnt)->mnt_ns);
+ return !IS_ERR_OR_NULL(ns) && !is_umount_ns(ns);
}
extern struct mount *__lookup_mnt(struct vfsmount *, struct dentry *);
diff --git a/fs/namespace.c b/fs/namespace.c
index 70fe01d810df..0b4be12c02de 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -1016,7 +1016,7 @@ static inline bool check_anonymous_mnt(struct mount *mnt)
{
u64 seq;
- if (!is_anon_ns(mnt->mnt_ns))
+ if (!is_anon_ns(mnt->mnt_ns) || is_umount_ns(mnt->mnt_ns))
return false;
seq = mnt->mnt_ns->seq_origin;
@@ -1400,9 +1400,11 @@ static void mntput_no_expire(struct mount *mnt)
{
LIST_HEAD(list);
int count;
+ struct mnt_namespace *ns;
rcu_read_lock();
- if (likely(READ_ONCE(mnt->mnt_ns))) {
+ ns = READ_ONCE(mnt->mnt_ns);
+ if (likely(ns && !is_umount_ns(ns))) {
/*
* Since we don't do lock_mount_hash() here,
* ->mnt_ns can change under us. However, if it's
@@ -1438,6 +1440,18 @@ static void mntput_no_expire(struct mount *mnt)
mnt->mnt.mnt_flags |= MNT_DOOMED;
rcu_read_unlock();
+ if (mnt_ns_attached(mnt)) {
+ struct mnt_namespace *ns;
+
+ move_from_ns(mnt);
+ ns = mnt->mnt_ns;
+ if (ns) {
+ ns->nr_mounts--;
+ __touch_mnt_namespace(ns);
+ }
+ mnt->mnt_ns = NULL;
+ }
+
list_del(&mnt->mnt_instance);
if (unlikely(!list_empty(&mnt->mnt_expire)))
list_del(&mnt->mnt_expire);
@@ -1885,6 +1899,9 @@ static void umount_tree(struct mount *mnt, enum umount_tree_flags how)
* namespace, etc.
*/
mnt_notify_add(p);
+
+ mnt_add_to_ns(umount_mnt_ns, p);
+ umount_mnt_ns->nr_mounts++;
}
}
@@ -4804,7 +4821,7 @@ static int can_idmap_mount(const struct mount_kattr *kattr, struct mount *mnt)
return -EPERM;
/* Mount has already been visible in the filesystem hierarchy. */
- if (!is_anon_ns(mnt->mnt_ns))
+ if (!is_anon_ns(mnt->mnt_ns) || is_umount_ns(mnt->mnt_ns))
return -EINVAL;
return 0;
--
2.51.0
next prev parent reply other threads:[~2025-10-02 12:55 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-02 12:48 [PATCH 0/4] export mount info for "unmounted" mounts Bhavik Sachdev
2025-10-02 12:48 ` [PATCH 1/4] fs/namespace: add umount_mnt_ns mount namespace for unmounted mounts Bhavik Sachdev
2025-10-02 12:48 ` Bhavik Sachdev [this message]
2025-10-02 16:34 ` [PATCH 2/4] fs/namespace: add umounted mounts to umount_mnt_ns Al Viro
2025-10-03 5:03 ` Pavel Tikhomirov
2025-10-06 13:45 ` Christian Brauner
2025-10-07 18:40 ` Aleksa Sarai
2025-10-02 12:48 ` [PATCH 3/4] statmount: allow for "unmounted" mounts Bhavik Sachdev
2025-10-02 12:48 ` [PATCH 4/4] fs/stat: export mnt_ns_id through statx Bhavik Sachdev
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=20251002125422.203598-3-b.sachdev1904@gmail.com \
--to=b.sachdev1904@gmail.com \
--cc=acme@redhat.com \
--cc=alexander@mihalicyn.com \
--cc=avagin@gmail.com \
--cc=brauner@kernel.org \
--cc=cyphar@cyphar.com \
--cc=djwong@kernel.org \
--cc=jack@suse.cz \
--cc=john.g.garry@oracle.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=namhyung@kernel.org \
--cc=ptikhomirov@virtuozzo.com \
--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