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 bnobt, 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}")"
44 _xfs_force_bdev data $SCRATCH_MNT
46 echo "+ make some files"
48 for x in `seq 1 1024`; do
49 touch "${SCRATCH_MNT}/junk.${x}"
50 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
51 if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
52 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
56 for x in `seq 2 64`; do
57 touch "${TESTFILE}.${x}"
59 inode="$(stat -c '%i' "${TESTFILE}.1")"
60 agcount="$(_xfs_mount_agcount $SCRATCH_MNT)"
61 umount "${SCRATCH_MNT}"
64 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
66 echo "+ corrupt image"
67 for ag in $(seq 1 $((agcount - 1))) 0; do
68 _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
71 # Try to append to files; this should fail
72 echo "+ mount image && modify files"
73 if _try_scratch_mount >> $seqres.full 2>&1; then
75 for x in `seq 1 64`; do
76 $XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full 2>> $seqres.full
78 umount "${SCRATCH_MNT}"
82 _repair_scratch_fs >> $seqres.full 2>&1
88 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
91 ls -la "${TESTDIR}" >> $seqres.full
93 for x in `seq 1 64`; do
94 test -s "${TESTFILE}.${x}" || broken=1
96 echo "broken: ${broken}"
98 # Try appending again, now that we've fixed the fs
99 echo "+ modify files (2)"
100 for x in `seq 1 64`; do
101 $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
103 umount "${SCRATCH_MNT}"
106 _repair_scratch_fs >> $seqres.full 2>&1
111 echo "+ chattr -R -i"
112 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
114 echo "+ check files (2)"
116 for x in `seq 1 64`; do
117 test -s "${TESTFILE}.${x}" || broken=1
119 echo "broken: ${broken}"
120 umount "${SCRATCH_MNT}"
122 echo "+ check fs (2)"
123 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"