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