statmount: add a new supported_mask field
PATCH v2 1/1 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.
---
I ran into this problem recently. We have a variety of kernels running that have varying levels of support of statmount(), and I need to be
able to fall back to /proc scraping if support for everything isn't present. This is difficult currently since statmount() doesn't set the flag in the return mask if the field is empty.
---
Changes in v2:
- Fix the assignment of the mask and setting of new bit in return mask
- Add WARN_ON_ONCE() when there are bits present in return mask that are not present in STATMOUNT_SUPPORTED
- Link to v1: https://lore.kernel.org/r/[email protected]
--- fs/namespace.c | 23 +++++++++++++++++++++++ include/uapi/linux/mount.h | 4 +++- 2 files changed, 26 insertions(+), 1 deletion(-)
fs/namespace.c +23 -0
@@ -5317,6 +5317,21 @@ static int grab_requested_root(struct mnt_namespace *ns, struct path *root)return 0 ; } +/* This must be updated whenever a new flag is added */ +#define STATMOUNT_SUPPORTED (STATMOUNT_SB_BASIC | \ + STATMOUNT_MNT_BASIC | \ + STATMOUNT_PROPAGATE_FROM | \ + STATMOUNT_MNT_ROOT | \ + STATMOUNT_MNT_POINT | \ + STATMOUNT_FS_TYPE | \ + STATMOUNT_MNT_NS_ID | \ + STATMOUNT_MNT_OPTS | \ + STATMOUNT_FS_SUBTYPE | \ + STATMOUNT_SB_SOURCE | \ + STATMOUNT_OPT_ARRAY | \ + STATMOUNT_OPT_SEC_ARRAY | \ + STATMOUNT_SUPPORTED_MASK) +static int do_statmount (struct kstatmount *s,u64 mnt_id,u64 mnt_ns_id,struct mnt_namespace *ns) {
@@ -5386,9 +5401,17 @@ static int do_statmount(struct kstatmount *s, u64 mnt_id, u64 mnt_ns_id,if (!err && s->mask &STATMOUNT_MNT_NS_ID )statmount_mnt_ns_id (s, ns); +if (!err && s->mask &STATMOUNT_SUPPORTED_MASK ) { + s->sm.mask |=STATMOUNT_SUPPORTED_MASK ; + s->sm.supported_mask =STATMOUNT_SUPPORTED ; + } +if (err)return err; +/* Are there bits in the return mask not present in STATMOUNT_SUPPORTED? */ +WARN_ON_ONCE (~STATMOUNT_SUPPORTED & s->sm.mask); +return 0 ; }
include/uapi/linux/mount.h +3 -1
@@ -179,7 +179,8 @@ struct statmount {__u32 opt_array;/* [str] Array of nul terminated fs options */ __u32 opt_sec_num;/* Number of security options */ __u32 opt_sec_array;/* [str] Array of nul terminated security options */ -__u64 __spare2[46 ]; +__u64 supported_mask;/* Mask flags that this kernel supports */ +__u64 __spare2[45 ];char str[];/* Variable size part containing strings */ };
@@ -217,6 +218,7 @@ struct mnt_id_req {#define STATMOUNT_SB_SOURCE 0x00000200U/* Want/got sb_source */ #define STATMOUNT_OPT_ARRAY 0x00000400U/* Want/got opt_... */ #define STATMOUNT_OPT_SEC_ARRAY 0x00000800U/* Want/got opt_sec... */ +#define STATMOUNT_SUPPORTED_MASK 0x00001000U/* Want/got supported mask flags */ /* * Special @mnt_id values that can be passed to listmount
---
base-commit: 57c64cb6ddfb6c79a6c3fc2e434303c40f700964
change-id: 20250203-statmount-f7da9bec0f23
Best regards,
Signature · 1 line
Jeff Layton <[email protected]>
Quoted 6 lines · Jeff Layton
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.
Quoted 6 lines
Add a new
STATMOUNT_SUPPORTED_MASKflag 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.[...]
Applied to the vfs-6.15.mount branch of the vfs/vfs.git tree. Patches in the vfs-6.15.mount branch should appear in linux-next soon.
Please report any outstanding bugs that were missed during review in a new review to the original patch series allowing us to drop it.
It's encouraged to provide Acked-bys and Reviewed-bys even though the patch has now been applied. If possible patch trailers will be updated.
Note that commit hashes shown below are subject to change due to rebase, trailer updates or similar. If in doubt, please check the listed branch.
tree: https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git branch: vfs-6.15.mount
[1/1] statmount: add a new supported_mask field
https://git.kernel.org/vfs/vfs/c/f0445f381ab4