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