Skip to content

Commit 4401054

Browse files
jtlaytonbrauner
authored andcommitted
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 <[email protected]> Signed-off-by: Jeff Layton <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Miklos Szeredi <[email protected]> Signed-off-by: Christian Brauner <[email protected]>
1 parent ed9d95f commit 4401054

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

fs/namespace.c

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5012,6 +5012,32 @@ static void statmount_fs_subtype(struct kstatmount *s, struct seq_file *seq)
50125012
seq_puts(seq, sb->s_subtype);
50135013
}
50145014

5015+
static int statmount_sb_source(struct kstatmount *s, struct seq_file *seq)
5016+
{
5017+
struct super_block *sb = s->mnt->mnt_sb;
5018+
struct mount *r = real_mount(s->mnt);
5019+
5020+
if (sb->s_op->show_devname) {
5021+
size_t start = seq->count;
5022+
int ret;
5023+
5024+
ret = sb->s_op->show_devname(seq, s->mnt->mnt_root);
5025+
if (ret)
5026+
return ret;
5027+
5028+
if (unlikely(seq_has_overflowed(seq)))
5029+
return -EAGAIN;
5030+
5031+
/* Unescape the result */
5032+
seq->buf[seq->count] = '\0';
5033+
seq->count = start;
5034+
seq_commit(seq, string_unescape_inplace(seq->buf + start, UNESCAPE_OCTAL));
5035+
} else if (r->mnt_devname) {
5036+
seq_puts(seq, r->mnt_devname);
5037+
}
5038+
return 0;
5039+
}
5040+
50155041
static void statmount_mnt_ns_id(struct kstatmount *s, struct mnt_namespace *ns)
50165042
{
50175043
s->sm.mask |= STATMOUNT_MNT_NS_ID;
@@ -5075,6 +5101,10 @@ static int statmount_string(struct kstatmount *s, u64 flag)
50755101
sm->fs_subtype = start;
50765102
statmount_fs_subtype(s, seq);
50775103
break;
5104+
case STATMOUNT_SB_SOURCE:
5105+
sm->sb_source = start;
5106+
ret = statmount_sb_source(s, seq);
5107+
break;
50785108
default:
50795109
WARN_ON_ONCE(true);
50805110
return -EINVAL;
@@ -5223,6 +5253,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
52235253
if (!err && s->mask & STATMOUNT_FS_SUBTYPE)
52245254
err = statmount_string(s, STATMOUNT_FS_SUBTYPE);
52255255

5256+
if (!err && s->mask & STATMOUNT_SB_SOURCE)
5257+
err = statmount_string(s, STATMOUNT_SB_SOURCE);
5258+
52265259
if (!err && s->mask & STATMOUNT_MNT_NS_ID)
52275260
statmount_mnt_ns_id(s, ns);
52285261

@@ -5244,7 +5277,8 @@ static inline bool retry_statmount(const long ret, size_t *seq_size)
52445277
}
52455278

52465279
#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \
5247-
STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE)
5280+
STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | \
5281+
STATMOUNT_FS_SUBTYPE | STATMOUNT_SB_SOURCE)
52485282

52495283
static int prepare_kstatmount(struct kstatmount *ks, struct mnt_id_req *kreq,
52505284
struct statmount __user *buf, size_t bufsize,

include/uapi/linux/mount.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ struct statmount {
174174
__u32 mnt_point; /* [str] Mountpoint relative to current root */
175175
__u64 mnt_ns_id; /* ID of the mount namespace */
176176
__u32 fs_subtype; /* [str] Subtype of fs_type (if any) */
177-
__u32 __spare1[1];
177+
__u32 sb_source; /* [str] Source string of the mount */
178178
__u64 __spare2[48];
179179
char str[]; /* Variable size part containing strings */
180180
};
@@ -210,6 +210,7 @@ struct mnt_id_req {
210210
#define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */
211211
#define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */
212212
#define STATMOUNT_FS_SUBTYPE 0x00000100U /* Want/got fs_subtype */
213+
#define STATMOUNT_SB_SOURCE 0x00000200U /* Want/got sb_source */
213214

214215
/*
215216
* Special @mnt_id values that can be passed to listmount

0 commit comments

Comments
 (0)