generic: test MADV_POPULATE_READ with IO errors
[xfstests-dev.git] / tests / xfs / 117
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 117
6 #
7 # Create and populate an XFS filesystem, corrupt an inode, then see how
8 # the kernel and xfs_repair deal with it.
9 #
10 . ./common/preamble
11 _begin_fstest fuzzers
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16     cd /
17     #rm -f $tmp.*
18 }
19
20 # Import common functions.
21 . ./common/filter
22 . ./common/attr
23 . ./common/populate
24
25 # real QA test starts here
26 _supported_fs xfs
27
28 _require_scratch
29 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
30 _require_attrs
31 _require_populate_commands
32 _require_xfs_db_blocktrash_z_command
33 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
34
35 victimdir="${SCRATCH_MNT}/scratchdir"
36
37 echo "+ create scratch fs"
38 _scratch_mkfs_xfs > /dev/null
39
40 echo "+ mount fs image"
41 _scratch_mount
42 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
43
44 echo "+ make some files"
45 mkdir -p "$victimdir"
46
47 rootdir="$(stat -c '%i' "$SCRATCH_MNT")"
48 rootchunk=$(( rootdir / 64 ))
49
50 # First we create some dummy file so that the victim files don't get created
51 # in the same inode chunk as the root directory, because a corrupt inode in
52 # the root chunk causes mount to fail.
53 for ((i = 0; i < 256; i++)); do
54         fname="$SCRATCH_MNT/dummy.$i"
55         touch "$fname"
56         ino="$(stat -c '%i' "$fname")"
57         ichunk=$(( ino / 64 ))
58         test "$ichunk" -gt "$rootchunk" && break
59 done
60
61 # Now create some victim files
62 inos=()
63 for ((i = 0; i < 64; i++)); do
64         fname="$victimdir/test.$i"
65         touch "$fname"
66         inos+=("$(stat -c '%i' "$fname")")
67 done
68 echo "First victim inode is: " >> $seqres.full
69 stat -c '%i' "$fname" >> $seqres.full
70 umount "${SCRATCH_MNT}"
71
72 echo "+ check fs"
73 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
74
75 echo "+ corrupt image"
76 for ino in "${inos[@]}"; do
77         _scratch_xfs_db -x -c "inode ${ino}" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full 2>&1
78 done
79
80 echo "+ mount image && modify files"
81 broken=1
82 if _try_scratch_mount >> $seqres.full 2>&1; then
83         for ((i = 0; i < 64; i++)); do
84                 fname="$victimdir/test.$i"
85                 stat "$fname" &>> $seqres.full
86                 test $? -eq 0 && broken=0
87                 touch "$fname" &>> $seqres.full
88                 test $? -eq 0 && broken=0
89         done
90         umount "${SCRATCH_MNT}"
91 fi
92 echo "broken: ${broken}"
93
94 echo "+ repair fs"
95 _repair_scratch_fs >> $seqres.full 2>&1
96
97 echo "+ mount image (2)"
98 _scratch_mount
99
100 echo "+ chattr -R -i"
101 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
102
103 echo "+ modify files (2)"
104 broken=0
105 for x in `seq 1 64`; do
106         test -e "${TESTFILE}.${x}" || continue
107         echo "test ${x}" >> $seqres.full
108         stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
109         test $? -ne 0 && broken=1
110         touch "${TESTFILE}.${x}" >> $seqres.full 2>&1
111         test $? -ne 0 && broken=1
112         echo "${x}: broken=${broken}" >> $seqres.full
113 done
114 echo "broken: ${broken}"
115 umount "${SCRATCH_MNT}"
116
117 echo "+ check fs (2)"
118 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
119
120 status=0
121 exit