btrfs: qgroup: Dirty all qgroups before rescan
PATCH 1/1 btrfs: qgroup: Dirty all qgroups before rescan
[BUG]
In the following case, rescan won't zero out the number of qgroup 1/0:
------
$ mkfs.btrfs -fq $DEV $ mount $DEV /mnt
$ btrfs quota enable /mnt $ btrfs qgroup create 1/0 /mnt $ btrfs sub create /mnt/sub $ btrfs qgroup assign 0/257 1/0 /mnt
$ dd if=/dev/urandom of=/mnt/sub/file bs=1k count=1000 $ btrfs sub snap /mnt/sub /mnt/snap $ btrfs quota rescan -w /mnt $ btrfs qgroup show -pcre /mnt qgroupid rfer excl max_rfer max_excl parent child -------- ---- ---- -------- -------- ------ ----- 0/5 16.00KiB 16.00KiB none none --- --- 0/257 1016.00KiB 16.00KiB none none 1/0 --- 0/258 1016.00KiB 16.00KiB none none --- --- 1/0 1016.00KiB 16.00KiB none none --- 0/257
so far so good, but:
$ btrfs qgroup remove 0/257 1/0 /mnt
WARNING: quotas may be inconsistent, rescan needed
$ btrfs quota rescan -w /mnt
$ btrfs qgroup show -pcre /mnt
qgoupid rfer excl max_rfer max_excl parent child
-------- ---- ---- -------- -------- ------ -----
0/5 16.00KiB 16.00KiB none none --- ---
0/257 1016.00KiB 16.00KiB none none --- ---
0/258 1016.00KiB 16.00KiB none none --- ---
1/0 1016.00KiB 16.00KiB none none --- ---
^^^^^^^^^^ ^^^^^^^^ not cleared
------[CAUSE]
Before rescan we call qgroup_rescan_zero_tracking() to zero out all qgroups' accounting numbers.
However we don't mark all these qgroups dirty, but rely on rescan to mark qgroup dirty.
If we have high level qgroup but without any child (orphan group), it won't be marked dirty during rescan, since we can reach that qgroup.
This will cause QGROUP_INFO item of orphan qgroups never updated in quota tree, thus its number will stay the same in "btrfs qgroup show" output.
[FIX]
Just mark all qgroup dirty in qgroup_rescan_zero_tracking(), so even we have orphan qgroups their QGROUP_INFO item will still get updated during rescan.
--- fs/btrfs/qgroup.c | 1 + 1 file changed, 1 insertion(+)
fs/btrfs/qgroup.c +1 -0
@@ -2864,6 +2864,7 @@ qgroup_rescan_zero_tracking(struct btrfs_fs_info *fs_info) qgroup->rfer_cmpr =0 ; qgroup->excl =0 ; qgroup->excl_cmpr =0 ; +qgroup_dirty (fs_info, qgroup); }spin_unlock (&fs_info->qgroup_lock); }
Signature · 1 line
2.18.0
Quoted 51 lines · Qu Wenruo
[BUG]
In the following case, rescan won't zero out the number of qgroup 1/0:
------$ mkfs.btrfs -fq $DEV $ mount $DEV /mnt$ btrfs quota enable /mnt $ btrfs qgroup create 1/0 /mnt $ btrfs sub create /mnt/sub $ btrfs qgroup assign 0/257 1/0 /mnt$ dd if=/dev/urandom of=/mnt/sub/file bs=1k count=1000 $ btrfs sub snap /mnt/sub /mnt/snap $ btrfs quota rescan -w /mnt $ btrfs qgroup show -pcre /mnt qgroupid rfer excl max_rfer max_excl parent child -------- ---- ---- -------- -------- ------ ----- 0/5 16.00KiB 16.00KiB none none --- --- 0/257 1016.00KiB 16.00KiB none none 1/0 --- 0/258 1016.00KiB 16.00KiB none none --- --- 1/0 1016.00KiB 16.00KiB none none --- 0/257so far so good, but:
$ btrfs qgroup remove 0/257 1/0 /mnt WARNING: quotas may be inconsistent, rescan needed $ btrfs quota rescan -w /mnt $ btrfs qgroup show -pcre /mnt qgoupid rfer excl max_rfer max_excl parent child -------- ---- ---- -------- -------- ------ ----- 0/5 16.00KiB 16.00KiB none none --- --- 0/257 1016.00KiB 16.00KiB none none --- --- 0/258 1016.00KiB 16.00KiB none none --- --- 1/0 1016.00KiB 16.00KiB none none --- --- ^^^^^^^^^^ ^^^^^^^^ not cleared ------[CAUSE]
Before rescan we callqgroup_rescan_zero_tracking()to zero out all qgroups' accounting numbers.However we don't mark all these qgroups dirty, but rely on rescan to mark qgroup dirty.
If we have high level qgroup but without any child (orphan group), it won't be marked dirty during rescan, since we can reach that qgroup.
This will cause
QGROUP_INFOitem of orphan qgroups never updated in quota tree, thus its number will stay the same in "btrfs qgroup show" output.
Quoted 7 lines
[FIX]
Just mark all qgroup dirty inqgroup_rescan_zero_tracking(), so even we have orphan qgroups theirQGROUP_INFOitem will still get updated during rescan.Reported-by Misono Tomohiro <[email protected]>Signed-off-by Qu Wenruo <[email protected]>
DOesn't this warrant an xfstests as well ?
Quoted 17 lines
--- fs/btrfs/qgroup.c | 1 + 1 file changed, 1 insertion(+)fs/btrfs/qgroup.c +1
-0@@ -2864,6 +2864,7 @@ qgroup_rescan_zero_tracking(struct btrfs_fs_info *fs_info) qgroup->rfer_cmpr =0 ; qgroup->excl =0 ; qgroup->excl_cmpr =0 ; +qgroup_dirty (fs_info, qgroup); }spin_unlock (&fs_info->qgroup_lock); }
Quoted 59 lines · Nikolay Borisov
Quoted 56 lines · Qu Wenruo
[BUG]
In the following case, rescan won't zero out the number of qgroup 1/0:
------$ mkfs.btrfs -fq $DEV $ mount $DEV /mnt$ btrfs quota enable /mnt $ btrfs qgroup create 1/0 /mnt $ btrfs sub create /mnt/sub $ btrfs qgroup assign 0/257 1/0 /mnt$ dd if=/dev/urandom of=/mnt/sub/file bs=1k count=1000 $ btrfs sub snap /mnt/sub /mnt/snap $ btrfs quota rescan -w /mnt $ btrfs qgroup show -pcre /mnt qgroupid rfer excl max_rfer max_excl parent child -------- ---- ---- -------- -------- ------ ----- 0/5 16.00KiB 16.00KiB none none --- --- 0/257 1016.00KiB 16.00KiB none none 1/0 --- 0/258 1016.00KiB 16.00KiB none none --- --- 1/0 1016.00KiB 16.00KiB none none --- 0/257so far so good, but:
$ btrfs qgroup remove 0/257 1/0 /mnt WARNING: quotas may be inconsistent, rescan needed $ btrfs quota rescan -w /mnt $ btrfs qgroup show -pcre /mnt qgoupid rfer excl max_rfer max_excl parent child -------- ---- ---- -------- -------- ------ ----- 0/5 16.00KiB 16.00KiB none none --- --- 0/257 1016.00KiB 16.00KiB none none --- --- 0/258 1016.00KiB 16.00KiB none none --- --- 1/0 1016.00KiB 16.00KiB none none --- --- ^^^^^^^^^^ ^^^^^^^^ not cleared ------[CAUSE]
Before rescan we callqgroup_rescan_zero_tracking()to zero out all qgroups' accounting numbers.However we don't mark all these qgroups dirty, but rely on rescan to mark qgroup dirty.
If we have high level qgroup but without any child (orphan group), it won't be marked dirty during rescan, since we can reach that qgroup.
This will cause
QGROUP_INFOitem of orphan qgroups never updated in quota tree, thus its number will stay the same in "btrfs qgroup show" output.[FIX]
Just mark all qgroup dirty inqgroup_rescan_zero_tracking(), so even we have orphan qgroups theirQGROUP_INFOitem will still get updated during rescan.
Quoted 4 lines
Quoted 2 lines
Reported-by Misono Tomohiro <[email protected]>Signed-off-by Qu Wenruo <[email protected]>DOesn't this warrant an xfstests as well ?
Just crafting. :)
Thanks,
Qu
Quoted 22 lines
Quoted 10 lines
--- fs/btrfs/qgroup.c | 1 + 1 file changed, 1 insertion(+)fs/btrfs/qgroup.c +0
-0fs/btrfs/qgroup.c qgroup_rescan_zero_tracking(struct btrfs_fs_info *fs_info) · line 2870
Quoted 7 lines
fs/btrfs/qgroup.c +1
-0@@ -2864,6 +2864,7 @@ qgroup_rescan_zero_tracking(struct btrfs_fs_info *fs_info) qgroup->rfer_cmpr =0 ; qgroup->excl =0 ; qgroup->excl_cmpr =0 ; +qgroup_dirty (fs_info, qgroup); }spin_unlock (&fs_info->qgroup_lock); }--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html