xfs/007: fix regressions on V4 filesystems
[xfstests-dev.git] / tests / xfs / 086
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. 086
6 #
7 # Create and populate an XFS filesystem, corrupt an AGF, 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 test "${agcount}" -gt 1 || _notrun "Single-AG XFS not supported"
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 for ag in $(seq 1 $((agcount - 1))) 0; do
68         _scratch_xfs_db -x -c "agf ${ag}" -c "agf ${ag}" -c "stack" -c "blocktrash -x 32 -o +64 -y 4096 -z ${FUZZ_ARGS}" >> $seqres.full 2>&1
69 done
70
71 # Try to append to files; this should fail
72 echo "+ mount image && modify files"
73 if _try_scratch_mount >> $seqres.full 2>&1; then
74
75         for x in `seq 1 64`; do
76                 $XFS_IO_PROG -f -c "pwrite -S 0x62 0 ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
77         done
78         umount "${SCRATCH_MNT}"
79 fi
80
81 echo "+ repair fs"
82 _repair_scratch_fs >> $seqres.full 2>&1
83
84 echo "+ mount image"
85 _scratch_mount
86
87 echo "+ chattr -R -i"
88 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
89
90 echo "+ check files"
91 broken=0
92 for x in `seq 1 64`; do
93         test -s "${TESTFILE}.${x}" || broken=1
94 done
95 echo "broken: ${broken}"
96
97 # Try appending again, now that we've fixed the fs
98 echo "+ modify files (2)"
99 for x in `seq 1 64`; do
100         $XFS_IO_PROG -f -c "pwrite -S 0x62 ${blksz} ${blksz}" "${TESTFILE}.${x}" >> $seqres.full
101 done
102 umount "${SCRATCH_MNT}"
103
104 echo "+ repair fs"
105 _repair_scratch_fs >> $seqres.full 2>&1
106
107 echo "+ mount image"
108 _scratch_mount
109
110 echo "+ chattr -R -i"
111 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/"
112
113 echo "+ check files (2)"
114 broken=0
115 for x in `seq 1 64`; do
116         test -s "${TESTFILE}.${x}" || broken=1
117 done
118 echo "broken: ${broken}"
119 umount "${SCRATCH_MNT}"
120
121 echo "+ check fs (2)"
122 _scratch_xfs_repair -n >> $seqres.full 2>&1 || _fail "xfs_repair should not fail"
123
124 status=0
125 exit