Whamcloud - gitweb
b=17477
[fs/lustre-release.git] / lustre / tests / recovery-small.sh
1 #!/bin/bash
2
3 set -e
4
5 #         bug  5494 7288 5493
6 ALWAYS_EXCEPT="24   27   52 $RECOVERY_SMALL_EXCEPT"
7
8 PTLDEBUG=${PTLDEBUG:--1}
9 LUSTRE=${LUSTRE:-`dirname $0`/..}
10 . $LUSTRE/tests/test-framework.sh
11 init_test_env $@
12 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
13
14 if [ "$FAILURE_MODE" = "HARD" ] && mixed_ost_devs; then
15     CONFIG_EXCEPTIONS="52"
16     echo -n "Several ost services on one ost node are used with FAILURE_MODE=$FAILURE_MODE. "
17     echo "Except the tests: $CONFIG_EXCEPTIONS"
18     ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
19 fi
20
21 remote_mds_nodsh && skip "remote MDS with nodsh" && exit 0
22
23 # also long tests: 19, 21a, 21e, 21f, 23, 27
24 #                                   1  2.5  2.5    4    4          (min)"
25 [ "$SLOW" = "no" ] && EXCEPT_SLOW="17  26a  26b    50   51     57"
26
27 build_test_filter
28
29 # Allow us to override the setup if we already have a mounted system by
30 # setting SETUP=" " and CLEANUP=" "
31 SETUP=${SETUP:-""}
32 CLEANUP=${CLEANUP:-""}
33
34 check_and_setup_lustre
35
36 assert_DIR
37 rm -rf $DIR/[df][0-9]*
38
39 test_1() {
40     drop_request "mcreate $DIR/f1"  || return 1
41     drop_reint_reply "mcreate $DIR/f2"    || return 2
42 }
43 run_test 1 "mcreate: drop req, drop rep"
44
45 test_2() {
46     drop_request "tchmod 111 $DIR/f2"  || return 1
47     drop_reint_reply "tchmod 666 $DIR/f2"    || return 2
48 }
49 run_test 2 "chmod: drop req, drop rep"
50
51 test_3() {
52     drop_request "statone $DIR/f2" || return 1
53     drop_reply "statone $DIR/f2"   || return 2
54 }
55 run_test 3 "stat: drop req, drop rep"
56
57 SAMPLE_NAME=f0.recovery-small.junk
58 SAMPLE_FILE=$TMP/$SAMPLE_NAME
59 # make this big, else test 9 doesn't wait for bulk -- bz 5595
60 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=4
61
62 test_4() {
63     do_facet client "cp $SAMPLE_FILE $DIR/$SAMPLE_NAME" || return 1
64     drop_request "cat $DIR/$SAMPLE_NAME > /dev/null"   || return 2
65     drop_reply "cat $DIR/$SAMPLE_NAME > /dev/null"     || return 3
66 }
67 run_test 4 "open: drop req, drop rep"
68
69 RENAMED_AGAIN=$DIR/f0.renamed-again
70
71 test_5() {
72     drop_request "mv $DIR/$SAMPLE_NAME $DIR/$tfile-renamed" || return 1
73     drop_reint_reply "mv $DIR/$tfile-renamed $RENAMED_AGAIN" || return 2
74     do_facet client "checkstat -v $RENAMED_AGAIN"  || return 3
75 }
76 run_test 5 "rename: drop req, drop rep"
77
78 [ ! -e $RENAMED_AGAIN ] && cp $SAMPLE_FILE $RENAMED_AGAIN
79 LINK1=$DIR/f0.link1
80 LINK2=$DIR/f0.link2
81
82 test_6() {
83     drop_request "mlink $RENAMED_AGAIN $LINK1" || return 1
84     drop_reint_reply "mlink $RENAMED_AGAIN $LINK2"   || return 2
85 }
86 run_test 6 "link: drop req, drop rep"
87
88 [ ! -e $LINK1 ] && mlink $RENAMED_AGAIN $LINK1
89 [ ! -e $LINK2 ] && mlink $RENAMED_AGAIN $LINK2
90 test_7() {
91     drop_request "munlink $LINK1"   || return 1
92     drop_reint_reply "munlink $LINK2"     || return 2
93 }
94 run_test 7 "unlink: drop req, drop rep"
95
96 #bug 1423
97 test_8() {
98     drop_reint_reply "touch $DIR/$tfile"    || return 1
99 }
100 run_test 8 "touch: drop rep (bug 1423)"
101
102 #bug 1420
103 test_9() {
104     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
105
106     pause_bulk "cp /etc/profile $DIR/$tfile"       || return 1
107     do_facet client "cp $SAMPLE_FILE $DIR/${tfile}.2"  || return 2
108     do_facet client "sync"
109     do_facet client "rm $DIR/$tfile $DIR/${tfile}.2" || return 3
110 }
111 run_test 9 "pause bulk on OST (bug 1420)"
112
113 #bug 1521
114 test_10() {
115     do_facet client mcreate $DIR/$tfile        || return 1
116     drop_bl_callback "chmod 0777 $DIR/$tfile"  || echo "evicted as expected"
117     # wait for the mds to evict the client
118     #echo "sleep $(($TIMEOUT*2))"
119     #sleep $(($TIMEOUT*2))
120     do_facet client touch $DIR/$tfile || echo "touch failed, evicted"
121     do_facet client checkstat -v -p 0777 $DIR/$tfile  || return 3
122     do_facet client "munlink $DIR/$tfile"
123 }
124 run_test 10 "finish request on server after client eviction (bug 1521)"
125
126 #bug 2460
127 # wake up a thread waiting for completion after eviction
128 test_11(){
129     do_facet client multiop $DIR/$tfile Ow  || return 1
130     do_facet client multiop $DIR/$tfile or  || return 2
131
132     cancel_lru_locks osc
133
134     do_facet client multiop $DIR/$tfile or  || return 3
135     drop_bl_callback multiop $DIR/$tfile Ow || echo "evicted as expected"
136
137     do_facet client munlink $DIR/$tfile  || return 4
138 }
139 run_test 11 "wake up a thread waiting for completion after eviction (b=2460)"
140
141 #b=2494
142 test_12(){
143     $LCTL mark multiop $DIR/$tfile OS_c 
144     do_facet $SINGLEMDS "lctl set_param fail_loc=0x115"
145     clear_failloc $SINGLEMDS $((TIMEOUT * 2)) &
146     multiop_bg_pause $DIR/$tfile OS_c || return 1
147     PID=$!
148 #define OBD_FAIL_MDS_CLOSE_NET           0x115
149     kill -USR1 $PID
150     echo "waiting for multiop $PID"
151     wait $PID || return 2
152     do_facet client munlink $DIR/$tfile  || return 3
153 }
154 run_test 12 "recover from timed out resend in ptlrpcd (b=2494)"
155
156 # Bug 113, check that readdir lost recv timeout works.
157 test_13() {
158     mkdir -p $DIR/$tdir || return 1
159     touch $DIR/$tdir/newentry || return
160 # OBD_FAIL_MDS_READPAGE_NET|OBD_FAIL_ONCE
161     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000104"
162     ls $DIR/$tdir || return 3
163     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
164     rm -rf $DIR/$tdir || return 4
165 }
166 run_test 13 "mdc_readpage restart test (bug 1138)"
167
168 # Bug 113, check that readdir lost send timeout works.
169 test_14() {
170     mkdir -p $DIR/$tdir
171     touch $DIR/$tdir/newentry
172 # OBD_FAIL_MDS_SENDPAGE|OBD_FAIL_ONCE
173     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000106"
174     ls $DIR/$tdir || return 1
175     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
176 }
177 run_test 14 "mdc_readpage resend test (bug 1138)"
178
179 test_15() {
180     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000128"
181     touch $DIR/$tfile && return 1
182     return 0
183 }
184 run_test 15 "failed open (-ENOMEM)"
185
186 READ_AHEAD=`lctl get_param -n llite.*.max_read_ahead_mb | head -n 1`
187 stop_read_ahead() {
188    lctl set_param -n llite.*.max_read_ahead_mb 0
189 }
190
191 start_read_ahead() {
192    lctl set_param -n llite.*.max_read_ahead_mb $READ_AHEAD
193 }
194
195 test_16() {
196     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
197
198     do_facet client cp $SAMPLE_FILE $DIR
199     sync
200     stop_read_ahead
201
202 #define OBD_FAIL_PTLRPC_BULK_PUT_NET 0x504 | OBD_FAIL_ONCE
203     do_facet ost1 "lctl set_param fail_loc=0x80000504"
204     cancel_lru_locks osc
205     # OST bulk will time out here, client resends
206     do_facet client "cmp $SAMPLE_FILE $DIR/${SAMPLE_FILE##*/}" || return 1
207     do_facet ost1 lctl set_param fail_loc=0
208     # give recovery a chance to finish (shouldn't take long)
209     sleep $TIMEOUT
210     do_facet client "cmp $SAMPLE_FILE $DIR/${SAMPLE_FILE##*/}" || return 2
211     start_read_ahead
212 }
213 run_test 16 "timeout bulk put, don't evict client (2732)"
214
215 test_17() {
216     local at_max_saved=0
217
218     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
219
220     # With adaptive timeouts, bulk_get won't expire until adaptive_timeout_max
221     if at_is_valid && at_is_enabled; then
222         at_max_saved=$(at_max_get ost1)
223         at_max_set $TIMEOUT ost1
224     fi
225
226     # OBD_FAIL_PTLRPC_BULK_GET_NET 0x0503 | OBD_FAIL_ONCE
227     # OST bulk will time out here, client retries
228     do_facet ost1 lctl set_param fail_loc=0x80000503
229     # need to ensure we send an RPC
230     do_facet client cp /etc/termcap $DIR/$tfile
231     sync
232
233     # with AT, client will wait adaptive_max*factor+net_latency before
234     # expiring the req, hopefully timeout*2 is enough
235     sleep $(($TIMEOUT*2))
236
237     do_facet ost1 lctl set_param fail_loc=0
238     do_facet client "df $DIR"
239     # expect cmp to succeed, client resent bulk
240     do_facet client "cmp /etc/termcap $DIR/$tfile" || return 3
241     do_facet client "rm $DIR/$tfile" || return 4
242     [ $at_max_saved -ne 0 ] && $(at_max_set $at_max_saved ost1)
243     return 0
244 }
245 run_test 17 "timeout bulk get, don't evict client (2732)"
246
247 test_18a() {
248     [ -z ${ost2_svc} ] && skip "needs 2 osts" && return 0
249
250     do_facet client mkdir -p $DIR/$tdir
251     f=$DIR/$tdir/$tfile
252
253     cancel_lru_locks osc
254     pgcache_empty || return 1
255
256     # 1 stripe on ost2
257     lfs setstripe $f -s $((128 * 1024)) -i 1 -c 1
258
259     do_facet client cp $SAMPLE_FILE $f
260     sync
261     local osc2dev=`lctl get_param -n devices | grep ${ost2_svc}-osc- | egrep -v 'MDT' | awk '{print $1}'`
262     $LCTL --device $osc2dev deactivate || return 3
263     # my understanding is that there should be nothing in the page
264     # cache after the client reconnects?     
265     rc=0
266     pgcache_empty || rc=2
267     $LCTL --device $osc2dev activate
268     rm -f $f
269     return $rc
270 }
271 run_test 18a "manual ost invalidate clears page cache immediately"
272
273 test_18b() {
274     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
275
276     do_facet client mkdir -p $DIR/$tdir
277     f=$DIR/$tdir/$tfile
278     f2=$DIR/$tdir/${tfile}-2
279
280     cancel_lru_locks osc
281     pgcache_empty || return 1
282
283     # shouldn't have to set stripe size of count==1
284     lfs setstripe $f -s $((128 * 1024)) -i 0 -c 1
285     lfs setstripe $f2 -s $((128 * 1024)) -i 0 -c 1
286
287     do_facet client cp $SAMPLE_FILE $f
288     sync
289     ost_evict_client
290     # allow recovery to complete
291     sleep $((TIMEOUT + 2))
292     # my understanding is that there should be nothing in the page
293     # cache after the client reconnects?     
294     rc=0
295     pgcache_empty || rc=2
296     rm -f $f $f2
297     return $rc
298 }
299 run_test 18b "eviction and reconnect clears page cache (2766)"
300
301 test_18c() {
302     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
303
304     do_facet client mkdir -p $DIR/$tdir
305     f=$DIR/$tdir/$tfile
306     f2=$DIR/$tdir/${tfile}-2
307
308     cancel_lru_locks osc
309     pgcache_empty || return 1
310
311     # shouldn't have to set stripe size of count==1
312     lfs setstripe $f -s $((128 * 1024)) -i 0 -c 1
313     lfs setstripe $f2 -s $((128 * 1024)) -i 0 -c 1
314
315     do_facet client cp $SAMPLE_FILE $f
316     sync
317     ost_evict_client
318
319     # OBD_FAIL_OST_CONNECT_NET2
320     # lost reply to connect request
321     do_facet ost1 lctl set_param fail_loc=0x80000225
322     # force reconnect
323     df $MOUNT > /dev/null 2>&1
324     sleep 2
325     # my understanding is that there should be nothing in the page
326     # cache after the client reconnects?     
327     rc=0
328     pgcache_empty || rc=2
329     rm -f $f $f2
330     return $rc
331 }
332 run_test 18c "Dropped connect reply after eviction handing (14755)"
333
334 test_19a() {
335     f=$DIR/$tfile
336     do_facet client mcreate $f        || return 1
337     drop_ldlm_cancel "chmod 0777 $f"  || echo "evicted as expected"
338
339     do_facet client checkstat -v -p 0777 $f  || echo evicted
340     # let the client reconnect
341     sleep 5
342     do_facet client "munlink $f"
343 }
344 run_test 19a "test expired_lock_main on mds (2867)"
345
346 test_19b() {
347     f=$DIR/$tfile
348     do_facet client multiop $f Ow  || return 1
349     do_facet client multiop $f or  || return 2
350
351     cancel_lru_locks osc
352
353     do_facet client multiop $f or  || return 3
354     drop_ldlm_cancel multiop $f Ow  || echo "client evicted, as expected"
355
356     do_facet client munlink $f  || return 4
357 }
358 run_test 19b "test expired_lock_main on ost (2867)"
359
360 test_20a() {    # bug 2983 - ldlm_handle_enqueue cleanup
361         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
362
363         mkdir -p $DIR/$tdir
364         lfs setstripe $DIR/$tdir/${tfile} -i 0 -c 1
365         multiop_bg_pause $DIR/$tdir/${tfile} O_wc || return 1
366         MULTI_PID=$!
367         cancel_lru_locks osc
368 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
369         do_facet ost1 lctl set_param fail_loc=0x80000308
370         kill -USR1 $MULTI_PID
371         wait $MULTI_PID
372         rc=$?
373         [ $rc -eq 0 ] && error "multiop didn't fail enqueue: rc $rc" || true
374 }
375 run_test 20a "ldlm_handle_enqueue error (should return error)" 
376
377 test_20b() {    # bug 2986 - ldlm_handle_enqueue error during open
378         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
379
380         mkdir -p $DIR/$tdir
381         lfs setstripe $DIR/$tdir/${tfile} -i 0 -c 1
382         cancel_lru_locks osc
383 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
384         do_facet ost1 lctl set_param fail_loc=0x80000308
385         dd if=/etc/hosts of=$DIR/$tdir/$tfile && \
386                 error "didn't fail open enqueue" || true
387 }
388 run_test 20b "ldlm_handle_enqueue error (should return error)"
389
390 test_21a() {
391        mkdir -p $DIR/$tdir-1
392        mkdir -p $DIR/$tdir-2
393        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
394        close_pid=$!
395
396        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000129"
397        multiop $DIR/$tdir-2/f Oc &
398        open_pid=$!
399        sleep 1
400        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
401
402        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
403        kill -USR1 $close_pid
404        cancel_lru_locks mdc
405        wait $close_pid || return 1
406        wait $open_pid || return 2
407        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
408
409        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
410        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
411
412        rm -rf $DIR/$tdir-*
413 }
414 run_test 21a "drop close request while close and open are both in flight"
415
416 test_21b() {
417        mkdir -p $DIR/$tdir-1
418        mkdir -p $DIR/$tdir-2
419        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
420        close_pid=$!
421
422        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
423        mcreate $DIR/$tdir-2/f &
424        open_pid=$!
425        sleep 1
426        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
427
428        kill -USR1 $close_pid
429        cancel_lru_locks mdc
430        wait $close_pid || return 1
431        wait $open_pid || return 3
432
433        $CHECKSTAT -t file $DIR/$tdir-1/f || return 4
434        $CHECKSTAT -t file $DIR/$tdir-2/f || return 5
435        rm -rf $DIR/$tdir-*
436 }
437 run_test 21b "drop open request while close and open are both in flight"
438
439 test_21c() {
440        mkdir -p $DIR/$tdir-1
441        mkdir -p $DIR/$tdir-2
442        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
443        close_pid=$!
444
445        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
446        mcreate $DIR/$tdir-2/f &
447        open_pid=$!
448        sleep 3
449        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
450
451        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
452        kill -USR1 $close_pid
453        cancel_lru_locks mdc
454        wait $close_pid || return 1
455        wait $open_pid || return 2
456
457        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
458
459        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
460        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
461        rm -rf $DIR/$tdir-*
462 }
463 run_test 21c "drop both request while close and open are both in flight"
464
465 test_21d() {
466        mkdir -p $DIR/$tdir-1
467        mkdir -p $DIR/$tdir-2
468        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
469        pid=$!
470
471        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000129"
472        multiop $DIR/$tdir-2/f Oc &
473        sleep 1
474        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
475
476        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
477        kill -USR1 $pid
478        cancel_lru_locks mdc
479        wait $pid || return 1
480        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
481
482        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
483        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
484
485        rm -rf $DIR/$tdir-*
486 }
487 run_test 21d "drop close reply while close and open are both in flight"
488
489 test_21e() {
490        mkdir -p $DIR/$tdir-1
491        mkdir -p $DIR/$tdir-2
492        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
493        pid=$!
494
495        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
496        touch $DIR/$tdir-2/f &
497        sleep 1
498        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
499
500        kill -USR1 $pid
501        cancel_lru_locks mdc
502        wait $pid || return 1
503
504        sleep $TIMEOUT
505        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
506        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
507        rm -rf $DIR/$tdir-*
508 }
509 run_test 21e "drop open reply while close and open are both in flight"
510
511 test_21f() {
512        mkdir -p $DIR/$tdir-1
513        mkdir -p $DIR/$tdir-2
514        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
515        pid=$!
516
517        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
518        touch $DIR/$tdir-2/f &
519        sleep 1
520        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
521
522        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
523        kill -USR1 $pid
524        cancel_lru_locks mdc
525        wait $pid || return 1
526        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
527
528        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
529        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
530        rm -rf $DIR/$tdir-*
531 }
532 run_test 21f "drop both reply while close and open are both in flight"
533
534 test_21g() {
535        mkdir -p $DIR/$tdir-1
536        mkdir -p $DIR/$tdir-2
537        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
538        pid=$!
539
540        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
541        touch $DIR/$tdir-2/f &
542        sleep 1
543        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
544
545        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
546        kill -USR1 $pid
547        cancel_lru_locks mdc
548        wait $pid || return 1
549        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
550
551        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
552        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
553        rm -rf $DIR/$tdir-*
554 }
555 run_test 21g "drop open reply and close request while close and open are both in flight"
556
557 test_21h() {
558        mkdir -p $DIR/$tdir-1
559        mkdir -p $DIR/$tdir-2
560        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
561        pid=$!
562
563        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
564        touch $DIR/$tdir-2/f &
565        touch_pid=$!
566        sleep 1
567        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
568
569        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
570        cancel_lru_locks mdc
571        kill -USR1 $pid
572        wait $pid || return 1
573        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
574
575        wait $touch_pid || return 2
576
577        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
578        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
579        rm -rf $DIR/$tdir-*
580 }
581 run_test 21h "drop open request and close reply while close and open are both in flight"
582
583 # bug 3462 - multiple MDC requests
584 test_22() {
585     f1=$DIR/${tfile}-1
586     f2=$DIR/${tfile}-2
587     
588     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
589     multiop $f2 Oc &
590     close_pid=$!
591
592     sleep 1
593     multiop $f1 msu || return 1
594
595     cancel_lru_locks mdc
596     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
597
598     wait $close_pid || return 2
599     rm -rf $f2 || return 4
600 }
601 run_test 22 "drop close request and do mknod"
602
603 test_23() { #b=4561
604     multiop_bg_pause $DIR/$tfile O_c || return 1
605     pid=$!
606     # give a chance for open
607     sleep 5
608
609     # try the close
610     drop_request "kill -USR1 $pid"
611
612     fail $SINGLEMDS
613     wait $pid || return 1
614     return 0
615 }
616 run_test 23 "client hang when close a file after mds crash"
617
618 test_24() { # bug 11710 details correct fsync() behavior
619         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
620
621         mkdir -p $DIR/$tdir
622         lfs setstripe $DIR/$tdir -s 0 -i 0 -c 1
623         cancel_lru_locks osc
624         multiop_bg_pause $DIR/$tdir/$tfile Owy_wyc || return 1
625         MULTI_PID=$!
626         ost_evict_client
627         kill -USR1 $MULTI_PID
628         wait $MULTI_PID
629         rc=$?
630         lctl set_param fail_loc=0x0
631         client_reconnect
632         [ $rc -eq 0 ] && error_ignore 5494 "multiop didn't fail fsync: rc $rc" || true
633 }
634 run_test 24 "fsync error (should return error)"
635
636 test_26a() {      # was test_26 bug 5921 - evict dead exports by pinger
637 # this test can only run from a client on a separate node.
638         remote_ost || { skip "local OST" && return 0; }
639         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
640         remote_mds || { skip "local MDS" && return 0; }
641         OST_FILE=obdfilter.${ost1_svc}.num_exports
642         OST_EXP="`do_facet ost1 lctl get_param -n $OST_FILE`"
643         OST_NEXP1=`echo $OST_EXP | cut -d' ' -f2`
644         echo starting with $OST_NEXP1 OST exports
645 # OBD_FAIL_PTLRPC_DROP_RPC 0x505
646         do_facet client lctl set_param fail_loc=0x505
647         # evictor takes PING_EVICT_TIMEOUT + 3 * PING_INTERVAL to evict.
648         # But if there's a race to start the evictor from various obds,
649         # the loser might have to wait for the next ping.
650         echo Waiting for $(($TIMEOUT * 8)) secs
651         sleep $(($TIMEOUT * 8))
652         OST_EXP="`do_facet ost1 lctl get_param -n $OST_FILE`"
653         OST_NEXP2=`echo $OST_EXP | cut -d' ' -f2`
654         echo ending with $OST_NEXP2 OST exports
655         do_facet client lctl set_param fail_loc=0x0
656         [ $OST_NEXP1 -le $OST_NEXP2 ] && error "client not evicted"
657         return 0
658 }
659 run_test 26a "evict dead exports"
660
661 test_26b() {      # bug 10140 - evict dead exports by pinger
662         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
663
664         client_df
665         zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
666         sleep 1 # wait connections being established
667         MDS_FILE=mdt.${mds1_svc}.num_exports
668         MDS_NEXP1="`do_facet $SINGLEMDS lctl get_param -n $MDS_FILE | cut -d' ' -f2`"
669         OST_FILE=obdfilter.${ost1_svc}.num_exports
670         OST_NEXP1="`do_facet ost1 lctl get_param -n $OST_FILE | cut -d' ' -f2`"
671         echo starting with $OST_NEXP1 OST and $MDS_NEXP1 MDS exports
672         zconf_umount `hostname` $MOUNT2 -f
673         # evictor takes PING_EVICT_TIMEOUT + 3 * PING_INTERVAL to evict.  
674         # But if there's a race to start the evictor from various obds, 
675         # the loser might have to wait for the next ping.
676         echo Waiting for $(($TIMEOUT * 3)) secs
677         sleep $(($TIMEOUT * 3))
678         OST_NEXP2="`do_facet ost1 lctl get_param -n $OST_FILE | cut -d' ' -f2`"
679         MDS_NEXP2="`do_facet $SINGLEMDS lctl get_param -n $MDS_FILE | cut -d' ' -f2`"
680         echo ending with $OST_NEXP2 OST and $MDS_NEXP2 MDS exports
681         [ $OST_NEXP1 -le $OST_NEXP2 ] && error "client not evicted from OST"
682         [ $MDS_NEXP1 -le $MDS_NEXP2 ] && error "client not evicted from MDS"
683         return 0
684 }
685 run_test 26b "evict dead exports"
686
687 test_27() {
688         mkdir -p $DIR/$tdir
689         writemany -q -a $DIR/$tdir/$tfile 0 5 &
690         CLIENT_PID=$!
691         sleep 1
692         local save_FAILURE_MODE=$FAILURE_MODE
693         FAILURE_MODE="SOFT"
694         facet_failover $SINGLEMDS
695 #define OBD_FAIL_OSC_SHUTDOWN            0x407
696         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000407
697         # need to wait for reconnect
698         echo -n waiting for fail_loc
699         while [ $(do_facet $SINGLEMDS lctl get_param -n fail_loc) -eq -2147482617 ]; do
700             sleep 1
701             echo -n .
702         done
703         do_facet $SINGLEMDS lctl get_param -n fail_loc
704         facet_failover $SINGLEMDS
705         #no crashes allowed!
706         kill -USR1 $CLIENT_PID
707         wait $CLIENT_PID 
708         true
709         FAILURE_MODE=$save_FAILURE_MODE
710 }
711 run_test 27 "fail LOV while using OSC's"
712
713 test_28() {      # bug 6086 - error adding new clients
714         do_facet client mcreate $DIR/$tfile       || return 1
715         drop_bl_callback "chmod 0777 $DIR/$tfile" ||echo "evicted as expected"
716         #define OBD_FAIL_MDS_CLIENT_ADD 0x12f
717         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012f"
718         # fail once (evicted), reconnect fail (fail_loc), ok
719         df || (sleep 10; df) || (sleep 10; df) || error "reconnect failed"
720         rm -f $DIR/$tfile
721         fail $SINGLEMDS         # verify MDS last_rcvd can be loaded
722 }
723 run_test 28 "handle error adding new clients (bug 6086)"
724
725 test_50() {
726         mkdir -p $DIR/$tdir
727         # put a load of file creates/writes/deletes
728         writemany -q $DIR/$tdir/$tfile 0 5 &
729         CLIENT_PID=$!
730         echo writemany pid $CLIENT_PID
731         sleep 10
732         FAILURE_MODE="SOFT"
733         fail $SINGLEMDS
734         # wait for client to reconnect to MDS
735         sleep 60
736         fail $SINGLEMDS
737         sleep 60
738         fail $SINGLEMDS
739         # client process should see no problems even though MDS went down
740         sleep $TIMEOUT
741         kill -USR1 $CLIENT_PID
742         wait $CLIENT_PID 
743         rc=$?
744         echo writemany returned $rc
745         #these may fail because of eviction due to slow AST response.
746         [ $rc -eq 0 ] || error_ignore 13652 "writemany returned rc $rc" || true
747 }
748 run_test 50 "failover MDS under load"
749
750 test_51() {
751         mkdir -p $DIR/$tdir
752         # put a load of file creates/writes/deletes
753         writemany -q $DIR/$tdir/$tfile 0 5 &
754         CLIENT_PID=$!
755         sleep 1
756         FAILURE_MODE="SOFT"
757         facet_failover $SINGLEMDS
758         # failover at various points during recovery
759         SEQ="1 5 10 $(seq $TIMEOUT 5 $(($TIMEOUT+10)))"
760         echo will failover at $SEQ
761         for i in $SEQ
762           do
763           echo failover in $i sec
764           sleep $i
765           facet_failover $SINGLEMDS
766         done
767         # client process should see no problems even though MDS went down
768         # and recovery was interrupted
769         sleep $TIMEOUT
770         kill -USR1 $CLIENT_PID
771         wait $CLIENT_PID 
772         rc=$?
773         echo writemany returned $rc
774         [ $rc -eq 0 ] || error_ignore 13652 "writemany returned rc $rc" || true
775 }
776 run_test 51 "failover MDS during recovery"
777
778 test_52_guts() {
779         do_facet client "mkdir -p $DIR/$tdir"
780         do_facet client "writemany -q -a $DIR/$tdir/$tfile 300 5" &
781         CLIENT_PID=$!
782         echo writemany pid $CLIENT_PID
783         sleep 10
784         FAILURE_MODE="SOFT"
785         fail ost1
786         rc=0
787         wait $CLIENT_PID || rc=$?
788         # active client process should see an EIO for down OST
789         [ $rc -eq 5 ] && { echo "writemany correctly failed $rc" && return 0; }
790         # but timing or failover setup may allow success
791         [ $rc -eq 0 ] && { echo "writemany succeeded" && return 0; }
792         echo "writemany returned $rc"
793         return $rc
794 }
795
796 test_52() {
797         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
798
799         mkdir -p $DIR/$tdir
800         test_52_guts
801         rc=$?
802         [ $rc -ne 0 ] && { return $rc; }
803         # wait for client to reconnect to OST
804         sleep 30
805         test_52_guts
806         rc=$?
807         [ $rc -ne 0 ] && { return $rc; }
808         sleep 30
809         test_52_guts
810         rc=$?
811         client_reconnect
812         #return $rc
813 }
814 run_test 52 "failover OST under load"
815
816 # test of open reconstruct
817 test_53() {
818         touch $DIR/$tfile
819         drop_ldlm_reply "openfile -f O_RDWR:O_CREAT -m 0755 $DIR/$tfile" ||\
820                 return 2
821 }
822 run_test 53 "touch: drop rep"
823
824 test_54() {
825         zconf_mount `hostname` $MOUNT2
826         touch $DIR/$tfile
827         touch $DIR2/$tfile.1
828         sleep 10
829         cat $DIR2/$tfile.missing # save transno = 0, rc != 0 into last_rcvd
830         fail $SINGLEMDS
831         umount $MOUNT2
832         ERROR=`dmesg | egrep "(test 54|went back in time)" | tail -n1 | grep "went back in time"`
833         [ x"$ERROR" == x ] || error "back in time occured"
834 }
835 run_test 54 "back in time"
836
837 # bug 11330 - liblustre application death during I/O locks up OST
838 test_55() {
839         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
840
841         mkdir -p $DIR/$tdir
842
843         # first dd should be finished quickly
844         lfs setstripe DIR/$tdir/$tfile-1 -c 1 -i 0
845         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=32M count=4  &
846         DDPID=$!
847         count=0
848         echo  "step1: testing ......"
849         while [ true ]; do
850             if [ -z `ps x | awk '$1 == '$DDPID' { print $5 }'` ]; then break; fi
851             count=$[count+1]
852             if [ $count -gt 64 ]; then
853                 error "dd should be finished!"
854             fi
855             sleep 1
856         done    
857         echo "(dd_pid=$DDPID, time=$count)successful"
858
859         lfs setstripe DIR/$tdir/$tfile-2 -c 1 -i 0
860         #define OBD_FAIL_OST_DROP_REQ            0x21d
861         do_facet ost1 lctl set_param fail_loc=0x0000021d
862         # second dd will be never finished
863         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=32M count=4  &        
864         DDPID=$!
865         count=0
866         echo  "step2: testing ......"
867         while [ $count -le 64 ]; do
868             dd_name="`ps x | awk '$1 == '$DDPID' { print $5 }'`"            
869             if [ -z  $dd_name ]; then 
870                 ls -l $DIR/$tdir
871                 echo  "debug: (dd_name=$dd_name, dd_pid=$DDPID, time=$count)"
872                 error "dd shouldn't be finished!"
873             fi
874             count=$[count+1]
875             sleep 1
876         done    
877         echo "(dd_pid=$DDPID, time=$count)successful"
878
879         #Recover fail_loc and dd will finish soon
880         do_facet ost1 lctl set_param fail_loc=0
881         count=0
882         echo  "step3: testing ......"
883         while [ true ]; do
884             if [ -z `ps x | awk '$1 == '$DDPID' { print $5 }'` ]; then break; fi
885             count=$[count+1]
886             if [ $count -gt 500 ]; then
887                 error "dd should be finished!"
888             fi
889             sleep 1
890         done    
891         echo "(dd_pid=$DDPID, time=$count)successful"
892
893         rm -rf $DIR/$tdir
894 }
895 run_test 55 "ost_brw_read/write drops timed-out read/write request"
896
897 test_56() { # b=11277
898 #define OBD_FAIL_MDS_RESEND      0x136
899         touch $DIR/$tfile
900         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000136"
901         stat $DIR/$tfile
902         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
903         rm -f $DIR/$tfile
904 }
905 run_test 56 "do not allow reconnect to busy exports"
906
907 test_57_helper() {
908         # no oscs means no client or mdt 
909         while lctl get_param osc.*.* > /dev/null 2>&1; do
910                 : # loop until proc file is removed
911         done
912 }
913
914 test_57() { # bug 10866
915         test_57_helper &
916         pid=$!
917         sleep 1
918 #define OBD_FAIL_LPROC_REMOVE            0xB00
919         lctl set_param fail_loc=0x80000B00
920         zconf_umount `hostname` $DIR
921         lctl set_param fail_loc=0x80000B00
922         fail_abort $SINGLEMDS
923         kill -9 $pid
924         lctl set_param fail_loc=0
925         mount_client $DIR
926         do_facet client "df $DIR"
927 }
928 run_test 57 "read procfs entries causes kernel crash"
929
930 test_58() { # bug 11546
931 #define OBD_FAIL_MDC_ENQUEUE_PAUSE        0x801
932         touch $DIR/$tfile
933         ls -la $DIR/$tfile
934         lctl set_param fail_loc=0x80000801
935         cp $DIR/$tfile /dev/null &
936         pid=$!
937         sleep 1
938         lctl set_param fail_loc=0
939         drop_bl_callback rm -f $DIR/$tfile
940         wait $pid
941         do_facet client "df $DIR"
942 }
943 run_test 58 "Eviction in the middle of open RPC reply processing"
944
945 test_59() { # bug 10589
946         zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
947         echo $DIR2 | grep -q $MOUNT2 || error "DIR2 is not set properly: $DIR2"
948 #define OBD_FAIL_LDLM_CANCEL_EVICT_RACE  0x311
949         lctl set_param fail_loc=0x311
950         writes=$(LANG=C dd if=/dev/zero of=$DIR2/$tfile count=1 2>&1)
951         [ $? = 0 ] || error "dd write failed"
952         writes=$(echo $writes | awk  -F '+' '/out/ {print $1}')
953         lctl set_param fail_loc=0
954         sync
955         zconf_umount `hostname` $MOUNT2 -f
956         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1)
957         [ $? = 0 ] || error "dd read failed"
958         reads=$(echo $reads | awk -F '+' '/in/ {print $1}')
959         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
960 }
961 run_test 59 "Read cancel race on client eviction"
962
963 equals_msg `basename $0`: test complete, cleaning up
964 check_and_cleanup_lustre
965 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true