xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 098
1 #! /bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3 # Copyright (c) 2015 Oracle, Inc.  All Rights Reserved.
4 #
5 # FS QA Test No. 098
6 #
7 # Create and populate an XFS filesystem, corrupt the journal, then see how
8 # the kernel and xfs_repair deal with it.
9 #
10 . ./common/preamble
11 _begin_fstest fuzzers
12
13 # Override the default cleanup function.
14 _cleanup()
15 {
16     cd /
17     #rm -f $tmp.*
18 }
19
20 # Import common functions.
21 . ./common/filter
22 . ./common/attr
23 . ./common/populate
24
25 # real QA test starts here
26 _supported_fs xfs
27
28 # We corrupt XFS on purpose, and check if assert failures would crash system.
29 _require_no_xfs_bug_on_assert
30 _require_scratch
31 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
32 _require_attrs
33 _require_populate_commands
34 _require_xfs_db_blocktrash_z_command
35 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
36
37 TESTDIR="${SCRATCH_MNT}/scratchdir"
38 TESTFILE="${TESTDIR}/testfile"
39
40 echo "+ create scratch fs"
41 _scratch_mkfs_xfs > /dev/null
42
43 echo "+ mount fs image"
44 _scratch_mount
45 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
46
47 echo "+ make some files"
48 mkdir -p "${TESTDIR}"
49 for x in `seq 1 1024`; do
50         touch "${SCRATCH_MNT}/junk.${x}"
51         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
52         if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
53                 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
54                 break
55         fi
56 done
57 for x in `seq 2 64`; do
58         touch "${TESTFILE}.${x}"
59 done
60 inode="$(stat -c '%i' "${TESTFILE}.1")"
61 umount "${SCRATCH_MNT}"
62
63 echo "+ check fs"
64 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
65
66 echo "+ corrupt image"
67 logstart="$(_scratch_xfs_get_sb_field logstart)"
68 logstart="$(_scratch_xfs_db -c "convert fsblock ${logstart} byte" | sed -e 's/^.*(\([0-9]*\).*$/\1/g')"
69 logblocks="$(_scratch_xfs_get_sb_field logblocks)"
70
71 if [ "$USE_EXTERNAL" = yes ] && [ ! -z "$SCRATCH_LOGDEV" ]; then
72         logdev=$SCRATCH_LOGDEV
73 else
74         logdev=$SCRATCH_DEV
75 fi
76 $XFS_IO_PROG -f -c "pwrite -S 0x62 ${logstart} $((logblocks * blksz))" $logdev >> $seqres.full
77
78 echo "+ mount image"
79 _try_scratch_mount 2>/dev/null && _fail "mount should not succeed"
80
81 echo "+ repair fs"
82 _repair_scratch_fs >> $seqres.full 2>&1
83
84 # We may trigger assert related WARNINGs if we corrupt log on a
85 # CONFIG_XFS_WARN or CONFIG_XFS_DEBUG (CONFIG_XFS_ASSERT_FATAL is
86 # disabled) build, so filter them.
87 _check_dmesg _filter_assert_dmesg
88
89 echo "+ mount image (2)"
90 _scratch_mount
91
92 echo "+ chattr -R -i"
93 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
94
95 echo "+ modify files (2)"
96 broken=0
97 for x in `seq 1 64`; do
98         test -e "${TESTFILE}.${x}" || continue
99         echo moo | dd oflag=append conv=notrunc of="${TESTFILE}.${x}" 2>/dev/null
100         test $? -ne 0 && broken=1
101 done
102 echo "broken: ${broken}"
103 umount "${SCRATCH_MNT}"
104
105 echo "+ check fs (2)"
106 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
107
108 status=0
109 exit