xfs: convert tests to SPDX license tags
[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 _supported_os Linux
34
35 _require_scratch
36 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
37 _require_attrs
38 _require_populate_commands
39 _require_xfs_db_blocktrash_z_command
40 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
41
42 rm -f $seqres.full
43 TESTDIR="${SCRATCH_MNT}/scratchdir"
44 TESTFILE="${TESTDIR}/testfile"
45
46 echo "+ create scratch fs"
47 _scratch_mkfs_xfs > /dev/null
48
49 echo "+ mount fs image"
50 _scratch_mount
51 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
52
53 echo "+ make some files"
54 mkdir -p "${TESTDIR}"
55 for x in `seq 1 1024`; do
56         touch "${SCRATCH_MNT}/junk.${x}"
57         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
58         if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
59                 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
60                 break
61         fi
62 done
63 for x in `seq 2 64`; do
64         touch "${TESTFILE}.${x}"
65 done
66 inode="$(stat -c '%i' "${TESTFILE}.1")"
67 agcount="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g')"
68 umount "${SCRATCH_MNT}"
69
70 echo "+ check fs"
71 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
72
73 echo "+ corrupt image"
74 for ag in $(seq 1 $((agcount - 1))) 0; do
75         _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
76 done
77
78 # Try to append to files; this should fail
79 echo "+ mount image"
80 if _try_scratch_mount >> $seqres.full 2>&1; then
81
82         echo "+ modify files"
83         for x in `seq 1 64`; do
84                 $XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
85         done
86         umount "${SCRATCH_MNT}"
87 fi
88
89 echo "+ repair fs"
90 _scratch_xfs_repair >> $seqres.full 2>&1
91
92 echo "+ mount image"
93 _scratch_mount
94
95 echo "+ chattr -R -i"
96 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
97
98 echo "+ check files"
99 ls -la "${TESTDIR}" >> $seqres.full
100 broken=0
101 for x in `seq 1 64`; do
102         test -s "${TESTFILE}.${x}" || broken=1
103 done
104 echo "broken: ${broken}"
105
106 # Try appending again, now that we've fixed the fs
107 echo "+ modify files (2)"
108 for x in `seq 1 64`; do
109         $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
110 done
111 umount "${SCRATCH_MNT}"
112
113 echo "+ repair fs"
114 _scratch_xfs_repair >> $seqres.full 2>&1
115
116 echo "+ mount image"
117 _scratch_mount
118
119 echo "+ chattr -R -i"
120 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
121
122 echo "+ check files (2)"
123 broken=0
124 for x in `seq 1 64`; do
125         test -s "${TESTFILE}.${x}" || broken=1
126 done
127 echo "broken: ${broken}"
128 umount "${SCRATCH_MNT}"
129
130 echo "+ check fs (2)"
131 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
132
133 status=0
134 exit