Whamcloud - gitweb
b=21927 recovery-small, replay-single 18 <-> 20 interop fix
[fs/lustre-release.git] / lustre / tests / replay-single.sh
1 #!/bin/bash
2
3 set -e
4 #set -v
5
6 #
7 # This test needs to be run on the client
8 #
9 SAVE_PWD=$PWD
10 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
11 SETUP=${SETUP:-}
12 CLEANUP=${CLEANUP:-}
13 . $LUSTRE/tests/test-framework.sh
14 init_test_env $@
15 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
16 CHECK_GRANT=${CHECK_GRANT:-"yes"}
17 GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
18
19 remote_mds_nodsh && log "SKIP: remote MDS with nodsh" && exit 0
20
21 # Skip these tests
22 # bug number:
23 ALWAYS_EXCEPT="$REPLAY_SINGLE_EXCEPT"
24
25 if [ "$FAILURE_MODE" = "HARD" ] && mixed_ost_devs; then
26     CONFIG_EXCEPTIONS="0b 42 47 61a 61c"
27     echo -n "Several ost services on one ost node are used with FAILURE_MODE=$FAILURE_MODE. "
28     echo "Except the tests: $CONFIG_EXCEPTIONS"
29     ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
30 fi
31
32 #                                                  63 min  7 min  AT AT AT AT"
33 [ "$SLOW" = "no" ] && EXCEPT_SLOW="1 2 3 4 6 12 16 44a     44b    65 66 67 68"
34
35 build_test_filter
36
37 check_and_setup_lustre
38
39 mkdir -p $DIR
40
41 assert_DIR
42 rm -rf $DIR/[df][0-9]*
43
44 test_0a() {     # was test_0
45     replay_barrier mds
46     fail mds
47 }
48 run_test 0a "empty replay"
49
50 test_0b() {
51     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
52
53     # this test attempts to trigger a race in the precreation code,
54     # and must run before any other objects are created on the filesystem
55     fail ost1
56     createmany -o $DIR/$tfile 20 || return 1
57     unlinkmany $DIR/$tfile 20 || return 2
58 }
59 run_test 0b "ensure object created after recover exists. (3284)"
60
61 test_0c() {
62     replay_barrier mds
63     umount $DIR
64     facet_failover mds
65     zconf_mount `hostname` $DIR || error "mount fails"
66     clients_up || error "post-failover df failed"
67 }
68 run_test 0c "expired recovery with no clients"
69
70 test_1() {
71     replay_barrier mds
72     mcreate $DIR/$tfile
73     fail mds
74     $CHECKSTAT -t file $DIR/$tfile || return 1
75     rm $DIR/$tfile
76 }
77 run_test 1 "simple create"
78
79 test_2a() {
80     replay_barrier mds
81     touch $DIR/$tfile
82     fail mds
83     $CHECKSTAT -t file $DIR/$tfile || return 1
84     rm $DIR/$tfile
85 }
86 run_test 2a "touch"
87
88 test_2b() {
89     mcreate $DIR/$tfile
90     replay_barrier mds
91     touch $DIR/$tfile
92     fail mds
93     $CHECKSTAT -t file $DIR/$tfile || return 1
94     rm $DIR/$tfile
95 }
96 run_test 2b "touch"
97
98 test_3a() {
99     local file=$DIR/$tfile
100     replay_barrier mds
101     mcreate $file
102     openfile -f O_DIRECTORY $file
103     fail mds
104     $CHECKSTAT -t file $file || return 2
105     rm $file
106 }
107 run_test 3a "replay failed open(O_DIRECTORY)"
108
109 test_3b() {
110     replay_barrier mds
111 #define OBD_FAIL_MDS_OPEN_PACK | OBD_FAIL_ONCE
112     do_facet mds "lctl set_param fail_loc=0x80000114"
113     touch $DIR/$tfile
114     do_facet mds "lctl set_param fail_loc=0"
115     fail mds
116     $CHECKSTAT -t file $DIR/$tfile && return 2
117     return 0
118 }
119 run_test 3b "replay failed open -ENOMEM"
120
121 test_3c() {
122     replay_barrier mds
123 #define OBD_FAIL_MDS_ALLOC_OBDO | OBD_FAIL_ONCE
124     do_facet mds "lctl set_param fail_loc=0x80000128"
125     touch $DIR/$tfile
126     do_facet mds "lctl set_param fail_loc=0"
127     fail mds
128
129     $CHECKSTAT -t file $DIR/$tfile && return 2
130     return 0
131 }
132 run_test 3c "replay failed open -ENOMEM"
133
134 test_4a() {     # was test_4
135     replay_barrier mds
136     for i in `seq 10`; do
137         echo "tag-$i" > $DIR/$tfile-$i
138     done
139     fail mds
140     for i in `seq 10`; do
141       grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
142     done
143 }
144 run_test 4a "|x| 10 open(O_CREAT)s"
145
146 test_4b() {
147     replay_barrier mds
148     rm -rf $DIR/$tfile-*
149     fail mds
150     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
151 }
152 run_test 4b "|x| rm 10 files"
153
154 # The idea is to get past the first block of precreated files on both
155 # osts, and then replay.
156 test_5() {
157     replay_barrier mds
158     for i in `seq 220`; do
159         echo "tag-$i" > $DIR/$tfile-$i
160     done
161     fail mds
162     for i in `seq 220`; do
163       grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
164     done
165     rm -rf $DIR/$tfile-*
166     sleep 3
167     # waiting for commitment of removal
168 }
169 run_test 5 "|x| 220 open(O_CREAT)"
170
171
172 test_6a() {     # was test_6
173     mkdir -p $DIR/$tdir
174     replay_barrier mds
175     mcreate $DIR/$tdir/$tfile
176     fail mds
177     $CHECKSTAT -t dir $DIR/$tdir || return 1
178     $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
179     sleep 2
180     # waiting for log process thread
181 }
182 run_test 6a "mkdir + contained create"
183
184 test_6b() {
185     mkdir -p $DIR/$tdir
186     replay_barrier mds
187     rm -rf $DIR/$tdir
188     fail mds
189     $CHECKSTAT -t dir $DIR/$tdir && return 1 || true
190 }
191 run_test 6b "|X| rmdir"
192
193 test_7() {
194     mkdir -p $DIR/$tdir
195     replay_barrier mds
196     mcreate $DIR/$tdir/$tfile
197     fail mds
198     $CHECKSTAT -t dir $DIR/$tdir || return 1
199     $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
200     rm -fr $DIR/$tdir
201 }
202 run_test 7 "mkdir |X| contained create"
203
204 test_8() {
205     replay_barrier mds
206     multiop_bg_pause $DIR/$tfile mo_c || return 4
207     MULTIPID=$!
208     fail mds
209     ls $DIR/$tfile
210     $CHECKSTAT -t file $DIR/$tfile || return 1
211     kill -USR1 $MULTIPID || return 2
212     wait $MULTIPID || return 3
213     rm $DIR/$tfile
214 }
215 run_test 8 "creat open |X| close"
216
217 test_9() {
218     replay_barrier mds
219     mcreate $DIR/$tfile
220     local old_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
221     fail mds
222     local new_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
223
224     echo " old_inum == $old_inum, new_inum == $new_inum"
225     if [ $old_inum -eq $new_inum  ] ;
226     then
227         echo " old_inum and new_inum match"
228     else
229         echo "!!!! old_inum and new_inum NOT match"
230         return 1
231     fi
232     rm $DIR/$tfile
233 }
234 run_test 9  "|X| create (same inum/gen)"
235
236 test_10() {
237     mcreate $DIR/$tfile
238     replay_barrier mds
239     mv $DIR/$tfile $DIR/$tfile-2
240     rm -f $DIR/$tfile
241     fail mds
242     $CHECKSTAT $DIR/$tfile && return 1
243     $CHECKSTAT $DIR/$tfile-2 ||return 2
244     rm $DIR/$tfile-2
245     return 0
246 }
247 run_test 10 "create |X| rename unlink"
248
249 test_11() {
250     mcreate $DIR/$tfile
251     echo "old" > $DIR/$tfile
252     mv $DIR/$tfile $DIR/$tfile-2
253     replay_barrier mds
254     echo "new" > $DIR/$tfile
255     grep new $DIR/$tfile
256     grep old $DIR/$tfile-2
257     fail mds
258     grep new $DIR/$tfile || return 1
259     grep old $DIR/$tfile-2 || return 2
260 }
261 run_test 11 "create open write rename |X| create-old-name read"
262
263 test_12() {
264     mcreate $DIR/$tfile
265     multiop_bg_pause $DIR/$tfile o_tSc || return 3
266     pid=$!
267     rm -f $DIR/$tfile
268     replay_barrier mds
269     kill -USR1 $pid
270     wait $pid || return 1
271
272     fail mds
273     [ -e $DIR/$tfile ] && return 2
274     return 0
275 }
276 run_test 12 "open, unlink |X| close"
277
278
279 # 1777 - replay open after committed chmod that would make
280 #        a regular open a failure
281 test_13() {
282     mcreate $DIR/$tfile
283     multiop_bg_pause $DIR/$tfile O_wc || return 3
284     pid=$!
285     chmod 0 $DIR/$tfile
286     $CHECKSTAT -p 0 $DIR/$tfile
287     replay_barrier mds
288     fail mds
289     kill -USR1 $pid
290     wait $pid || return 1
291
292     $CHECKSTAT -s 1 -p 0 $DIR/$tfile || return 2
293     rm $DIR/$tfile || return 4
294     return 0
295 }
296 run_test 13 "open chmod 0 |x| write close"
297
298 test_14() {
299     multiop_bg_pause $DIR/$tfile O_tSc || return 4
300     pid=$!
301     rm -f $DIR/$tfile
302     replay_barrier mds
303     kill -USR1 $pid || return 1
304     wait $pid || return 2
305
306     fail mds
307     [ -e $DIR/$tfile ] && return 3
308     return 0
309 }
310 run_test 14 "open(O_CREAT), unlink |X| close"
311
312 test_15() {
313     multiop_bg_pause $DIR/$tfile O_tSc || return 5
314     pid=$!
315     rm -f $DIR/$tfile
316     replay_barrier mds
317     touch $DIR/g11 || return 1
318     kill -USR1 $pid
319     wait $pid || return 2
320
321     fail mds
322     [ -e $DIR/$tfile ] && return 3
323     touch $DIR/h11 || return 4
324     return 0
325 }
326 run_test 15 "open(O_CREAT), unlink |X|  touch new, close"
327
328 test_16() {
329     replay_barrier mds
330     mcreate $DIR/$tfile
331     munlink $DIR/$tfile
332     mcreate $DIR/$tfile-2
333     fail mds
334     [ -e $DIR/$tfile ] && return 1
335     [ -e $DIR/$tfile-2 ] || return 2
336     munlink $DIR/$tfile-2 || return 3
337 }
338 run_test 16 "|X| open(O_CREAT), unlink, touch new,  unlink new"
339
340 test_17() {
341     replay_barrier mds
342     multiop_bg_pause $DIR/$tfile O_c || return 4
343     pid=$!
344     fail mds
345     kill -USR1 $pid || return 1
346     wait $pid || return 2
347     $CHECKSTAT -t file $DIR/$tfile || return 3
348     rm $DIR/$tfile
349 }
350 run_test 17 "|X| open(O_CREAT), |replay| close"
351
352 test_18() {
353     replay_barrier mds
354     multiop_bg_pause $DIR/$tfile O_tSc || return 8
355     pid=$!
356     rm -f $DIR/$tfile
357     touch $DIR/$tfile-2 || return 1
358     echo "pid: $pid will close"
359     kill -USR1 $pid
360     wait $pid || return 2
361
362     fail mds
363     [ -e $DIR/$tfile ] && return 3
364     [ -e $DIR/$tfile-2 ] || return 4
365     # this touch frequently fails
366     touch $DIR/$tfile-3 || return 5
367     munlink $DIR/$tfile-2 || return 6
368     munlink $DIR/$tfile-3 || return 7
369     return 0
370 }
371 run_test 18 "|X| open(O_CREAT), unlink, touch new, close, touch, unlink"
372
373 # bug 1855 (a simpler form of test_11 above)
374 test_19() {
375     replay_barrier mds
376     mcreate $DIR/$tfile
377     echo "old" > $DIR/$tfile
378     mv $DIR/$tfile $DIR/$tfile-2
379     grep old $DIR/$tfile-2
380     fail mds
381     grep old $DIR/$tfile-2 || return 2
382 }
383 run_test 19 "|X| mcreate, open, write, rename "
384
385 test_20a() {    # was test_20
386     replay_barrier mds
387     multiop_bg_pause $DIR/$tfile O_tSc || return 3
388     pid=$!
389     rm -f $DIR/$tfile
390
391     fail mds
392     kill -USR1 $pid
393     wait $pid || return 1
394     [ -e $DIR/$tfile ] && return 2
395     return 0
396 }
397 run_test 20a "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
398
399 test_20b() { # bug 10480
400     BEFOREUSED=`df -P $DIR | tail -1 | awk '{ print $3 }'`
401
402     dd if=/dev/zero of=$DIR/$tfile bs=4k count=10000 &
403     pid=$!
404     while [ ! -e $DIR/$tfile ] ; do
405         sleep 0.060s                           # give dd a chance to start
406     done
407
408     lfs getstripe $DIR/$tfile || return 1
409     rm -f $DIR/$tfile || return 2       # make it an orphan
410     mds_evict_client
411     client_up || client_up || true    # reconnect
412
413     fail mds                            # start orphan recovery
414     wait_recovery_complete mds || error "MDS recovery not done"
415
416     # For interop with 2.0 only:
417     # FIXME just because recovery is done doesn't mean we've finished
418     # orphan cleanup.  Fake it with a sleep for now...
419     sleep 10
420
421     AFTERUSED=`df -P $DIR | tail -1 | awk '{ print $3 }'`
422     log "before $BEFOREUSED, after $AFTERUSED"
423     [ $AFTERUSED -gt $((BEFOREUSED + 20)) ] && \
424         error "after $AFTERUSED > before $BEFOREUSED" && return 5
425     return 0
426 }
427 run_test 20b "write, unlink, eviction, replay, (test mds_cleanup_orphans)"
428
429 test_20c() { # bug 10480
430     multiop $DIR/$tfile Ow_c &
431     pid=$!
432     # give multiop a chance to open
433     sleep 1
434
435     ls -la $DIR/$tfile
436
437     mds_evict_client
438     client_up || client_up || true    # reconnect
439
440     kill -USR1 $pid
441     wait $pid || return 1
442     [ -s $DIR/$tfile ] || error "File was truncated"
443
444     return 0
445 }
446 run_test 20c "check that client eviction does not affect file content"
447
448 test_21() {
449     replay_barrier mds
450     multiop_bg_pause $DIR/$tfile O_tSc || return 5
451     pid=$!
452     rm -f $DIR/$tfile
453     touch $DIR/g11 || return 1
454
455     fail mds
456     kill -USR1 $pid
457     wait $pid || return 2
458     [ -e $DIR/$tfile ] && return 3
459     touch $DIR/h11 || return 4
460     return 0
461 }
462 run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"
463
464 test_22() {
465     multiop_bg_pause $DIR/$tfile O_tSc || return 3
466     pid=$!
467
468     replay_barrier mds
469     rm -f $DIR/$tfile
470
471     fail mds
472     kill -USR1 $pid
473     wait $pid || return 1
474     [ -e $DIR/$tfile ] && return 2
475     return 0
476 }
477 run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"
478
479 test_23() {
480     multiop_bg_pause $DIR/$tfile O_tSc || return 5
481     pid=$!
482
483     replay_barrier mds
484     rm -f $DIR/$tfile
485     touch $DIR/g11 || return 1
486
487     fail mds
488     kill -USR1 $pid
489     wait $pid || return 2
490     [ -e $DIR/$tfile ] && return 3
491     touch $DIR/h11 || return 4
492     return 0
493 }
494 run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"
495
496 test_24() {
497     multiop_bg_pause $DIR/$tfile O_tSc || return 3
498     pid=$!
499
500     replay_barrier mds
501     fail mds
502     rm -f $DIR/$tfile
503     kill -USR1 $pid
504     wait $pid || return 1
505     [ -e $DIR/$tfile ] && return 2
506     return 0
507 }
508 run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"
509
510 test_25() {
511     multiop_bg_pause $DIR/$tfile O_tSc || return 3
512     pid=$!
513     rm -f $DIR/$tfile
514
515     replay_barrier mds
516     fail mds
517     kill -USR1 $pid
518     wait $pid || return 1
519     [ -e $DIR/$tfile ] && return 2
520     return 0
521 }
522 run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
523
524 test_26() {
525     replay_barrier mds
526     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
527     pid1=$!
528     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
529     pid2=$!
530     rm -f $DIR/$tfile-1
531     rm -f $DIR/$tfile-2
532     kill -USR1 $pid2
533     wait $pid2 || return 1
534
535     fail mds
536     kill -USR1 $pid1
537     wait $pid1 || return 2
538     [ -e $DIR/$tfile-1 ] && return 3
539     [ -e $DIR/$tfile-2 ] && return 4
540     return 0
541 }
542 run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"
543
544 test_27() {
545     replay_barrier mds
546     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
547     pid1=$!
548     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
549     pid2=$!
550     rm -f $DIR/$tfile-1
551     rm -f $DIR/$tfile-2
552
553     fail mds
554     kill -USR1 $pid1
555     wait $pid1 || return 1
556     kill -USR1 $pid2
557     wait $pid2 || return 2
558     [ -e $DIR/$tfile-1 ] && return 3
559     [ -e $DIR/$tfile-2 ] && return 4
560     return 0
561 }
562 run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"
563
564 test_28() {
565     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
566     pid1=$!
567     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
568     pid2=$!
569     replay_barrier mds
570     rm -f $DIR/$tfile-1
571     rm -f $DIR/$tfile-2
572     kill -USR1 $pid2
573     wait $pid2 || return 1
574
575     fail mds
576     kill -USR1 $pid1
577     wait $pid1 || return 2
578     [ -e $DIR/$tfile-1 ] && return 3
579     [ -e $DIR/$tfile-2 ] && return 4
580     return 0
581 }
582 run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"
583
584 test_29() {
585     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
586     pid1=$!
587     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
588     pid2=$!
589     replay_barrier mds
590     rm -f $DIR/$tfile-1
591     rm -f $DIR/$tfile-2
592
593     fail mds
594     kill -USR1 $pid1
595     wait $pid1 || return 1
596     kill -USR1 $pid2
597     wait $pid2 || return 2
598     [ -e $DIR/$tfile-1 ] && return 3
599     [ -e $DIR/$tfile-2 ] && return 4
600     return 0
601 }
602 run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"
603
604 test_30() {
605     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
606     pid1=$!
607     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
608     pid2=$!
609     rm -f $DIR/$tfile-1
610     rm -f $DIR/$tfile-2
611
612     replay_barrier mds
613     fail mds
614     kill -USR1 $pid1
615     wait $pid1 || return 1
616     kill -USR1 $pid2
617     wait $pid2 || return 2
618     [ -e $DIR/$tfile-1 ] && return 3
619     [ -e $DIR/$tfile-2 ] && return 4
620     return 0
621 }
622 run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"
623
624 test_31() {
625     multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
626     pid1=$!
627     multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
628     pid2=$!
629     rm -f $DIR/$tfile-1
630
631     replay_barrier mds
632     rm -f $DIR/$tfile-2
633     fail mds
634     kill -USR1 $pid1
635     wait $pid1 || return 1
636     kill -USR1 $pid2
637     wait $pid2 || return 2
638     [ -e $DIR/$tfile-1 ] && return 3
639     [ -e $DIR/$tfile-2 ] && return 4
640     return 0
641 }
642 run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"
643
644 # tests for bug 2104; completion without crashing is success.  The close is
645 # stale, but we always return 0 for close, so the app never sees it.
646 test_32() {
647     multiop_bg_pause $DIR/$tfile O_c || return 2
648     pid1=$!
649     multiop_bg_pause $DIR/$tfile O_c || return 3
650     pid2=$!
651     mds_evict_client
652     client_up || client_up || return 1
653     kill -USR1 $pid1
654     kill -USR1 $pid2
655     wait $pid1 || return 4
656     wait $pid2 || return 5
657     return 0
658 }
659 run_test 32 "close() notices client eviction; close() after client eviction"
660
661 # Abort recovery before client complete
662 test_33a() {    # was test_33
663     replay_barrier mds
664     createmany -o $DIR/$tfile-%d 100
665     fail_abort mds
666     # this file should be gone, because the replay was aborted
667     $CHECKSTAT -t file $DIR/$tfile-* && return 3
668     unlinkmany $DIR/$tfile-%d 0 100
669     return 0
670 }
671 run_test 33a "abort recovery before client does replay"
672
673 test_34() {
674     multiop_bg_pause $DIR/$tfile O_c || return 2
675     pid=$!
676     rm -f $DIR/$tfile
677
678     replay_barrier mds
679     fail_abort mds
680     kill -USR1 $pid
681     wait $pid || return 3
682     [ -e $DIR/$tfile ] && return 1
683     sync
684     return 0
685 }
686 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
687
688 # bug 2278 - generate one orphan on OST, then destroy it during llog recovery
689 test_35() {
690     touch $DIR/$tfile
691
692 #define OBD_FAIL_MDS_REINT_NET_REP       0x119
693     do_facet mds "lctl set_param fail_loc=0x80000119"
694     rm -f $DIR/$tfile &
695     sleep 1
696     sync
697     sleep 1
698     # give a chance to remove from MDS
699     fail_abort mds
700     $CHECKSTAT -t file $DIR/$tfile && return 1 || true
701 }
702 run_test 35 "test recovery from llog for unlink op"
703
704 # b=2432 resent cancel after replay uses wrong cookie,
705 # so don't resend cancels
706 test_36() {
707     replay_barrier mds
708     touch $DIR/$tfile
709     checkstat $DIR/$tfile
710     facet_failover mds
711     cancel_lru_locks mdc
712     if dmesg | grep "unknown lock cookie"; then
713         echo "cancel after replay failed"
714         return 1
715     fi
716 }
717 run_test 36 "don't resend cancel"
718
719 # b=2368
720 # directory orphans can't be unlinked from PENDING directory
721 test_37() {
722     rmdir $DIR/$tfile 2>/dev/null
723     multiop_bg_pause $DIR/$tfile dD_c || return 2
724     pid=$!
725     rmdir $DIR/$tfile
726
727     replay_barrier mds
728     # clear the dmesg buffer so we only see errors from this recovery
729     dmesg -c >/dev/null
730     fail_abort mds
731     kill -USR1 $pid
732     dmesg | grep  "mds_unlink_orphan.*error .* unlinking orphan" && return 1
733     wait $pid || return 3
734     sync
735     return 0
736 }
737 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
738
739 test_38() {
740     createmany -o $DIR/$tfile-%d 800
741     unlinkmany $DIR/$tfile-%d 0 400
742     replay_barrier mds
743     fail mds
744     unlinkmany $DIR/$tfile-%d 400 400
745     sleep 2
746     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
747 }
748 run_test 38 "test recovery from unlink llog (test llog_gen_rec) "
749
750 test_39() { # bug 4176
751     createmany -o $DIR/$tfile-%d 800
752     replay_barrier mds
753     unlinkmany $DIR/$tfile-%d 0 400
754     fail mds
755     unlinkmany $DIR/$tfile-%d 400 400
756     sleep 2
757     ls -1f $DIR/$tfile-*
758     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
759 }
760 run_test 39 "test recovery from unlink llog (test llog_gen_rec) "
761
762 count_ost_writes() {
763     lctl get_param -n osc.*.stats | awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
764 }
765
766 #b=2477,2532
767 test_40(){
768     $LCTL mark multiop $MOUNT/$tfile OS_c
769     multiop $MOUNT/$tfile OS_c  &
770     PID=$!
771     writeme -s $MOUNT/${tfile}-2 &
772     WRITE_PID=$!
773     sleep 1
774     facet_failover mds
775 #define OBD_FAIL_MDS_CONNECT_NET         0x117
776     do_facet mds "lctl set_param fail_loc=0x80000117"
777     kill -USR1 $PID
778     stat1=`count_ost_writes`
779     sleep $TIMEOUT
780     stat2=`count_ost_writes`
781     echo "$stat1, $stat2"
782     if [ $stat1 -lt $stat2 ]; then
783        echo "writes continuing during recovery"
784        RC=0
785     else
786        echo "writes not continuing during recovery, bug 2477"
787        RC=4
788     fi
789     echo "waiting for writeme $WRITE_PID"
790     kill $WRITE_PID
791     wait $WRITE_PID
792
793     echo "waiting for multiop $PID"
794     wait $PID || return 2
795     do_facet client munlink $MOUNT/$tfile  || return 3
796     do_facet client munlink $MOUNT/${tfile}-2  || return 3
797     return $RC
798 }
799 run_test 40 "cause recovery in ptlrpc, ensure IO continues"
800
801 #b=2814
802 # make sure that a read to one osc doesn't try to double-unlock its page just
803 # because another osc is invalid.  trigger_group_io used to mistakenly return
804 # an error if any oscs were invalid even after having successfully put rpcs
805 # on valid oscs.  This was fatal if the caller was ll_readpage who unlocked
806 # the page, guarnateeing that the unlock from the RPC completion would
807 # assert on trying to unlock the unlocked page.
808 test_41() {
809     [ $OSTCOUNT -lt 2 ] && \
810         skip_env "skipping test 41: we don't have a second OST to test with" && \
811         return
812
813     local f=$MOUNT/$tfile
814     # make sure the start of the file is ost1
815     lfs setstripe $f -s $((128 * 1024)) -i 0
816     do_facet client dd if=/dev/zero of=$f bs=4k count=1 || return 3
817     cancel_lru_locks osc
818     # fail ost2 and read from ost1
819     local osc2dev=`lctl get_param -n devices | grep ${ost2_svc}-osc- | awk '{print $1}'`
820     [ "$osc2dev" ] || return 4
821     $LCTL --device $osc2dev deactivate || return 1
822     do_facet client dd if=$f of=/dev/null bs=4k count=1 || return 3
823     $LCTL --device $osc2dev activate || return 2
824     return 0
825 }
826 run_test 41 "read from a valid osc while other oscs are invalid"
827
828 # test MDS recovery after ost failure
829 test_42() {
830     blocks=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
831     createmany -o $DIR/$tfile-%d 800
832     replay_barrier ost1
833     unlinkmany $DIR/$tfile-%d 0 400
834     debugsave
835     lctl set_param debug=-1
836     facet_failover ost1
837
838     # osc is evicted, fs is smaller (but only with failout OSTs (bug 7287)
839     #blocks_after=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
840     #[ $blocks_after -lt $blocks ] || return 1
841     echo wait for MDS to timeout and recover
842     sleep $((TIMEOUT * 2))
843     debugrestore
844     unlinkmany $DIR/$tfile-%d 400 400
845     $CHECKSTAT -t file $DIR/$tfile-* && return 2 || true
846 }
847 run_test 42 "recovery after ost failure"
848
849 # timeout in MDS/OST recovery RPC will LBUG MDS
850 test_43() { # bug 2530
851     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
852
853     replay_barrier mds
854
855     # OBD_FAIL_OST_CREATE_NET 0x204
856     do_facet ost1 "lctl set_param fail_loc=0x80000204"
857     fail mds
858     sleep 10
859     do_facet ost1 "lctl set_param fail_loc=0"
860
861     return 0
862 }
863 run_test 43 "mds osc import failure during recovery; don't LBUG"
864
865 test_44a() { # was test_44
866     local at_max_saved=0
867
868     mdcdev=`lctl get_param -n devices | awk '/-mdc-/ {print $1}'`
869     [ "$mdcdev" ] || return 2
870     [ $(echo $mdcdev | wc -w) -eq 1 ] || { echo $mdcdev=$mdcdev && return 3; }
871
872     # adaptive timeouts slow this way down
873     if at_is_enabled; then
874         at_max_saved=$(at_max_get mds)
875         at_max_set 40 mds
876     fi
877
878     local dev=$(get_mds_mdt_device_proc_path)
879     for i in `seq 1 10`; do
880         echo "$i of 10 ($(date +%s))"
881         do_facet mds "lctl get_param -n mdt.*.$dev.timeouts | grep service"
882         #define OBD_FAIL_TGT_CONN_RACE     0x701
883         do_facet mds "lctl set_param fail_loc=0x80000701"
884         # lctl below may fail, it is valid case
885         $LCTL --device $mdcdev recover
886         df $MOUNT
887     done
888
889     do_facet mds "lctl set_param fail_loc=0"
890     [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds
891     return 0
892 }
893 run_test 44a "race in target handle connect"
894
895 test_44b() {
896     local mdcdev=`lctl get_param -n devices | awk '/-mdc-/ {print $1}'`
897     [ "$mdcdev" ] || return 2
898     [ $(echo $mdcdev | wc -w) -eq 1 ] || { echo $mdcdev=$mdcdev && return 3; }
899
900     local dev=$(get_mds_mdt_device_proc_path)
901     for i in `seq 1 10`; do
902         echo "$i of 10 ($(date +%s))"
903         do_facet mds "lctl get_param -n mdt.*.$dev.timeouts | grep service"
904         #define OBD_FAIL_TGT_DELAY_RECONNECT 0x704
905         do_facet mds "lctl set_param fail_loc=0x80000704"
906         # lctl below may fail, it is valid case
907         $LCTL --device $mdcdev recover
908         df $MOUNT
909     done
910     do_facet mds "lctl set_param fail_loc=0"
911     return 0
912 }
913 run_test 44b "race in target handle connect"
914
915 # Handle failed close
916 test_45() {
917     local mdcdev=`lctl get_param -n devices | awk '/-mdc-/ {print $1}'`
918     [ "$mdcdev" ] || return 2
919     [ $(echo $mdcdev | wc -w) -eq 1 ] || { echo $mdcdev=$mdcdev && return 3; }
920
921     $LCTL --device $mdcdev recover || return 6 
922
923     multiop_bg_pause $DIR/$tfile O_c || return 1
924     pid=$!
925
926     # This will cause the CLOSE to fail before even
927     # allocating a reply buffer
928     $LCTL --device $mdcdev deactivate || return 4
929
930     # try the close
931     kill -USR1 $pid
932     wait $pid || return 1
933
934     $LCTL --device $mdcdev activate || return 5
935     sleep 1
936
937     $CHECKSTAT -t file $DIR/$tfile || return 2
938     return 0
939 }
940 run_test 45 "Handle failed close"
941
942 test_46() {
943     dmesg -c >/dev/null
944     drop_reply "touch $DIR/$tfile"
945     fail mds
946     # ironically, the previous test, 45, will cause a real forced close,
947     # so just look for one for this test
948     dmesg | grep -i "force closing client file handle for $tfile" && return 1
949     return 0
950 }
951 run_test 46 "Don't leak file handle after open resend (3325)"
952
953 test_47() { # bug 2824
954     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
955
956     # create some files to make sure precreate has been done on all
957     # OSTs. (just in case this test is run independently)
958     createmany -o $DIR/$tfile 20  || return 1
959
960     # OBD_FAIL_OST_CREATE_NET 0x204
961     fail ost1
962     do_facet ost1 "lctl set_param fail_loc=0x80000204"
963     client_up || return 2
964
965     # let the MDS discover the OST failure, attempt to recover, fail
966     # and recover again.
967     sleep $((3 * TIMEOUT))
968
969     # Without 2824, this createmany would hang
970     createmany -o $DIR/$tfile 20 || return 3
971     unlinkmany $DIR/$tfile 20 || return 4
972
973     do_facet ost1 "lctl set_param fail_loc=0"
974     return 0
975 }
976 run_test 47 "MDS->OSC failure during precreate cleanup (2824)"
977
978 test_48() {
979     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
980     [ "$OSTCOUNT" -lt "2" ] && skip_env "$OSTCOUNT < 2 OSTs -- skipping" && return
981
982     replay_barrier mds
983     createmany -o $DIR/$tfile 20  || return 1
984     facet_failover mds
985     #define OBD_FAIL_OST_EROFS 0x216
986     do_facet ost1 "lctl set_param fail_loc=0x80000216"
987     client_up || return 2
988
989     createmany -o $DIR/$tfile 20 20 || return 2
990     unlinkmany $DIR/$tfile 40 || return 3
991     return 0
992 }
993 run_test 48 "MDS->OSC failure during precreate cleanup (2824)"
994
995 test_49a() {
996     multiop $DIR/$tfile O_c &
997     pid=$!
998     sleep 1
999     rm -rf $DIR/$tfile
1000
1001 #define OBD_FAIL_MDS_ALL_REPLY_NET       0x122
1002     do_facet mds "lctl set_param fail_loc=0x80000122"
1003     kill -USR1 $pid
1004     do_facet mds "lctl set_param fail_loc=0"
1005
1006     replay_barrier_nodf mds
1007     fail mds
1008
1009     wait $pid || return 1
1010     $CHECKSTAT -t file $DIR/$tfile && return 2
1011     return 0
1012 }
1013 run_test 49a "mds fail after close reply is dropped: open|create "
1014
1015 test_49c() {
1016     touch $DIR/$tfile
1017     multiop $DIR/$tfile o_c &
1018     pid=$!
1019     sleep 1
1020     rm -rf $DIR/$tfile
1021
1022 #define OBD_FAIL_MDS_ALL_REPLY_NET       0x122
1023     do_facet mds "lctl set_param fail_loc=0x80000122"
1024     kill -USR1 $pid
1025     do_facet mds "lctl set_param fail_loc=0"
1026
1027     replay_barrier_nodf mds
1028     fail mds
1029
1030     wait $pid || return 1
1031     $CHECKSTAT -t file $DIR/$tfile && return 2
1032     return 0
1033 }
1034 run_test 49c "mds fail after close reply is dropped: open"
1035
1036 test_50() {
1037     local oscdev=`do_facet mds lctl get_param -n devices | grep ${ost1_svc}-osc | awk '{print $1}' | head -1`
1038     [ "$oscdev" ] || return 1
1039     do_facet mds $LCTL --device $oscdev recover || return 2
1040     do_facet mds $LCTL --device $oscdev recover || return 3
1041     # give the mds_lov_sync threads a chance to run
1042     sleep 5
1043 }
1044 run_test 50 "Double OSC recovery, don't LASSERT (3812)"
1045
1046 # b3764 timed out lock replay
1047 test_52() {
1048     touch $DIR/$tfile
1049     cancel_lru_locks mdc
1050
1051     multiop $DIR/$tfile s || return 1
1052     replay_barrier mds
1053 #define OBD_FAIL_LDLM_REPLY              0x30c
1054     do_facet mds "lctl set_param fail_loc=0x8000030c"
1055     fail mds || return 2
1056     do_facet mds "lctl set_param fail_loc=0x0"
1057
1058     $CHECKSTAT -t file $DIR/$tfile-* && return 3 || true
1059 }
1060 run_test 52 "time out lock replay (3764)"
1061
1062 # bug 3462 - simultaneous MDC requests
1063 test_53a() {
1064     mkdir -p $DIR/${tdir}-1
1065     mkdir -p $DIR/${tdir}-2
1066     multiop $DIR/${tdir}-1/f O_c &
1067     close_pid=$!
1068     # give multiop a chance to open
1069     sleep 1
1070
1071     #define OBD_FAIL_MDS_CLOSE_NET 0x115
1072     do_facet mds "lctl set_param fail_loc=0x80000115"
1073     kill -USR1 $close_pid
1074     cancel_lru_locks mdc # force the close
1075     do_facet mds "lctl set_param fail_loc=0"
1076     mcreate $DIR/${tdir}-2/f || return 1
1077
1078     # close should still be here
1079     [ -d /proc/$close_pid ] || return 2
1080     replay_barrier_nodf mds
1081     fail mds
1082     wait $close_pid || return 3
1083
1084     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1085     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1086     rm -rf $DIR/${tdir}-*
1087 }
1088 run_test 53a "|X| close request while two MDC requests in flight"
1089
1090 test_53b() {
1091     rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1092
1093     mkdir -p $DIR/$tdir-1
1094     mkdir -p $DIR/$tdir-2
1095
1096     multiop_bg_pause $DIR/$tdir-1/f O_c || return 6
1097     close_pid=$!
1098
1099     #define OBD_FAIL_MDS_REINT_NET 0x107
1100     do_facet mds "lctl set_param fail_loc=0x80000107"
1101     mcreate $DIR/${tdir}-2/f &
1102     open_pid=$!
1103     sleep 1
1104
1105     do_facet mds "lctl set_param fail_loc=0"
1106     kill -USR1 $close_pid
1107     cancel_lru_locks mdc # force the close
1108     wait $close_pid || return 1
1109     # open should still be here
1110     [ -d /proc/$open_pid ] || return 2
1111
1112     replay_barrier_nodf mds
1113     fail mds
1114     wait $open_pid || return 3
1115
1116     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1117     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1118     rm -rf $DIR/${tdir}-*
1119 }
1120 run_test 53b "|X| open request while two MDC requests in flight"
1121
1122 test_53c() {
1123     rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1124
1125     mkdir -p $DIR/${tdir}-1
1126     mkdir -p $DIR/${tdir}-2
1127     multiop $DIR/${tdir}-1/f O_c &
1128     close_pid=$!
1129
1130 #define OBD_FAIL_MDS_REINT_NET           0x107
1131     do_facet mds "lctl set_param fail_loc=0x80000107"
1132     mcreate $DIR/${tdir}-2/f &
1133     open_pid=$!
1134     sleep 1
1135
1136 #define OBD_FAIL_MDS_CLOSE_NET           0x115
1137     do_facet mds "lctl set_param fail_loc=0x80000115"
1138     kill -USR1 $close_pid
1139     cancel_lru_locks mdc  # force the close
1140
1141     replay_barrier_nodf mds
1142     fail_nodf mds
1143     wait $open_pid || return 1
1144     sleep 2
1145     # close should be gone
1146     [ -d /proc/$close_pid ] && return 2
1147     do_facet mds "lctl set_param fail_loc=0"
1148
1149     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1150     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1151     rm -rf $DIR/${tdir}-*
1152 }
1153 run_test 53c "|X| open request and close request while two MDC requests in flight"
1154
1155 test_53d() {
1156     rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1157
1158     mkdir -p $DIR/${tdir}-1
1159     mkdir -p $DIR/${tdir}-2
1160     multiop $DIR/${tdir}-1/f O_c &
1161     close_pid=$!
1162     # give multiop a chance to open
1163     sleep 1
1164
1165 #define OBD_FAIL_MDS_CLOSE_NET_REP       0x13b
1166     do_facet mds "lctl set_param fail_loc=0x8000013b"
1167     kill -USR1 $close_pid
1168     cancel_lru_locks mdc  # force the close
1169     do_facet mds "lctl set_param fail_loc=0"
1170     mcreate $DIR/${tdir}-2/f || return 1
1171
1172     # close should still be here
1173     [ -d /proc/$close_pid ] || return 2
1174     replay_barrier_nodf mds
1175     fail mds
1176     wait $close_pid || return 3
1177
1178     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1179     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1180     rm -rf $DIR/${tdir}-*
1181 }
1182 run_test 53d "|X| close reply while two MDC requests in flight"
1183
1184 test_53e() {
1185     rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1186
1187     mkdir -p $DIR/$tdir-1
1188     mkdir -p $DIR/$tdir-2
1189     multiop $DIR/$tdir-1/f O_c &
1190     close_pid=$!
1191
1192     #define OBD_FAIL_MDS_REINT_NET_REP       0x119
1193     do_facet mds "lctl set_param fail_loc=0x80000119"
1194     mcreate $DIR/${tdir}-2/f &
1195     open_pid=$!
1196     sleep 1
1197
1198     do_facet mds "lctl set_param fail_loc=0"
1199     kill -USR1 $close_pid
1200     cancel_lru_locks mdc  # force the close
1201     wait $close_pid || return 1
1202     # open should still be here
1203     [ -d /proc/$open_pid ] || return 2
1204
1205     replay_barrier_nodf mds
1206     fail mds
1207     wait $open_pid || return 3
1208
1209     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1210     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1211     rm -rf $DIR/${tdir}-*
1212 }
1213 run_test 53e "|X| open reply while two MDC requests in flight"
1214
1215 test_53f() {
1216         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1217
1218         mkdir -p $DIR/${tdir}-1
1219         mkdir -p $DIR/${tdir}-2
1220         multiop $DIR/${tdir}-1/f O_c &
1221         close_pid=$!
1222
1223 #define OBD_FAIL_MDS_REINT_NET_REP       0x119
1224         do_facet mds "lctl set_param fail_loc=0x80000119"
1225         mcreate $DIR/${tdir}-2/f &
1226         open_pid=$!
1227         sleep 1
1228
1229 #define OBD_FAIL_MDS_CLOSE_NET_REP       0x13b
1230         do_facet mds "lctl set_param fail_loc=0x8000013b"
1231         kill -USR1 $close_pid
1232         cancel_lru_locks mdc
1233
1234         replay_barrier_nodf mds
1235         fail_nodf mds
1236         wait $open_pid || return 1
1237         sleep 2
1238         #close should be gone
1239         [ -d /proc/$close_pid ] && return 2
1240         do_facet mds "lctl set_param fail_loc=0"
1241
1242         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1243         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1244         rm -rf $DIR/${tdir}-*
1245 }
1246 run_test 53f "|X| open reply and close reply while two MDC requests in flight"
1247
1248 test_53g() {
1249         rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1250
1251         mkdir -p $DIR/${tdir}-1
1252         mkdir -p $DIR/${tdir}-2
1253         multiop $DIR/${tdir}-1/f O_c &
1254         close_pid=$!
1255
1256 #define OBD_FAIL_MDS_REINT_NET_REP       0x119
1257         do_facet mds "lctl set_param fail_loc=0x80000119"
1258         mcreate $DIR/${tdir}-2/f &
1259         open_pid=$!
1260         sleep 1
1261
1262 #define OBD_FAIL_MDS_CLOSE_NET           0x115
1263         do_facet mds "lctl set_param fail_loc=0x80000115"
1264         kill -USR1 $close_pid
1265         cancel_lru_locks mdc # force the close
1266
1267         do_facet mds "lctl set_param fail_loc=0"
1268         replay_barrier_nodf mds
1269         fail_nodf mds
1270         wait $open_pid || return 1
1271         sleep 2
1272         # close should be gone
1273         [ -d /proc/$close_pid ] && return 2
1274
1275         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1276         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1277         rm -rf $DIR/${tdir}-*
1278 }
1279 run_test 53g "|X| drop open reply and close request while close and open are both in flight"
1280
1281 test_53h() {
1282     rm -rf $DIR/${tdir}-1 $DIR/${tdir}-2
1283
1284     mkdir -p $DIR/${tdir}-1
1285     mkdir -p $DIR/${tdir}-2
1286     multiop $DIR/${tdir}-1/f O_c &
1287     close_pid=$!
1288
1289 #define OBD_FAIL_MDS_REINT_NET           0x107
1290     do_facet mds "lctl set_param fail_loc=0x80000107"
1291     mcreate $DIR/${tdir}-2/f &
1292     open_pid=$!
1293     sleep 1
1294
1295 #define OBD_FAIL_MDS_CLOSE_NET_REP       0x13b
1296     do_facet mds "lctl set_param fail_loc=0x8000013b"
1297     kill -USR1 $close_pid
1298     cancel_lru_locks mdc  # force the close
1299     sleep 1
1300
1301     replay_barrier_nodf mds
1302     fail_nodf mds
1303     wait $open_pid || return 1
1304     sleep 2
1305     # close should be gone
1306     [ -d /proc/$close_pid ] && return 2
1307     do_facet mds "lctl set_param fail_loc=0"
1308
1309     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1310     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1311     rm -rf $DIR/${tdir}-*
1312 }
1313 run_test 53h "|X| open request and close reply while two MDC requests in flight"
1314
1315 #b3761 ASSERTION(hash != 0) failed
1316 test_55() {
1317 # OBD_FAIL_MDS_OPEN_CREATE | OBD_FAIL_ONCE
1318     do_facet mds "lctl set_param fail_loc=0x8000012b"
1319     touch $DIR/$tfile &
1320     # give touch a chance to run
1321     sleep 5
1322     do_facet mds "lctl set_param fail_loc=0x0"
1323     rm $DIR/$tfile
1324     return 0
1325 }
1326 run_test 55 "let MDS_CHECK_RESENT return the original return code instead of 0"
1327
1328 #b3440 ASSERTION(rec->ur_fid2->id) failed
1329 test_56() {
1330     ln -s foo $DIR/$tfile
1331     replay_barrier mds
1332     #drop_reply "cat $DIR/$tfile"
1333     fail mds
1334     sleep 10
1335 }
1336 run_test 56 "don't replay a symlink open request (3440)"
1337
1338 #recovery one mds-ost setattr from llog
1339 test_57() {
1340 #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1341     do_facet mds "lctl set_param fail_loc=0x8000012c"
1342     touch $DIR/$tfile
1343     replay_barrier mds
1344     fail mds
1345     sleep 1
1346     $CHECKSTAT -t file $DIR/$tfile || return 1
1347     do_facet mds "lctl set_param fail_loc=0x0"
1348     rm $DIR/$tfile
1349 }
1350 run_test 57 "test recovery from llog for setattr op"
1351
1352 #recovery many mds-ost setattr from llog
1353 test_58a() {
1354     mkdir -p $DIR/$tdir
1355 #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1356     do_facet mds "lctl set_param fail_loc=0x8000012c"
1357     createmany -o $DIR/$tdir/$tfile-%d 2500
1358     replay_barrier mds
1359     fail mds
1360     sleep 2
1361     $CHECKSTAT -t file $DIR/$tdir/$tfile-* >/dev/null || return 1
1362     do_facet mds "lctl set_param fail_loc=0x0"
1363     unlinkmany $DIR/$tdir/$tfile-%d 2500
1364     rmdir $DIR/$tdir
1365 }
1366 run_test 58a "test recovery from llog for setattr op (test llog_gen_rec)"
1367
1368 test_58b() {
1369     mount_client $MOUNT2
1370     mkdir -p $DIR/$tdir
1371     touch $DIR/$tdir/$tfile
1372     replay_barrier mds
1373     setfattr -n trusted.foo -v bar $DIR/$tdir/$tfile
1374     fail mds
1375     VAL=`getfattr --absolute-names --only-value -n trusted.foo $MOUNT2/$tdir/$tfile`
1376     [ x$VAL = x"bar" ] || return 1
1377     rm -f $DIR/$tdir/$tfile
1378     rmdir $DIR/$tdir
1379     zconf_umount `hostname` $MOUNT2
1380 }
1381 run_test 58b "test replay of setxattr op"
1382
1383 test_58c() { # bug 16570
1384         mount_client $MOUNT2
1385         mkdir -p $DIR/$tdir
1386         touch $DIR/$tdir/$tfile
1387         drop_request "setfattr -n trusted.foo -v bar $DIR/$tdir/$tfile" || \
1388                 return 1
1389         VAL=`getfattr --absolute-names --only-value -n trusted.foo $MOUNT2/$tdir/$tfile`
1390         [ x$VAL = x"bar" ] || return 2
1391         drop_reint_reply "setfattr -n trusted.foo1 -v bar1 $DIR/$tdir/$tfile" || \
1392                 return 3
1393         VAL=`getfattr --absolute-names --only-value -n trusted.foo1 $MOUNT2/$tdir/$tfile`
1394         [ x$VAL = x"bar1" ] || return 4
1395         rm -f $DIR/$tdir/$tfile
1396         rmdir $DIR/$tdir
1397         zconf_umount `hostname` $MOUNT2
1398 }
1399 run_test 58c "resend/reconstruct setxattr op"
1400
1401 # log_commit_thread vs filter_destroy race used to lead to import use after free
1402 # bug 11658
1403 test_59() {
1404     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1405
1406     mkdir -p $DIR/$tdir
1407     createmany -o $DIR/$tdir/$tfile-%d 200
1408     sync
1409     unlinkmany $DIR/$tdir/$tfile-%d 200
1410 #define OBD_FAIL_PTLRPC_DELAY_RECOV       0x507
1411     do_facet ost1 "lctl set_param fail_loc=0x507"
1412     fail ost1
1413     fail mds
1414     do_facet ost1 "lctl set_param fail_loc=0x0"
1415     sleep 20
1416     rmdir $DIR/$tdir
1417 }
1418 run_test 59 "test log_commit_thread vs filter_destroy race"
1419
1420 # race between add unlink llog vs cat log init in post_recovery (only for b1_6)
1421 # bug 12086: should no oops and No ctxt error for this test
1422 test_60() {
1423     mkdir -p $DIR/$tdir
1424     createmany -o $DIR/$tdir/$tfile-%d 200
1425     replay_barrier mds
1426     unlinkmany $DIR/$tdir/$tfile-%d 0 100
1427     fail mds
1428     unlinkmany $DIR/$tdir/$tfile-%d 100 100
1429     local no_ctxt=`dmesg | grep "No ctxt"`
1430     [ -z "$no_ctxt" ] || error "ctxt is not initialized in recovery"
1431 }
1432 run_test 60 "test llog post recovery init vs llog unlink"
1433
1434 #test race  llog recovery thread vs llog cleanup
1435 test_61a() {
1436     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1437
1438     mkdir -p $DIR/$tdir
1439     createmany -o $DIR/$tdir/$tfile-%d 800
1440     replay_barrier ost1
1441 #   OBD_FAIL_OST_LLOG_RECOVERY_TIMEOUT 0x221
1442     unlinkmany $DIR/$tdir/$tfile-%d 800
1443     do_facet ost "lctl set_param fail_loc=0x80000221"
1444     facet_failover ost1
1445     sleep 10
1446     fail ost1
1447     sleep 30
1448     do_facet ost "lctl set_param fail_loc=0x0"
1449     $CHECKSTAT -t file $DIR/$tdir/$tfile-* && return 1
1450     rmdir $DIR/$tdir
1451 }
1452 run_test 61a "test race llog recovery vs llog cleanup"
1453
1454 #test race  mds llog sync vs llog cleanup
1455 test_61b() {
1456 #   OBD_FAIL_MDS_LLOG_SYNC_TIMEOUT 0x13a
1457     do_facet mds "lctl set_param fail_loc=0x8000013a"
1458     facet_failover mds
1459     sleep 10
1460     fail mds
1461     do_facet client dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 || return 1
1462 }
1463 run_test 61b "test race mds llog sync vs llog cleanup"
1464
1465 #test race  cancel cookie cb vs llog cleanup
1466 test_61c() {
1467     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1468
1469 #   OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT 0x222
1470     touch $DIR/$tfile
1471     do_facet ost "lctl set_param fail_loc=0x80000222"
1472     rm $DIR/$tfile
1473     sleep 10
1474     fail ost1
1475 }
1476 run_test 61c "test race mds llog sync vs llog cleanup"
1477
1478 test_61d() { # bug 16002
1479 #define OBD_FAIL_OBD_LLOG_SETUP        0x605
1480     stop mds
1481     do_facet mds "lctl set_param fail_loc=0x80000605"
1482     start mds $MDSDEV $MDS_MOUNT_OPTS && error "mds start should have failed"
1483     do_facet mds "lctl set_param fail_loc=0"
1484     start mds $MDSDEV $MDS_MOUNT_OPTS || error "cannot restart mds"
1485 }
1486 run_test 61d "error in llog_setup should cleanup the llog context correctly"
1487
1488 test_62() { # Bug 15756 - don't mis-drop resent replay
1489     mkdir -p $DIR/$tdir
1490     replay_barrier mds
1491     createmany -o $DIR/$tdir/$tfile- 25
1492 #define OBD_FAIL_TGT_REPLAY_DROP         0x707
1493     do_facet mds "lctl set_param fail_loc=0x80000707"
1494     fail mds
1495     do_facet mds "lctl set_param fail_loc=0"
1496     unlinkmany $DIR/$tdir/$tfile- 25 || return 2
1497     return 0
1498 }
1499 run_test 62 "don't mis-drop resent replay"
1500
1501 #Adaptive Timeouts (bug 3055)
1502 AT_MAX_SET=0
1503
1504 at_cleanup () {
1505     local var
1506     local facet
1507     local at_new
1508
1509     echo "Cleaning up AT ..."
1510     if [ -n "$ATOLDBASE" ]; then
1511         local at_history=$($LCTL get_param -n at_history)
1512         do_facet mds "lctl set_param at_history=$at_history" || true
1513         do_facet ost1 "lctl set_param at_history=$at_history" || true
1514     fi
1515
1516     if [ $AT_MAX_SET -ne 0 ]; then
1517         for facet in mds client ost; do
1518             var=AT_MAX_SAVE_${facet}
1519             echo restore AT on $facet to saved value ${!var}
1520             at_max_set ${!var} $facet
1521             at_new=$(at_max_get $facet)
1522             echo Restored AT value on $facet $at_new
1523             [ $at_new -eq ${!var} ] || \
1524             error "$facet : AT value was not restored SAVED ${!var} NEW $at_new"
1525         done
1526     fi
1527 }
1528
1529 at_start()
1530 {
1531     local at_max_new=600
1532
1533     # Save at_max original values
1534     local facet
1535     if [ $AT_MAX_SET -eq 0 ]; then
1536         # Suppose that all osts have the same at_max
1537         for facet in mds client ost; do
1538             eval AT_MAX_SAVE_${facet}=$(at_max_get $facet)
1539         done
1540     fi
1541     local at_max
1542     for facet in mds client ost; do
1543         at_max=$(at_max_get $facet)
1544         if [ $at_max -ne $at_max_new ]; then
1545             echo "AT value on $facet is $at_max, set it by force temporarily to $at_max_new"
1546             at_max_set $at_max_new $facet
1547             AT_MAX_SET=1
1548         fi
1549     done
1550
1551     if [ -z "$ATOLDBASE" ]; then
1552         ATOLDBASE=$(do_facet mds "lctl get_param -n at_history")
1553         # speed up the timebase so we can check decreasing AT
1554         do_facet mds "lctl set_param at_history=8" || true
1555         do_facet ost1 "lctl set_param at_history=8" || true
1556
1557         # sleep for a while to cool down, should be > 8s and also allow
1558         # at least one ping to be sent. simply use TIMEOUT to be safe.
1559         sleep $TIMEOUT
1560     fi
1561 }
1562
1563 test_65a() #bug 3055
1564 {
1565     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1566
1567     at_start || return 0
1568     $LCTL dk > /dev/null
1569     debugsave
1570     lctl set_param debug="+other"
1571     # Slow down a request to the current service time, this is critical
1572     # because previous tests may have caused this value to increase.
1573     REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
1574                awk '/portal 12/ {print $5}'`
1575     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1576
1577     do_facet mds lctl set_param fail_val=$((${REQ_DELAY} * 1000))
1578 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1579     do_facet mds lctl set_param fail_loc=0x8000050a
1580     createmany -o $DIR/$tfile 10 > /dev/null
1581     unlinkmany $DIR/$tfile 10 > /dev/null
1582     # check for log message
1583     $LCTL dk | grep "Early reply #" || error "No early reply"
1584     # client should show REQ_DELAY estimates
1585     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1586     sleep 9
1587     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1588 }
1589 run_test 65a "AT: verify early replies"
1590
1591 test_65b() #bug 3055
1592 {
1593     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1594
1595     at_start || return 0
1596     # turn on D_ADAPTTO
1597     debugsave
1598     lctl set_param debug="+other"
1599     $LCTL dk > /dev/null
1600     # Slow down a request to the current service time, this is critical
1601     # because previous tests may have caused this value to increase.
1602     REQ_DELAY=`lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts |
1603                awk '/portal 6/ {print $5}'`
1604     REQ_DELAY=$((${REQ_DELAY} + ${REQ_DELAY} / 4 + 5))
1605
1606     do_facet ost1 lctl set_param fail_val=${REQ_DELAY}
1607 #define OBD_FAIL_OST_BRW_PAUSE_PACK      0x224
1608     do_facet ost1 lctl set_param fail_loc=0x224
1609
1610     rm -f $DIR/$tfile
1611     lfs setstripe $DIR/$tfile --index=0 --count=1
1612     # force some real bulk transfer
1613     multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
1614
1615     do_facet ost1 lctl set_param fail_loc=0
1616     # check for log message
1617     $LCTL dk | grep "Early reply #" || error "No early reply"
1618     debugrestore
1619     # client should show REQ_DELAY estimates
1620     lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts | grep portal
1621 }
1622 run_test 65b "AT: verify early replies on packed reply / bulk"
1623
1624 test_66a() #bug 3055
1625 {
1626     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1627
1628     at_start || return 0
1629     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1630     # adjust 5s at a time so no early reply is sent (within deadline)
1631     do_facet mds "lctl set_param fail_val=5000"
1632 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1633     do_facet mds "lctl set_param fail_loc=0x8000050a"
1634     createmany -o $DIR/$tfile 20 > /dev/null
1635     unlinkmany $DIR/$tfile 20 > /dev/null
1636     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1637     do_facet mds "lctl set_param fail_val=10000"
1638     do_facet mds "lctl set_param fail_loc=0x8000050a"
1639     createmany -o $DIR/$tfile 20 > /dev/null
1640     unlinkmany $DIR/$tfile 20 > /dev/null
1641     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1642     do_facet mds "lctl set_param fail_loc=0"
1643     sleep 9
1644     createmany -o $DIR/$tfile 20 > /dev/null
1645     unlinkmany $DIR/$tfile 20 > /dev/null
1646     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal | grep "portal 12"
1647     CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $5}')
1648     WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $7}')
1649     echo "Current MDT timeout $CUR, worst $WORST"
1650     [ $CUR -lt $WORST ] || error "Current $CUR should be less than worst $WORST"
1651 }
1652 run_test 66a "AT: verify MDT service time adjusts with no early replies"
1653
1654 test_66b() #bug 3055
1655 {
1656     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1657
1658     at_start || return 0
1659     ORIG=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $4}')
1660     lctl set_param fail_val=$(($ORIG + 5))
1661 #define OBD_FAIL_PTLRPC_PAUSE_REP      0x50c
1662     lctl set_param fail_loc=0x50c
1663     ls $DIR/$tfile > /dev/null 2>&1
1664     lctl set_param fail_loc=0
1665     CUR=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $4}')
1666     WORST=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $6}')
1667     echo "network timeout orig $ORIG, cur $CUR, worst $WORST"
1668     [ $WORST -gt $ORIG ] || error "Worst $WORST should be worse than orig $ORIG"
1669 }
1670 run_test 66b "AT: verify net latency adjusts"
1671
1672 test_67a() #bug 3055
1673 {
1674     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1675
1676     at_start || return 0
1677     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1678     # sleeping threads may drive values above this
1679     do_facet ost1 "lctl set_param fail_val=400"
1680 #define OBD_FAIL_PTLRPC_PAUSE_REQ    0x50a
1681     do_facet ost1 "lctl set_param fail_loc=0x50a"
1682     createmany -o $DIR/$tfile 20 > /dev/null
1683     unlinkmany $DIR/$tfile 20 > /dev/null
1684     do_facet ost1 "lctl set_param fail_loc=0"
1685     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1686     ATTEMPTS=$(($CONN2 - $CONN1))
1687     echo "$ATTEMPTS osc reconnect attemps on gradual slow"
1688     [ $ATTEMPTS -gt 0 ] && error_ignore 13721 "AT should have prevented reconnect"
1689     return 0
1690 }
1691 run_test 67a "AT: verify slow request processing doesn't induce reconnects"
1692
1693 test_67b() #bug 3055
1694 {
1695     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1696
1697     at_start || return 0
1698     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1699
1700     # exhaust precreations on ost1
1701     local OST=$(lfs osts | grep 0": " | awk '{print $2}' | sed -e 's/_UUID$//')
1702     local mdtosc=$(get_mdtosc_proc_path $OST)
1703     local last_id=$(do_facet mds lctl get_param -n osc.$mdtosc.prealloc_last_id)
1704     local next_id=$(do_facet mds lctl get_param -n osc.$mdtosc.prealloc_next_id)
1705
1706     mkdir -p $DIR/$tdir/${OST}
1707     lfs setstripe $DIR/$tdir/${OST} -o 0 -c 1 || error "setstripe"
1708     echo "Creating to objid $last_id on ost $OST..."
1709 #define OBD_FAIL_OST_PAUSE_CREATE        0x223
1710     do_facet ost1 "lctl set_param fail_val=20000"
1711     do_facet ost1 "lctl set_param fail_loc=0x80000223"
1712     createmany -o $DIR/$tdir/${OST}/f $next_id $((last_id - next_id + 2))
1713
1714     client_reconnect
1715     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1716     log "phase 2"
1717     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1718     ATTEMPTS=$(($CONN2 - $CONN1))
1719     echo "$ATTEMPTS osc reconnect attemps on instant slow"
1720     # do it again; should not timeout
1721     do_facet ost1 "lctl set_param fail_loc=0x80000223"
1722     cp /etc/profile $DIR/$tfile || error "cp failed"
1723     do_facet ost1 "lctl set_param fail_loc=0"
1724     client_reconnect
1725     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1726     CONN3=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1727     ATTEMPTS=$(($CONN3 - $CONN2))
1728     echo "$ATTEMPTS osc reconnect attemps on 2nd slow"
1729     [ $ATTEMPTS -gt 0 ] && error "AT should have prevented reconnect"
1730     return 0
1731 }
1732 run_test 67b "AT: verify instant slowdown doesn't induce reconnects"
1733
1734 test_68 () #bug 13813
1735 {
1736     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1737
1738     at_start || return 0
1739     local ldlm_enqueue_min=$(find /sys -name ldlm_enqueue_min)
1740     [ -z "$ldlm_enqueue_min" ] && skip "missing /sys/.../ldlm_enqueue_min" && return 0
1741     local ldlm_enqueue_min_r=$(do_facet ost1 "find /sys -name ldlm_enqueue_min")
1742     [ -z "$ldlm_enqueue_min_r" ] && skip "missing /sys/.../ldlm_enqueue_min in the ost1" && return 0
1743     local ENQ_MIN=$(cat $ldlm_enqueue_min)
1744     local ENQ_MIN_R=$(do_facet ost1 "cat $ldlm_enqueue_min_r")
1745     echo $TIMEOUT >> $ldlm_enqueue_min
1746     do_facet ost1 "echo $TIMEOUT >> $ldlm_enqueue_min_r"
1747
1748     rm -rf $DIR/$tdir
1749     mkdir -p $DIR/$tdir
1750     lfs setstripe $DIR/$tdir --index=0 --count=1
1751 #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
1752     lctl set_param fail_val=$(($TIMEOUT - 1))
1753     lctl set_param fail_loc=0x80000312
1754     cp /etc/profile $DIR/$tdir/${tfile}_1 || error "1st cp failed $?"
1755     lctl set_param fail_val=$((TIMEOUT * 5 / 4))
1756     lctl set_param fail_loc=0x80000312
1757     cp /etc/profile $DIR/$tdir/${tfile}_2 || error "2nd cp failed $?"
1758     lctl set_param fail_loc=0
1759
1760     echo $ENQ_MIN >> $ldlm_enqueue_min
1761     do_facet ost1 "echo $ENQ_MIN_R >> $ldlm_enqueue_min_r"
1762     rm -rf $DIR/$tdir
1763     return 0
1764 }
1765 run_test 68 "AT: verify slowing locks"
1766
1767 at_cleanup
1768 # end of AT tests includes above lines
1769
1770 # start multi-client tests
1771 test_70a () {
1772         [ -z "$CLIENTS" ] && \
1773                 { skip "Need two or more clients." && return; }
1774         [ $CLIENTCOUNT -lt 2 ] && \
1775                 { skip "Need two or more clients, have $CLIENTCOUNT" && return; }
1776
1777         echo "mount clients $CLIENTS ..."
1778         zconf_mount_clients $CLIENTS $DIR
1779
1780         local clients=${CLIENTS//,/ }
1781         echo "Write/read files on $DIR ; clients $CLIENTS ... "
1782         for CLIENT in $clients; do
1783                 do_node $CLIENT dd bs=1M count=10 if=/dev/zero \
1784                         of=$DIR/${tfile}_${CLIENT} 2>/dev/null || \
1785                                 error "dd failed on $CLIENT"
1786         done
1787
1788         local prev_client=$(echo $clients | sed 's/^.* \(.\+\)$/\1/')
1789         for C in ${CLIENTS//,/ }; do
1790                 do_node $prev_client dd if=$DIR/${tfile}_${C} of=/dev/null 2>/dev/null || \
1791                         error "dd if=$DIR/${tfile}_${C} failed on $prev_client"
1792                 prev_client=$C
1793         done
1794         
1795         ls $DIR
1796 }
1797 run_test 70a "check multi client t-f"
1798
1799 test_70b () {
1800         local clients=${CLIENTS:-$HOSTNAME}
1801
1802         zconf_mount_clients $clients $DIR
1803         
1804         local duration=300
1805         [ "$SLOW" = "no" ] && duration=60
1806         local cmd="rundbench 1 -t $duration"
1807         local PID=""
1808         do_nodesv $clients "set -x; MISSING_DBENCH_OK=$MISSING_DBENCH_OK \
1809                 PATH=:$PATH:$LUSTRE/utils:$LUSTRE/tests/:$DBENCH_LIB \
1810                 DBENCH_LIB=$DBENCH_LIB TESTSUITE=$TESTSUITE TESTNAME=$TESTNAME \
1811                 LCTL=$LCTL $cmd" &
1812         PID=$!
1813         log "Started rundbench load PID=$PID ..."
1814
1815         ELAPSED=0
1816         NUM_FAILOVERS=0
1817         START_TS=$(date +%s)
1818         CURRENT_TS=$START_TS
1819         while [ $ELAPSED -lt $duration ]; do
1820                 sleep 1
1821                 replay_barrier mds
1822                 sleep 1 # give clients a time to do operations
1823                 # Increment the number of failovers
1824                 NUM_FAILOVERS=$((NUM_FAILOVERS+1))
1825                 log "$TESTNAME fail mds1 $NUM_FAILOVERS times"
1826                 facet_failover mds
1827                 CURRENT_TS=$(date +%s)
1828                 ELAPSED=$((CURRENT_TS - START_TS))
1829         done
1830
1831         wait $PID || error "rundbench load on $CLIENTS failed!"
1832 }
1833 run_test 70b "mds recovery; $CLIENTCOUNT clients"
1834 # end multi-client tests
1835
1836 # vbr export handling
1837 test_71a() {
1838     delayed_recovery_enabled || { skip "No delayed recovery support"; return 0; }
1839
1840     UUID=$(lctl dl | awk '/mdc.*-mdc-/ { print $5 }')
1841     echo "Client UUID is $UUID"
1842     replay_barrier mds
1843     umount $DIR
1844     facet_failover mds
1845     zconf_mount `hostname` $DIR || error "mount fails"
1846     client_up || error "post-failover df failed"
1847     do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|grep $UUID" || \
1848         error "no delayed exports"
1849     OLD_AGE=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age")
1850     NEW_AGE=10
1851     do_facet mds "lctl set_param mds.${mds_svc}.stale_export_age=$NEW_AGE"
1852     sleep $((NEW_AGE + 2))
1853     do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|grep \"$UUID.*EXPIRED\"" || \
1854         error "exports didn't expire"
1855     do_facet mds "lctl set_param mds.${mds_svc}.evict_client=$UUID"
1856     do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|grep $UUID" && \
1857         error "Export wasn't removed manually"
1858     do_facet mds "lctl set_param mds.${mds_svc}.stale_export_age=$OLD_AGE"
1859     return 0;
1860 }
1861 run_test 71a "lost client export is kept"
1862
1863 test_71b() {
1864     delayed_recovery_enabled || { skip "No delayed recovery support"; return 0; }
1865
1866     FAKE_NUM=10
1867     create_fake_exports mds $FAKE_NUM
1868     NUM=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|wc -l")
1869     [ $NUM -eq 0 ] && error "no fake exports $NUM - $FAKE_NUM"
1870     OLD_AGE=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age")
1871     NEW_AGE=10
1872     do_facet mds "lctl set_param mds.${mds_svc}.stale_export_age=$NEW_AGE"
1873     sleep $((NEW_AGE + 2))
1874     EX_NUM=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|grep -c EXPIRED")
1875     [ "$EX_NUM" -eq "$NUM" ] || error "not all exports are expired $EX_NUM != $NUM"
1876     do_facet mds "lctl set_param mds.${mds_svc}.flush_stale_exports=1"
1877     do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|grep EXPIRED" && \
1878         error "Exports weren't flushed"
1879     do_facet mds "lctl set_param mds.${mds_svc}.stale_export_age=$OLD_AGE"
1880     return 0;
1881 }
1882 run_test 71b "stale exports are expired, lctl flushes them"
1883
1884 test_71c() {
1885     delayed_recovery_enabled || { skip "No delayed recovery support"; return 0; }
1886
1887     FAKE_NUM=10
1888     create_fake_exports mds $FAKE_NUM
1889     NUM=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|wc -l")
1890     [ "$NUM" -eq "$FAKE_NUM" ] || error "no fake exports $NUM - $FAKE_NUM"
1891     OLD_AGE=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age")
1892     NEW_AGE=10
1893     do_facet mds "lctl set_param mds.${mds_svc}.stale_export_age=$NEW_AGE"
1894     sleep $((NEW_AGE + 2))
1895     EX_NUM=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|grep -c EXPIRED")
1896     [ "$EX_NUM" -eq "$NUM" ] || error "not all exports are expired $EX_NUM != $NUM"
1897
1898     umount $DIR
1899     zconf_mount `hostname` $DIR || error "mount fails"
1900
1901     NUM=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|wc -l")
1902     [ $NUM -eq 0 ] || error "$NUM fake exports are still exists"
1903     do_facet mds "lctl set_param mds.${mds_svc}.stale_export_age=$OLD_AGE"
1904     return 0;
1905 }
1906 run_test 71c "stale exports are expired, new client connection flush them"
1907
1908 test_71d() {
1909     delayed_recovery_enabled || { skip "No delayed recovery support"; return 0; }
1910
1911     FAKE_NUM=10
1912     create_fake_exports mds $FAKE_NUM
1913     NUM=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|wc -l")
1914     [ "$NUM" -eq "$FAKE_NUM" ] || error "no fake exports $NUM - $FAKE_NUM"
1915     OLD_AGE=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age")
1916     NEW_AGE=10
1917     do_facet mds "lctl conf_param ${mds_svc}.mdt.stale_export_age=$NEW_AGE"
1918     sleep $((NEW_AGE + 2))
1919     EX_NUM=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|grep -c EXPIRED")
1920     [ "$EX_NUM" -eq "$NUM" ] || error "not all exports are expired $EX_NUM != $NUM"
1921
1922     fail mds
1923
1924     FAIL_AGE=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_export_age")
1925     [ $FAIL_AGE -eq $NEW_AGE ] || error "new age wasn't set after recovery"
1926     NUM=$(do_facet mds "lctl get_param -n mds.${mds_svc}.stale_exports|wc -l")
1927     [ $NUM -eq 0 ] || error "$NUM fake exports are still exists"
1928     do_facet mds "lctl conf_param ${mds_svc}.mdt.stale_export_age=$OLD_AGE"
1929     return 0;
1930 }
1931 run_test 71d "expired exports, server init removes them, conf_param works"
1932
1933 # end vbr exports tests
1934
1935 test_72() { #bug 16711
1936     replay_barrier mds
1937     multiop_bg_pause $DIR/$tfile O_c || return 4
1938     pid=$!
1939 #define OBD_FAIL_TGT_REPLAY_DELAY 0x709
1940     do_facet mds "lctl set_param fail_loc=0x80000709"
1941     fail mds
1942     kill -USR1 $pid || return 1
1943     wait $pid || return 2
1944     $CHECKSTAT -t file $DIR/$tfile || return 3
1945 }
1946 run_test 72 "target_finish_recovery vs process_recovery_queue race"
1947
1948 test_73a() {
1949     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1950     pid=$!
1951     rm -f $DIR/$tfile
1952
1953     replay_barrier mds
1954 #define OBD_FAIL_LDLM_ENQUEUE       0x302
1955     do_facet mds "lctl set_param fail_loc=0x80000302"
1956     fail mds
1957     kill -USR1 $pid
1958     wait $pid || return 1
1959     [ -e $DIR/$tfile ] && return 2
1960     return 0
1961 }
1962 run_test 73a "open(O_CREAT), unlink, replay, reconnect before open replay , close"
1963
1964 test_73b() {
1965     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1966     pid=$!
1967     rm -f $DIR/$tfile
1968
1969     replay_barrier mds
1970 #define OBD_FAIL_LDLM_REPLY       0x30c
1971     do_facet mds "lctl set_param fail_loc=0x8000030c"
1972     fail mds
1973     kill -USR1 $pid
1974     wait $pid || return 1
1975     [ -e $DIR/$tfile ] && return 2
1976     return 0
1977 }
1978 run_test 73b "open(O_CREAT), unlink, replay, reconnect at open_replay reply, close"
1979
1980 test_73c() {
1981     multiop_bg_pause $DIR/$tfile O_tSc || return 3
1982     pid=$!
1983     rm -f $DIR/$tfile
1984
1985     replay_barrier mds
1986 #define OBD_FAIL_TGT_LAST_REPLAY       0x710
1987     do_facet mds "lctl set_param fail_loc=0x80000710"
1988     fail mds
1989     kill -USR1 $pid
1990     wait $pid || return 1
1991     [ -e $DIR/$tfile ] && return 2
1992     return 0
1993 }
1994 run_test 73c "open(O_CREAT), unlink, replay, reconnect at last_replay, close"
1995
1996 test_80a() {
1997     do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
1998
1999     replay_barrier ost1
2000     lfs setstripe -i 0 -c 1 $DIR/$tfile
2001     dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 || error "Cannot write"
2002     cksum=`md5sum $DIR/$tfile | awk '{print $1}'`
2003     cancel_lru_locks osc
2004     fail ost1
2005     dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
2006     cksum2=`md5sum $DIR/$tfile | awk '{print $1}'`
2007     if [ $cksum != $cksum2 ] ; then
2008         error "New checksum $cksum2 does not match original $cksum"
2009     fi
2010 }
2011 run_test 80a "write replay"
2012
2013 test_80b() {
2014     do_facet ost1 "lctl set_param -n obdfilter.${ost1_svc}.sync_journal 0"
2015
2016     replay_barrier ost1
2017     lfs setstripe -i 0 -c 1 $DIR/$tfile
2018     dd if=/dev/urandom of=$DIR/$tfile bs=1024k count=8 || error "Cannot write"
2019     sleep 1 # Give it a chance to flush dirty data
2020     echo TESTTEST | dd of=$DIR/$tfile bs=1 count=8 seek=64
2021     cksum=`md5sum $DIR/$tfile | awk '{print $1}'`
2022     cancel_lru_locks osc
2023     fail ost1
2024     dd if=$DIR/$tfile of=/dev/null bs=1024k count=8 || error "Cannot read"
2025     cksum2=`md5sum $DIR/$tfile | awk '{print $1}'`
2026     if [ $cksum != $cksum2 ] ; then
2027         error "New checksum $cksum2 does not match original $cksum"
2028     fi
2029 }
2030 run_test 80b "write replay with changed data (checksum resend)"
2031
2032 test_81a() {
2033     mkdir -p $DIR/$tdir
2034     createmany -o $DIR/$tdir/$tfile- 10 || return 1
2035 #define OBD_FAIL_MDS_FAIL_LOV_LOG_ADD       0x140
2036     do_facet mds "lctl set_param fail_loc=0x80000140"
2037     unlinkmany $DIR/$tdir/$tfile- 10 || return 2
2038 }
2039 run_test 81a "fail log_add during unlink recovery"
2040
2041 test_81b() {
2042     mkdir -p $DIR/$tdir
2043     createmany -o $DIR/$tdir/$tfile- 10 || return 1
2044     replay_barrier mds
2045     unlinkmany $DIR/$tdir/$tfile- 10 || return 2
2046 #define OBD_FAIL_MDS_FAIL_LOV_LOG_ADD       0x140
2047     do_facet mds "lctl set_param fail_loc=0x80000140"
2048     fail mds
2049 }
2050 run_test 81b "fail log_add during unlink recovery"
2051
2052 test_82() { #bug 18927
2053     multiop_bg_pause $DIR/$tfile O_c || return 1
2054     pid1=$!
2055     multiop_bg_pause $DIR/$tfile o:O_CREAT:O_RDONLY:_c || return 2
2056     pid2=$!
2057     rm -f $DIR/$tfile
2058     replay_barrier mds
2059     fail mds
2060     kill -USR1 $pid1
2061     wait $pid1 || return 3
2062     kill -USR1 $pid2
2063     wait $pid2 || return 4
2064     [ -e $DIR/$tfile ] && return 5
2065     return 0
2066 }
2067 run_test 82 "second open|creat in replay with open orphan"
2068
2069 test_83() { #bug 19224
2070 #define OBD_FAIL_MDS_SPLIT_OPEN  0x142
2071     do_facet mds "lctl set_param fail_loc=0x80000142"
2072     # open will sleep after first transaction
2073     touch $DIR/$tfile &
2074     PID=$!
2075     sleep 2
2076     # set barrier between open transactions
2077     replay_barrier_nodf mds
2078     createmany -o $DIR/$tfile- 10
2079     # open should finish now
2080     wait $PID || return 1
2081     fail mds
2082     rm $DIR/$tfile || return 2
2083     unlinkmany $DIR/$tfile- 10 || return 3
2084     return 0
2085 }
2086 run_test 83 "open replay with barrier between transactions"
2087
2088 test_84() {
2089 #define OBD_FAIL_OBD_FAIL_MDS_SPLIT_OPEN 0x142
2090     do_facet mds "lctl set_param fail_loc=0x80000142"
2091     createmany -o $DIR/$tfile- 1 &
2092     PID=$!
2093     mds_evict_client
2094     wait $PID || true
2095     client_up || client_up || true    # reconnect
2096 }
2097 run_test 84 "stale open during export disconnect"
2098
2099 test_85a() { #bug 16774
2100     lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
2101
2102     for i in `seq 100`; do
2103         echo "tag-$i" > $DIR/$tfile-$i
2104         grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
2105     done
2106
2107     lov_id=`lctl dl | grep "clilov"` 
2108     addr=`echo $lov_id | awk '{print $4}' | awk -F '-' '{print $3}'`
2109     count=`lctl get_param -n ldlm.namespaces.*MDT0000*$addr.lock_unused_count`
2110     echo "before recovery: unused locks count = $count"
2111
2112     fail mds
2113     
2114     count2=`lctl get_param -n ldlm.namespaces.*MDT0000*$addr.lock_unused_count`
2115     echo "after recovery: unused locks count = $count2"
2116
2117     if [ $count2 -ge $count ]; then
2118         error "unused locks are not canceled"
2119     fi
2120 }
2121 run_test 85a "check the cancellation of unused locks during recovery(IBITS)"
2122
2123 test_85b() { #bug 16774
2124     lctl set_param -n ldlm.cancel_unused_locks_before_replay "1"
2125
2126     lfs setstripe -o 0 -c 1 $DIR
2127
2128     for i in `seq 100`; do
2129         dd if=/dev/urandom of=$DIR/$tfile-$i bs=4096 count=32 >/dev/null 2>&1
2130     done
2131
2132     cancel_lru_locks osc
2133
2134     for i in `seq 100`; do
2135         dd if=$DIR/$tfile-$i of=/dev/null bs=4096 count=32 >/dev/null 2>&1
2136     done
2137
2138     lov_id=`lctl dl | grep "clilov"` 
2139     addr=`echo $lov_id | awk '{print $4}' | awk -F '-' '{print $3}'`
2140     count=`lctl get_param -n ldlm.namespaces.*OST0000*$addr.lock_unused_count`
2141     echo "before recovery: unused locks count = $count"
2142
2143     fail ost1
2144     
2145     count2=`lctl get_param -n ldlm.namespaces.*OST0000*$addr.lock_unused_count`
2146     echo "after recovery: unused locks count = $count2"
2147
2148     if [ $count2 -ge $count ]; then
2149         error "unused locks are not canceled"
2150     fi
2151 }
2152 run_test 85b "check the cancellation of unused locks during recovery(EXTENT)"
2153
2154 equals_msg `basename $0`: test complete, cleaning up
2155 check_and_cleanup_lustre
2156 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG && grep -q FAIL $TESTSUITELOG && exit 1 || true