generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / btrfs / 036
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2014 Fujitsu.  All Rights Reserved.
4 #
5 # FS QA Test No. btrfs/036
6 #
7 # Regression test for running snapshots and send concurrently.
8 #
9 . ./common/preamble
10 _begin_fstest auto quick send snapshot
11
12 snapshots_pid=0
13
14 # Override the default cleanup function.
15 _cleanup()
16 {
17         # kill backgroud snapshots
18         if [ $snapshots_pid -ne 0 ] && ps -p $snapshots_pid | grep -q $snapshots_pid; then
19                 kill -TERM $snapshots_pid 2> /dev/null
20                 wait $snapshots_pid
21         fi
22         rm -f $tmp.*
23 }
24
25 do_snapshots()
26 {
27         # Wait for any running 'btrfs subvolume snapshot' subcommand before
28         # exitting so that after the test kills the subshell running this
29         # function, it does not fail with EBUSY when unmounting the scratch
30         # device.
31         trap "wait; exit" SIGTERM
32
33         i=2
34         while [ 1 ]
35         do
36                 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT/snap_1 \
37                         $SCRATCH_MNT/snap_$i >> $seqres.full 2>&1
38                 let i=$i+1
39                 sleep 1
40         done
41 }
42
43 # Import common functions.
44 . ./common/filter
45
46 # real QA test starts here
47 _supported_fs btrfs
48 _require_scratch
49
50 _scratch_mkfs > /dev/null 2>&1
51 _scratch_mount
52
53 touch $SCRATCH_MNT/foo
54
55 # get file with fragments by using backwards writes.
56 for i in `seq 10240 -1 1`; do
57         $XFS_IO_PROG -f -d -c "pwrite $(($i * 4096)) 4096" \
58                 $SCRATCH_MNT/foo > /dev/null | _filter_xfs_io
59 done
60
61 $BTRFS_UTIL_PROG subvolume snapshot -r $SCRATCH_MNT \
62         $SCRATCH_MNT/snap_1 >> $seqres.full 2>&1
63
64 do_snapshots &
65 snapshots_pid=$!
66
67 $BTRFS_UTIL_PROG send -f /dev/null $SCRATCH_MNT/snap_1 2>&1 | _filter_scratch
68
69 status=0 ; exit