Skip to contentSkip to conversation

btrfs: qgroup: Dirty all qgroups before rescan

PATCH Superseded Qu Wenruo 4 participants 4 messages Aug 9, 2018 Btrfs file system

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Qu Wenruo

author
#0 lore raw

PATCH v2 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 qgroups dirty, but rely on rescan to mark qgroups dirty.

If we have any high level qgroup but without any child (orphan group), it won't be marked dirty during rescan, since we can not reach that qgroup.

This will cause QGROUP_INFO items of orphan qgroups never get updated in quota tree, thus their numbers will stay the same in "btrfs qgroup show" output.

[FIX]
Just mark all qgroups dirty in qgroup_rescan_zero_tracking(), so even we have orphan qgroups their QGROUP_INFO items will still get updated during rescan.

---
changelog:
v2:
Fix some grammar errors in commit message.

---
 fs/btrfs/qgroup.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/qgroup.c +1 -0
index 48c1c3e7baf3..5a5372b33d96 100644
@@ -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
#1 lore raw
Quoted 72 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/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 qgroups dirty, but rely on rescan to mark qgroups dirty.

If we have any high level qgroup but without any child (orphan group), it won't be marked dirty during rescan, since we can not reach that qgroup.

This will cause QGROUP_INFO items of orphan qgroups never get updated in quota tree, thus their numbers will stay the same in "btrfs qgroup show" output.

[FIX]
Just mark all qgroups dirty in qgroup_rescan_zero_tracking(), so even we have orphan qgroups their QGROUP_INFO items will still get updated during rescan.

---
changelog:
v2:
Fix some grammar errors in commit message.

---
 fs/btrfs/qgroup.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/qgroup.c +0 -0
index 48c1c3e7baf3..5a5372b33d96 100644

fs/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);
 }

Yes, this and previous patch
[PATCH] btrfs: qgroup: Don't populating excl numbers for snapshot src if it belongs to other qgroups
resolves the problem I see.

So, this will reset all the qgroup items not rescanned in first transaction commit by btrfs_run_qgroups(), but I don't think it is a problem.

Tested-by/Reviewed-by: Misono Tomohiro <[email protected]>

Thanks,
Misono

#2 lore raw
In reply to Qu Wenruo
Quoted 37 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/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
------
Quoted 8 lines

[CAUSE]
Before rescan we call qgroup_rescan_zero_tracking() to zero out all qgroups' accounting numbers.

However we don't mark all qgroups dirty, but rely on rescan to mark qgroups dirty.

If we have any high level qgroup but without any child (orphan group),

That sentence is confusing. An orphan, by definition [1], is someone (or something in this case) without parents.
But you mention a group without children, so that should be named "childless" or simply say "without children".
So one part of the sentence is wrong, either what is in parenthesis or what comes before them.

[1] https://www.thefreedictionary.com/orphan

Quoted 41 lines

it
won't be marked dirty during rescan, since we can not reach that qgroup.

This will cause QGROUP_INFO items of orphan qgroups never get updated in quota tree, thus their numbers will stay the same in "btrfs qgroup show" output.

[FIX]
Just mark all qgroups dirty in qgroup_rescan_zero_tracking(), so even we have orphan qgroups their QGROUP_INFO items will still get updated during rescan.

---
changelog:
v2:
Fix some grammar errors in commit message.

---
 fs/btrfs/qgroup.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/qgroup.c +1 -1
index 48c1c3e7baf3..5a5372b33d96 100644
@@ -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);
 }
--

2.18.0

--
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

Signature · 3 lines
Filipe David Manana,

“Whether you think you can, or you think you can't — you're right.”
#3 lore raw
Quoted 45 lines · Filipe Manana
Quoted 44 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/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 qgroups dirty, but rely on rescan to mark qgroups dirty.

Quoted 6 lines
Quoted 1 line

If we have any high level qgroup but without any child (orphan group),

That sentence is confusing. An orphan, by definition [1], is someone (or something in this case) without parents.
But you mention a group without children, so that should be named "childless" or simply say "without children".

Makes sense, I'll correct the commit message in next version.

Thanks,
Qu

Quoted 49 lines

So one part of the sentence is wrong, either what is in parenthesis or what comes before them.

[1] https://www.thefreedictionary.com/orphan

Quoted 41 lines

it
won't be marked dirty during rescan, since we can not reach that qgroup.

This will cause QGROUP_INFO items of orphan qgroups never get updated in quota tree, thus their numbers will stay the same in "btrfs qgroup show" output.

[FIX]
Just mark all qgroups dirty in qgroup_rescan_zero_tracking(), so even we have orphan qgroups their QGROUP_INFO items will still get updated during rescan.

---
changelog:
v2:
Fix some grammar errors in commit message.

---
 fs/btrfs/qgroup.c | 1 +
 1 file changed, 1 insertion(+)
fs/btrfs/qgroup.c +1 -1
index 48c1c3e7baf3..5a5372b33d96 100644
@@ -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);
 }
--

2.18.0

--
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