Whamcloud - gitweb
LU-1193 tests: test script fixes for incompatibility
[fs/lustre-release.git] / lustre / tests / recovery-small.sh
1 #!/bin/bash
2
3 set -e
4
5 #         bug  5494 5493
6 ALWAYS_EXCEPT="24   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 init_logging
14
15 require_dsh_mds || exit 0
16
17 # also long tests: 19, 21a, 21e, 21f, 23, 27
18 #                                   1  2.5  2.5    4    4          (min)"
19 [ "$SLOW" = "no" ] && EXCEPT_SLOW="17  26a  26b    50   51     57"
20
21 build_test_filter
22
23 # Allow us to override the setup if we already have a mounted system by
24 # setting SETUP=" " and CLEANUP=" "
25 SETUP=${SETUP:-""}
26 CLEANUP=${CLEANUP:-""}
27
28 check_and_setup_lustre
29
30 assert_DIR
31 rm -rf $DIR/[df][0-9]*
32
33 test_1() {
34     drop_request "mcreate $DIR/f1"  || return 1
35     drop_reint_reply "mcreate $DIR/f2"    || return 2
36 }
37 run_test 1 "mcreate: drop req, drop rep"
38
39 test_2() {
40     drop_request "tchmod 111 $DIR/f2"  || return 1
41     drop_reint_reply "tchmod 666 $DIR/f2"    || return 2
42 }
43 run_test 2 "chmod: drop req, drop rep"
44
45 test_3() {
46     drop_request "statone $DIR/f2" || return 1
47     drop_reply "statone $DIR/f2"   || return 2
48 }
49 run_test 3 "stat: drop req, drop rep"
50
51 SAMPLE_NAME=f0.recovery-small.junk
52 SAMPLE_FILE=$TMP/$SAMPLE_NAME
53 # make this big, else test 9 doesn't wait for bulk -- bz 5595
54 dd if=/dev/urandom of=$SAMPLE_FILE bs=1M count=4
55
56 test_4() {
57     do_facet client "cp $SAMPLE_FILE $DIR/$SAMPLE_NAME" || return 1
58     drop_request "cat $DIR/$SAMPLE_NAME > /dev/null"   || return 2
59     drop_reply "cat $DIR/$SAMPLE_NAME > /dev/null"     || return 3
60 }
61 run_test 4 "open: drop req, drop rep"
62
63 RENAMED_AGAIN=$DIR/f0.renamed-again
64
65 test_5() {
66     drop_request "mv $DIR/$SAMPLE_NAME $DIR/$tfile-renamed" || return 1
67     drop_reint_reply "mv $DIR/$tfile-renamed $RENAMED_AGAIN" || return 2
68     do_facet client "checkstat -v $RENAMED_AGAIN"  || return 3
69 }
70 run_test 5 "rename: drop req, drop rep"
71
72 [ ! -e $RENAMED_AGAIN ] && cp $SAMPLE_FILE $RENAMED_AGAIN
73 LINK1=$DIR/f0.link1
74 LINK2=$DIR/f0.link2
75
76 test_6() {
77     drop_request "mlink $RENAMED_AGAIN $LINK1" || return 1
78     drop_reint_reply "mlink $RENAMED_AGAIN $LINK2"   || return 2
79 }
80 run_test 6 "link: drop req, drop rep"
81
82 [ ! -e $LINK1 ] && mlink $RENAMED_AGAIN $LINK1
83 [ ! -e $LINK2 ] && mlink $RENAMED_AGAIN $LINK2
84 test_7() {
85     drop_request "munlink $LINK1"   || return 1
86     drop_reint_reply "munlink $LINK2"     || return 2
87 }
88 run_test 7 "unlink: drop req, drop rep"
89
90 #bug 1423
91 test_8() {
92     drop_reint_reply "touch $DIR/$tfile"    || return 1
93 }
94 run_test 8 "touch: drop rep (bug 1423)"
95
96 #bug 1420
97 test_9() {
98     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
99
100     pause_bulk "cp /etc/profile $DIR/$tfile"       || return 1
101     do_facet client "cp $SAMPLE_FILE $DIR/${tfile}.2"  || return 2
102     do_facet client "sync"
103     do_facet client "rm $DIR/$tfile $DIR/${tfile}.2" || return 3
104 }
105 run_test 9 "pause bulk on OST (bug 1420)"
106
107 #bug 1521
108 test_10() {
109     do_facet client mcreate $DIR/$tfile        || return 1
110     drop_bl_callback "chmod 0777 $DIR/$tfile"  || echo "evicted as expected"
111     # wait for the mds to evict the client
112     #echo "sleep $(($TIMEOUT*2))"
113     #sleep $(($TIMEOUT*2))
114     do_facet client touch $DIR/$tfile || echo "touch failed, evicted"
115     do_facet client checkstat -v -p 0777 $DIR/$tfile  || return 3
116     do_facet client "munlink $DIR/$tfile"
117 }
118 run_test 10 "finish request on server after client eviction (bug 1521)"
119
120 #bug 2460
121 # wake up a thread waiting for completion after eviction
122 test_11(){
123     do_facet client multiop $DIR/$tfile Ow  || return 1
124     do_facet client multiop $DIR/$tfile or  || return 2
125
126     cancel_lru_locks osc
127
128     do_facet client multiop $DIR/$tfile or  || return 3
129     drop_bl_callback multiop $DIR/$tfile Ow || echo "evicted as expected"
130
131     do_facet client munlink $DIR/$tfile  || return 4
132 }
133 run_test 11 "wake up a thread waiting for completion after eviction (b=2460)"
134
135 #b=2494
136 test_12(){
137     $LCTL mark multiop $DIR/$tfile OS_c 
138     do_facet $SINGLEMDS "lctl set_param fail_loc=0x115"
139     clear_failloc $SINGLEMDS $((TIMEOUT * 2)) &
140     multiop_bg_pause $DIR/$tfile OS_c || return 1
141     PID=$!
142 #define OBD_FAIL_MDS_CLOSE_NET           0x115
143     kill -USR1 $PID
144     echo "waiting for multiop $PID"
145     wait $PID || return 2
146     do_facet client munlink $DIR/$tfile  || return 3
147 }
148 run_test 12 "recover from timed out resend in ptlrpcd (b=2494)"
149
150 # Bug 113, check that readdir lost recv timeout works.
151 test_13() {
152     mkdir -p $DIR/$tdir || return 1
153     touch $DIR/$tdir/newentry || return
154 # OBD_FAIL_MDS_READPAGE_NET|OBD_FAIL_ONCE
155     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000104"
156     ls $DIR/$tdir || return 3
157     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
158     rm -rf $DIR/$tdir || return 4
159 }
160 run_test 13 "mdc_readpage restart test (bug 1138)"
161
162 # Bug 113, check that readdir lost send timeout works.
163 test_14() {
164     mkdir -p $DIR/$tdir
165     touch $DIR/$tdir/newentry
166 # OBD_FAIL_MDS_SENDPAGE|OBD_FAIL_ONCE
167     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000106"
168     ls $DIR/$tdir || return 1
169     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
170 }
171 run_test 14 "mdc_readpage resend test (bug 1138)"
172
173 test_15() {
174     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000128"
175     touch $DIR/$tfile && return 1
176     return 0
177 }
178 run_test 15 "failed open (-ENOMEM)"
179
180 READ_AHEAD=`lctl get_param -n llite.*.max_read_ahead_mb | head -n 1`
181 stop_read_ahead() {
182    lctl set_param -n llite.*.max_read_ahead_mb 0
183 }
184
185 start_read_ahead() {
186    lctl set_param -n llite.*.max_read_ahead_mb $READ_AHEAD
187 }
188
189 test_16() {
190     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
191
192     do_facet client cp $SAMPLE_FILE $DIR
193     sync
194     stop_read_ahead
195
196 #define OBD_FAIL_PTLRPC_BULK_PUT_NET 0x504 | OBD_FAIL_ONCE
197     do_facet ost1 "lctl set_param fail_loc=0x80000504"
198     cancel_lru_locks osc
199     # OST bulk will time out here, client resends
200     do_facet client "cmp $SAMPLE_FILE $DIR/${SAMPLE_FILE##*/}" || return 1
201     do_facet ost1 lctl set_param fail_loc=0
202     # give recovery a chance to finish (shouldn't take long)
203     sleep $TIMEOUT
204     do_facet client "cmp $SAMPLE_FILE $DIR/${SAMPLE_FILE##*/}" || return 2
205     start_read_ahead
206 }
207 run_test 16 "timeout bulk put, don't evict client (2732)"
208
209 test_17() {
210     local at_max_saved=0
211
212     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
213
214     # With adaptive timeouts, bulk_get won't expire until adaptive_timeout_max
215     if at_is_enabled; then
216         at_max_saved=$(at_max_get ost1)
217         at_max_set $TIMEOUT ost1
218     fi
219
220     # OBD_FAIL_PTLRPC_BULK_GET_NET 0x0503 | OBD_FAIL_ONCE
221     # OST bulk will time out here, client retries
222     do_facet ost1 lctl set_param fail_loc=0x80000503
223     # need to ensure we send an RPC
224     do_facet client cp $SAMPLE_FILE $DIR/$tfile
225     sync
226
227     # with AT, client will wait adaptive_max*factor+net_latency before
228     # expiring the req, hopefully timeout*2 is enough
229     sleep $(($TIMEOUT*2))
230
231     do_facet ost1 lctl set_param fail_loc=0
232     do_facet client "df $DIR"
233     # expect cmp to succeed, client resent bulk
234     do_facet client "cmp $SAMPLE_FILE $DIR/$tfile" || return 3
235     do_facet client "rm $DIR/$tfile" || return 4
236     [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved ost1
237     return 0
238 }
239 run_test 17 "timeout bulk get, don't evict client (2732)"
240
241 test_18a() {
242     [ -z ${ost2_svc} ] && skip_env "needs 2 osts" && return 0
243
244     do_facet client mkdir -p $DIR/$tdir
245     f=$DIR/$tdir/$tfile
246
247     cancel_lru_locks osc
248     pgcache_empty || return 1
249
250     # 1 stripe on ost2
251     $LFS setstripe -i 1 -c 1 $f
252     stripe_index=$($LFS getstripe -i $f)
253     if [ $stripe_index -ne 1 ]; then
254         $LFS getstripe $f
255         error "$f: stripe_index $stripe_index != 1" && return
256     fi
257
258     do_facet client cp $SAMPLE_FILE $f
259     sync
260     local osc2dev=`lctl get_param -n devices | grep ${ost2_svc}-osc- | egrep -v 'MDT' | awk '{print $1}'`
261     $LCTL --device $osc2dev deactivate || return 3
262     # my understanding is that there should be nothing in the page
263     # cache after the client reconnects?     
264     rc=0
265     pgcache_empty || rc=2
266     $LCTL --device $osc2dev activate
267     rm -f $f
268     return $rc
269 }
270 run_test 18a "manual ost invalidate clears page cache immediately"
271
272 test_18b() {
273     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
274
275     do_facet client mkdir -p $DIR/$tdir
276     f=$DIR/$tdir/$tfile
277
278     cancel_lru_locks osc
279     pgcache_empty || return 1
280
281     $LFS setstripe -i 0 -c 1 $f
282     stripe_index=$($LFS getstripe -i $f)
283     if [ $stripe_index -ne 0 ]; then
284         $LFS getstripe $f
285         error "$f: stripe_index $stripe_index != 0" && return
286     fi
287
288     do_facet client cp $SAMPLE_FILE $f
289     sync
290     ost_evict_client
291     # allow recovery to complete
292     sleep $((TIMEOUT + 2))
293     # my understanding is that there should be nothing in the page
294     # cache after the client reconnects?     
295     rc=0
296     pgcache_empty || rc=2
297     rm -f $f
298     return $rc
299 }
300 run_test 18b "eviction and reconnect clears page cache (2766)"
301
302 test_18c() {
303     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
304
305     do_facet client mkdir -p $DIR/$tdir
306     f=$DIR/$tdir/$tfile
307
308     cancel_lru_locks osc
309     pgcache_empty || return 1
310
311     $LFS setstripe -i 0 -c 1 $f
312     stripe_index=$($LFS getstripe -i $f)
313     if [ $stripe_index -ne 0 ]; then
314         $LFS getstripe $f
315         error "$f: stripe_index $stripe_index != 0" && return
316     fi
317
318     do_facet client cp $SAMPLE_FILE $f
319     sync
320     ost_evict_client
321
322     # OBD_FAIL_OST_CONNECT_NET2
323     # lost reply to connect request
324     do_facet ost1 lctl set_param fail_loc=0x80000225
325     # force reconnect
326     sleep 1
327     df $MOUNT > /dev/null 2>&1
328     sleep 2
329     # my understanding is that there should be nothing in the page
330     # cache after the client reconnects?     
331     rc=0
332     pgcache_empty || rc=2
333     rm -f $f
334     return $rc
335 }
336 run_test 18c "Dropped connect reply after eviction handing (14755)"
337
338 test_19a() {
339     f=$DIR/$tfile
340     do_facet client mcreate $f        || return 1
341     drop_ldlm_cancel "chmod 0777 $f"  || echo "evicted as expected"
342
343     do_facet client checkstat -v -p 0777 $f  || echo evicted
344     # let the client reconnect
345     sleep 5
346     do_facet client "munlink $f"
347 }
348 run_test 19a "test expired_lock_main on mds (2867)"
349
350 test_19b() {
351     f=$DIR/$tfile
352     do_facet client multiop $f Ow  || return 1
353     do_facet client multiop $f or  || return 2
354
355     cancel_lru_locks osc
356
357     do_facet client multiop $f or  || return 3
358     drop_ldlm_cancel multiop $f Ow  || echo "client evicted, as expected"
359
360     do_facet client munlink $f  || return 4
361 }
362 run_test 19b "test expired_lock_main on ost (2867)"
363
364 test_20a() {    # bug 2983 - ldlm_handle_enqueue cleanup
365         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
366
367         mkdir -p $DIR/$tdir
368         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${tfile}
369         multiop_bg_pause $DIR/$tdir/${tfile} O_wc || return 1
370         MULTI_PID=$!
371         cancel_lru_locks osc
372 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
373         do_facet ost1 lctl set_param fail_loc=0x80000308
374         kill -USR1 $MULTI_PID
375         wait $MULTI_PID
376         rc=$?
377         [ $rc -eq 0 ] && error "multiop didn't fail enqueue: rc $rc" || true
378 }
379 run_test 20a "ldlm_handle_enqueue error (should return error)" 
380
381 test_20b() {    # bug 2986 - ldlm_handle_enqueue error during open
382         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
383
384         mkdir -p $DIR/$tdir
385         $LFS setstripe -i 0 -c 1 $DIR/$tdir/${tfile}
386         cancel_lru_locks osc
387 #define OBD_FAIL_LDLM_ENQUEUE_EXTENT_ERR 0x308
388         do_facet ost1 lctl set_param fail_loc=0x80000308
389         dd if=/etc/hosts of=$DIR/$tdir/$tfile && \
390                 error "didn't fail open enqueue" || true
391 }
392 run_test 20b "ldlm_handle_enqueue error (should return error)"
393
394 test_21a() {
395        mkdir -p $DIR/$tdir-1
396        mkdir -p $DIR/$tdir-2
397        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
398        close_pid=$!
399
400        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000129"
401        multiop $DIR/$tdir-2/f Oc &
402        open_pid=$!
403        sleep 1
404        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
405
406        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
407        kill -USR1 $close_pid
408        cancel_lru_locks mdc
409        wait $close_pid || return 1
410        wait $open_pid || return 2
411        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
412
413        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
414        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
415
416        rm -rf $DIR/$tdir-*
417 }
418 run_test 21a "drop close request while close and open are both in flight"
419
420 test_21b() {
421        mkdir -p $DIR/$tdir-1
422        mkdir -p $DIR/$tdir-2
423        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
424        close_pid=$!
425
426        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
427        mcreate $DIR/$tdir-2/f &
428        open_pid=$!
429        sleep 1
430        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
431
432        kill -USR1 $close_pid
433        cancel_lru_locks mdc
434        wait $close_pid || return 1
435        wait $open_pid || return 3
436
437        $CHECKSTAT -t file $DIR/$tdir-1/f || return 4
438        $CHECKSTAT -t file $DIR/$tdir-2/f || return 5
439        rm -rf $DIR/$tdir-*
440 }
441 run_test 21b "drop open request while close and open are both in flight"
442
443 test_21c() {
444        mkdir -p $DIR/$tdir-1
445        mkdir -p $DIR/$tdir-2
446        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
447        close_pid=$!
448
449        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
450        mcreate $DIR/$tdir-2/f &
451        open_pid=$!
452        sleep 3
453        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
454
455        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
456        kill -USR1 $close_pid
457        cancel_lru_locks mdc
458        wait $close_pid || return 1
459        wait $open_pid || return 2
460
461        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
462
463        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
464        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
465        rm -rf $DIR/$tdir-*
466 }
467 run_test 21c "drop both request while close and open are both in flight"
468
469 test_21d() {
470        mkdir -p $DIR/$tdir-1
471        mkdir -p $DIR/$tdir-2
472        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
473        pid=$!
474
475        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000129"
476        multiop $DIR/$tdir-2/f Oc &
477        sleep 1
478        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
479
480        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
481        kill -USR1 $pid
482        cancel_lru_locks mdc
483        wait $pid || return 1
484        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
485
486        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
487        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
488
489        rm -rf $DIR/$tdir-*
490 }
491 run_test 21d "drop close reply while close and open are both in flight"
492
493 test_21e() {
494        mkdir -p $DIR/$tdir-1
495        mkdir -p $DIR/$tdir-2
496        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
497        pid=$!
498
499        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
500        touch $DIR/$tdir-2/f &
501        sleep 1
502        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
503
504        kill -USR1 $pid
505        cancel_lru_locks mdc
506        wait $pid || return 1
507
508        sleep $TIMEOUT
509        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
510        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
511        rm -rf $DIR/$tdir-*
512 }
513 run_test 21e "drop open reply while close and open are both in flight"
514
515 test_21f() {
516        mkdir -p $DIR/$tdir-1
517        mkdir -p $DIR/$tdir-2
518        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
519        pid=$!
520
521        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
522        touch $DIR/$tdir-2/f &
523        sleep 1
524        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
525
526        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
527        kill -USR1 $pid
528        cancel_lru_locks mdc
529        wait $pid || return 1
530        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
531
532        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
533        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
534        rm -rf $DIR/$tdir-*
535 }
536 run_test 21f "drop both reply while close and open are both in flight"
537
538 test_21g() {
539        mkdir -p $DIR/$tdir-1
540        mkdir -p $DIR/$tdir-2
541        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
542        pid=$!
543
544        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
545        touch $DIR/$tdir-2/f &
546        sleep 1
547        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
548
549        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
550        kill -USR1 $pid
551        cancel_lru_locks mdc
552        wait $pid || return 1
553        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
554
555        $CHECKSTAT -t file $DIR/$tdir-1/f || return 2
556        $CHECKSTAT -t file $DIR/$tdir-2/f || return 3
557        rm -rf $DIR/$tdir-*
558 }
559 run_test 21g "drop open reply and close request while close and open are both in flight"
560
561 test_21h() {
562        mkdir -p $DIR/$tdir-1
563        mkdir -p $DIR/$tdir-2
564        multiop_bg_pause $DIR/$tdir-1/f O_c || return 1
565        pid=$!
566
567        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
568        touch $DIR/$tdir-2/f &
569        touch_pid=$!
570        sleep 1
571        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
572
573        do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000122"
574        cancel_lru_locks mdc
575        kill -USR1 $pid
576        wait $pid || return 1
577        do_facet $SINGLEMDS "lctl set_param fail_loc=0"
578
579        wait $touch_pid || return 2
580
581        $CHECKSTAT -t file $DIR/$tdir-1/f || return 3
582        $CHECKSTAT -t file $DIR/$tdir-2/f || return 4
583        rm -rf $DIR/$tdir-*
584 }
585 run_test 21h "drop open request and close reply while close and open are both in flight"
586
587 # bug 3462 - multiple MDC requests
588 test_22() {
589     f1=$DIR/${tfile}-1
590     f2=$DIR/${tfile}-2
591     
592     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
593     multiop $f2 Oc &
594     close_pid=$!
595
596     sleep 1
597     multiop $f1 msu || return 1
598
599     cancel_lru_locks mdc
600     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
601
602     wait $close_pid || return 2
603     rm -rf $f2 || return 4
604 }
605 run_test 22 "drop close request and do mknod"
606
607 test_23() { #b=4561
608     multiop_bg_pause $DIR/$tfile O_c || return 1
609     pid=$!
610     # give a chance for open
611     sleep 5
612
613     # try the close
614     drop_request "kill -USR1 $pid"
615
616     fail $SINGLEMDS
617     wait $pid || return 1
618     return 0
619 }
620 run_test 23 "client hang when close a file after mds crash"
621
622 test_24() { # bug 11710 details correct fsync() behavior
623         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
624
625         mkdir -p $DIR/$tdir
626         $LFS setstripe -i 0 -c 1 $DIR/$tdir
627         cancel_lru_locks osc
628         multiop_bg_pause $DIR/$tdir/$tfile Owy_wyc || return 1
629         MULTI_PID=$!
630         ost_evict_client
631         kill -USR1 $MULTI_PID
632         wait $MULTI_PID
633         rc=$?
634         lctl set_param fail_loc=0x0
635         client_reconnect
636         [ $rc -eq 0 ] && error_ignore 5494 "multiop didn't fail fsync: rc $rc" || true
637 }
638 run_test 24 "fsync error (should return error)"
639
640 wait_client_evicted () {
641         local facet=$1
642         local exports=$2
643         local varsvc=${facet}_svc
644
645         wait_update $(facet_active_host $facet) \
646                 "lctl get_param -n *.${!varsvc}.num_exports | cut -d' ' -f2" \
647                 $((exports - 1)) $3
648 }
649
650 test_26a() {      # was test_26 bug 5921 - evict dead exports by pinger
651 # this test can only run from a client on a separate node.
652         remote_ost || { skip "local OST" && return 0; }
653         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
654         remote_mds || { skip "local MDS" && return 0; }
655
656         if [ $(facet_host mgs) = $(facet_host ost1) ]; then
657                 skip "msg and ost1 are at the same node"
658                 return 0
659         fi
660
661         check_timeout || return 1
662
663         local OST_NEXP=$(do_facet ost1 lctl get_param -n obdfilter.${ost1_svc}.num_exports | cut -d' ' -f2)
664
665         echo starting with $OST_NEXP OST exports
666 # OBD_FAIL_PTLRPC_DROP_RPC 0x505
667         do_facet client lctl set_param fail_loc=0x505
668         # evictor takes PING_EVICT_TIMEOUT + 3 * PING_INTERVAL to evict.
669         # But if there's a race to start the evictor from various obds,
670         # the loser might have to wait for the next ping.
671
672         local rc=0
673         wait_client_evicted ost1 $OST_NEXP $((TIMEOUT * 2 + TIMEOUT * 3 / 4))
674         rc=$?
675         do_facet client lctl set_param fail_loc=0x0
676         [ $rc -eq 0 ] || error "client not evicted from OST"
677 }
678 run_test 26a "evict dead exports"
679
680 test_26b() {      # bug 10140 - evict dead exports by pinger
681         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
682
683         if [ $(facet_host mgs) = $(facet_host ost1) ]; then
684                 skip "msg and ost1 are at the same node"
685                 return 0
686         fi
687
688         check_timeout || return 1
689         clients_up
690         zconf_mount `hostname` $MOUNT2 ||
691                 { error "Failed to mount $MOUNT2"; return 2; }
692         sleep 1 # wait connections being established
693
694         local MDS_NEXP=$(do_facet $SINGLEMDS lctl get_param -n mdt.${mds1_svc}.num_exports | cut -d' ' -f2)
695         local OST_NEXP=$(do_facet ost1 lctl get_param -n obdfilter.${ost1_svc}.num_exports | cut -d' ' -f2)
696
697         echo starting with $OST_NEXP OST and $MDS_NEXP MDS exports
698
699         zconf_umount `hostname` $MOUNT2 -f
700
701         # PING_INTERVAL max(obd_timeout / 4, 1U)
702         # PING_EVICT_TIMEOUT (PING_INTERVAL * 6)
703
704         # evictor takes PING_EVICT_TIMEOUT + 3 * PING_INTERVAL to evict.  
705         # But if there's a race to start the evictor from various obds, 
706         # the loser might have to wait for the next ping.
707         # = 9 * PING_INTERVAL + PING_INTERVAL
708         # = 10 PING_INTERVAL = 10 obd_timeout / 4 = 2.5 obd_timeout
709         # let's wait $((TIMEOUT * 3)) # bug 19887
710         local rc=0
711         wait_client_evicted ost1 $OST_NEXP $((TIMEOUT * 3)) || \
712                 error "Client was not evicted by ost" rc=1
713         wait_client_evicted $SINGLEMDS $MDS_NEXP $((TIMEOUT * 3)) || \
714                 error "Client was not evicted by mds"
715 }
716 run_test 26b "evict dead exports"
717
718 test_27() {
719         mkdir -p $DIR/$tdir
720         writemany -q -a $DIR/$tdir/$tfile 0 5 &
721         CLIENT_PID=$!
722         sleep 1
723         local save_FAILURE_MODE=$FAILURE_MODE
724         FAILURE_MODE="SOFT"
725         facet_failover $SINGLEMDS
726 #define OBD_FAIL_OSC_SHUTDOWN            0x407
727         do_facet $SINGLEMDS lctl set_param fail_loc=0x80000407
728         # need to wait for reconnect
729         echo waiting for fail_loc
730         wait_update_facet $SINGLEMDS "lctl get_param -n fail_loc" "-2147482617"
731         facet_failover $SINGLEMDS
732         #no crashes allowed!
733         kill -USR1 $CLIENT_PID
734         wait $CLIENT_PID 
735         true
736         FAILURE_MODE=$save_FAILURE_MODE
737 }
738 run_test 27 "fail LOV while using OSC's"
739
740 test_28() {      # bug 6086 - error adding new clients
741         do_facet client mcreate $DIR/$tfile       || return 1
742         drop_bl_callback "chmod 0777 $DIR/$tfile" ||echo "evicted as expected"
743         #define OBD_FAIL_MDS_CLIENT_ADD 0x12f
744         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012f"
745         # fail once (evicted), reconnect fail (fail_loc), ok
746         client_up || (sleep 10; client_up) || (sleep 10; client_up) || error "reconnect failed"
747         rm -f $DIR/$tfile
748         fail $SINGLEMDS         # verify MDS last_rcvd can be loaded
749 }
750 run_test 28 "handle error adding new clients (bug 6086)"
751
752 test_29a() { # bug 22273 - error adding new clients
753         #define OBD_FAIL_TGT_CLIENT_ADD 0x711
754         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000711"
755         # fail abort so client will be new again
756         fail_abort $SINGLEMDS
757         client_up || error "reconnect failed"
758         return 0
759 }
760 run_test 29a "error adding new clients doesn't cause LBUG (bug 22273)"
761
762 test_29b() { # bug 22273 - error adding new clients
763         #define OBD_FAIL_TGT_CLIENT_ADD 0x711
764         do_facet ost1 "lctl set_param fail_loc=0x80000711"
765         # fail abort so client will be new again
766         fail_abort ost1
767         client_up || error "reconnect failed"
768         return 0
769 }
770 run_test 29b "error adding new clients doesn't cause LBUG (bug 22273)"
771
772 test_50() {
773         mkdir -p $DIR/$tdir
774         # put a load of file creates/writes/deletes
775         writemany -q $DIR/$tdir/$tfile 0 5 &
776         CLIENT_PID=$!
777         echo writemany pid $CLIENT_PID
778         sleep 10
779         FAILURE_MODE="SOFT"
780         fail $SINGLEMDS
781         # wait for client to reconnect to MDS
782         sleep 60
783         fail $SINGLEMDS
784         sleep 60
785         fail $SINGLEMDS
786         # client process should see no problems even though MDS went down
787         sleep $TIMEOUT
788         kill -USR1 $CLIENT_PID
789         wait $CLIENT_PID 
790         rc=$?
791         echo writemany returned $rc
792         #these may fail because of eviction due to slow AST response.
793         [ $rc -eq 0 ] || error_ignore 13652 "writemany returned rc $rc" || true
794 }
795 run_test 50 "failover MDS under load"
796
797 test_51() {
798         #define OBD_FAIL_MDS_SYNC_CAPA_SL                    0x1310
799         do_facet ost1 lctl set_param fail_loc=0x00001310
800
801         mkdir -p $DIR/$tdir
802         # put a load of file creates/writes/deletes
803         writemany -q $DIR/$tdir/$tfile 0 5 &
804         CLIENT_PID=$!
805         sleep 1
806         FAILURE_MODE="SOFT"
807         facet_failover $SINGLEMDS
808         # failover at various points during recovery
809         SEQ="1 5 10 $(seq $TIMEOUT 5 $(($TIMEOUT+10)))"
810         echo will failover at $SEQ
811         for i in $SEQ
812           do
813           echo failover in $i sec
814           sleep $i
815           facet_failover $SINGLEMDS
816         done
817         # client process should see no problems even though MDS went down
818         # and recovery was interrupted
819         sleep $TIMEOUT
820         kill -USR1 $CLIENT_PID
821         wait $CLIENT_PID 
822         rc=$?
823         echo writemany returned $rc
824         [ $rc -eq 0 ] || error_ignore 13652 "writemany returned rc $rc" || true
825 }
826 run_test 51 "failover MDS during recovery"
827
828 test_52_guts() {
829         do_facet client "mkdir -p $DIR/$tdir"
830         do_facet client "writemany -q -a $DIR/$tdir/$tfile 300 5" &
831         CLIENT_PID=$!
832         echo writemany pid $CLIENT_PID
833         sleep 10
834         FAILURE_MODE="SOFT"
835         fail ost1
836         rc=0
837         wait $CLIENT_PID || rc=$?
838         # active client process should see an EIO for down OST
839         [ $rc -eq 5 ] && { echo "writemany correctly failed $rc" && return 0; }
840         # but timing or failover setup may allow success
841         [ $rc -eq 0 ] && { echo "writemany succeeded" && return 0; }
842         echo "writemany returned $rc"
843         return $rc
844 }
845
846 test_52() {
847         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
848
849         mkdir -p $DIR/$tdir
850         test_52_guts
851         rc=$?
852         [ $rc -ne 0 ] && { return $rc; }
853         # wait for client to reconnect to OST
854         sleep 30
855         test_52_guts
856         rc=$?
857         [ $rc -ne 0 ] && { return $rc; }
858         sleep 30
859         test_52_guts
860         rc=$?
861         client_reconnect
862         #return $rc
863 }
864 run_test 52 "failover OST under load"
865
866 # test of open reconstruct
867 test_53() {
868         touch $DIR/$tfile
869         drop_ldlm_reply "openfile -f O_RDWR:O_CREAT -m 0755 $DIR/$tfile" ||\
870                 return 2
871 }
872 run_test 53 "touch: drop rep"
873
874 test_54() {
875         zconf_mount `hostname` $MOUNT2
876         touch $DIR/$tfile
877         touch $DIR2/$tfile.1
878         sleep 10
879         cat $DIR2/$tfile.missing # save transno = 0, rc != 0 into last_rcvd
880         fail $SINGLEMDS
881         umount $MOUNT2
882         ERROR=`dmesg | egrep "(test 54|went back in time)" | tail -n1 | grep "went back in time"`
883         [ x"$ERROR" == x ] || error "back in time occured"
884 }
885 run_test 54 "back in time"
886
887 # bug 11330 - liblustre application death during I/O locks up OST
888 test_55() {
889         remote_ost_nodsh && skip "remote OST with nodsh" && return 0
890
891         mkdir -p $DIR/$tdir
892
893         # first dd should be finished quickly
894         $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile-1
895         dd if=/dev/zero of=$DIR/$tdir/$tfile-1 bs=32M count=4  &
896         DDPID=$!
897         count=0
898         echo  "step1: testing ......"
899         while [ true ]; do
900             if [ -z `ps x | awk '$1 == '$DDPID' { print $5 }'` ]; then break; fi
901             count=$[count+1]
902             if [ $count -gt 64 ]; then
903                 error "dd should be finished!"
904             fi
905             sleep 1
906         done    
907         echo "(dd_pid=$DDPID, time=$count)successful"
908
909         $LFS setstripe -c 1 -i 0 $DIR/$tdir/$tfile-2
910         #define OBD_FAIL_OST_DROP_REQ            0x21d
911         do_facet ost1 lctl set_param fail_loc=0x0000021d
912         # second dd will be never finished
913         dd if=/dev/zero of=$DIR/$tdir/$tfile-2 bs=32M count=4  &        
914         DDPID=$!
915         count=0
916         echo  "step2: testing ......"
917         while [ $count -le 64 ]; do
918             dd_name="`ps x | awk '$1 == '$DDPID' { print $5 }'`"            
919             if [ -z  $dd_name ]; then 
920                 ls -l $DIR/$tdir
921                 echo  "debug: (dd_name=$dd_name, dd_pid=$DDPID, time=$count)"
922                 error "dd shouldn't be finished!"
923             fi
924             count=$[count+1]
925             sleep 1
926         done    
927         echo "(dd_pid=$DDPID, time=$count)successful"
928
929         #Recover fail_loc and dd will finish soon
930         do_facet ost1 lctl set_param fail_loc=0
931         count=0
932         echo  "step3: testing ......"
933         while [ true ]; do
934             if [ -z `ps x | awk '$1 == '$DDPID' { print $5 }'` ]; then break; fi
935             count=$[count+1]
936             if [ $count -gt 500 ]; then
937                 error "dd should be finished!"
938             fi
939             sleep 1
940         done    
941         echo "(dd_pid=$DDPID, time=$count)successful"
942
943         rm -rf $DIR/$tdir
944 }
945 run_test 55 "ost_brw_read/write drops timed-out read/write request"
946
947 test_56() { # b=11277
948 #define OBD_FAIL_MDS_RESEND      0x136
949         touch $DIR/$tfile
950         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000136"
951         stat $DIR/$tfile
952         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
953         rm -f $DIR/$tfile
954 }
955 run_test 56 "do not allow reconnect to busy exports"
956
957 test_57_helper() {
958         # no oscs means no client or mdt 
959         while lctl get_param osc.*.* > /dev/null 2>&1; do
960                 : # loop until proc file is removed
961         done
962 }
963
964 test_57() { # bug 10866
965         test_57_helper &
966         pid=$!
967         sleep 1
968 #define OBD_FAIL_LPROC_REMOVE            0xB00
969         lctl set_param fail_loc=0x80000B00
970         zconf_umount `hostname` $DIR
971         lctl set_param fail_loc=0x80000B00
972         fail_abort $SINGLEMDS
973         kill -9 $pid
974         lctl set_param fail_loc=0
975         mount_client $DIR
976         do_facet client "df $DIR"
977 }
978 run_test 57 "read procfs entries causes kernel crash"
979
980 test_58() { # bug 11546
981 #define OBD_FAIL_MDC_ENQUEUE_PAUSE        0x801
982         touch $DIR/$tfile
983         ls -la $DIR/$tfile
984         lctl set_param fail_loc=0x80000801
985         cp $DIR/$tfile /dev/null &
986         pid=$!
987         sleep 1
988         lctl set_param fail_loc=0
989         drop_bl_callback rm -f $DIR/$tfile
990         wait $pid
991         do_facet client "df $DIR"
992 }
993 run_test 58 "Eviction in the middle of open RPC reply processing"
994
995 test_59() { # bug 10589
996         zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
997         echo $DIR2 | grep -q $MOUNT2 || error "DIR2 is not set properly: $DIR2"
998 #define OBD_FAIL_LDLM_CANCEL_EVICT_RACE  0x311
999         lctl set_param fail_loc=0x311
1000         writes=$(LANG=C dd if=/dev/zero of=$DIR2/$tfile count=1 2>&1)
1001         [ $? = 0 ] || error "dd write failed"
1002         writes=$(echo $writes | awk  -F '+' '/out/ {print $1}')
1003         lctl set_param fail_loc=0
1004         sync
1005         zconf_umount `hostname` $MOUNT2 -f
1006         reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1)
1007         [ $? = 0 ] || error "dd read failed"
1008         reads=$(echo $reads | awk -F '+' '/in/ {print $1}')
1009         [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
1010 }
1011 run_test 59 "Read cancel race on client eviction"
1012
1013 err17935 () {
1014     # we assume that all md changes are in the MDT0 changelog
1015     if [ $MDSCOUNT -gt 1 ]; then
1016         error_ignore 17935 $*
1017     else
1018         error $*
1019     fi
1020 }
1021
1022 test_60() {
1023         MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
1024             awk '{gsub(/_UUID/,""); print $1}' | head -1)
1025
1026         NUM_FILES=15000
1027         mkdir -p $DIR/$tdir
1028
1029         # Register (and start) changelog
1030         USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
1031         echo "Registered as $MDT0 changelog user $USER"
1032
1033         # Generate a large number of changelog entries
1034         createmany -o $DIR/$tdir/$tfile $NUM_FILES
1035         sync
1036         sleep 5
1037
1038         # Unlink files in the background
1039         unlinkmany $DIR/$tdir/$tfile $NUM_FILES &
1040         CLIENT_PID=$!
1041         sleep 1
1042
1043         # Failover the MDS while unlinks are happening
1044         facet_failover $SINGLEMDS
1045
1046         # Wait for unlinkmany to finish
1047         wait $CLIENT_PID
1048
1049         # Check if all the create/unlink events were recorded
1050         # in the changelog
1051         $LFS changelog $MDT0 >> $DIR/$tdir/changelog
1052         local cl_count=$(grep UNLNK $DIR/$tdir/changelog | wc -l)
1053         echo "$cl_count unlinks in $MDT0 changelog"
1054
1055         do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $USER
1056         USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
1057             mdd.$MDT0.changelog_users | wc -l) - 2 ))
1058         if [ $USERS -eq 0 ]; then
1059             [ $cl_count -eq $NUM_FILES ] || \
1060                 err17935 "Recorded ${cl_count} unlinks out of $NUM_FILES"
1061             # Also make sure we can clear large changelogs
1062             cl_count=$($LFS changelog $FSNAME | wc -l)
1063             [ $cl_count -le 2 ] || \
1064                 error "Changelog not empty: $cl_count entries"
1065         else
1066             # If there are other users, there may be other unlinks in the log
1067             [ $cl_count -ge $NUM_FILES ] || \
1068                 err17935 "Recorded ${cl_count} unlinks out of $NUM_FILES"
1069             echo "$USERS other changelog users; can't verify clear"
1070         fi
1071 }
1072 run_test 60 "Add Changelog entries during MDS failover"
1073
1074 test_61()
1075 {
1076         local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
1077         mdtosc=${mdtosc/-MDT*/-MDT\*}
1078         local cflags="osc.$mdtosc.connect_flags"
1079         do_facet $SINGLEMDS "lctl get_param -n $cflags" |grep -q skip_orphan
1080         [ $? -ne 0 ] && skip "don't have skip orphan feature" && return
1081
1082         mkdir -p $DIR/$tdir || error "mkdir dir $DIR/$tdir failed"
1083         # Set the default stripe of $DIR/$tdir to put the files to ost1
1084         $LFS setstripe -c 1 -i 0 $DIR/$tdir
1085
1086         replay_barrier $SINGLEMDS
1087         createmany -o $DIR/$tdir/$tfile-%d 10 
1088         local oid=`do_facet ost1 "lctl get_param -n obdfilter.${ost1_svc}.last_id"`
1089
1090         fail_abort $SINGLEMDS
1091         
1092         touch $DIR/$tdir/$tfile
1093         local id=`$LFS getstripe $DIR/$tdir/$tfile | awk '$1 == 0 { print $2 }'`
1094         [ $id -le $oid ] && error "the orphan objid was reused, failed"
1095
1096         # Cleanup
1097         rm -rf $DIR/$tdir
1098 }
1099 run_test 61 "Verify to not reuse orphan objects - bug 17025"
1100
1101 check_cli_ir_state()
1102 {
1103         local NODE=${1:-$HOSTNAME}
1104         local st
1105         st=$(do_node $NODE "lctl get_param mgc.*.ir_state |
1106                             awk '/imperative_recovery:/ { print \\\$2}'")
1107         [ $st != ON -o $st != OFF ] ||
1108                 error "Error state $st, must be ON or OFF"
1109         echo -n $st
1110 }
1111
1112 check_target_ir_state()
1113 {
1114         local target=${1}
1115         local name=${target}_svc
1116         local recovery_proc=obdfilter.${!name}.recovery_status
1117         local st
1118
1119         st=$(do_facet $target "lctl get_param -n $recovery_proc |
1120                                awk '/IR:/{ print \\\$2}'")
1121         [ $st != ON -o $st != OFF ] ||
1122                 error "Error state $st, must be ON or OFF"
1123         echo -n $st
1124 }
1125
1126 set_ir_status()
1127 {
1128         do_facet mgs lctl set_param -n mgs.MGS.live.$FSNAME="state=$1"
1129 }
1130
1131 get_ir_status()
1132 {
1133         local state=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
1134                                     awk '/state:/{ print \\\$2 }'")
1135         echo -n ${state/,/}
1136 }
1137
1138 nidtbl_version_mgs()
1139 {
1140         local ver=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
1141                                   awk '/nidtbl_version:/{ print \\\$2 }'")
1142         echo -n $ver
1143 }
1144
1145 # nidtbl_version_client <mds1|client> [node]
1146 nidtbl_version_client()
1147 {
1148         local cli=$1
1149         local node=${2:-$HOSTNAME}
1150
1151         if [ X$cli = Xclient ]; then
1152                 cli=$FSNAME-client
1153         else
1154                 local obdtype=${cli/%[0-9]*/}
1155                 [ $obdtype != mds ] && error "wrong parameters $cli"
1156
1157                 node=$(facet_active_host $cli)
1158                 local t=${cli}_svc
1159                 cli=${!t}
1160         fi
1161
1162         local vers=$(do_node $node "lctl get_param -n mgc.*.ir_state" |
1163                      awk "/$cli/{print \$6}" |sort -u)
1164
1165         # in case there are multiple mounts on the client node
1166         local arr=($vers)
1167         [ ${#arr[@]} -ne 1 ] && error "versions on client node mismatch"
1168         echo -n $vers
1169 }
1170
1171 nidtbl_versions_match()
1172 {
1173         [ $(nidtbl_version_mgs) -eq $(nidtbl_version_client ${1:-client}) ]
1174 }
1175
1176 target_instance_match()
1177 {
1178         local srv=$1
1179         local obdtype
1180         local cliname
1181
1182         obdtype=${srv/%[0-9]*/}
1183         case $obdtype in
1184         mds)
1185                 obdname="mdt"
1186                 cliname="mdc"
1187                 ;;
1188         ost)
1189                 obdname="obdfilter"
1190                 cliname="osc"
1191                 ;;
1192         *)
1193                 error "invalid target type" $srv
1194                 return 1
1195                 ;;
1196         esac
1197
1198         local target=${srv}_svc
1199         local si=$(do_facet $srv lctl get_param -n $obdname.${!target}.instance)
1200         local ci=$(lctl get_param -n $cliname.${!target}-${cliname}-*.import | \
1201                   awk '/instance/{ print $2 }' |head -1)
1202
1203         return $([ $si -eq $ci ])
1204 }
1205
1206 test_100()
1207 {
1208         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1209                 { skip "MGS without IR support"; return 0; }
1210
1211         # disable IR
1212         set_ir_status disabled
1213
1214         local saved_FAILURE_MODE=$FAILURE_MODE
1215         [ $(facet_host mgs) = $(facet_host ost1) ] && FAILURE_MODE="SOFT"
1216         fail ost1
1217
1218         # valid check
1219         nidtbl_versions_match &&
1220                 error "version must differ due to IR disabled"
1221         target_instance_match ost1 || error "instance mismatch"
1222
1223         # restore env
1224         set_ir_status full
1225         FAILURE_MODE=$saved_FAILURE_MODE
1226 }
1227 run_test 100 "IR: Make sure normal recovery still works w/o IR"
1228
1229 test_101()
1230 {
1231         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1232                 { skip "MGS without IR support"; return 0; }
1233
1234         set_ir_status full
1235
1236         local OST1_IMP=$(get_osc_import_name client ost1)
1237
1238         # disable pinger recovery
1239         lctl set_param -n osc.$OST1_IMP.pinger_recov=0
1240
1241         fail ost1
1242
1243         target_instance_match ost1 || error "instance mismatch"
1244         nidtbl_versions_match || error "version must match"
1245
1246         lctl set_param -n osc.$OST1_IMP.pinger_recov=1
1247 }
1248 run_test 101 "IR: Make sure IR works w/o normal recovery"
1249
1250 test_102()
1251 {
1252         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1253                 { skip "MGS without IR support"; return 0; }
1254
1255         local clients=${CLIENTS:-$HOSTNAME}
1256         local old_version
1257         local new_version
1258         local mgsdev=mgs
1259
1260         set_ir_status full
1261
1262         # let's have a new nidtbl version
1263         fail ost1
1264
1265         # sleep for a while so that clients can see the failure of ost
1266         # it must be MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC.
1267         # int mgc_request.c:
1268         # define MGC_TIMEOUT_MIN_SECONDS   5
1269         # define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 *
1270         local count=30  # 20 seconds at most
1271         while [ $count -gt 0 ]; do
1272                 nidtbl_versions_match && break
1273                 sleep 1
1274                 count=$((count-1))
1275         done
1276
1277         nidtbl_versions_match || error "nidtbl mismatch"
1278
1279         # get the version #
1280         old_version=$(nidtbl_version_client client)
1281
1282         zconf_umount_clients $clients $MOUNT || error "Cannot umount client"
1283
1284         # restart mgs
1285         combined_mgs_mds && mgsdev=mds1
1286         remount_facet $mgsdev
1287         fail ost1
1288
1289         zconf_mount_clients $clients $MOUNT || error "Cannot mount client"
1290
1291         # check new version
1292         new_version=$(nidtbl_version_client client)
1293         [ $new_version -lt $old_version ] &&
1294                 error "nidtbl version wrong after mgs restarts"
1295         return 0
1296 }
1297 run_test 102 "IR: New client gets updated nidtbl after MGS restart"
1298
1299 test_103()
1300 {
1301         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1302                 { skip "MGS without IR support"; return 0; }
1303
1304         combined_mgs_mds && skip "mgs and mds on the same target" && return 0
1305
1306         # workaround solution to generate config log on the mds
1307         remount_facet mds1
1308
1309         stop mgs
1310         stop mds1
1311
1312         # We need this test because mds is like a client in IR context.
1313         start mds1 $MDSDEV1 || error "MDS should start w/o mgs"
1314
1315         # start mgs and remount mds w/ ir
1316         start mgs $MGSDEV
1317         clients_up
1318
1319         # remount client so that fsdb will be created on the MGS
1320         umount_client $MOUNT || error "umount failed"
1321         mount_client $MOUNT || error "mount failed"
1322
1323         # sleep 30 seconds so the MDS has a chance to detect MGS restarting
1324         local count=30
1325         while [ $count -gt 0 ]; do
1326                 [ $(nidtbl_version_client mds1) -ne 0 ] && break
1327                 sleep 1
1328                 count=$((count-1))
1329         done
1330
1331         # after a while, mds should be able to reconnect to mgs and fetch
1332         # up-to-date nidtbl version
1333         nidtbl_versions_match mds1 || error "mds nidtbl mismatch"
1334
1335         # reset everything
1336         set_ir_status full
1337 }
1338 run_test 103 "IR: MDS can start w/o MGS and get updated nidtbl later"
1339
1340 test_104()
1341 {
1342         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1343                 { skip "MGS without IR support"; return 0; }
1344
1345         set_ir_status full
1346
1347         stop ost1
1348         start ost1 $(ostdevname 1) "$OST_MOUNT_OPTS -onoir" ||
1349                 error "OST1 cannot start"
1350         clients_up
1351
1352         local ir_state=$(check_target_ir_state ost1)
1353         [ $ir_state = "OFF" ] || error "ir status on ost1 should be OFF"
1354 }
1355 run_test 104 "IR: ost can disable IR voluntarily"
1356
1357 test_105()
1358 {
1359         [ -z "$RCLIENTS" ] && skip "Needs multiple clients" && return 0
1360         do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
1361                 { skip "MGS without IR support"; return 0; }
1362
1363         set_ir_status full
1364
1365         # get one of the clients from client list
1366         local rcli=$(echo $RCLIENTS |cut -d' ' -f 1)
1367
1368         local old_MOUNTOPT=$MOUNTOPT
1369         MOUNTOPT=${MOUNTOPT},noir
1370         zconf_umount $rcli $MOUNT || error "umount failed"
1371         zconf_mount $rcli $MOUNT || error "mount failed"
1372
1373         # make sure lustre mount at $rcli disabling IR
1374         local ir_state=$(check_cli_ir_state $rcli)
1375         [ $ir_state = OFF ] || error "IR state must be OFF at $rcli"
1376
1377         # make sure MGS's state is Partial
1378         [ $(get_ir_status) = "partial" ] || error "MGS IR state must be partial"
1379
1380         fail ost1
1381         # make sure IR on ost1 is OFF
1382         local ir_state=$(check_target_ir_state ost1)
1383         [ $ir_state = "OFF" ] || error "IR status on ost1 should be OFF"
1384
1385         # restore it
1386         MOUNTOPT=$old_MOUNTOPT
1387         zconf_umount $rcli $MOUNT || error "umount failed"
1388         zconf_mount $rcli $MOUNT || error "mount failed"
1389
1390         # make sure MGS's state is full
1391         [ $(get_ir_status) = "full" ] || error "MGS IR status must be full"
1392
1393         fail ost1
1394         # make sure IR on ost1 is ON
1395         local ir_state=$(check_target_ir_state ost1)
1396         [ $ir_state = "ON" ] || error "IR status on ost1 should be OFF"
1397
1398         return 0
1399 }
1400 run_test 105 "IR: NON IR clients support"
1401
1402 complete $(basename $0) $SECONDS
1403 check_and_cleanup_lustre
1404 exit_status