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