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 seqres=$RESULT_DIR/$seq
15 echo "QA output created by $seq"
19 status=1 # failure is the default!
20 trap "_cleanup; exit \$status" 0 1 2 3 15
28 # get standard environment, filters and checks
31 . ./common/filter.btrfs
33 # remove previous $seqres.full before test
36 # real QA test starts here
41 _scratch_mkfs > /dev/null 2>&1
46 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/subvol" > /dev/null
47 _pwrite_byte 0xcdcd 0 1M "$SCRATCH_MNT/subvol/file1" > /dev/null
49 # Ensure that buffered file data is persisted, so we won't have an
50 # empty file in the snapshot.
52 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/subvol" \
53 "$SCRATCH_MNT/snapshot" > /dev/null
56 $BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null
57 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
59 # Create high level qgroup
60 $BTRFS_UTIL_PROG qgroup create 1/0 "$SCRATCH_MNT"
62 $BTRFS_UTIL_PROG qgroup assign "$SCRATCH_MNT/snapshot" 1/0 "$SCRATCH_MNT" \
63 2>&1 | _filter_btrfs_qgroup_assign_warnings
65 # Above assignment will mark qgroup inconsistent due to the shared extents
66 # between subvol/snapshot/high level qgroup, do rescan here.
67 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
69 # Now remove the qgroup relationship and make 1/0 childless
70 # Due to the shared extent outside of 1/0, we will mark qgroup inconsistent
71 # and keep the number of qgroup 1/0.
72 $BTRFS_UTIL_PROG qgroup remove "$SCRATCH_MNT/snapshot" 1/0 "$SCRATCH_MNT" \
73 2>&1 | _filter_btrfs_qgroup_assign_warnings
75 # Above removal also marks qgroup inconsistent, rescan again
76 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
78 # After the test, btrfs check will verify qgroup numbers to catch any
81 echo "Silence is golden"