btrfs/012: check free size of scratch device before copying files
[xfstests-dev.git] / tests / xfs / 141
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Red Hat, Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 141
6 #
7 # Use the XFS log record CRC error injection mechanism to test torn writes to
8 # the log. The error injection mechanism writes an invalid CRC and shuts down
9 # the filesystem. The test verifies that a subsequent remount recovers the log
10 # and that the filesystem is consistent.
11 #
12 # Note that this test requires a DEBUG mode kernel.
13 #
14 seq=`basename $0`
15 seqres=$RESULT_DIR/$seq
16 echo "QA output created by $seq"
17
18 here=`pwd`
19 tmp=/tmp/$$
20 status=1        # failure is the default!
21 trap "_cleanup; exit \$status" 0 1 2 3 15
22
23 _cleanup()
24 {
25         cd /
26         rm -f $tmp.*
27         $KILLALL_PROG -9 fsstress > /dev/null 2>&1
28         wait > /dev/null 2>&1
29 }
30
31 rm -f $seqres.full
32
33 # get standard environment, filters and checks
34 . ./common/rc
35 . ./common/inject
36
37 # real QA test starts here
38
39 # Modify as appropriate.
40 _supported_fs xfs
41 _require_xfs_io_error_injection "log_bad_crc"
42 _require_scratch
43 _require_command "$KILLALL_PROG" killall
44
45 echo "Silence is golden."
46
47 _scratch_mkfs >> $seqres.full 2>&1 || _fail "mkfs failed"
48 _scratch_mount
49
50 sdev=$(_short_dev $SCRATCH_DEV)
51
52 nr_times=$((TIME_FACTOR * 5))
53 while [ $nr_times -gt 0 ]; do
54         # Enable error injection. Use a random bad crc factor up to 100
55         # (increase this value to run fsstress longer).
56         factor=$((RANDOM % 100 + 1))
57         echo iteration $i log_badcrc_factor: $factor >> $seqres.full 2>&1
58         _scratch_inject_error "log_bad_crc" "$factor"
59
60         # Run fsstress until the filesystem shuts down. It will shut down
61         # automatically when error injection triggers.
62         $FSSTRESS_PROG -d $SCRATCH_MNT -p 4 -n 999999 >> $seqres.full 2>&1
63
64         # Verify that we can remount the fs. Log recovery should handle the torn
65         # write.
66         _scratch_unmount
67         _scratch_mount
68         nr_times=$((nr_times - 1))
69 done
70
71 # success, all done
72 status=0
73 exit