Clean up supported flags for ioctls
David Sterba
maintainercover Clean up supported flags for ioctls
The subvolume args passed as the vol_args_v2 should be separated by the ioctl using them, add that for existing ioctls. The upcoming subvolume deletion-by-id will add new flags, so this should be considered preparatory patchset.
David Sterba (3):
btrfs: define support masks for ioctl volume args v2
btrfs: use ioctl args support mask for subvolume create/delete
btrfs: use ioctl args support mask for device delete
fs/btrfs/ioctl.c | 7 ++----- include/uapi/linux/btrfs.h | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-)
Signature · 1 line
2.25.0
David Sterba
maintainerPATCH 1/3 btrfs: define support masks for ioctl volume args v2
The ioctl data for devices or subvolumes can be passed via btrfs_ioctl_vol_args or btrfs_ioctl_vol_args_v2. The latter is more versatile and needs some caution as some of the flags make sense only for some ioctls.
As we're going to extend the flags, define support masks for each ioctl class separately.
--- include/uapi/linux/btrfs.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)
include/uapi/linux/btrfs.h +13 -3
@@ -97,16 +97,26 @@ struct btrfs_ioctl_qgroup_limit_args { };/* -* flags for subvolumes +* Arguments for specification of subvolumes or devices, supporting by-name or +* by-id and flags * -* Used by: -* struct btrfs_ioctl_vol_args_v2.flags +* The set of supported flags depends on the ioctl * * BTRFS_SUBVOL_RDONLY is also provided/consumed by the following ioctls: * - BTRFS_IOC_SUBVOL_GETFLAGS * - BTRFS_IOC_SUBVOL_SETFLAGS */ +/* Supported flags for BTRFS_IOC_RM_DEV_V2 */ +#define BTRFS_DEVICE_REMOVE_ARGS_MASK \ + (BTRFS_DEVICE_SPEC_BY_ID) + +/* Supported flags for BTRFS_IOC_SNAP_CREATE_V2 and BTRFS_IOC_SUBVOL_CREATE_V2 */ +#define BTRFS_SUBVOL_CREATE_ARGS_MASK \ + (BTRFS_SUBVOL_CREATE_ASYNC | \ + BTRFS_SUBVOL_RDONLY | \ + BTRFS_SUBVOL_QGROUP_INHERIT) +struct btrfs_ioctl_vol_args_v2 {__s64 fd;__u64 transid;
Signature · 1 line
2.25.0
Re: [PATCH 1/3] btrfs: define support masks for ioctl volume args v2
Quoted 50 lines · David Sterba
The ioctl data for devices or subvolumes can be passed via
btrfs_ioctl_vol_argsorbtrfs_ioctl_vol_args_v2. The latter is more versatile and needs some caution as some of the flags make sense only for some ioctls.As we're going to extend the flags, define support masks for each ioctl
class separately.Signed-off-by David Sterba <[email protected]>--- include/uapi/linux/btrfs.h | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-)include/uapi/linux/btrfs.h +1
-1@@ -97,16 +97,26 @@ struct btrfs_ioctl_qgroup_limit_args { };/* -* flags for subvolumes +* Arguments for specification of subvolumes or devices, supporting by-name or
+ * by-id and flags
*
- * Used by:
- * struct btrfs_ioctl_vol_args_v2.flags
+ * The set of supported flags depends on the ioctl
*
*BTRFS_SUBVOL_RDONLYis also provided/consumed by the following
ioctls:
* -BTRFS_IOC_SUBVOL_GETFLAGS
* -BTRFS_IOC_SUBVOL_SETFLAGS
*/include/uapi/linux/btrfs.h +2
-0+/* Supported flags for BTRFS_IOC_RM_DEV_V2 */ +#define BTRFS_DEVICE_REMOVE_ARGS_MASK \include/uapi/linux/btrfs.h +3
-0+ (BTRFS_DEVICE_SPEC_BY_ID ) + +/* Supported flags for BTRFS_IOC_SNAP_CREATE_V2 and
BTRFS_IOC_SUBVOL_CREATE_V2*/
+#defineBTRFS_SUBVOL_CREATE_ARGS_MASK\include/uapi/linux/btrfs.h +1
-0+ (BTRFS_SUBVOL_CREATE_ASYNC |\
include/uapi/linux/btrfs.h +1
-0+ BTRFS_SUBVOL_RDONLY |\
include/uapi/linux/btrfs.h struct btrfs_ioctl_qgroup_limit_args { · line 122
Quoted 5 lines
include/uapi/linux/btrfs.h +2
-0+ BTRFS_SUBVOL_QGROUP_INHERIT) + struct btrfs_ioctl_vol_args_v2 { __s64 fd; __u64 transid;
Looks good to me,
David Sterba
maintainerPATCH 2/3 btrfs: use ioctl args support mask for subvolume create/delete
In reply to David SterbaUsing the defined mask instead of flag enumeration in the ioctl handler is preferred. No functional changes.
--- fs/btrfs/ioctl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)
fs/btrfs/ioctl.c +1 -3
@@ -1838,9 +1838,7 @@ static noinline int btrfs_ioctl_snap_create_v2(struct file *file,return PTR_ERR (vol_args); vol_args->name[BTRFS_SUBVOL_NAME_MAX ] ='\0' ; -if (vol_args->flags & - ~(BTRFS_SUBVOL_CREATE_ASYNC |BTRFS_SUBVOL_RDONLY | -BTRFS_SUBVOL_QGROUP_INHERIT )) { +if (vol_args->flags & ~BTRFS_SUBVOL_CREATE_ARGS_MASK ) { ret = -EOPNOTSUPP ; goto free_args; }
Signature · 1 line
2.25.0
Re: [PATCH 2/3] btrfs: use ioctl args support mask for subvolume create/delete
Quoted 24 lines · David Sterba
Using the defined mask instead of flag enumeration in the ioctl handler
is preferred. No functional changes.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ioctl.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-)fs/btrfs/ioctl.c +1
-3@@ -1838,9 +1838,7 @@ static noinline int btrfs_ioctl_snap_create_v2(struct file *file, return PTR_ERR(vol_args); vol_args->name[BTRFS_SUBVOL_NAME_MAX ] ='\0' ; -if (vol_args->flags & - ~(BTRFS_SUBVOL_CREATE_ASYNC |BTRFS_SUBVOL_RDONLY | -BTRFS_SUBVOL_QGROUP_INHERIT )) { +if (vol_args->flags & ~BTRFS_SUBVOL_CREATE_ARGS_MASK ) { ret = -EOPNOTSUPP ; goto free_args;
Quoted 1 line
}
Looks good to me,
David Sterba
maintainerPATCH 3/3 btrfs: use ioctl args support mask for device delete
In reply to David SterbaWhen the device remove v2 ioctl was added, the full support mask was added to sanity check the flags. However this would allow to let the subvolume related flags to be accepted. This is not supposed to happen.
Use the correct support mask, which means that now any of BTRFS_SUBVOL_CREATE_ASYNC, BTRFS_SUBVOL_RDONLY or BTRFS_SUBVOL_QGROUP_INHERIT will be rejected as ENOTSUPP. Though this is a user-visible change, specifying subvolume flags for device deletion does not make sense and there are hopefully no applications doing that.
--- fs/btrfs/ioctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
fs/btrfs/ioctl.c +1 -2
@@ -3075,8 +3075,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg) goto err_drop; } -/* Check for compatibility reject unknown flags */ -if (vol_args->flags & ~BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED ) { +if (vol_args->flags & ~BTRFS_DEVICE_REMOVE_ARGS_MASK ) { ret = -EOPNOTSUPP ; goto out; }
Signature · 1 line
2.25.0
Re: [PATCH 3/3] btrfs: use ioctl args support mask for device delete
Quoted 32 lines · David Sterba
When the device remove v2 ioctl was added, the full support mask was added to sanity check the flags. However this would allow to let the subvolume related flags to be accepted. This is not supposed to happen.
Use the correct support mask, which means that now any of
BTRFS_SUBVOL_CREATE_ASYNC,BTRFS_SUBVOL_RDONLYorBTRFS_SUBVOL_QGROUP_INHERITwill be rejected as ENOTSUPP. Though this is
a user-visible change, specifying subvolume flags for device deletion does not make sense and there are hopefully no applications doing that.Signed-off-by David Sterba <[email protected]>--- fs/btrfs/ioctl.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)fs/btrfs/ioctl.c +1
-2@@ -3075,8 +3075,7 @@ static long btrfs_ioctl_rm_dev_v2(struct file *file, void __user *arg) goto err_drop; } -/* Check for compatibility reject unknown flags */ -if (vol_args->flags & ~BTRFS_VOL_ARG_V2_FLAGS_SUPPORTED ) { +if (vol_args->flags & ~BTRFS_DEVICE_REMOVE_ARGS_MASK ) { ret = -EOPNOTSUPP ; goto out;
Quoted 1 line
}
Looks good to me,
Quoted 5 lines · David Sterba
The subvolume args passed as the
vol_args_v2should be separated by the ioctl using them, add that for existing ioctls. The upcoming subvolume deletion-by-id will add new flags, so this should be considered preparatory patchset.
Quoted 9 lines
David Sterba (3):
btrfs: define support masks for ioctl volume args v2
btrfs: use ioctl args support mask for subvolume create/delete
btrfs: use ioctl args support mask for device deletefs/btrfs/ioctl.c | 7 ++----- include/uapi/linux/btrfs.h | 16 +++++++++++++--- 2 files changed, 15 insertions(+), 8 deletions(-)
For the whole series:
I was only worried about patch 3 but I see you have intentionally done it this way and I'm fine with this.