Whamcloud - gitweb
LU-7346 tests: Reintroduce SLOW tests to review process
[fs/lustre-release.git] / lustre / tests / replay-ost-single.sh
1 #!/bin/bash
2
3 set -e
4
5 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
6 SETUP=${SETUP:-""}
7 CLEANUP=${CLEANUP:-""}
8 . $LUSTRE/tests/test-framework.sh
9 init_test_env $@
10 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
11 init_logging
12
13 # While we do not use OSTCOUNT=1 setup anymore,
14 # ost1failover_HOST is used
15 #ostfailover_HOST=${ostfailover_HOST:-$ost_HOST}
16 #failover= must be defined in OST_MKFS_OPTIONS if ostfailover_HOST != ost_HOST
17
18 require_dsh_ost || exit 0
19
20 # bug number for skipped test:
21 ALWAYS_EXCEPT="$REPLAY_OST_SINGLE_EXCEPT"
22 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
23
24 # bug number for SLOW test:
25 #                                  40  (min)"
26 [ "$SLOW" = "no" ] && EXCEPT_SLOW="5"
27
28 if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
29 # bug number for skipped test:      LU-2285
30         ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3"
31 # bug number for slowed tests:                          LU-2887
32         #                                               32  12.5  (min)"
33         [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 8a  8b"
34 fi
35
36 build_test_filter
37
38 check_and_setup_lustre
39 assert_DIR
40 rm -rf $DIR/[df][0-9]*
41
42 TDIR=$DIR/d0.${TESTSUITE}
43 mkdir -p $TDIR
44 $SETSTRIPE $TDIR -i 0 -c 1
45 $GETSTRIPE $TDIR
46
47 test_0a() {
48         zconf_umount $(hostname) $MOUNT -f
49         # needs to run during initial client->OST connection
50         #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
51         do_facet ost1 "lctl set_param fail_loc=0x80000211"
52         zconf_mount $(hostname) $MOUNT && df $MOUNT || error "0a mount fail"
53 }
54 run_test 0a "target handle mismatch (bug 5317)"
55
56 test_0b() {
57         fail ost1
58         cp /etc/profile  $TDIR/$tfile
59         sync
60         diff /etc/profile $TDIR/$tfile
61         rm -f $TDIR/$tfile
62 }
63 run_test 0b "empty replay"
64
65 test_1() {
66         date > $TDIR/$tfile || error "error creating $TDIR/$tfile"
67         fail ost1
68         $CHECKSTAT -t file $TDIR/$tfile || error "check for file failed"
69         rm -f $TDIR/$tfile
70 }
71 run_test 1 "touch"
72
73 test_2() {
74         for i in $(seq 10); do
75                 echo "tag-$i" > $TDIR/$tfile-$i ||
76                         error "create $TDIR/$tfile-$i failed"
77         done
78         fail ost1
79         for i in $(seq 10); do
80                 grep -q "tag-$i" $TDIR/$tfile-$i ||
81                         error "grep $TDIR/$tfile-$i failed"
82         done
83         rm -f $TDIR/$tfile-*
84 }
85 run_test 2 "|x| 10 open(O_CREAT)s"
86
87 test_3() {
88         verify=$ROOT/tmp/verify-$$
89         dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile &
90         ddpid=$!
91         sync &
92         fail ost1
93         wait $ddpid || error "wait for dd failed"
94         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
95         rm -f $verify $TDIR/$tfile
96 }
97 run_test 3 "Fail OST during write, with verification"
98
99 test_4() {
100         verify=$ROOT/tmp/verify-$$
101         dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile
102         # invalidate cache, so that we're reading over the wire
103         cancel_lru_locks osc
104         cmp $verify $TDIR/$tfile &
105         cmppid=$!
106         fail ost1
107         wait $cmppid || error "wait on cmp failed"
108         rm -f $verify $TDIR/$tfile
109 }
110 run_test 4 "Fail OST during read, with verification"
111
112 iozone_bg () {
113     local args=$@
114
115     local tmppipe=$TMP/${TESTSUITE}.${TESTNAME}.pipe
116     mkfifo $tmppipe
117
118     echo "+ iozone $args"
119     iozone $args > $tmppipe &
120
121     local pid=$!
122
123     echo "tmppipe=$tmppipe"
124     echo iozone pid=$pid
125
126     # iozone exit code is 0 even if iozone is not completed
127     # need to check iozone output  on "complete"
128     local iozonelog=$TMP/${TESTSUITE}.iozone.log
129     rm -f $iozonelog
130     cat $tmppipe | while read line ; do
131         echo "$line"
132         echo "$line" >>$iozonelog
133     done;
134
135     local rc=0
136     wait $pid
137     rc=$?
138     if ! $(tail -1 $iozonelog | grep -q complete); then
139         echo iozone failed!
140         rc=1
141     fi
142     rm -f $tmppipe
143     rm -f $iozonelog
144     return $rc
145 }
146
147 test_5() {
148         if [ -z "$(which iozone 2> /dev/null)" ]; then
149                 skip_env "iozone missing"
150                 return 0
151         fi
152
153         # striping is -c 1, get min of available
154         local minavail=$(lctl get_param -n osc.*[oO][sS][cC][-_]*.kbytesavail |
155                 sort -n | head -n1)
156         local size=$(( minavail * 3/4 ))
157         local GB=1048576  # 1048576KB == 1GB
158
159         if (( size > GB )); then
160                 size=$GB
161         fi
162         local iozone_opts="-i 0 -i 1 -i 2 -+d -r 4 -s $size -f $TDIR/$tfile"
163
164         iozone_bg $iozone_opts &
165         local pid=$!
166
167         echo iozone bg pid=$pid
168
169         sleep 8
170         fail ost1
171         local rc=0
172         wait $pid || error "wait on iozone failed"
173         rc=$?
174         log "iozone rc=$rc"
175         rm -f $TDIR/$tfile
176         wait_delete_completed_mds
177         [ $rc -eq 0 ] || error "iozone failed"
178         return $rc
179 }
180 run_test 5 "Fail OST during iozone"
181
182 kbytesfree() {
183    calc_osc_kbytes kbytesfree
184 }
185
186 test_6() {
187         remote_mds_nodsh && skip "remote MDS with nodsh" && return 0
188
189         local f=$TDIR/$tfile
190         sync && sleep 5 && sync  # wait for delete thread
191
192         # wait till space is returned, following
193         # (( $before > $after_dd)) test counting on that
194         wait_mds_ost_sync || error "first wait_mds_ost_sync failed"
195         wait_destroy_complete || error "first wait_destroy_complete failed"
196
197         local before=$(kbytesfree)
198         dd if=/dev/urandom bs=4096 count=1280 of=$f || error "dd failed"
199         $GETSTRIPE $f || error "$GETSTRIPE $f failed"
200         local stripe_index=$(lfs getstripe -i $f)
201
202         sync
203         sleep 2 # ensure we have a fresh statfs
204         sync
205
206         #define OBD_FAIL_MDS_REINT_NET_REP       0x119
207         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
208
209         # retry till statfs returns useful results
210         local after_dd=$(kbytesfree)
211         local i=0
212         while (( $before <= $after_dd && $i < 20 )); do
213                 sync
214                 sleep 1
215                 let ++i
216                 after_dd=$(kbytesfree)
217         done
218
219         log "before: $before after_dd: $after_dd took $i seconds"
220         (( $before > $after_dd )) ||
221                 error "space grew after dd: before:$before after_dd:$after_dd"
222         rm -f $f
223         fail ost$((stripe_index + 1))
224         wait_recovery_complete ost$((stripe_index + 1)) ||
225                 error "OST$((stripe_index + 1)) recovery not completed"
226         $CHECKSTAT -t file $f && return 2 || true
227         sync
228         # let the delete happen
229         wait_mds_ost_sync || error "second wait_mds_ost_sync failed"
230         wait_delete_completed || error "second wait_delete_completed failed"
231         local after=$(kbytesfree)
232         log "before: $before after: $after"
233         (( $before <= $after + $(fs_log_size) )) ||
234                 error "$before > $after + logsize $(fs_log_size)"
235 }
236 run_test 6 "Fail OST before obd_destroy"
237
238 test_7() {
239         local f=$TDIR/$tfile
240         sync && sleep 5 && sync # wait for delete thread
241
242         # wait till space is returned, following
243         # (( $before > $after_dd)) test counting on that
244         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
245         wait_destroy_complete || error "wait_destroy_complete failed"
246
247         local before=$(kbytesfree)
248         dd if=/dev/urandom bs=4096 count=1280 of=$f ||
249                 error "dd to file failed: $?"
250
251         sync
252         local after_dd=$(kbytesfree)
253         local i=0
254         while (( $before <= $after_dd && $i < 10 )); do
255                 sync
256                 sleep 1
257                 let ++i
258                 after_dd=$(kbytesfree)
259         done
260
261         log "before: $before after_dd: $after_dd took $i seconds"
262         (( $before > $after_dd )) ||
263                 error "space grew after dd: before:$before after_dd:$after_dd"
264         replay_barrier ost1
265         rm -f $f
266         fail ost1
267         wait_recovery_complete ost1 || error "OST recovery not done"
268         $CHECKSTAT -t file $f && return 2 || true
269         sync
270         # let the delete happen
271         wait_mds_ost_sync || error "wait_mds_ost_sync failed"
272         wait_delete_completed || error "wait_delete_completed failed"
273         local after=$(kbytesfree)
274         log "before: $before after: $after"
275         (( $before <= $after + $(fs_log_size) )) ||
276                  error "$before > $after + logsize $(fs_log_size)"
277 }
278 run_test 7 "Fail OST before obd_destroy"
279
280 test_8a() {
281         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
282                 { skip "Need MDS version at least 2.3.0"; return; }
283         verify=$ROOT/tmp/verify-$$
284         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
285                 error "Create verify file failed"
286         #define OBD_FAIL_OST_DQACQ_NET 0x230
287         do_facet ost1 "lctl set_param fail_loc=0x230"
288         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
289         ddpid=$!
290         sleep $TIMEOUT  # wait for the io to become redo io
291         if ! ps -p $ddpid  > /dev/null 2>&1; then
292                 error "redo io finished incorrectly"
293         fi
294         do_facet ost1 "lctl set_param fail_loc=0"
295         wait $ddpid || true
296         cancel_lru_locks osc
297         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
298         rm -f $verify $TDIR/$tfile
299         message=$(dmesg | grep "redo for recoverable error -115")
300         [ -z "$message" ] || error "redo error messages found in dmesg"
301 }
302 run_test 8a "Verify redo io: redo io when get -EINPROGRESS error"
303
304 test_8b() {
305         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
306                 { skip "Need MDS version at least 2.3.0"; return; }
307         verify=$ROOT/tmp/verify-$$
308         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
309                 error "Create verify file failed"
310         #define OBD_FAIL_OST_DQACQ_NET 0x230
311         do_facet ost1 "lctl set_param fail_loc=0x230"
312         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
313         ddpid=$!
314         sleep $TIMEOUT  # wait for the io to become redo io
315         fail ost1
316         do_facet ost1 "lctl set_param fail_loc=0"
317         wait $ddpid || error "dd did not complete"
318         cancel_lru_locks osc
319         cmp $verify $TDIR/$tfile || error "compare $verify $TDIR/$tfile failed"
320         rm -f $verify $TDIR/$tfile
321 }
322 run_test 8b "Verify redo io: redo io should success after recovery"
323
324 test_8c() {
325         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
326                 { skip "Need MDS version at least 2.3.0"; return; }
327         verify=$ROOT/tmp/verify-$$
328         dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
329                 error "Create verify file failed"
330         #define OBD_FAIL_OST_DQACQ_NET 0x230
331         do_facet ost1 "lctl set_param fail_loc=0x230"
332         dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
333         ddpid=$!
334         sleep $TIMEOUT  # wait for the io to become redo io
335         ost_evict_client
336         # allow recovery to complete
337         sleep $((TIMEOUT + 2))
338         do_facet ost1 "lctl set_param fail_loc=0"
339         wait $ddpid
340         cancel_lru_locks osc
341         cmp $verify $TDIR/$tfile && error "compare files should fail"
342         rm -f $verify $TDIR/$tfile
343 }
344 run_test 8c "Verify redo io: redo io should fail after eviction"
345
346 test_8d() {
347         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
348                 { skip "Need MDS version at least 2.3.0"; return; }
349         #define OBD_FAIL_MDS_DQACQ_NET 0x187
350         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
351         # test the non-intent create path
352         mcreate $TDIR/$tfile &
353         cpid=$!
354         sleep $TIMEOUT
355         if ! ps -p $cpid  > /dev/null 2>&1; then
356                 error "mknod finished incorrectly"
357         fi
358         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
359         wait $cpid || error "mcreate did not complete"
360         stat $TDIR/$tfile || error "mknod failed"
361
362         rm $TDIR/$tfile
363
364         #define OBD_FAIL_MDS_DQACQ_NET 0x187
365         do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
366         # test the intent create path
367         openfile -f O_RDWR:O_CREAT $TDIR/$tfile &
368         cpid=$!
369         sleep $TIMEOUT
370         if ! ps -p $cpid > /dev/null 2>&1; then
371                 error "open finished incorrectly"
372         fi
373         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
374         wait $cpid || error "openfile failed"
375         stat $TDIR/$tfile || error "open failed"
376 }
377 run_test 8d "Verify redo creation on -EINPROGRESS"
378
379 test_8e() {
380         [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
381                 { skip "Need MDS version at least 2.3.0"; return; }
382         sleep 1 # ensure we have a fresh statfs
383         #define OBD_FAIL_OST_STATFS_EINPROGRESS 0x231
384         do_facet ost1 "lctl set_param fail_loc=0x231"
385         df $MOUNT &
386         dfpid=$!
387         sleep $TIMEOUT
388         if ! ps -p $dfpid  > /dev/null 2>&1; then
389                         do_facet ost1 "lctl set_param fail_loc=0"
390                         error "df shouldn't have completed!"
391         fi
392 }
393 run_test 8e "Verify that ptlrpc resends request on -EINPROGRESS"
394
395 test_9() {
396         [ $(lustre_version_code ost1) -ge $(version_code 2.6.54) ] ||
397                 { skip "Need OST version at least 2.6.54"; return; }
398         $SETSTRIPE -i 0 -c 1 $DIR/$tfile || "setstripe failed"
399         replay_barrier ost1
400         # do IO
401         dd if=/dev/zero of=$DIR/$tfile count=1 bs=1M > /dev/null ||
402                 error "failed to write"
403         # failover, replay and resend replayed waiting request
404         #define OBD_FAIL_TGT_REPLAY_DELAY2       0x714
405         do_facet ost1 $LCTL set_param fail_loc=0x00000714
406         do_facet ost1 $LCTL set_param fail_val=$TIMEOUT
407         fail ost1
408         do_facet ost1 $LCTL set_param fail_loc=0
409         do_facet ost1 "dmesg | tail -n 100" |
410                 sed -n '/no req deadline/,$ p' | grep -q 'Already past' &&
411                 return 1
412         return 0
413 }
414 run_test 9 "Verify that no req deadline happened during recovery"
415
416 complete $SECONDS
417 check_and_cleanup_lustre
418 exit_status