Skip to content

Commit 5d23515

Browse files
lorddoskiaskdave
authored andcommitted
btrfs: Move qgroup rescan on quota enable to btrfs_quota_enable
Currently btrfs_run_qgroups is doing a bit too much. Not only is it responsible for synchronizing in-memory state of qgroups to disk but it also contains code to trigger the initial qgroup rescan when quota is enabled initially. This condition is detected by checking that BTRFS_FS_QUOTA_ENABLED is not set and BTRFS_FS_QUOTA_ENABLING is set. Nothing really requires from the code to be structured (and scattered) the way it is so let's streamline things. First move the quota rescan code into btrfs_quota_enable, where its invocation is closer to the use. This also makes the FS_QUOTA_ENABLING flag redundant so let's remove it as well. This has been tested with a full xfstest run with qgroups enabled on the scratch device of every xfstest and no regressions were observed. Signed-off-by: Nikolay Borisov <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 7ce311d commit 5d23515

File tree

2 files changed

+10
-26
lines changed

2 files changed

+10
-26
lines changed

fs/btrfs/ctree.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -707,7 +707,6 @@ struct btrfs_delayed_root;
707707
#define BTRFS_FS_LOG_RECOVERING 4
708708
#define BTRFS_FS_OPEN 5
709709
#define BTRFS_FS_QUOTA_ENABLED 6
710-
#define BTRFS_FS_QUOTA_ENABLING 7
711710
#define BTRFS_FS_UPDATE_UUID_TREE_GEN 9
712711
#define BTRFS_FS_CREATING_FREE_SPACE_TREE 10
713712
#define BTRFS_FS_BTREE_ERR 11

fs/btrfs/qgroup.c

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -826,10 +826,8 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,
826826
int slot;
827827

828828
mutex_lock(&fs_info->qgroup_ioctl_lock);
829-
if (fs_info->quota_root) {
830-
set_bit(BTRFS_FS_QUOTA_ENABLING, &fs_info->flags);
829+
if (fs_info->quota_root)
831830
goto out;
832-
}
833831

834832
fs_info->qgroup_ulist = ulist_alloc(GFP_KERNEL);
835833
if (!fs_info->qgroup_ulist) {
@@ -923,8 +921,15 @@ int btrfs_quota_enable(struct btrfs_trans_handle *trans,
923921
}
924922
spin_lock(&fs_info->qgroup_lock);
925923
fs_info->quota_root = quota_root;
926-
set_bit(BTRFS_FS_QUOTA_ENABLING, &fs_info->flags);
924+
set_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags);
927925
spin_unlock(&fs_info->qgroup_lock);
926+
ret = qgroup_rescan_init(fs_info, 0, 1);
927+
if (!ret) {
928+
qgroup_rescan_zero_tracking(fs_info);
929+
btrfs_queue_work(fs_info->qgroup_rescan_workers,
930+
&fs_info->qgroup_rescan_work);
931+
}
932+
928933
out_free_path:
929934
btrfs_free_path(path);
930935
out_free_root:
@@ -2080,17 +2085,9 @@ int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
20802085
{
20812086
struct btrfs_root *quota_root = fs_info->quota_root;
20822087
int ret = 0;
2083-
int start_rescan_worker = 0;
20842088

20852089
if (!quota_root)
2086-
goto out;
2087-
2088-
if (!test_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags) &&
2089-
test_bit(BTRFS_FS_QUOTA_ENABLING, &fs_info->flags))
2090-
start_rescan_worker = 1;
2091-
2092-
if (test_and_clear_bit(BTRFS_FS_QUOTA_ENABLING, &fs_info->flags))
2093-
set_bit(BTRFS_FS_QUOTA_ENABLED, &fs_info->flags);
2090+
return ret;
20942091

20952092
spin_lock(&fs_info->qgroup_lock);
20962093
while (!list_empty(&fs_info->dirty_qgroups)) {
@@ -2119,18 +2116,6 @@ int btrfs_run_qgroups(struct btrfs_trans_handle *trans,
21192116
if (ret)
21202117
fs_info->qgroup_flags |= BTRFS_QGROUP_STATUS_FLAG_INCONSISTENT;
21212118

2122-
if (!ret && start_rescan_worker) {
2123-
ret = qgroup_rescan_init(fs_info, 0, 1);
2124-
if (!ret) {
2125-
qgroup_rescan_zero_tracking(fs_info);
2126-
btrfs_queue_work(fs_info->qgroup_rescan_workers,
2127-
&fs_info->qgroup_rescan_work);
2128-
}
2129-
ret = 0;
2130-
}
2131-
2132-
out:
2133-
21342119
return ret;
21352120
}
21362121

0 commit comments

Comments
 (0)