mirror of
git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2025-08-05 16:54:27 +00:00
fs: add the ability for statmount() to report the sb_source
/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> Link: https://lore.kernel.org/r/20241111-statmount-v4-3-2eaf35d07a80@kernel.org Acked-by: Miklos Szeredi <mszeredi@redhat.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
This commit is contained in:
parent
ed9d95f691
commit
44010543fc
2 changed files with 37 additions and 2 deletions
|
@ -5012,6 +5012,32 @@ static void statmount_fs_subtype(struct kstatmount *s, struct seq_file *seq)
|
||||||
seq_puts(seq, sb->s_subtype);
|
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)
|
static void statmount_mnt_ns_id(struct kstatmount *s, struct mnt_namespace *ns)
|
||||||
{
|
{
|
||||||
s->sm.mask |= STATMOUNT_MNT_NS_ID;
|
s->sm.mask |= STATMOUNT_MNT_NS_ID;
|
||||||
|
@ -5075,6 +5101,10 @@ static int statmount_string(struct kstatmount *s, u64 flag)
|
||||||
sm->fs_subtype = start;
|
sm->fs_subtype = start;
|
||||||
statmount_fs_subtype(s, seq);
|
statmount_fs_subtype(s, seq);
|
||||||
break;
|
break;
|
||||||
|
case STATMOUNT_SB_SOURCE:
|
||||||
|
sm->sb_source = start;
|
||||||
|
ret = statmount_sb_source(s, seq);
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
WARN_ON_ONCE(true);
|
WARN_ON_ONCE(true);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
@ -5223,6 +5253,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
|
||||||
if (!err && s->mask & STATMOUNT_FS_SUBTYPE)
|
if (!err && s->mask & STATMOUNT_FS_SUBTYPE)
|
||||||
err = statmount_string(s, 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)
|
if (!err && s->mask & STATMOUNT_MNT_NS_ID)
|
||||||
statmount_mnt_ns_id(s, ns);
|
statmount_mnt_ns_id(s, ns);
|
||||||
|
|
||||||
|
@ -5244,7 +5277,8 @@ static inline bool retry_statmount(const long ret, size_t *seq_size)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \
|
#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,
|
static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq,
|
||||||
struct statmount __user *buf, size_t bufsize,
|
struct statmount __user *buf, size_t bufsize,
|
||||||
|
|
|
@ -174,7 +174,7 @@ struct statmount {
|
||||||
__u32 mnt_point; /* [str] Mountpoint relative to current root */
|
__u32 mnt_point; /* [str] Mountpoint relative to current root */
|
||||||
__u64 mnt_ns_id; /* ID of the mount namespace */
|
__u64 mnt_ns_id; /* ID of the mount namespace */
|
||||||
__u32 fs_subtype; /* [str] Subtype of fs_type (if any) */
|
__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];
|
__u64 __spare2[48];
|
||||||
char str[]; /* Variable size part containing strings */
|
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_NS_ID 0x00000040U /* Want/got mnt_ns_id */
|
||||||
#define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */
|
#define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */
|
||||||
#define STATMOUNT_FS_SUBTYPE 0x00000100U /* Want/got fs_subtype */
|
#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
|
* Special @mnt_id values that can be passed to listmount
|
||||||
|
|
Loading…
Add table
Reference in a new issue