2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc. All Rights Reserved.
7 # Create and populate an XFS filesystem, corrupt the inobt, then see how
8 # the kernel and xfs_repair deal with it.
13 # Override the default cleanup function.
20 # Import common functions.
25 # real QA test starts here
29 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
31 _require_populate_commands
32 _require_xfs_db_blocktrash_z_command
33 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
35 TESTDIR="${SCRATCH_MNT}/scratchdir"
36 TESTFILE="${TESTDIR}/testfile"
38 echo "+ create scratch fs"
39 _scratch_mkfs_xfs > /dev/null
41 echo "+ mount fs image"
43 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
45 echo "+ make some files"
47 for x in `seq 1 1024`; do
48 touch "${SCRATCH_MNT}/junk.${x}"
49 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
50 if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
51 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
55 for x in `seq 2 64`; do
56 touch "${TESTFILE}.${x}"
58 inode="$(stat -c '%i' "${TESTFILE}.1")"
59 agcount="$(_xfs_mount_agcount $SCRATCH_MNT)"
60 umount "${SCRATCH_MNT}"
63 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
65 echo "+ corrupt image"
66 for ag in $(seq 1 $((agcount - 1))) 0; do
67 _scratch_xfs_db -x -c "agi ${ag}" -c "agi ${ag}" -c "addr root" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full 2>&1
70 echo "+ mount image && modify files"
72 if _try_scratch_mount >> $seqres.full 2>&1; then
74 for x in `seq 65 70`; do
75 touch "${TESTFILE}.${x}" 2> /dev/null && broken=0
77 umount "${SCRATCH_MNT}"
79 echo "broken: ${broken}"
82 _repair_scratch_fs >> $seqres.full 2>&1
84 echo "+ mount image (2)"
88 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
90 echo "+ modify files (2)"
92 # Make sure that we still have the scratch directory after repairing our
93 # corrupted filesystem, because repair could have nuked it.
95 for x in `seq 65 70`; do
96 touch "${TESTFILE}.${x}" || broken=1
98 echo "broken: ${broken}"
99 umount "${SCRATCH_MNT}"
101 echo "+ check fs (2)"
102 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"