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