btrfs/079: fix failure to umount scratch fs due to running filefrag process
[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 _supported_os Linux
39 _require_scratch
40
41 # default sleep interval
42 sleep_time=1
43
44 # stress test runtime
45 runtime=120
46
47 _scratch_mkfs > /dev/null 2>&1
48 _scratch_mount
49
50 mkdir -p "$SCRATCH_MNT/snapshots"
51 $BTRFS_UTIL_PROG subvolume create "$SCRATCH_MNT/src" > /dev/null
52 $BTRFS_UTIL_PROG quota enable "$SCRATCH_MNT" > /dev/null
53 $BTRFS_UTIL_PROG quota rescan -w "$SCRATCH_MNT" > /dev/null
54
55 fill_workload()
56 {
57         trap "wait; exit" SIGTERM
58         local i=0
59         while true; do
60                 _pwrite_byte 0xcd 0 8K "$SCRATCH_MNT/src/large_$i" > /dev/null
61                 _pwrite_byte 0xcd 0 2K "$SCRATCH_MNT/src/inline_$i" > /dev/null
62
63                 # Randomly remove some files for every 5 loop
64                 if [ $(( $i % 5 )) -eq 0 ]; then
65                         victim=$(ls "$SCRATCH_MNT/src" | sort -R | head -n1)
66                         rm "$SCRATCH_MNT/src/$victim"
67                 fi
68                 i=$((i + 1))
69         done
70 }
71
72 snapshot_workload()
73 {
74         trap "wait; exit" SIGTERM
75         local i=0
76         while true; do
77                 sleep $sleep_time
78                 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/src" \
79                         "$SCRATCH_MNT/snapshots/$i" > /dev/null
80                 i=$((i + 1))
81         done
82 }
83
84 delete_workload()
85 {
86         trap "wait; exit" SIGTERM
87         while true; do
88                 sleep $((sleep_time * 2))
89                 victim=$(ls "$SCRATCH_MNT/snapshots" | sort -R | head -n1)
90                 $BTRFS_UTIL_PROG subvolume delete \
91                         "$SCRATCH_MNT/snapshots/$victim" > /dev/null
92         done
93 }
94
95 fill_workload &
96 fill_pid=$!
97
98 sleep $((sleep_time * 2))
99 snapshot_workload &
100 snapshot_pid=$!
101 delete_workload &
102 delete_pid=$!
103
104 sleep $runtime
105 kill $fill_pid
106 wait $fill_pid
107 kill $snapshot_pid
108 wait $snapshot_pid
109 kill $delete_pid
110 wait $delete_pid
111
112 # success, all done
113 echo "Silence is golden"
114
115 status=0
116 exit