c63b9d60f79c7f04b4a83c734b65d6fb9e3b9a9c
[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 seq=`basename $0`
11 seqres=$RESULT_DIR/$seq
12 echo "QA output created by $seq"
13
14 here=`pwd`
15 tmp=/tmp/$$
16 status=1        # failure is the default!
17 trap "_cleanup; exit \$status" 0 1 2 3 15
18
19 _cleanup()
20 {
21     cd /
22     #rm -f $tmp.*
23 }
24
25 # get standard environment, filters and checks
26 . ./common/rc
27 . ./common/filter
28 . ./common/attr
29 . ./common/populate
30
31 # real QA test starts here
32 _supported_fs xfs
33 _supported_os Linux
34
35 # We corrupt XFS on purpose, and check if assert failures would crash system.
36 _require_no_xfs_bug_on_assert
37 _require_scratch
38 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
39 _require_attrs
40 _require_populate_commands
41 _require_xfs_db_blocktrash_z_command
42 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
43
44 rm -f $seqres.full
45
46 TESTDIR="${SCRATCH_MNT}/scratchdir"
47 TESTFILE="${TESTDIR}/testfile"
48
49 echo "+ create scratch fs"
50 _scratch_mkfs_xfs > /dev/null
51
52 echo "+ mount fs image"
53 _scratch_mount
54 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
55
56 echo "+ make some files"
57 mkdir -p "${TESTDIR}"
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"
63                 break
64         fi
65 done
66 for x in `seq 2 64`; do
67         touch "${TESTFILE}.${x}"
68 done
69 inode="$(stat -c '%i' "${TESTFILE}.1")"
70 umount "${SCRATCH_MNT}"
71
72 echo "+ check fs"
73 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
74
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
80
81 echo "+ mount image"
82 _try_scratch_mount 2>/dev/null && _fail "mount should not succeed"
83
84 echo "+ repair fs"
85 _repair_scratch_fs >> $seqres.full 2>&1
86
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
91
92 echo "+ mount image (2)"
93 _scratch_mount
94
95 echo "+ chattr -R -i"
96 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
97
98 echo "+ modify files (2)"
99 broken=0
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
104 done
105 echo "broken: ${broken}"
106 umount "${SCRATCH_MNT}"
107
108 echo "+ check fs (2)"
109 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
110
111 status=0
112 exit