fsx/fsstress: round blocksize properly
[xfstests-dev.git] / tests / ext4 / 006
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. 006
6 #
7 # Create and populate an ext4 filesystem, fuzz the metadata, then see how
8 # the kernel reacts, how e2fsck fares in fixing the mess, and then
9 # try more kernel accesses to see if it really fixed things.
10 #
11 seq=`basename $0`
12 seqres=$RESULT_DIR/$seq
13 echo "QA output created by $seq"
14
15 here=`pwd`
16 tmp=/tmp/$$
17 status=1        # failure is the default!
18 trap "_cleanup; exit \$status" 0 1 2 3 15
19
20 _cleanup()
21 {
22     cd /
23     #rm -f $tmp.*
24 }
25
26 # get standard environment, filters and checks
27 . ./common/rc
28 . ./common/filter
29 . ./common/attr
30 . ./common/populate
31 . ./common/fuzzy
32
33 if [ ! -x "$(which e2fuzz)" ]; then
34         _notrun "Couldn't find e2fuzz"
35 fi
36
37 # real QA test starts here
38 _supported_fs ext4
39
40 _require_scratch
41 _require_attrs
42 _require_populate_commands
43
44 repair_scratch() {
45         fsck_pass="$1"
46
47         FSCK_LOG="${tmp}-fuzz-${fsck_pass}.log"
48         echo "++ fsck pass ${fsck_pass}" > "${FSCK_LOG}"
49         e2fsck -f -y "${SCRATCH_DEV}"
50         res=$?
51         if [ "${res}" -eq 0 ]; then
52                 echo "++ allegedly fixed, reverify" >> "${FSCK_LOG}"
53                 _check_scratch_fs -n >> "${FSCK_LOG}" 2>&1
54                 res=$?
55         fi
56         echo "++ fsck returns ${res}" >> "${FSCK_LOG}"
57         if [ "${res}" -eq 0 ]; then
58                 echo "++ fsck thinks we are done" >> "${FSCK_LOG}"
59                 cat "${FSCK_LOG}"
60                 return 0
61         elif [ "${fsck_pass}" -eq "${FSCK_PASSES}" ]; then
62                 echo "++ fsck did not fix in ${FSCK_PASSES} passes." >> "${FSCK_LOG}"
63                 cat "${FSCK_LOG}"
64                 return 0
65         fi
66         cat "${FSCK_LOG}"
67         if [ "${fsck_pass}" -gt 1 ]; then
68                 cmp -s "${tmp}-fuzz-$((fsck_pass - 1)).log" "${FSCK_LOG}"
69                 if [ $? -eq 0 ]; then
70                         echo "++ fsck makes no progress"
71                         return 2
72                 fi
73         fi
74         return 1
75 }
76
77 rm -f $seqres.full
78 echo "See interesting results in $seqres.full" | sed -e "s,$RESULT_DIR,RESULT_DIR,g"
79 SRCDIR=`pwd`
80 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-b 32 -v"
81 test -z "${FSCK_PASSES}" && FSCK_PASSES=10
82 BLK_SZ=4096
83
84 echo "fuzzing ext4 with FUZZ_ARGS=$FUZZ_ARGS and FSCK_PASSES=$FSCK_PASSES" > $seqres.full
85
86 echo "+ create scratch fs" >> $seqres.full
87 _scratch_mkfs_ext4 >> $seqres.full 2>&1
88
89 echo "+ populate fs image" >> $seqres.full
90 _scratch_populate >> $seqres.full
91
92 echo "+ check fs" >> $seqres.full
93 _check_scratch_fs >> $seqres.full 2>&1 || _fail "should pass initial fsck"
94
95 echo "++ corrupt image" >> $seqres.full
96 e2fuzz ${FUZZ_ARGS} ${SCRATCH_DEV} >> $seqres.full 2>&1
97
98 echo "++ mount image" >> $seqres.full
99 _try_scratch_mount >> $seqres.full 2>&1
100
101 echo "++ test scratch" >> $seqres.full
102 _scratch_fuzz_test >> $seqres.full 2>&1
103
104 echo "++ modify scratch" >> $seqres.full
105 _scratch_fuzz_modify >> $seqres.full 2>&1
106
107 echo "++ unmount" >> $seqres.full
108 umount "${SCRATCH_MNT}"
109
110 # repair in a loop...
111 for p in $(seq 1 "${FSCK_PASSES}"); do
112         repair_scratch "$p" >> $seqres.full 2>&1 && break
113 done
114 echo "+ fsck loop returns ${fsck_loop_ret}" >> $seqres.full
115
116 echo "++ check fs for round 2" >> $seqres.full
117 _check_scratch_fs >> $seqres.full 2>&1
118
119 ROUND2_LOG="${tmp}-round2-${fsck_pass}.log"
120 echo "++ mount image (2)" >> $ROUND2_LOG
121 _try_scratch_mount >> $ROUND2_LOG 2>&1
122
123 echo "++ chattr -R -i" >> $ROUND2_LOG
124 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/" > /dev/null 2>> $ROUND2_LOG
125
126 echo "++ test scratch" >> $ROUND2_LOG
127 _scratch_fuzz_test >> $ROUND2_LOG 2>&1
128
129 echo "++ modify scratch" >> $ROUND2_LOG
130 _scratch_fuzz_modify >> $ROUND2_LOG 2>&1
131
132 echo "++ unmount" >> $ROUND2_LOG
133 umount "${SCRATCH_MNT}" >> $ROUND2_LOG 2>&1
134
135 cat "$ROUND2_LOG" >> $seqres.full
136
137 echo "++ check fs (2)" >> $seqres.full
138 _check_scratch_fs >> $seqres.full 2>&1
139
140 egrep -q '(did not fix|makes no progress)' $seqres.full && echo "e2fsck failed" | tee -a $seqres.full
141 if [ "$(wc -l < "$ROUND2_LOG")" -ne 8 ]; then
142         echo "e2fsck did not fix everything" | tee -a $seqres.full
143 fi
144 echo "finished fuzzing" | tee -a "$seqres.full"
145
146 status=0
147 exit