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