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