2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an XFS filesystem, corrupt an inode, then see how
8 # the kernel and xfs_repair deal with it.
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
16 status=1 # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
25 # get standard environment, filters and checks
31 # real QA test starts here
36 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
38 _require_populate_commands
39 _require_xfs_db_blocktrash_z_command
40 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
43 TESTDIR="${SCRATCH_MNT}/scratchdir"
44 TESTFILE="${TESTDIR}/testfile"
46 echo "+ create scratch fs"
47 _scratch_mkfs_xfs > /dev/null
49 echo "+ mount fs image"
51 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
53 echo "+ make some files"
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"
63 for x in `seq 2 64`; do
64 touch "${TESTFILE}.${x}"
66 inode="$(stat -c '%i' "${TESTFILE}.1")"
67 umount "${SCRATCH_MNT}"
70 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
72 echo "+ corrupt image"
73 seq "${inode}" "$((inode + 64))" | while read ino; do
74 _scratch_xfs_db -x -c "inode ${ino}" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full 2>&1
78 if _try_scratch_mount >> $seqres.full 2>&1; then
82 for x in `seq 1 64`; do
83 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
84 test $? -ne 0 && broken=1
85 touch "${TESTFILE}.${x}" >> $seqres.full 2>&1
86 test $? -ne 0 && broken=1
88 echo "broken: ${broken}"
89 umount "${SCRATCH_MNT}"
93 _scratch_xfs_repair >> $seqres.full 2>&1
95 echo "+ mount image (2)"
99 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
101 echo "+ modify files (2)"
103 for x in `seq 1 64`; do
104 test -e "${TESTFILE}.${x}" || continue
105 echo "test ${x}" >> $seqres.full
106 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
107 test $? -ne 0 && broken=1
108 touch "${TESTFILE}.${x}" >> $seqres.full 2>&1
109 test $? -ne 0 && broken=1
110 echo "${x}: broken=${broken}" >> $seqres.full
112 echo "broken: ${broken}"
113 umount "${SCRATCH_MNT}"
115 echo "+ check fs (2)"
116 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"