generic: test MADV_POPULATE_READ with IO errors
[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 . ./common/preamble
13 _begin_fstest auto qgroup dangerous
14
15 # Import common functions.
16 . ./common/filter
17
18 # real QA test starts here
19
20 # Modify as appropriate.
21 _supported_fs btrfs
22 _require_scratch
23
24 # default sleep interval
25 sleep_time=1
26
27 # stress test runtime
28 runtime=120
29
30 _scratch_mkfs > /dev/null 2>&1
31 _scratch_mount
32
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
37
38 fill_workload()
39 {
40         trap "wait; exit" SIGTERM
41         local i=0
42         while true; do
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
45
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"
50                 fi
51                 i=$((i + 1))
52         done
53 }
54
55 snapshot_workload()
56 {
57         trap "wait; exit" SIGTERM
58         local i=0
59         while true; do
60                 sleep $sleep_time
61                 $BTRFS_UTIL_PROG subvolume snapshot "$SCRATCH_MNT/src" \
62                         "$SCRATCH_MNT/snapshots/$i" > /dev/null
63                 i=$((i + 1))
64         done
65 }
66
67 delete_workload()
68 {
69         trap "wait; exit" SIGTERM
70         while true; do
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.
75                         continue
76                 fi
77                 $BTRFS_UTIL_PROG subvolume delete \
78                         "$SCRATCH_MNT/snapshots/$victim" > /dev/null
79         done
80 }
81
82 fill_workload &
83 fill_pid=$!
84
85 sleep $((sleep_time * 2))
86 snapshot_workload &
87 snapshot_pid=$!
88 delete_workload &
89 delete_pid=$!
90
91 sleep $runtime
92 kill $fill_pid
93 wait $fill_pid
94 kill $snapshot_pid
95 wait $snapshot_pid
96 kill $delete_pid
97 wait $delete_pid
98
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.
105
106 $BTRFS_UTIL_PROG subvolume sync $SCRATCH_MNT >> $seqres.full
107
108 # success, all done
109 echo "Silence is golden"
110
111 status=0
112 exit