btrfs: qgroup: allow quick inherit if snapshot is created and added to the same parent
authorQu Wenruo <wqu@suse.com>
Mon, 26 Feb 2024 03:51:13 +0000 (14:21 +1030)
committerDavid Sterba <dsterba@suse.com>
Tue, 5 Mar 2024 16:13:24 +0000 (17:13 +0100)
commitb20fe56cd285dbbf64874ec9d1c81f8a8ac2f821
tree89f2db4f6541c21f657e0a7a7681f8e84b6a8eb1
parent86211eea8ae1676cc819d2b4fdc8d995394be07d
btrfs: qgroup: allow quick inherit if snapshot is created and added to the same parent

Currently "btrfs subvolume snapshot -i <qgroupid>" would always mark the
qgroup inconsistent.

This can be annoying if the fs has a lot of snapshots, and needs qgroup
to get the accounting for the amount of bytes it can free for each
snapshot.

Although we have the new simple quote as a solution, there is also a
case where we can skip the full scan, if all the following conditions
are met:

- The source subvolume belongs to a higher level parent qgroup
- The parent qgroup already owns all its bytes exclusively
- The new snapshot is also added to the same parent qgroup

In that case, we only need to add nodesize to the parent qgroup and
avoid a full rescan.

This patch would add the extra quick accounting update for such inherit.

Signed-off-by: Qu Wenruo <wqu@suse.com>
Reviewed-by: David Sterba <dsterba@suse.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/qgroup.c