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 journal, 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
35 # We corrupt XFS on purpose, and check if assert failures would crash system.
36 _require_no_xfs_bug_on_assert
38 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
40 _require_populate_commands
41 _require_xfs_db_blocktrash_z_command
42 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
46 TESTDIR="${SCRATCH_MNT}/scratchdir"
47 TESTFILE="${TESTDIR}/testfile"
49 echo "+ create scratch fs"
50 _scratch_mkfs_xfs > /dev/null
52 echo "+ mount fs image"
54 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
56 echo "+ make some files"
58 for x in `seq 1 1024`; do
59 touch "${SCRATCH_MNT}/junk.${x}"
60 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
61 if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
62 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
66 for x in `seq 2 64`; do
67 touch "${TESTFILE}.${x}"
69 inode="$(stat -c '%i' "${TESTFILE}.1")"
70 umount "${SCRATCH_MNT}"
73 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
75 echo "+ corrupt image"
76 logstart="$(_scratch_xfs_get_sb_field logstart)"
77 logstart="$(_scratch_xfs_db -c "convert fsblock ${logstart} byte" | sed -e 's/^.*(\([0-9]*\).*$/\1/g')"
78 logblocks="$(_scratch_xfs_get_sb_field logblocks)"
79 $XFS_IO_PROG -f -c "pwrite -S 0x62 ${logstart} $((logblocks * blksz))" "${SCRATCH_DEV}" >> $seqres.full
82 _try_scratch_mount 2>/dev/null && _fail "mount should not succeed"
85 _repair_scratch_fs >> $seqres.full 2>&1
87 # We may trigger assert related WARNINGs if we corrupt log on a
88 # CONFIG_XFS_WARN or CONFIG_XFS_DEBUG (CONFIG_XFS_ASSERT_FATAL is
89 # disabled) build, so filter them.
90 _check_dmesg _filter_assert_dmesg
92 echo "+ mount image (2)"
96 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
98 echo "+ modify files (2)"
100 for x in `seq 1 64`; do
101 test -e "${TESTFILE}.${x}" || continue
102 echo moo | dd oflag=append conv=notrunc of="${TESTFILE}.${x}" 2>/dev/null
103 test $? -ne 0 && broken=1
105 echo "broken: ${broken}"
106 umount "${SCRATCH_MNT}"
108 echo "+ check fs (2)"
109 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"