fstests: move test group info to test files
[xfstests-dev.git] / tests / xfs / 057
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2017 Red Hat, Inc. All Rights Reserved.
4 #
5 # FS QA Test No. 057
6 #
7 # Attempt to reproduce log recovery failure by writing corrupt log records over
8 # the last good tail in the log. The tail is force pinned while a workload runs
9 # the head as close as possible behind the tail. Once the head is pinned,
10 # corrupted log records are written to the log and the filesystem shuts down.
11 #
12 # While log recovery should handle the corrupted log records, it has historical
13 # problems dealing with the situation where the corrupted log records may have
14 # overwritten the tail of the previous good record in the log. If this occurs,
15 # log recovery may fail.
16 #
17 # This can be reproduced more reliably under non-default conditions such as with
18 # the smallest supported FSB sizes and/or largest supported log buffer sizes and
19 # counts (logbufs and logbsize mount options).
20 #
21 # Note that this test requires a DEBUG mode kernel.
22 #
23 . ./common/preamble
24 _begin_fstest auto log
25
26 # Override the default cleanup function.
27 _cleanup()
28 {
29         cd /
30         rm -f $tmp.*
31         $KILLALL_PROG -9 fsstress > /dev/null 2>&1
32         [ -e /sys/fs/xfs/$sdev/errortag/log_item_pin ] &&
33                 echo 0 > /sys/fs/xfs/$sdev/errortag/log_item_pin
34         wait > /dev/null 2>&1
35 }
36
37 # Import common functions.
38 . ./common/inject
39
40 # real QA test starts here
41
42 # Modify as appropriate.
43 _supported_fs xfs
44 _require_xfs_io_error_injection log_item_pin
45 _require_xfs_io_error_injection log_bad_crc
46 _require_scratch
47 _require_command "$KILLALL_PROG" killall
48
49 echo "Silence is golden."
50
51 sdev=$(_short_dev $SCRATCH_DEV)
52
53 # use a small log fs
54 _scratch_mkfs_sized $((1024 * 1024 * 500)) >> $seqres.full 2>&1 ||
55                 _fail "mkfs failed"
56 _scratch_mount
57
58 # populate the fs with some data and cycle the mount to reset the log head/tail
59 $FSSTRESS_PROG -d $SCRATCH_MNT -z -fcreat=1 -p 4 -n 100000 > /dev/null 2>&1
60 _scratch_cycle_mount || _fail "cycle mount failed"
61
62 # Pin the tail and start a file removal workload. File removal tends to
63 # reproduce the corruption more reliably.
64 _scratch_inject_error log_item_pin 1
65
66 rm -rf $SCRATCH_MNT/* > /dev/null 2>&1 &
67 workpid=$!
68
69 # wait for the head to stop pushing forward
70 prevhead=-1
71 head=`cat /sys/fs/xfs/$sdev/log/log_head_lsn`
72 while [ "$head" != "$prevhead" ]; do
73         sleep 5
74         prevhead=$head
75         head=`cat /sys/fs/xfs/$sdev/log/log_head_lsn`
76 done
77
78 # Once the head is pinned behind the tail, enable log record corruption and
79 # unpin the tail. All subsequent log buffer writes end up corrupted on-disk and
80 # result in log I/O errors.
81 _scratch_inject_error log_bad_crc 1
82 _scratch_inject_error log_item_pin 0
83
84 # wait for fs shutdown to kill the workload
85 wait $workpid
86
87 # cycle mount to test log recovery
88 _scratch_cycle_mount
89
90 # success, all done
91 status=0
92 exit