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
34 # We corrupt XFS on purpose, and check if assert failures would crash system.
35 _require_no_xfs_bug_on_assert
37 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
39 _require_populate_commands
40 _require_xfs_db_blocktrash_z_command
41 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
45 TESTDIR="${SCRATCH_MNT}/scratchdir"
46 TESTFILE="${TESTDIR}/testfile"
48 echo "+ create scratch fs"
49 _scratch_mkfs_xfs > /dev/null
51 echo "+ mount fs image"
53 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
55 echo "+ make some files"
57 for x in `seq 1 1024`; do
58 touch "${SCRATCH_MNT}/junk.${x}"
59 inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
60 if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
61 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
65 for x in `seq 2 64`; do
66 touch "${TESTFILE}.${x}"
68 inode="$(stat -c '%i' "${TESTFILE}.1")"
69 umount "${SCRATCH_MNT}"
72 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
74 echo "+ corrupt image"
75 logstart="$(_scratch_xfs_get_sb_field logstart)"
76 logstart="$(_scratch_xfs_db -c "convert fsblock ${logstart} byte" | sed -e 's/^.*(\([0-9]*\).*$/\1/g')"
77 logblocks="$(_scratch_xfs_get_sb_field logblocks)"
79 if [ "$USE_EXTERNAL" = yes ] && [ ! -z "$SCRATCH_LOGDEV" ]; then
80 logdev=$SCRATCH_LOGDEV
84 $XFS_IO_PROG -f -c "pwrite -S 0x62 ${logstart} $((logblocks * blksz))" $logdev >> $seqres.full
87 _try_scratch_mount 2>/dev/null && _fail "mount should not succeed"
90 _repair_scratch_fs >> $seqres.full 2>&1
92 # We may trigger assert related WARNINGs if we corrupt log on a
93 # CONFIG_XFS_WARN or CONFIG_XFS_DEBUG (CONFIG_XFS_ASSERT_FATAL is
94 # disabled) build, so filter them.
95 _check_dmesg _filter_assert_dmesg
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 moo | dd oflag=append conv=notrunc of="${TESTFILE}.${x}" 2>/dev/null
108 test $? -ne 0 && broken=1
110 echo "broken: ${broken}"
111 umount "${SCRATCH_MNT}"
113 echo "+ check fs (2)"
114 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"