2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
7 # Test if btrfs will lockup at subvolume deletion when qgroups are enabled.
9 # This bug is going to be fixed by a patch for the kernel titled
10 # "btrfs: qgroup: Don't trigger backref walk at delayed ref insert time".
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
18 status=1 # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
27 # get standard environment, filters and checks
31 # remove previous $seqres.full before test
34 # real QA test starts here
36 # Modify as appropriate.
40 # default sleep interval
46 _scratch_mkfs > /dev/null 2>&1
49 mkdir -p "$SCRATCH_MNT/snapshots"
50 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/src" > /dev/null
51 $BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null
52 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
56 trap "wait; exit" SIGTERM
59 _pwrite_byte 0xcd 0 8K "$SCRATCH_MNT/src/large_$i" > /dev/null
60 _pwrite_byte 0xcd 0 2K "$SCRATCH_MNT/src/inline_$i" > /dev/null
62 # Randomly remove some files for every 5 loop
63 if [ $(( $i % 5 )) -eq 0 ]; then
64 victim=$(ls "$SCRATCH_MNT/src" | sort -R | head -n1)
65 rm "$SCRATCH_MNT/src/$victim"
73 trap "wait; exit" SIGTERM
77 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/src" \
78 "$SCRATCH_MNT/snapshots/$i" > /dev/null
85 trap "wait; exit" SIGTERM
87 sleep $((sleep_time * 2))
88 victim=$(ls "$SCRATCH_MNT/snapshots" | sort -R | head -n1)
89 $BTRFS_UTIL_PROG subvolume delete \
90 "$SCRATCH_MNT/snapshots/$victim" > /dev/null
97 sleep $((sleep_time * 2))
111 # By the async nature of qgroup tree scan and subvolume delete, the latest
112 # qgroup counts at the time of umount might not be upto date, if it isn't
113 # then the check will report the difference in count. The difference in
114 # qgroup counts are anyway updated in the following mount, so it is not a
115 # real issue that this test case is trying to verify. So make sure the
116 # qgroup counts are in sync before unmount happens.
118 $BTRFS_UTIL_PROG subvolume sync $SCRATCH_MNT >> $seqres.full
121 echo "Silence is golden"