xfs/530: skip test if user MKFS_OPTIONS screw up formatting
[xfstests-dev.git] / tests / xfs / 093
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. 093
6 #
7 # Create and populate an XFS filesystem, corrupt the inobt, 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 _require_scratch
29 test -n "${FORCE_FUZZ}" || _require_scratch_xfs_crc
30 _require_attrs
31 _require_populate_commands
32 _require_xfs_db_blocktrash_z_command
33 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-n 8 -3"
34
35 TESTDIR="${SCRATCH_MNT}/scratchdir"
36 TESTFILE="${TESTDIR}/testfile"
37
38 echo "+ create scratch fs"
39 _scratch_mkfs_xfs > /dev/null
40
41 echo "+ mount fs image"
42 _scratch_mount
43 blksz="$(stat -f -c '%s' "${SCRATCH_MNT}")"
44
45 echo "+ make some files"
46 mkdir -p "${TESTDIR}"
47 for x in `seq 1 1024`; do
48         touch "${SCRATCH_MNT}/junk.${x}"
49         inode="$(stat -c '%i' "${SCRATCH_MNT}/junk.${x}")"
50         if [ "$x" -gt 512 ] && [ "$((inode % 64))" -eq 0 ]; then
51                 mv "${SCRATCH_MNT}/junk.${x}" "${TESTFILE}.1"
52                 break
53         fi
54 done
55 for x in `seq 2 64`; do
56         touch "${TESTFILE}.${x}"
57 done
58 inode="$(stat -c '%i' "${TESTFILE}.1")"
59 agcount="$(_xfs_mount_agcount $SCRATCH_MNT)"
60 umount "${SCRATCH_MNT}"
61
62 echo "+ check fs"
63 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
64
65 echo "+ corrupt image"
66 for ag in $(seq 1 $((agcount - 1))) 0; do
67         _scratch_xfs_db -x -c "agi ${ag}" -c "agi ${ag}" -c "addr root" -c "stack" -c "blocktrash -x 32 -y $((blksz * 8)) -z ${FUZZ_ARGS}" >> $seqres.full 2>&1
68 done
69
70 echo "+ mount image && modify files"
71 broken=1
72 if _try_scratch_mount >> $seqres.full 2>&1; then
73
74         for x in `seq 65 70`; do
75                 touch "${TESTFILE}.${x}" 2> /dev/null && broken=0
76         done
77         umount "${SCRATCH_MNT}"
78 fi
79 echo "broken: ${broken}"
80
81 echo "+ repair fs"
82 _repair_scratch_fs >> $seqres.full 2>&1
83
84 echo "+ mount image (2)"
85 _scratch_mount
86
87 echo "+ chattr -R -i"
88 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
89
90 echo "+ modify files (2)"
91 broken=0
92 # Make sure that we still have the scratch directory after repairing our
93 # corrupted filesystem, because repair could have nuked it.
94 mkdir -p "${TESTDIR}"
95 for x in `seq 65 70`; do
96         touch "${TESTFILE}.${x}" || broken=1
97 done
98 echo "broken: ${broken}"
99 umount "${SCRATCH_MNT}"
100
101 echo "+ check fs (2)"
102 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
103
104 status=0
105 exit