xfs: fix old fuzz test invocations of xfs_repair
[xfstests-dev.git] / tests / xfs / 089
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. 089
6 #
7 # Create and populate an XFS filesystem, corrupt the bnobt, then see how
8 # the kernel and xfs_repair deal with it.
9 #
10 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     cd /
22     #rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/attr
29 . ./common/populate
30
31 # real QA test starts here
32 _supported_fs xfs
33
34 _require_scratch
35 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
36 _require_attrs
37 _require_populate_commands
38 _require_xfs_db_blocktrash_z_command
39 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
40
41 rm -f $seqres.full
42 TESTDIR="${SCRATCH_MNT}/scratchdir"
43 TESTFILE="${TESTDIR}/testfile"
44
45 echo "+ create scratch fs"
46 _scratch_mkfs_xfs > /dev/null
47
48 echo "+ mount fs image"
49 _scratch_mount
50 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
51
52 echo "+ make some files"
53 mkdir -p "${TESTDIR}"
54 for x in `seq 1 1024`; do
55         touch "${SCRATCH_MNT}/junk.${x}"
56         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
57         if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
58                 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
59                 break
60         fi
61 done
62 for x in `seq 2 64`; do
63         touch "${TESTFILE}.${x}"
64 done
65 inode="$(stat -c '%i' "${TESTFILE}.1")"
66 agcount="$(_xfs_mount_agcount $SCRATCH_MNT)"
67 umount "${SCRATCH_MNT}"
68
69 echo "+ check fs"
70 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
71
72 echo "+ corrupt image"
73 for ag in $(seq 1 $((agcount - 1))) 0; do
74         _scratch_xfs_db -x -c "agf ${ag}" -c "agf ${ag}" -c "addr bnoroot" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full 2>&1
75 done
76
77 # Try to append to files; this should fail
78 echo "+ mount image && modify files"
79 if _try_scratch_mount >> $seqres.full 2>&1; then
80
81         for x in `seq 1 64`; do
82                 $XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full 2>> $seqres.full
83         done
84         umount "${SCRATCH_MNT}"
85 fi
86
87 echo "+ repair fs"
88 _repair_scratch_fs >> $seqres.full 2>&1
89
90 echo "+ mount image"
91 _scratch_mount
92
93 echo "+ chattr -R -i"
94 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
95
96 echo "+ check files"
97 ls -la "${TESTDIR}" >> $seqres.full
98 broken=0
99 for x in `seq 1 64`; do
100         test -s "${TESTFILE}.${x}" || broken=1
101 done
102 echo "broken: ${broken}"
103
104 # Try appending again, now that we've fixed the fs
105 echo "+ modify files (2)"
106 for x in `seq 1 64`; do
107         $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
108 done
109 umount "${SCRATCH_MNT}"
110
111 echo "+ repair fs"
112 _repair_scratch_fs >> $seqres.full 2>&1
113
114 echo "+ mount image"
115 _scratch_mount
116
117 echo "+ chattr -R -i"
118 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
119
120 echo "+ check files (2)"
121 broken=0
122 for x in `seq 1 64`; do
123         test -s "${TESTFILE}.${x}" || broken=1
124 done
125 echo "broken: ${broken}"
126 umount "${SCRATCH_MNT}"
127
128 echo "+ check fs (2)"
129 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
130
131 status=0
132 exit