btrfs: qgroup: replace modifing qgroup_flags to bitops
RFC PATCH v2 1/1 btrfs: qgroup: replace modifing qgroup_flags to bitops
This patch replaces the code modifying or checking qgroup_flags to bitops like set_bit or test_bit. This patch fixes potential race condition on qgroup_flags. Before this, it adds enum that represents flag number for using bitops. This patch doesn't deleted existing variable for compatibility.
Signed-off-by Sidong Yang <[email protected]>
---
v2:
- adds BTRFS_QGROUP_STATUS_FLAG_NUM_*
This patch added enums for bitops. Because existing defined values is also used in btrfs-progs. And I don't know to break it.
And using bitops, it needs casting for its type. I don't know it's good idea. It's better to change qgroup_flags type than cast it?
fs/btrfs/ioctl.c | 2 +- fs/btrfs/qgroup.c | 68 ++++++++++++++++----------------- include/uapi/linux/btrfs_tree.h | 12 ++++-- 3 files changed, 42 insertions(+), 40 deletions(-)
fs/btrfs/ioctl.c +1 -1
@@ -4435,7 +4435,7 @@ static long btrfs_ioctl_quota_rescan_status(struct btrfs_fs_info *fs_info,if (!capable (CAP_SYS_ADMIN ))return -EPERM ; -if (fs_info->qgroup_flags &BTRFS_QGROUP_STATUS_FLAG_RESCAN ) { +if (test_bit (BTRFS_QGROUP_STATUS_FLAG_NUM_RESCAN , (unsigned long *)&fs_info->qgroup_flags)) { qsa.flags =1 ; qsa.progress = fs_info->qgroup_rescan_progress.objectid; }
fs/btrfs/qgroup.c +32 -36
210 lines not on this page · raw message
include/uapi/linux/btrfs_tree.h +9 -3
@@ -956,14 +956,20 @@ static inline __u16 btrfs_qgroup_level(__u64 qgroupid)return (__u16)(qgroupid >>BTRFS_QGROUP_LEVEL_SHIFT ); } +enum { +BTRFS_QGROUP_STATUS_FLAG_NUM_ON , +BTRFS_QGROUP_STATUS_FLAG_NUM_RESCAN , +BTRFS_QGROUP_STATUS_FLAG_NUM_INCONSISTENT , +}; +/* * is subvolume quota turned on? */ -#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << 0) +#define BTRFS_QGROUP_STATUS_FLAG_ON (1ULL << BTRFS_QGROUP_STATUS_FLAG_NUM_ON)/* * RESCAN is set during the initialization phase */ -#define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << 1) +#define BTRFS_QGROUP_STATUS_FLAG_RESCAN (1ULL << BTRFS_QGROUP_STATUS_FLAG_NUM_RESCAN)/* * Some qgroup entries are known to be out of date, * either because the configuration has changed in a way that
@@ -971,7 +977,7 @@ static inline __u16 btrfs_qgroup_level(__u64 qgroupid)* with a non-qgroup-aware version. * Turning qouta off and on again makes it inconsistent, too. */ -#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << 2) +#define BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT (1ULL << BTRFS_QGROUP_STATUS_FLAG_NUM_INCONSISTENT)#define BTRFS_QGROUP_STATUS_VERSION 1
Signature · 1 line
2.25.1