From: Jeff Layton <jlayton@kernel.org>
To: Alexander Viro <viro@zeniv.linux.org.uk>,
Christian Brauner <brauner@kernel.org>, Jan Kara <jack@suse.cz>
Cc: Miklos Szeredi <miklos@szeredi.hu>, Ian Kent <raven@themaw.net>,
Josef Bacik <josef@toxicpanda.com>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org,
Jeff Layton <jlayton@kernel.org>
Subject: [PATCH v4 3/3] fs: add the ability for statmount() to report the sb_source
Date: Mon, 11 Nov 2024 10:09:57 -0500 [thread overview]
Message-ID: <20241111-statmount-v4-3-2eaf35d07a80@kernel.org> (raw)
In-Reply-To: <20241111-statmount-v4-0-2eaf35d07a80@kernel.org>
/proc/self/mountinfo displays the source for the mount, but statmount()
doesn't yet have a way to return it. Add a new STATMOUNT_SB_SOURCE flag,
claim the 32-bit __spare1 field to hold the offset into the str[] array.
Reviewed-by: Jan Kara <jack@suse.cz>
Signed-off-by: Jeff Layton <jlayton@kernel.org>
---
fs/namespace.c | 36 +++++++++++++++++++++++++++++++++++-
include/uapi/linux/mount.h | 3 ++-
2 files changed, 37 insertions(+), 2 deletions(-)
diff --git a/fs/namespace.c b/fs/namespace.c
index fc4f81891d544305caf863904c0a6e16562fab49..4f034dba5884ce3641b8e4048e21879e4bda896c 100644
--- a/fs/namespace.c
+++ b/fs/namespace.c
@@ -5014,6 +5014,32 @@ static void statmount_fs_subtype(struct kstatmount *s, struct seq_file *seq)
seq_puts(seq, sb->s_subtype);
}
+static int statmount_sb_source(struct kstatmount *s, struct seq_file *seq)
+{
+ struct super_block *sb = s->mnt->mnt_sb;
+ struct mount *r = real_mount(s->mnt);
+
+ if (sb->s_op->show_devname) {
+ size_t start = seq->count;
+ int ret;
+
+ ret = sb->s_op->show_devname(seq, s->mnt->mnt_root);
+ if (ret)
+ return ret;
+
+ if (unlikely(seq_has_overflowed(seq)))
+ return -EAGAIN;
+
+ /* Unescape the result */
+ seq->buf[seq->count] = '\0';
+ seq->count = start;
+ seq_commit(seq, string_unescape_inplace(seq->buf + start, UNESCAPE_OCTAL));
+ } else if (r->mnt_devname) {
+ seq_puts(seq, r->mnt_devname);
+ }
+ return 0;
+}
+
static void statmount_mnt_ns_id(struct kstatmount *s, struct mnt_namespace *ns)
{
s->sm.mask |= STATMOUNT_MNT_NS_ID;
@@ -5077,6 +5103,10 @@ static int statmount_string(struct kstatmount *s, u64 flag)
sm->fs_subtype = start;
statmount_fs_subtype(s, seq);
break;
+ case STATMOUNT_SB_SOURCE:
+ sm->sb_source = seq->count;
+ ret = statmount_sb_source(s, seq);
+ break;
default:
WARN_ON_ONCE(true);
return -EINVAL;
@@ -5225,6 +5255,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
if (!err && s->mask & STATMOUNT_FS_SUBTYPE)
err = statmount_string(s, STATMOUNT_FS_SUBTYPE);
+ if (!err && s->mask & STATMOUNT_SB_SOURCE)
+ err = statmount_string(s, STATMOUNT_SB_SOURCE);
+
if (!err && s->mask & STATMOUNT_MNT_NS_ID)
statmount_mnt_ns_id(s, ns);
@@ -5246,7 +5279,8 @@ static inline bool retry_statmount(const long ret, size_t *seq_size)
}
#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \
- STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE)
+ STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | \
+ STATMOUNT_FS_SUBTYPE | STATMOUNT_SB_SOURCE)
static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq,
struct statmount __user *buf, size_t bufsize,
diff --git a/include/uapi/linux/mount.h b/include/uapi/linux/mount.h
index 2e939dddf9cbabe574dafdb6cff9ad4cf9298a74..2b49e9131d77165899d8e3c17366c6afaa8b7795 100644
--- a/include/uapi/linux/mount.h
+++ b/include/uapi/linux/mount.h
@@ -174,7 +174,7 @@ struct statmount {
__u32 mnt_point; /* [str] Mountpoint relative to current root */
__u64 mnt_ns_id; /* ID of the mount namespace */
__u32 fs_subtype; /* [str] Subtype of fs_type (if any) */
- __u32 __spare1[1];
+ __u32 sb_source; /* [str] Source string of the mount */
__u64 __spare2[48];
char str[]; /* Variable size part containing strings */
};
@@ -210,6 +210,7 @@ struct mnt_id_req {
#define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */
#define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */
#define STATMOUNT_FS_SUBTYPE 0x00000100U /* Want/got fs_subtype */
+#define STATMOUNT_SB_SOURCE 0x00000200U /* Want/got sb_source */
/*
* Special @mnt_id values that can be passed to listmount
--
2.47.0
next prev parent reply other threads:[~2024-11-11 15:10 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-11 15:09 [PATCH v4 0/3] fs: allow statmount to fetch the fs_subtype and sb_source Jeff Layton
2024-11-11 15:09 ` [PATCH v4 1/3] fs: don't let statmount return empty strings Jeff Layton
2024-11-11 17:44 ` Jan Kara
2024-11-11 15:09 ` [PATCH v4 2/3] fs: add the ability for statmount() to report the fs_subtype Jeff Layton
2024-11-11 15:09 ` Jeff Layton [this message]
2024-11-12 10:32 ` [PATCH v4 0/3] fs: allow statmount to fetch the fs_subtype and sb_source Miklos Szeredi
2024-11-12 11:12 ` Jeff Layton
2024-11-12 13:39 ` Christian Brauner
2024-11-13 11:27 ` Karel Zak
2024-11-13 13:08 ` Miklos Szeredi
2024-11-13 13:45 ` Jeff Layton
2024-11-13 15:18 ` Jan Kara
2024-11-13 15:49 ` Miklos Szeredi
2024-11-13 16:00 ` Jan Kara
2024-11-14 1:45 ` Ian Kent
2024-11-14 11:56 ` Jan Kara
2024-11-14 13:20 ` Miklos Szeredi
2024-11-17 23:29 ` Ian Kent
2024-11-18 9:07 ` Jan Kara
2024-11-14 1:51 ` Ian Kent
2024-11-14 11:29 ` Christian Brauner
2024-11-14 12:29 ` Jeff Layton
2024-11-14 13:16 ` Miklos Szeredi
2024-11-14 14:48 ` Christian Brauner
2024-11-14 14:51 ` Jeff Layton
2024-11-14 15:09 ` Christian Brauner
2024-11-14 15:31 ` [PATCH] statmount: retrieve security mount options Christian Brauner
2024-11-14 16:12 ` Jeff Layton
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=20241111-statmount-v4-3-2eaf35d07a80@kernel.org \
--to=jlayton@kernel.org \
--cc=brauner@kernel.org \
--cc=jack@suse.cz \
--cc=josef@toxicpanda.com \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=miklos@szeredi.hu \
--cc=raven@themaw.net \
--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