Skip to content

Commit 8f6116b

Browse files
jtlaytonbrauner
authored andcommitted
statmount: add a new supported_mask field
Some of the fields in the statmount() reply can be optional. If the kernel has nothing to emit in that field, then it doesn't set the flag in the reply. This presents a problem: There is currently no way to know what mask flags the kernel supports since you can't always count on them being in the reply. Add a new STATMOUNT_SUPPORTED_MASK flag and field that the kernel can set in the reply. Userland can use this to determine if the fields it requires from the kernel are supported. This also gives us a way to deprecate fields in the future, if that should become necessary. Reviewed-by: Jan Kara <jack@suse.cz> Signed-off-by: Jeff Layton <jlayton@kernel.org> Link: https://lore.kernel.org/r/20250206-statmount-v2-1-6ae70a21c2ab@kernel.org Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 3129946 commit 8f6116b

2 files changed

Lines changed: 26 additions & 1 deletion

File tree

fs/namespace.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5410,6 +5410,21 @@ static int grab_requested_root(struct mnt_namespace *ns, struct path *root)
54105410
return 0;
54115411
}
54125412

5413+
/* This must be updated whenever a new flag is added */
5414+
#define STATMOUNT_SUPPORTED (STATMOUNT_SB_BASIC | \
5415+
STATMOUNT_MNT_BASIC | \
5416+
STATMOUNT_PROPAGATE_FROM | \
5417+
STATMOUNT_MNT_ROOT | \
5418+
STATMOUNT_MNT_POINT | \
5419+
STATMOUNT_FS_TYPE | \
5420+
STATMOUNT_MNT_NS_ID | \
5421+
STATMOUNT_MNT_OPTS | \
5422+
STATMOUNT_FS_SUBTYPE | \
5423+
STATMOUNT_SB_SOURCE | \
5424+
STATMOUNT_OPT_ARRAY | \
5425+
STATMOUNT_OPT_SEC_ARRAY | \
5426+
STATMOUNT_SUPPORTED_MASK)
5427+
54135428
static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
54145429
struct mnt_namespace *ns)
54155430
{
@@ -5479,9 +5494,17 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,
54795494
if (!err && s->mask & STATMOUNT_MNT_NS_ID)
54805495
statmount_mnt_ns_id(s, ns);
54815496

5497+
if (!err && s->mask & STATMOUNT_SUPPORTED_MASK) {
5498+
s->sm.mask |= STATMOUNT_SUPPORTED_MASK;
5499+
s->sm.supported_mask = STATMOUNT_SUPPORTED;
5500+
}
5501+
54825502
if (err)
54835503
return err;
54845504

5505+
/* Are there bits in the return mask not present in STATMOUNT_SUPPORTED? */
5506+
WARN_ON_ONCE(~STATMOUNT_SUPPORTED & s->sm.mask);
5507+
54855508
return 0;
54865509
}
54875510

include/uapi/linux/mount.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,8 @@ struct statmount {
179179
__u32 opt_array; /* [str] Array of nul terminated fs options */
180180
__u32 opt_sec_num; /* Number of security options */
181181
__u32 opt_sec_array; /* [str] Array of nul terminated security options */
182-
__u64 __spare2[46];
182+
__u64 supported_mask; /* Mask flags that this kernel supports */
183+
__u64 __spare2[45];
183184
char str[]; /* Variable size part containing strings */
184185
};
185186

@@ -217,6 +218,7 @@ struct mnt_id_req {
217218
#define STATMOUNT_SB_SOURCE 0x00000200U /* Want/got sb_source */
218219
#define STATMOUNT_OPT_ARRAY 0x00000400U /* Want/got opt_... */
219220
#define STATMOUNT_OPT_SEC_ARRAY 0x00000800U /* Want/got opt_sec... */
221+
#define STATMOUNT_SUPPORTED_MASK 0x00001000U /* Want/got supported mask flags */
220222

221223
/*
222224
* Special @mnt_id values that can be passed to listmount

0 commit comments

Comments
 (0)