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