Skip to content

Commit ed9d95f

Browse files
jtlaytonbrauner
authored andcommitted
fs: add the ability for statmount() to report the fs_subtype
/proc/self/mountinfo prints out the sb->s_subtype after the type. This is particularly useful for disambiguating FUSE mounts (at least when the userland driver bothers to set it). Add STATMOUNT_FS_SUBTYPE and claim one of the __spare2 fields to point to the offset into the str[] array. Reviewed-by: Jan Kara <[email protected]> Reviewed-by: Ian Kent <[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 75ead69 commit ed9d95f

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

fs/namespace.c

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5004,6 +5004,14 @@ 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+
50075015
static void statmount_mnt_ns_id(struct kstatmount *s, struct mnt_namespace *ns)
50085016
{
50095017
s->sm.mask |= STATMOUNT_MNT_NS_ID;
@@ -5040,7 +5048,7 @@ static int statmount_mnt_opts(struct kstatmount *s, struct seq_file *seq)
50405048

50415049
static int statmount_string(struct kstatmount *s, u64 flag)
50425050
{
5043-
int ret;
5051+
int ret = 0;
50445052
size_t kbufsize;
50455053
struct seq_file *seq = &s->seq;
50465054
struct statmount *sm = &s->sm;
@@ -5063,6 +5071,10 @@ static int statmount_string(struct kstatmount *s, u64 flag)
50635071
sm->mnt_opts = start;
50645072
ret = statmount_mnt_opts(s, seq);
50655073
break;
5074+
case STATMOUNT_FS_SUBTYPE:
5075+
sm->fs_subtype = start;
5076+
statmount_fs_subtype(s, seq);
5077+
break;
50665078
default:
50675079
WARN_ON_ONCE(true);
50685080
return -EINVAL;
@@ -5208,6 +5220,9 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
52085220
if (!err && s->mask & STATMOUNT_MNT_OPTS)
52095221
err = statmount_string(s, STATMOUNT_MNT_OPTS);
52105222

5223+
if (!err && s->mask & STATMOUNT_FS_SUBTYPE)
5224+
err = statmount_string(s, STATMOUNT_FS_SUBTYPE);
5225+
52115226
if (!err && s->mask & STATMOUNT_MNT_NS_ID)
52125227
statmount_mnt_ns_id(s, ns);
52135228

@@ -5229,7 +5244,7 @@ static inline bool retry_statmount(const long ret, size_t *seq_size)
52295244
}
52305245

52315246
#define STATMOUNT_STRING_REQ (STATMOUNT_MNT_ROOT | STATMOUNT_MNT_POINT | \
5232-
STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS)
5247+
STATMOUNT_FS_TYPE | STATMOUNT_MNT_OPTS | STATMOUNT_FS_SUBTYPE)
52335248

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

include/uapi/linux/mount.h

Lines changed: 4 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 __spare1[1];
178+
__u64 __spare2[48];
177179
char str[]; /* Variable size part containing strings */
178180
};
179181

@@ -207,6 +209,7 @@ 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 */
210213

211214
/*
212215
* Special @mnt_id values that can be passed to listmount

0 commit comments

Comments
 (0)