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