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.
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 victimdir="${SCRATCH_MNT}/scratchdir"
37 echo "+ create scratch fs"
38 _scratch_mkfs_xfs > /dev/null
40 echo "+ mount fs image"
42 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
44 echo "+ make some files"
47 rootdir="$(stat -c '%i' "$SCRATCH_MNT")"
48 rootchunk=$(( rootdir / 64 ))
50 # First we create some dummy file so that the victim files don't get created
51 # in the same inode chunk as the root directory, because a corrupt inode in
52 # the root chunk causes mount to fail.
53 for ((i = 0; i < 256; i++)); do
54 fname="$SCRATCH_MNT/dummy.$i"
56 ino="$(stat -c '%i' "$fname")"
57 ichunk=$(( ino / 64 ))
58 test "$ichunk" -gt "$rootchunk" && break
61 # Now create some victim files
63 for ((i = 0; i < 64; i++)); do
64 fname="$victimdir/test.$i"
66 inos+=("$(stat -c '%i' "$fname")")
68 echo "First victim inode is: " >> $seqres.full
69 stat -c '%i' "$fname" >> $seqres.full
70 umount "${SCRATCH_MNT}"
73 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
75 echo "+ corrupt image"
76 for ino in "${inos[@]}"; do
77 _scratch_xfs_db -x -c "inode ${ino}" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full 2>&1
80 echo "+ mount image && modify files"
82 if _try_scratch_mount >> $seqres.full 2>&1; then
83 for ((i = 0; i < 64; i++)); do
84 fname="$victimdir/test.$i"
85 stat "$fname" &>> $seqres.full
86 test $? -eq 0 && broken=0
87 touch "$fname" &>> $seqres.full
88 test $? -eq 0 && broken=0
90 umount "${SCRATCH_MNT}"
92 echo "broken: ${broken}"
95 _repair_scratch_fs >> $seqres.full 2>&1
97 echo "+ mount image (2)"
100 echo "+ chattr -R -i"
101 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
103 echo "+ modify files (2)"
105 for x in `seq 1 64`; do
106 test -e "${TESTFILE}.${x}" || continue
107 echo "test ${x}" >> $seqres.full
108 stat "${TESTFILE}.${x}" >> $seqres.full 2>&1
109 test $? -ne 0 && broken=1
110 touch "${TESTFILE}.${x}" >> $seqres.full 2>&1
111 test $? -ne 0 && broken=1
112 echo "${x}: broken=${broken}" >> $seqres.full
114 echo "broken: ${broken}"
115 umount "${SCRATCH_MNT}"
117 echo "+ check fs (2)"
118 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"