generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 070
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. 070
6 #
7 # As part of superblock verification, xfs_repair checks the primary sb and
8 # verifies all secondary sb's against the primary. In the event of geometry
9 # inconsistency, repair uses a heuristic that tracks the most frequently
10 # occurring settings across the set of N (agcount) superblocks.
11 #
12 # xfs_repair was subject to a bug that disregards this heuristic in the event
13 # that the last secondary superblock in the fs is corrupt. The side effect is an
14 # unnecessary and potentially time consuming brute force superblock scan.
15 #
16 # This is a regression test for the aforementioned xfs_repair bug. We
17 # intentionally corrupt the last superblock in the fs, run xfs_repair and
18 # verify it repairs the fs correctly. We explicitly detect a brute force scan
19 # and abort the repair to save time in the failure case.
20 #
21 . ./common/preamble
22 _begin_fstest auto quick repair
23
24 # Override the default cleanup function.
25 _cleanup()
26 {
27         cd /
28         rm -f $tmp.*
29         $KILLALL_PROG -9 $XFS_REPAIR_PROG > /dev/null 2>&1
30         wait > /dev/null 2>&1
31 }
32
33 # Start and monitor an xfs_repair of the scratch device. This test can induce a
34 # time consuming brute force superblock scan. Since a brute force scan means
35 # test failure, detect it and end the repair.
36 _xfs_repair_noscan()
37 {
38         # invoke repair directly so we can kill the process if need be
39         [ "$USE_EXTERNAL" = yes -a ! -z "$SCRATCH_LOGDEV" ] && \
40                 log_repair_opts="-l $SCRATCH_LOGDEV"
41         [ "$USE_EXTERNAL" = yes ] && [ -n "$SCRATCH_RTDEV" ] && \
42                 rt_repair_opts="-r $SCRATCH_RTDEV"
43         $XFS_REPAIR_PROG $log_repair_opts $rt_repair_opts $SCRATCH_DEV 2>&1 |
44                 tee -a $seqres.full > $tmp.repair &
45         repair_pid=$!
46
47         # monitor progress for as long as it is running
48         while [ `pgrep xfs_repair` ]; do
49                 grep "couldn't verify primary superblock" $tmp.repair \
50                         > /dev/null 2>&1
51                 if [ $? == 0 ]; then
52                         # we've started a brute force scan. kill repair and
53                         # fail the test
54                         kill -9 $repair_pid >> $seqres.full 2>&1
55                         wait >> $seqres.full 2>&1
56
57                         _fail "xfs_repair resorted to brute force scan"
58                 fi
59
60                 sleep 1
61         done
62
63         wait
64
65         cat $tmp.repair | _filter_repair
66 }
67
68 # Import common functions.
69 . ./common/filter
70 . ./common/repair
71
72 # real QA test starts here
73
74 # Modify as appropriate.
75 _supported_fs xfs
76 _require_scratch_nocheck
77 _require_command "$KILLALL_PROG" killall
78
79 _scratch_mkfs | _filter_mkfs > /dev/null 2> $tmp.mkfs
80 test "${PIPESTATUS[0]}" -eq 0 || _fail "mkfs failed"
81
82 . $tmp.mkfs # import agcount
83
84 # corrupt the last secondary sb in the fs
85 _scratch_xfs_db -x -c "sb $((agcount - 1))" -c "type data" \
86         -c "write fill 0xff 0 512"
87
88 # attempt to repair
89 _xfs_repair_noscan
90
91 # success, all done
92 status=0
93 exit