2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2018 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test if btrfs can clear high level childless qgroup's accounting numbers
10 # Fixed by the following kernel patch:
11 # "btrfs: qgroup: Dirty all qgroups before rescan"
14 _begin_fstest auto quick qgroup
16 # Import common functions.
18 . ./common/filter.btrfs
20 # real QA test starts here
24 _scratch_mkfs > /dev/null 2>&1
28 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" > /dev/null
29 _pwrite_byte 0xcdcd 0 1M "$SCRATCH_MNT/subvol/file1" > /dev/null
31 # Ensure that buffered file data is persisted, so we won't have an
32 # empty file in the snapshot.
34 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/subvol" \
35 "$SCRATCH_MNT/snapshot" > /dev/null
37 $BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null
38 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
40 # Create high level qgroup
41 $BTRFS_UTIL_PROG qgroup create 1/0 "$SCRATCH_MNT"
43 $BTRFS_UTIL_PROG qgroup assign "$SCRATCH_MNT/snapshot" 1/0 "$SCRATCH_MNT" \
44 2>&1 | _filter_btrfs_qgroup_assign_warnings
46 # Above assignment will mark qgroup inconsistent due to the shared extents
47 # between subvol/snapshot/high level qgroup, do rescan here.
48 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
50 # Now remove the qgroup relationship and make 1/0 childless
51 # Due to the shared extent outside of 1/0, we will mark qgroup inconsistent
52 # and keep the number of qgroup 1/0.
53 $BTRFS_UTIL_PROG qgroup remove "$SCRATCH_MNT/snapshot" 1/0 "$SCRATCH_MNT" \
54 2>&1 | _filter_btrfs_qgroup_assign_warnings
56 # Above removal also marks qgroup inconsistent, rescan again
57 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
59 # After the test, btrfs check will verify qgroup numbers to catch any
62 echo "Silence is golden"