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