tests: remove udf/101
[xfstests-dev.git] / tests / ext4 / 006
1 #! /bin/bash
2 # FS QA Test No. 006
3 #
4 # Create and populate an ext4 filesystem, fuzz the metadata, then see how
5 # the kernel reacts, how e2fsck fares in fixing the mess, and then
6 # try more kernel accesses to see if it really fixed things.
7 #
8 #-----------------------------------------------------------------------
9 # Copyright (c) 2015 Oracle, Inc.  All Rights Reserved.
10 #
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License as
13 # published by the Free Software Foundation.
14 #
15 # This program is distributed in the hope that it would be useful,
16 # but WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18 # GNU General Public License for more details.
19 #
20 # You should have received a copy of the GNU General Public License
21 # along with this program; if not, write the Free Software Foundation,
22 # Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
23 #-----------------------------------------------------------------------
24 #
25
26 seq=`basename $0`
27 seqres=$RESULT_DIR/$seq
28 echo "QA output created by $seq"
29
30 here=`pwd`
31 tmp=/tmp/$$
32 status=1        # failure is the default!
33 trap "_cleanup; exit \$status" 0 1 2 3 15
34
35 _cleanup()
36 {
37     cd /
38     #rm -f $tmp.*
39 }
40
41 # get standard environment, filters and checks
42 . ./common/rc
43 . ./common/filter
44 . ./common/attr
45 . ./common/populate
46 . ./common/fuzzy
47
48 if [ ! -x "$(which e2fuzz)" ]; then
49         _notrun "Couldn't find e2fuzz"
50 fi
51
52 # real QA test starts here
53 _supported_fs ext4
54 _supported_os Linux
55
56 _require_scratch
57 _require_attrs
58 _require_populate_commands
59
60 repair_scratch() {
61         fsck_pass="$1"
62
63         FSCK_LOG="${tmp}-fuzz-${fsck_pass}.log"
64         echo "++ fsck pass ${fsck_pass}" > "${FSCK_LOG}"
65         e2fsck -f -y "${SCRATCH_DEV}"
66         res=$?
67         if [ "${res}" -eq 0 ]; then
68                 echo "++ allegedly fixed, reverify" >> "${FSCK_LOG}"
69                 _check_scratch_fs -n >> "${FSCK_LOG}" 2>&1
70                 res=$?
71         fi
72         echo "++ fsck returns ${res}" >> "${FSCK_LOG}"
73         if [ "${res}" -eq 0 ]; then
74                 echo "++ fsck thinks we are done" >> "${FSCK_LOG}"
75                 cat "${FSCK_LOG}"
76                 return 0
77         elif [ "${fsck_pass}" -eq "${FSCK_PASSES}" ]; then
78                 echo "++ fsck did not fix in ${FSCK_PASSES} passes." >> "${FSCK_LOG}"
79                 cat "${FSCK_LOG}"
80                 return 0
81         fi
82         cat "${FSCK_LOG}"
83         if [ "${fsck_pass}" -gt 1 ]; then
84                 cmp -s "${tmp}-fuzz-$((fsck_pass - 1)).log" "${FSCK_LOG}"
85                 if [ $? -eq 0 ]; then
86                         echo "++ fsck makes no progress"
87                         return 2
88                 fi
89         fi
90         return 1
91 }
92
93 rm -f $seqres.full
94 echo "See interesting results in $seqres.full" | sed -e "s,$RESULT_DIR,RESULT_DIR,g"
95 SRCDIR=`pwd`
96 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-b 32 -v"
97 test -z "${FSCK_PASSES}" && FSCK_PASSES=10
98 BLK_SZ=4096
99
100 echo "fuzzing ext4 with FUZZ_ARGS=$FUZZ_ARGS and FSCK_PASSES=$FSCK_PASSES" > $seqres.full
101
102 echo "+ create scratch fs" >> $seqres.full
103 _scratch_mkfs_ext4 >> $seqres.full 2>&1
104
105 echo "+ populate fs image" >> $seqres.full
106 _scratch_populate >> $seqres.full
107
108 echo "+ check fs" >> $seqres.full
109 _check_scratch_fs >> $seqres.full 2>&1 || _fail "should pass initial fsck"
110
111 echo "++ corrupt image" >> $seqres.full
112 e2fuzz ${FUZZ_ARGS} ${SCRATCH_DEV} >> $seqres.full 2>&1
113
114 echo "++ mount image" >> $seqres.full
115 _scratch_mount >> $seqres.full 2>&1
116
117 echo "++ test scratch" >> $seqres.full
118 _scratch_fuzz_test >> $seqres.full 2>&1
119
120 echo "++ modify scratch" >> $seqres.full
121 _scratch_fuzz_modify >> $seqres.full 2>&1
122
123 echo "++ unmount" >> $seqres.full
124 umount "${SCRATCH_MNT}"
125
126 # repair in a loop...
127 for p in $(seq 1 "${FSCK_PASSES}"); do
128         repair_scratch "$p" >> $seqres.full 2>&1 && break
129 done
130 echo "+ fsck loop returns ${fsck_loop_ret}" >> $seqres.full
131
132 echo "++ check fs for round 2" >> $seqres.full
133 _check_scratch_fs >> $seqres.full 2>&1
134
135 ROUND2_LOG="${tmp}-round2-${fsck_pass}.log"
136 echo "++ mount image (2)" >> $ROUND2_LOG
137 _scratch_mount >> $ROUND2_LOG 2>&1
138
139 echo "++ chattr -R -i" >> $ROUND2_LOG
140 $CHATTR_PROG -R -f -i "${SCRATCH_MNT}/" > /dev/null 2>> $ROUND2_LOG
141
142 echo "++ test scratch" >> $ROUND2_LOG
143 _scratch_fuzz_test >> $ROUND2_LOG 2>&1
144
145 echo "++ modify scratch" >> $ROUND2_LOG
146 _scratch_fuzz_modify >> $ROUND2_LOG 2>&1
147
148 echo "++ unmount" >> $ROUND2_LOG
149 umount "${SCRATCH_MNT}" >> $ROUND2_LOG 2>&1
150
151 cat "$ROUND2_LOG" >> $seqres.full
152
153 echo "++ check fs (2)" >> $seqres.full
154 _check_scratch_fs >> $seqres.full 2>&1
155
156 egrep -q '(did not fix|makes no progress)' $seqres.full && echo "e2fsck failed" | tee -a $seqres.full
157 if [ "$(wc -l < "$ROUND2_LOG")" -ne 8 ]; then
158         echo "e2fsck did not fix everything" | tee -a $seqres.full
159 fi
160 echo "finished fuzzing" | tee -a "$seqres.full"
161
162 status=0
163 exit