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.
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
36 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
38 _require_populate_commands
39 _require_xfs_db_blocktrash_z_command
40 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
43 TESTDIR="${SCRATCH_MNT}/scratchdir"
44 TESTFILE="${TESTDIR}/testfile"
46 echo "+ create scratch fs"
47 _scratch_mkfs_xfs > /dev/null
49 echo "+ mount fs image"
51 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
53 echo "+ make some files"
55 for x in `seq 1 1024`; do
56 touch "${SCRATCH_MNT}/junk.${x}"
57 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
58 if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
59 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
63 for x in `seq 2 64`; do
64 touch "${TESTFILE}.${x}"
66 inode="$(stat -c '%i' "${TESTFILE}.1")"
67 agcount="$($XFS_INFO_PROG "${SCRATCH_MNT}" | grep agcount= | sed -e 's/^.*agcount=\([0-9]*\),.*$/\1/g')"
68 test "${agcount}" -gt 1 || _notrun "Single-AG XFS not supported"
69 umount "${SCRATCH_MNT}"
72 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
74 echo "+ corrupt image"
75 for ag in $(seq 1 $((agcount - 1))) 0; do
76 _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
79 # Try to append to files; this should fail
80 echo "+ mount image && modify files"
81 if _try_scratch_mount >> $seqres.full 2>&1; then
83 for x in `seq 1 64`; do
84 $XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
86 umount "${SCRATCH_MNT}"
90 _scratch_xfs_repair >> $seqres.full 2>&1
96 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
100 for x in `seq 1 64`; do
101 test -s "${TESTFILE}.${x}" || broken=1
103 echo "broken: ${broken}"
105 # Try appending again, now that we've fixed the fs
106 echo "+ modify files (2)"
107 for x in `seq 1 64`; do
108 $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
110 umount "${SCRATCH_MNT}"
113 _scratch_xfs_repair >> $seqres.full 2>&1
118 echo "+ chattr -R -i"
119 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
121 echo "+ check files (2)"
123 for x in `seq 1 64`; do
124 test -s "${TESTFILE}.${x}" || broken=1
126 echo "broken: ${broken}"
127 umount "${SCRATCH_MNT}"
129 echo "+ check fs (2)"
130 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"