Skip to content

Commit 3a6ffeb

Browse files
committed
Merge patch series "fs: allow statmount to fetch the fs_subtype and sb_source"
Jeff Layton <[email protected]> says: Meta has some internal logging that scrapes /proc/self/mountinfo today. I'd like to convert it to use listmount()/statmount(), so we can do a better job of monitoring with containers. We're missing some fields though. This patchset adds them. * patches from https://lore.kernel.org/r/[email protected]: fs: add the ability for statmount() to report the sb_source fs: add the ability for statmount() to report the fs_subtype fs: don't let statmount return empty strings Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Christian Brauner <[email protected]>
2 parents c4d7d90 + 4401054 commit 3a6ffeb

File tree

2 files changed

+67
-7
lines changed

2 files changed

+67
-7
lines changed

fs/namespace.c

Lines changed: 62 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5004,6 +5004,40 @@ static int statmount_fs_type(struct kstatmount *s, struct seq_file *seq)
50045004
return 0;
50055005
}
50065006

5007+
static void statmount_fs_subtype(struct kstatmount *s, struct seq_file *seq)
5008+
{
5009+
struct super_block *sb = s->mnt->mnt_sb;
5010+
5011+
if (sb->s_subtype)
5012+
seq_puts(seq, sb->s_subtype);
5013+
}
5014+
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+
50075041
static void statmount_mnt_ns_id(struct kstatmount *s, struct mnt_namespace *ns)
50085042
{
50095043
s->sm.mask |= STATMOUNT_MNT_NS_ID;
@@ -5040,33 +5074,48 @@ static int statmount_mnt_opts(struct kstatmount *s, struct seq_file *seq)
50405074

50415075
static int statmount_string(struct kstatmount *s, u64 flag)
50425076
{
5043-
int ret;
5077+
int ret = 0;
50445078
size_t kbufsize;
50455079
struct seq_file *seq = &s->seq;
50465080
struct statmount *sm = &s->sm;
5081+
u32 start = seq->count;
50475082

50485083
switch (flag) {
50495084
case STATMOUNT_FS_TYPE:
5050-
sm->fs_type = seq->count;
5085+
sm->fs_type = start;
50515086
ret = statmount_fs_type(s, seq);
50525087
break;
50535088
case STATMOUNT_MNT_ROOT:
5054-
sm->mnt_root = seq->count;
5089+
sm->mnt_root = start;
50555090
ret = statmount_mnt_root(s, seq);
50565091
break;
50575092
case STATMOUNT_MNT_POINT:
5058-
sm->mnt_point = seq->count;
5093+
sm->mnt_point = start;
50595094
ret = statmount_mnt_point(s, seq);
50605095
break;
50615096
case STATMOUNT_MNT_OPTS:
5062-
sm->mnt_opts = seq->count;
5097+
sm->mnt_opts = start;
50635098
ret = statmount_mnt_opts(s, seq);
50645099
break;
5100+
case STATMOUNT_FS_SUBTYPE:
5101+
sm->fs_subtype = start;
5102+
statmount_fs_subtype(s, seq);
5103+
break;
5104+
case STATMOUNT_SB_SOURCE:
5105+
sm->sb_source = start;
5106+
ret = statmount_sb_source(s, seq);
5107+
break;
50655108
default:
50665109
WARN_ON_ONCE(true);
50675110
return -EINVAL;
50685111
}
50695112

5113+
/*
5114+
* If nothing was emitted, return to avoid setting the flag
5115+
* and terminating the buffer.
5116+
*/
5117+
if (seq->count == start)
5118+
return ret;
50705119
if (unlikely(check_add_overflow(sizeof(*sm), seq->count, &kbufsize)))
50715120
return -EOVERFLOW;
50725121
if (kbufsize >= s->bufsize)
@@ -5201,6 +5250,12 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
52015250
if (!err && s->mask & STATMOUNT_MNT_OPTS)
52025251
err = statmount_string(s, STATMOUNT_MNT_OPTS);
52035252

5253+
if (!err && s->mask & STATMOUNT_FS_SUBTYPE)
5254+
err = statmount_string(s, STATMOUNT_FS_SUBTYPE);
5255+
5256+
if (!err && s->mask & STATMOUNT_SB_SOURCE)
5257+
err = statmount_string(s, STATMOUNT_SB_SOURCE);
5258+
52045259
if (!err && s->mask & STATMOUNT_MNT_NS_ID)
52055260
statmount_mnt_ns_id(s, ns);
52065261

@@ -5222,7 +5277,8 @@ static inline bool retry_statmount(const long ret, size_t *seq_size)
52225277
}
52235278

52245279
#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \
5225-
STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS)
5280+
STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | \
5281+
STATMOUNT_FS_SUBTYPE | STATMOUNT_SB_SOURCE)
52265282

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

include/uapi/linux/mount.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,9 @@ struct statmount {
173173
__u32 mnt_root; /* [str] Root of mount relative to root of fs */
174174
__u32 mnt_point; /* [str] Mountpoint relative to current root */
175175
__u64 mnt_ns_id; /* ID of the mount namespace */
176-
__u64 __spare2[49];
176+
__u32 fs_subtype; /* [str] Subtype of fs_type (if any) */
177+
__u32 sb_source; /* [str] Source string of the mount */
178+
__u64 __spare2[48];
177179
char str[]; /* Variable size part containing strings */
178180
};
179181

@@ -207,6 +209,8 @@ struct mnt_id_req {
207209
#define STATMOUNT_FS_TYPE 0x00000020U /* Want/got fs_type */
208210
#define STATMOUNT_MNT_NS_ID 0x00000040U /* Want/got mnt_ns_id */
209211
#define STATMOUNT_MNT_OPTS 0x00000080U /* Want/got mnt_opts */
212+
#define STATMOUNT_FS_SUBTYPE 0x00000100U /* Want/got fs_subtype */
213+
#define STATMOUNT_SB_SOURCE 0x00000200U /* Want/got sb_source */
210214

211215
/*
212216
* Special @mnt_id values that can be passed to listmount

0 commit comments

Comments
 (0)