common: kill _supported_os
[xfstests-dev.git] / tests / btrfs / 179
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (C) 2019 SUSE Linux Products GmbH. All Rights Reserved.
4 #
5 # FS QA Test 179
6 #
7 # Test if btrfs will lockup at subvolume deletion when qgroups are enabled.
8 #
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".
11 #
12 seq=`basename $0`
13 seqres=$RESULT_DIR/$seq
14 echo "QA output created by $seq"
15
16 here=`pwd`
17 tmp=/tmp/$$
18 status=1        # failure is the default!
19 trap "_cleanup; exit \$status" 0 1 2 3 15
20
21 _cleanup()
22 {
23         cd /
24         rm -f $tmp.*
25 }
26
27 # get standard environment, filters and checks
28 . ./common/rc
29 . ./common/filter
30
31 # remove previous $seqres.full before test
32 rm -f $seqres.full
33
34 # real QA test starts here
35
36 # Modify as appropriate.
37 _supported_fs btrfs
38 _require_scratch
39
40 # default sleep interval
41 sleep_time=1
42
43 # stress test runtime
44 runtime=120
45
46 _scratch_mkfs > /dev/null 2>&1
47 _scratch_mount
48
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
53
54 fill_workload()
55 {
56         trap "wait; exit" SIGTERM
57         local i=0
58         while true; do
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
61
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"
66                 fi
67                 i=$((i + 1))
68         done
69 }
70
71 snapshot_workload()
72 {
73         trap "wait; exit" SIGTERM
74         local i=0
75         while true; do
76                 sleep $sleep_time
77                 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/src" \
78                         "$SCRATCH_MNT/snapshots/$i" > /dev/null
79                 i=$((i + 1))
80         done
81 }
82
83 delete_workload()
84 {
85         trap "wait; exit" SIGTERM
86         while true; do
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
91         done
92 }
93
94 fill_workload &
95 fill_pid=$!
96
97 sleep $((sleep_time * 2))
98 snapshot_workload &
99 snapshot_pid=$!
100 delete_workload &
101 delete_pid=$!
102
103 sleep $runtime
104 kill $fill_pid
105 wait $fill_pid
106 kill $snapshot_pid
107 wait $snapshot_pid
108 kill $delete_pid
109 wait $delete_pid
110
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.
117
118 $BTRFS_UTIL_PROG subvolume sync $SCRATCH_MNT >> $seqres.full
119
120 # success, all done
121 echo "Silence is golden"
122
123 status=0
124 exit