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