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
35 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
37 _require_populate_commands
38 _require_xfs_db_blocktrash_z_command
39 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
42 TESTDIR="${SCRATCH_MNT}/scratchdir"
43 TESTFILE="${TESTDIR}/testfile"
45 echo "+ create scratch fs"
46 _scratch_mkfs_xfs > /dev/null
48 echo "+ mount fs image"
50 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
52 echo "+ make some files"
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"
62 for x in `seq 2 64`; do
63 touch "${TESTFILE}.${x}"
65 inode="$(stat -c '%i' "${TESTFILE}.1")"
66 umount "${SCRATCH_MNT}"
69 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
71 echo "+ corrupt image"
72 seq "${inode}" "$((inode + 63))" | while read ino; do
73 _scratch_xfs_db -x -c "inode ${ino}" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full 2>&1
76 echo "+ mount image && modify files"
78 if _try_scratch_mount >> $seqres.full 2>&1; then
80 for x in `seq 1 64`; do
81 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
82 test $? -eq 0 && broken=0
83 touch "${TESTFILE}.${x}" >> $seqres.full 2>&1
84 test $? -eq 0 && broken=0
86 umount "${SCRATCH_MNT}"
88 echo "broken: ${broken}"
91 _repair_scratch_fs >> $seqres.full 2>&1
93 echo "+ mount image (2)"
97 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
99 echo "+ modify files (2)"
101 for x in `seq 1 64`; do
102 test -e "${TESTFILE}.${x}" || continue
103 echo "test ${x}" >> $seqres.full
104 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
105 test $? -ne 0 && broken=1
106 touch "${TESTFILE}.${x}" >> $seqres.full 2>&1
107 test $? -ne 0 && broken=1
108 echo "${x}: broken=${broken}" >> $seqres.full
110 echo "broken: ${broken}"
111 umount "${SCRATCH_MNT}"
113 echo "+ check fs (2)"
114 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"