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 AGF, 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 test "${agcount}" -gt 1 || _notrun "Single-AG XFS not supported"
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 "stack" -c "blocktrash -x 32 -o +64 -y 4096 -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
78 umount "${SCRATCH_MNT}"
82 _repair_scratch_fs >> $seqres.full 2>&1
88 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
92 for x in `seq 1 64`; do
93 test -s "${TESTFILE}.${x}" || broken=1
95 echo "broken: ${broken}"
97 # Try appending again, now that we've fixed the fs
98 echo "+ modify files (2)"
99 for x in `seq 1 64`; do
100 $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
102 umount "${SCRATCH_MNT}"
105 _repair_scratch_fs >> $seqres.full 2>&1
110 echo "+ chattr -R -i"
111 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
113 echo "+ check files (2)"
115 for x in `seq 1 64`; do
116 test -s "${TESTFILE}.${x}" || broken=1
118 echo "broken: ${broken}"
119 umount "${SCRATCH_MNT}"
121 echo "+ check fs (2)"
122 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"