]> git.hungrycats.org Git - btrfs-progs/commitdiff
btrfs-progs: check: fix the inverted condition to load qgroups
authorQu Wenruo <wqu@suse.com>
Mon, 5 Oct 2026 07:52:08 +0000 (18:22 +1030)
committerQu Wenruo <wqu@suse.com>
Thu, 15 Oct 2026 04:19:39 +0000 (14:49 +1030)
[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>
check/qgroup-verify.c

index 68002ec2e2aee165f413c8864d26e5defcdad23d..7993cd22a21308340fc8a0288c47d7b2f7d2bc40 100644 (file)
@@ -953,7 +953,7 @@ loop:
         * items. The 2nd pass picks up relation items and glues them to their
         * respective count structures.
         */
-       key.objectid = search_relations ? 0 : BTRFS_QGROUP_RELATION_KEY;
+       key.objectid = search_relations ? BTRFS_QGROUP_RELATION_KEY : 0;
        key.type = 0;
        key.offset = 0;