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 _begin_fstest auto qgroup dangerous
15 # Import common functions.
18 # real QA test starts here
20 # Modify as appropriate.
24 # default sleep interval
30 _scratch_mkfs > /dev/null 2>&1
33 mkdir -p "$SCRATCH_MNT/snapshots"
34 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/src" > /dev/null
35 $BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null
36 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
40 trap "wait; exit" SIGTERM
43 _pwrite_byte 0xcd 0 8K "$SCRATCH_MNT/src/large_$i" > /dev/null
44 _pwrite_byte 0xcd 0 2K "$SCRATCH_MNT/src/inline_$i" > /dev/null
46 # Randomly remove some files for every 5 loop
47 if [ $(( $i % 5 )) -eq 0 ]; then
48 victim=$(ls "$SCRATCH_MNT/src" | sort -R | head -n1)
49 rm "$SCRATCH_MNT/src/$victim"
57 trap "wait; exit" SIGTERM
61 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/src" \
62 "$SCRATCH_MNT/snapshots/$i" > /dev/null
69 trap "wait; exit" SIGTERM
71 sleep $((sleep_time * 2))
72 victim=$(ls "$SCRATCH_MNT/snapshots" | sort -R | head -n1)
73 if [ -z "$victim" ]; then
74 # No snapshots available, sleep and retry later.
77 $BTRFS_UTIL_PROG subvolume delete \
78 "$SCRATCH_MNT/snapshots/$victim" > /dev/null
85 sleep $((sleep_time * 2))
99 # By the async nature of qgroup tree scan and subvolume delete, the latest
100 # qgroup counts at the time of umount might not be upto date, if it isn't
101 # then the check will report the difference in count. The difference in
102 # qgroup counts are anyway updated in the following mount, so it is not a
103 # real issue that this test case is trying to verify. So make sure the
104 # qgroup counts are in sync before unmount happens.
106 $BTRFS_UTIL_PROG subvolume sync $SCRATCH_MNT >> $seqres.full
109 echo "Silence is golden"