[BUG]
When a qgroup tree is higher than level 0 and has a qgroup relation
between the first subvolume and a higher level qgroup, the btrfs check
can failed to load qgroup tree.
A minimal reproducer looks like the following:
mkfs.btrfs -f -K -n 4k $dev > /dev/null
mount $dev $mnt
btrfs quota enable "$mnt"
btrfs quota rescan -w $mnt
for i in $(seq 1 32); do
btrfs subvolume create "$mnt/s$i" >/dev/null
done
id=$(btrfs subvolume list "$mnt" | awk 'NR==1 {print $2}')
btrfs qgroup create 1/1 "$mnt"
btrfs qgroup assign "0/$id" 1/1 "$mnt"
umount $mnt
btrfs check -Q $dev
The failure looks like:
Opening filesystem to check...
Checking filesystem on /dev/test/scratch1
UUID:
fbe3bc62-168a-4fec-8ef5-
ba5f92d8c22c
Print quota groups report for /dev/test/scratch1
UUID:
fbe3bc62-168a-4fec-8ef5-
ba5f92d8c22c
ERROR: failed to add qgroup relation, member=256 parent=
281474976710657: No such file or directory
ERROR: loading qgroups from disk: -2
extent buffer leak: start
30789632 len 4096
extent buffer leak: start
30793728 len 4096
[CAUSE]
With extra debug output, the following one line shows the problem pretty
well:
load_quota_info: search_relations=0 search_key=(246 0 0)
That's for the first loop of load_quota_info(), which should start from
the first leaf and load all qgroups into memory.
However the search key is not (0 0 0), it's the inverted condition
initializing the search key cause btrfs-check to grab the leaf with
qgroup relation items, not the first leaf.
Thus btrfs-check failed to load the qgroups in earlier leaves, causing
the above failure.
[FIX]
The code is not that well written, but as a hot fix just revert the
condition to fix the bug.
Issues: #1180
Signed-off-by: Qu Wenruo <wqu@suse.com>