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