Whamcloud - gitweb
b=16551 (att 19784)
[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
23 ALWAYS_EXCEPT="61d   $REPLAY_SINGLE_EXCEPT"
24
25 if [ "$FAILURE_MODE" = "HARD" ] && mixed_ost_devs; then
26     CONFIG_EXCEPTIONS="0b 42 47 61a 61c"
27     echo -n "Several ost services on one ost node are used with FAILURE_MODE=$FAILURE_MODE. "
28     echo "Except the tests: $CONFIG_EXCEPTIONS"
29     ALWAYS_EXCEPT="$ALWAYS_EXCEPT $CONFIG_EXCEPTIONS"
30 fi
31
32 #                                                  63 min  7 min  AT AT AT AT"
33 [ "$SLOW" = "no" ] && EXCEPT_SLOW="1 2 3 4 6 12 16 44a      44b    65 66 67 68"
34
35 build_test_filter
36
37 cleanup_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
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
1044     replay_barrier $SINGLEMDS
1045     createmany -o $DIR/$tfile 20  || return 1
1046     # OBD_FAIL_OST_EROFS 0x216
1047     fail $SINGLEMDS
1048     do_facet ost1 "lctl set_param fail_loc=0x80000216"
1049     df $MOUNT || return 2
1050
1051     createmany -o $DIR/$tfile 20 20 || return 2
1052     unlinkmany $DIR/$tfile 40 || return 3
1053
1054     do_facet ost1 "lctl set_param fail_loc=0"
1055     return 0
1056 }
1057 run_test 48 "MDS->OSC failure during precreate cleanup (2824)"
1058
1059 test_50() {
1060     local oscdev=`do_facet $SINGLEMDS lctl get_param -n devices | grep ${ost1_svc}-osc-MDT0000 | awk '{print $1}'`
1061     [ "$oscdev" ] || return 1
1062     do_facet $SINGLEMDS $LCTL --device $oscdev recover || return 2
1063     do_facet $SINGLEMDS $LCTL --device $oscdev recover || return 3
1064     # give the mds_lov_sync threads a chance to run
1065     sleep 5
1066 }
1067 run_test 50 "Double OSC recovery, don't LASSERT (3812)"
1068
1069 # b3764 timed out lock replay
1070 test_52() {
1071     touch $DIR/$tfile
1072     cancel_lru_locks mdc
1073
1074     multiop $DIR/$tfile s || return 1
1075     replay_barrier $SINGLEMDS
1076 #define OBD_FAIL_LDLM_REPLY              0x30c
1077     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000030c"
1078     fail $SINGLEMDS || return 2
1079     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1080
1081     $CHECKSTAT -t file $DIR/$tfile-* && return 3 || true
1082 }
1083 run_test 52 "time out lock replay (3764)"
1084
1085 # bug 3462 - simultaneous MDC requests
1086 test_53a() {
1087         mkdir -p $DIR/${tdir}-1
1088         mkdir -p $DIR/${tdir}-2
1089         multiop $DIR/${tdir}-1/f O_c &
1090         close_pid=$!
1091         # give multiop a change to open
1092         sleep 1
1093
1094         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1095         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1096         kill -USR1 $close_pid
1097         cancel_lru_locks mdc    # force the close
1098         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1099
1100         mcreate $DIR/${tdir}-2/f || return 1
1101
1102         # close should still be here
1103         [ -d /proc/$close_pid ] || return 2
1104
1105         replay_barrier_nodf $SINGLEMDS
1106         fail $SINGLEMDS
1107         wait $close_pid || return 3
1108
1109         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1110         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1111         rm -rf $DIR/${tdir}-*
1112 }
1113 run_test 53a "|X| close request while two MDC requests in flight"
1114
1115 test_53b() {
1116         mkdir -p $DIR/${tdir}-1
1117         mkdir -p $DIR/${tdir}-2
1118         multiop $DIR/${tdir}-1/f O_c &
1119         close_pid=$!
1120
1121         #define OBD_FAIL_MDS_REINT_NET 0x107
1122         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1123         mcreate $DIR/${tdir}-2/f &
1124         open_pid=$!
1125         sleep 1
1126
1127         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1128         kill -USR1 $close_pid
1129         cancel_lru_locks mdc    # force the close
1130         wait $close_pid || return 1
1131         # open should still be here
1132         [ -d /proc/$open_pid ] || return 2
1133
1134         replay_barrier_nodf $SINGLEMDS
1135         fail $SINGLEMDS
1136         wait $open_pid || return 3
1137
1138         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1139         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1140         rm -rf $DIR/${tdir}-*
1141 }
1142 run_test 53b "|X| open request while two MDC requests in flight"
1143
1144 test_53c() {
1145         mkdir -p $DIR/${tdir}-1
1146         mkdir -p $DIR/${tdir}-2
1147         multiop $DIR/${tdir}-1/f O_c &
1148         close_pid=$!
1149
1150         #define OBD_FAIL_MDS_REINT_NET 0x107
1151         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1152         mcreate $DIR/${tdir}-2/f &
1153         open_pid=$!
1154         sleep 1
1155
1156         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1157         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1158         kill -USR1 $close_pid
1159         cancel_lru_locks mdc    # force the close
1160
1161         replay_barrier_nodf $SINGLEMDS
1162         fail_nodf $SINGLEMDS
1163         wait $open_pid || return 1
1164         sleep 2
1165         # close should be gone
1166         [ -d /proc/$close_pid ] && return 2
1167         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1168
1169         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1170         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1171         rm -rf $DIR/${tdir}-*
1172 }
1173 run_test 53c "|X| open request and close request while two MDC requests in flight"
1174
1175 test_53d() {
1176         mkdir -p $DIR/${tdir}-1
1177         mkdir -p $DIR/${tdir}-2
1178         multiop $DIR/${tdir}-1/f O_c &
1179         close_pid=$!
1180         # give multiop a chance to open
1181         sleep 1
1182
1183         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13f
1184         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013f"
1185         kill -USR1 $close_pid
1186         cancel_lru_locks mdc    # force the close
1187         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1188         mcreate $DIR/${tdir}-2/f || return 1
1189
1190         # close should still be here
1191         [ -d /proc/$close_pid ] || return 2
1192         fail $SINGLEMDS
1193         wait $close_pid || return 3
1194
1195         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1196         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1197         rm -rf $DIR/${tdir}-*
1198 }
1199 run_test 53d "|X| close reply while two MDC requests in flight"
1200
1201 test_53e() {
1202         mkdir -p $DIR/${tdir}-1
1203         mkdir -p $DIR/${tdir}-2
1204         multiop $DIR/${tdir}-1/f O_c &
1205         close_pid=$!
1206
1207         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1208         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1209         mcreate $DIR/${tdir}-2/f &
1210         open_pid=$!
1211         sleep 1
1212
1213         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1214         kill -USR1 $close_pid
1215         cancel_lru_locks mdc    # force the close
1216         wait $close_pid || return 1
1217         # open should still be here
1218         [ -d /proc/$open_pid ] || return 2
1219
1220         replay_barrier_nodf $SINGLEMDS
1221         fail $SINGLEMDS
1222         wait $open_pid || return 3
1223
1224         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 4
1225         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 5
1226         rm -rf $DIR/${tdir}-*
1227 }
1228 run_test 53e "|X| open reply while two MDC requests in flight"
1229
1230 test_53f() {
1231         mkdir -p $DIR/${tdir}-1
1232         mkdir -p $DIR/${tdir}-2
1233         multiop $DIR/${tdir}-1/f O_c &
1234         close_pid=$!
1235
1236         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1237         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1238         mcreate $DIR/${tdir}-2/f &
1239         open_pid=$!
1240         sleep 1
1241
1242         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13f
1243         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013f"
1244         kill -USR1 $close_pid
1245         cancel_lru_locks mdc    # force the close
1246
1247         replay_barrier_nodf $SINGLEMDS
1248         fail_nodf $SINGLEMDS
1249         wait $open_pid || return 1
1250         sleep 2
1251         # close should be gone
1252         [ -d /proc/$close_pid ] && return 2
1253         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1254
1255         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1256         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1257         rm -rf $DIR/${tdir}-*
1258 }
1259 run_test 53f "|X| open reply and close reply while two MDC requests in flight"
1260
1261 test_53g() {
1262         mkdir -p $DIR/${tdir}-1
1263         mkdir -p $DIR/${tdir}-2
1264         multiop $DIR/${tdir}-1/f O_c &
1265         close_pid=$!
1266
1267         #define OBD_FAIL_MDS_REINT_NET_REP 0x119
1268         do_facet $SINGLEMDS "lctl set_param fail_loc=0x119"
1269         mcreate $DIR/${tdir}-2/f &
1270         open_pid=$!
1271         sleep 1
1272
1273         #define OBD_FAIL_MDS_CLOSE_NET 0x115
1274         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000115"
1275         kill -USR1 $close_pid
1276         cancel_lru_locks mdc    # force the close
1277
1278         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1279         replay_barrier_nodf $SINGLEMDS
1280         fail_nodf $SINGLEMDS
1281         wait $open_pid || return 1
1282         sleep 2
1283         # close should be gone
1284         [ -d /proc/$close_pid ] && return 2
1285
1286         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1287         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1288         rm -rf $DIR/${tdir}-*
1289 }
1290 run_test 53g "|X| drop open reply and close request while close and open are both in flight"
1291
1292 test_53h() {
1293         mkdir -p $DIR/${tdir}-1
1294         mkdir -p $DIR/${tdir}-2
1295         multiop $DIR/${tdir}-1/f O_c &
1296         close_pid=$!
1297
1298         #define OBD_FAIL_MDS_REINT_NET 0x107
1299         do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000107"
1300         mcreate $DIR/${tdir}-2/f &
1301         open_pid=$!
1302         sleep 1
1303
1304         #define OBD_FAIL_MDS_CLOSE_NET_REP 0x13f
1305         do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000013f"
1306         kill -USR1 $close_pid
1307         cancel_lru_locks mdc    # force the close
1308         sleep 1
1309
1310         replay_barrier_nodf $SINGLEMDS
1311         fail_nodf $SINGLEMDS
1312         wait $open_pid || return 1
1313         sleep 2
1314         # close should be gone
1315         [ -d /proc/$close_pid ] && return 2
1316         do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1317
1318         $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1319         $CHECKSTAT -t file $DIR/${tdir}-2/f || return 4
1320         rm -rf $DIR/${tdir}-*
1321 }
1322 run_test 53h "|X| open request and close reply while two MDC requests in flight"
1323
1324 #b_cray 54 "|X| open request and close reply while two MDC requests in flight"
1325
1326 #b3761 ASSERTION(hash != 0) failed
1327 test_55() {
1328 # OBD_FAIL_MDS_OPEN_CREATE | OBD_FAIL_ONCE
1329     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012b"
1330     touch $DIR/$tfile &
1331     # give touch a chance to run
1332     sleep 5
1333     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1334     rm $DIR/$tfile
1335     return 0
1336 }
1337 run_test 55 "let MDS_CHECK_RESENT return the original return code instead of 0"
1338
1339 #b3440 ASSERTION(rec->ur_fid2->id) failed
1340 test_56() {
1341     ln -s foo $DIR/$tfile
1342     replay_barrier $SINGLEMDS
1343     #drop_reply "cat $DIR/$tfile"
1344     fail $SINGLEMDS
1345     sleep 10
1346 }
1347 run_test 56 "don't replay a symlink open request (3440)"
1348
1349 #recovery one mds-ost setattr from llog
1350 test_57() {
1351 #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1352     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1353     touch $DIR/$tfile
1354     replay_barrier $SINGLEMDS
1355     fail $SINGLEMDS
1356     sleep 1
1357     $CHECKSTAT -t file $DIR/$tfile || return 1
1358     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1359     rm $DIR/$tfile
1360 }
1361 run_test 57 "test recovery from llog for setattr op"
1362
1363 #recovery many mds-ost setattr from llog
1364 test_58a() {
1365     mkdir -p $DIR/$tdir
1366 #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1367     do_facet $SINGLEMDS "lctl set_param fail_loc=0x8000012c"
1368     createmany -o $DIR/$tdir/$tfile-%d 2500
1369     replay_barrier $SINGLEMDS
1370     fail $SINGLEMDS
1371     sleep 2
1372     $CHECKSTAT -t file $DIR/$tdir/$tfile-* >/dev/null || return 1
1373     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1374     unlinkmany $DIR/$tdir/$tfile-%d 2500
1375     rmdir $DIR/$tdir
1376 }
1377 run_test 58a "test recovery from llog for setattr op (test llog_gen_rec)"
1378
1379 test_58b() {
1380     mount_client $MOUNT2
1381     mkdir -p $DIR/$tdir
1382     touch $DIR/$tdir/$tfile
1383     replay_barrier $SINGLEMDS
1384     setfattr -n trusted.foo -v bar $DIR/$tdir/$tfile
1385     fail $SINGLEMDS
1386     VAL=`getfattr --absolute-names --only-value -n trusted.foo $MOUNT2/$tdir/$tfile`
1387     [ x$VAL = x"bar" ] || return 1
1388     rm -f $DIR/$tdir/$tfile
1389     rmdir $DIR/$tdir
1390     zconf_umount `hostname` $MOUNT2
1391 }
1392 run_test 58b "test replay of setxattr op"
1393
1394 test_58c() { # bug 16570
1395         mount_client $MOUNT2
1396         mkdir -p $DIR/$tdir
1397         touch $DIR/$tdir/$tfile
1398         drop_request "setfattr -n trusted.foo -v bar $DIR/$tdir/$tfile" || \
1399                 return 1
1400         VAL=`getfattr --absolute-names --only-value -n trusted.foo $MOUNT2/$tdir/$tfile`
1401         [ x$VAL = x"bar" ] || return 2
1402         drop_reint_reply "setfattr -n trusted.foo1 -v bar1 $DIR/$tdir/$tfile" || \
1403                 return 3
1404         VAL=`getfattr --absolute-names --only-value -n trusted.foo1 $MOUNT2/$tdir/$tfile`
1405         [ x$VAL = x"bar1" ] || return 4
1406         rm -f $DIR/$tdir/$tfile
1407         rmdir $DIR/$tdir
1408         zconf_umount `hostname` $MOUNT2
1409 }
1410 run_test 58c "resend/reconstruct setxattr op"
1411
1412 # log_commit_thread vs filter_destroy race used to lead to import use after free
1413 # bug 11658
1414 test_59() {
1415     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1416
1417     mkdir -p $DIR/$tdir
1418     createmany -o $DIR/$tdir/$tfile-%d 200
1419     sync
1420     unlinkmany $DIR/$tdir/$tfile-%d 200
1421 #define OBD_FAIL_PTLRPC_DELAY_RECOV       0x507
1422     do_facet ost1 "lctl set_param fail_loc=0x507"
1423     fail ost1
1424     fail $SINGLEMDS
1425     do_facet ost1 "lctl set_param fail_loc=0x0"
1426     sleep 20
1427     rmdir $DIR/$tdir
1428 }
1429 run_test 59 "test log_commit_thread vs filter_destroy race"
1430
1431 # bug 17323
1432 test_59b() {
1433     mkdir -p $DIR/$tdir
1434     createmany -o $DIR/$tdir/$tfile-%d 2000
1435     sync
1436 #define OBD_FAIL_OBD_LOG_CANCEL_REP      0x606
1437     do_facet $SINGLEMDS "lctl set_param fail_loc=0x606"
1438     unlinkmany $DIR/$tdir/$tfile-%d 2000
1439     sleep 60
1440     do_facet $SINGLEMDS "lctl set_param fail_loc=0x0"
1441     do_facet $SINGLEMDS $LCTL dk | grep -q "RESENT cancel req" || return 1
1442     rmdir $DIR/$tdir
1443 }
1444 run_test 59b "resent handle in llog_origin_handle_cancel"
1445
1446 # race between add unlink llog vs cat log init in post_recovery (only for b1_6)
1447 # bug 12086: should no oops and No ctxt error for this test
1448 test_60() {
1449     mkdir -p $DIR/$tdir
1450     createmany -o $DIR/$tdir/$tfile-%d 200
1451     replay_barrier $SINGLEMDS
1452     unlinkmany $DIR/$tdir/$tfile-%d 0 100
1453     fail $SINGLEMDS
1454     unlinkmany $DIR/$tdir/$tfile-%d 100 100
1455     local no_ctxt=`dmesg | grep "No ctxt"`
1456     [ -z "$no_ctxt" ] || error "ctxt is not initialized in recovery"
1457 }
1458 run_test 60 "test llog post recovery init vs llog unlink"
1459
1460 #test race  llog recovery thread vs llog cleanup
1461 test_61a() {    # was test_61
1462     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1463
1464     mkdir $DIR/$tdir
1465     createmany -o $DIR/$tdir/$tfile-%d 800
1466     replay_barrier ost1 
1467 #   OBD_FAIL_OST_LLOG_RECOVERY_TIMEOUT 0x221 
1468     unlinkmany $DIR/$tdir/$tfile-%d 800 
1469     set_nodes_failloc "$(osts_nodes)" 0x80000221
1470     facet_failover ost1
1471     sleep 10 
1472     fail ost1
1473     sleep 30
1474     set_nodes_failloc "$(osts_nodes)" 0x0
1475     
1476     $CHECKSTAT -t file $DIR/$tdir/$tfile-* && return 1
1477     rmdir $DIR/$tdir
1478 }
1479 run_test 61a "test race llog recovery vs llog cleanup"
1480
1481 #test race  mds llog sync vs llog cleanup
1482 test_61b() {
1483 #   OBD_FAIL_MDS_LLOG_SYNC_TIMEOUT 0x140
1484     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000140"
1485     facet_failover $SINGLEMDS 
1486     sleep 10
1487     fail $SINGLEMDS
1488     do_facet client dd if=/dev/zero of=$DIR/$tfile bs=4k count=1 || return 1
1489 }
1490 run_test 61b "test race mds llog sync vs llog cleanup"
1491
1492 #test race  cancel cookie cb vs llog cleanup
1493 test_61c() {
1494     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1495
1496 #   OBD_FAIL_OST_CANCEL_COOKIE_TIMEOUT 0x222 
1497     touch $DIR/$tfile 
1498     set_nodes_failloc "$(osts_nodes)" 0x80000222
1499     rm $DIR/$tfile    
1500     sleep 10
1501     fail ost1
1502     set_nodes_failloc "$(osts_nodes)" 0x0
1503 }
1504 run_test 61c "test race mds llog sync vs llog cleanup"
1505
1506 test_62() { # Bug 15756 - don't mis-drop resent replay
1507     mkdir -p $DIR/$tdir
1508     replay_barrier $SINGLEMDS
1509     createmany -o $DIR/$tdir/$tfile- 25
1510 #define OBD_FAIL_TGT_REPLAY_DROP         0x706
1511     do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000707"
1512     facet_failover $SINGLEMDS
1513     df $MOUNT || return 1
1514     do_facet $SINGLEMDS "lctl set_param fail_loc=0"
1515     unlinkmany $DIR/$tdir/$tfile- 25 || return 2
1516     return 0
1517 }
1518 run_test 62 "don't mis-drop resent replay"
1519
1520 #Adaptive Timeouts (bug 3055)
1521 AT_MAX_SET=0
1522 # Suppose that all osts have the same at_max
1523 for facet in mds client ost; do
1524     eval AT_MAX_SAVE_${facet}=$(at_max_get $facet)
1525 done
1526
1527 at_start()
1528 {
1529     local at_max_new=600
1530     if ! at_is_valid; then
1531         skip "AT env is invalid"
1532         return 1
1533     fi
1534
1535     local at_max
1536
1537     for facet in mds client ost; do
1538         at_max=$(at_max_get $facet)
1539         if [ $at_max -ne $at_max_new ]; then
1540             echo "AT value on $facet is $at_max, set it by force temporarily to $at_max_new"
1541             at_max_set $at_max_new $facet
1542             AT_MAX_SET=1
1543         fi
1544     done
1545
1546     if [ -z "$ATOLDBASE" ]; then
1547         local at_history=$(do_facet mds "find /sys/ -name at_history")
1548         [ -z "$at_history" ] && skip "missing /sys/.../at_history " && return 1
1549         ATOLDBASE=$(do_facet mds "cat $at_history")
1550         # speed up the timebase so we can check decreasing AT
1551         do_facet mds "echo 8 >> $at_history"
1552         do_facet ost1 "echo 8 >> $at_history"
1553
1554         # sleep for a while to cool down, should be > 8s and also allow
1555         # at least one ping to be sent. simply use TIMEOUT to be safe.
1556         sleep $TIMEOUT
1557     fi
1558 }
1559
1560 test_65a() #bug 3055
1561 {
1562     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1563
1564     at_start || return 0
1565     $LCTL dk > /dev/null
1566     debugsave
1567     sysctl -w lnet.debug="+other"
1568     # Slow down a request to the current service time, this is critical
1569     # because previous tests may have caused this value to increase.
1570     REQ_DELAY=`lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts |
1571                awk '/portal 12/ {print $5}'`
1572     REQ_DELAY=$((${REQ_DELAY} + 5))
1573
1574     do_facet mds lctl set_param fail_val=$((${REQ_DELAY} * 1000))
1575 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1576     do_facet mds sysctl -w lustre.fail_loc=0x8000050a
1577     createmany -o $DIR/$tfile 10 > /dev/null
1578     unlinkmany $DIR/$tfile 10 > /dev/null
1579     # check for log message
1580     $LCTL dk | grep "Early reply #" || error "No early reply"
1581     debugrestore
1582     # client should show REQ_DELAY estimates
1583     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1584     sleep 9
1585     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep portal
1586 }
1587 run_test 65a "AT: verify early replies"
1588
1589 test_65b() #bug 3055
1590 {
1591     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1592
1593     at_start || return 0
1594     # turn on D_ADAPTTO
1595     debugsave
1596     sysctl -w lnet.debug="other trace"
1597     $LCTL dk > /dev/null
1598     # Slow down a request to the current service time, this is critical
1599     # because previous tests may have caused this value to increase.
1600     REQ_DELAY=`lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts |
1601                awk '/portal 6/ {print $5}'`
1602     REQ_DELAY=$((${REQ_DELAY} + 5))
1603
1604     do_facet ost1 lctl set_param fail_val=${REQ_DELAY}
1605 #define OBD_FAIL_OST_BRW_PAUSE_PACK      0x224
1606     do_facet ost1 sysctl -w lustre.fail_loc=0x224
1607
1608     rm -f $DIR/$tfile
1609     lfs setstripe $DIR/$tfile --index=0 --count=1
1610     # force some real bulk transfer
1611     multiop $DIR/$tfile oO_CREAT:O_RDWR:O_SYNC:w4096c
1612
1613     do_facet ost1 sysctl -w lustre.fail_loc=0
1614     # check for log message
1615     $LCTL dk | grep "Early reply #" || error "No early reply"
1616     debugrestore
1617     # client should show REQ_DELAY estimates
1618     lctl get_param -n osc.${FSNAME}-OST0000-osc-*.timeouts | grep portal
1619 }
1620 run_test 65b "AT: verify early replies on packed reply / bulk"
1621
1622 test_66a() #bug 3055
1623 {
1624     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1625
1626     at_start || return 0
1627     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1628     # adjust 5s at a time so no early reply is sent (within deadline)
1629     do_facet mds "sysctl -w lustre.fail_val=5000"
1630 #define OBD_FAIL_PTLRPC_PAUSE_REQ        0x50a
1631     do_facet mds "sysctl -w lustre.fail_loc=0x8000050a"
1632     createmany -o $DIR/$tfile 20 > /dev/null
1633     unlinkmany $DIR/$tfile 20 > /dev/null
1634     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1635     do_facet mds "sysctl -w lustre.fail_val=10000"
1636     do_facet mds "sysctl -w lustre.fail_loc=0x8000050a"
1637     createmany -o $DIR/$tfile 20 > /dev/null
1638     unlinkmany $DIR/$tfile 20 > /dev/null
1639     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1640     do_facet mds "sysctl -w lustre.fail_loc=0"
1641     sleep 9
1642     createmany -o $DIR/$tfile 20 > /dev/null
1643     unlinkmany $DIR/$tfile 20 > /dev/null
1644     lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | grep "portal 12"
1645     CUR=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $5}')
1646     WORST=$(lctl get_param -n mdc.${FSNAME}-MDT0000-mdc-*.timeouts | awk '/portal 12/ {print $7}')
1647     echo "Current MDT timeout $CUR, worst $WORST"
1648     [ $CUR -lt $WORST ] || error "Current $CUR should be less than worst $WORST"
1649 }
1650 run_test 66a "AT: verify MDT service time adjusts with no early replies"
1651
1652 test_66b() #bug 3055
1653 {
1654     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1655
1656     at_start || return 0
1657     ORIG=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $4}')
1658     sysctl -w lustre.fail_val=$(($ORIG + 5))
1659 #define OBD_FAIL_PTLRPC_PAUSE_REP      0x50c
1660     sysctl -w lustre.fail_loc=0x50c
1661     ls $DIR/$tfile > /dev/null 2>&1
1662     sysctl -w lustre.fail_loc=0
1663     CUR=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $4}')
1664     WORST=$(lctl get_param -n mdc.${FSNAME}-*.timeouts | awk '/network/ {print $6}')
1665     echo "network timeout orig $ORIG, cur $CUR, worst $WORST"
1666     [ $WORST -gt $ORIG ] || error "Worst $WORST should be worse than orig $ORIG"
1667 }
1668 run_test 66b "AT: verify net latency adjusts"
1669
1670 test_67a() #bug 3055
1671 {
1672     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1673
1674     at_start || return 0
1675     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1676     # sleeping threads may drive values above this
1677     do_facet ost1 "sysctl -w lustre.fail_val=400"
1678 #define OBD_FAIL_PTLRPC_PAUSE_REQ    0x50a
1679     do_facet ost1 "sysctl -w lustre.fail_loc=0x50a"
1680     createmany -o $DIR/$tfile 20 > /dev/null
1681     unlinkmany $DIR/$tfile 20 > /dev/null
1682     do_facet ost1 "sysctl -w lustre.fail_loc=0"
1683     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1684     ATTEMPTS=$(($CONN2 - $CONN1))
1685     echo "$ATTEMPTS osc reconnect attemps on gradual slow"
1686     [ $ATTEMPTS -gt 0 ] && error_ignore 13721 "AT should have prevented reconnect"
1687     return 0
1688 }
1689 run_test 67a "AT: verify slow request processing doesn't induce reconnects"
1690
1691 test_67b() #bug 3055
1692 {
1693     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1694
1695     at_start || return 0
1696     CONN1=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1697 #define OBD_FAIL_OST_PAUSE_CREATE        0x223
1698     do_facet ost1 "sysctl -w lustre.fail_val=20000"
1699     do_facet ost1 "sysctl -w lustre.fail_loc=0x80000223"
1700     cp /etc/profile $DIR/$tfile || error "cp failed"
1701     client_reconnect
1702     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1703     log "phase 2"
1704     CONN2=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1705     ATTEMPTS=$(($CONN2 - $CONN1))
1706     echo "$ATTEMPTS osc reconnect attemps on instant slow"
1707     # do it again; should not timeout
1708     do_facet ost1 "sysctl -w lustre.fail_loc=0x80000223"
1709     cp /etc/profile $DIR/$tfile || error "cp failed"
1710     do_facet ost1 "sysctl -w lustre.fail_loc=0"
1711     client_reconnect
1712     do_facet ost1 "lctl get_param -n ost.OSS.ost_create.timeouts"
1713     CONN3=$(lctl get_param -n osc.*.stats | awk '/_connect/ {total+=$2} END {print total}')
1714     ATTEMPTS=$(($CONN3 - $CONN2))
1715     echo "$ATTEMPTS osc reconnect attemps on 2nd slow"
1716     [ $ATTEMPTS -gt 0 ] && error "AT should have prevented reconnect"
1717     return 0
1718 }
1719 run_test 67b "AT: verify instant slowdown doesn't induce reconnects"
1720
1721 test_68 () #bug 13813
1722 {
1723     remote_ost_nodsh && skip "remote OST with nodsh" && return 0
1724
1725     at_start || return 0
1726     local ldlm_enqueue_min=$(find /sys -name ldlm_enqueue_min)
1727     [ -z "$ldlm_enqueue_min" ] && skip "missing /sys/.../ldlm_enqueue_min" && return 0
1728     local ENQ_MIN=$(cat $ldlm_enqueue_min)
1729     echo $TIMEOUT >> $ldlm_enqueue_min
1730     rm -f $DIR/${tfile}_[1-2]
1731     lfs setstripe $DIR/$tfile --index=0 --count=1
1732 #define OBD_FAIL_LDLM_PAUSE_CANCEL       0x312
1733     sysctl -w lustre.fail_val=$(($TIMEOUT - 1))
1734     sysctl -w lustre.fail_loc=0x80000312
1735     cp /etc/profile $DIR/${tfile}_1 || error "1st cp failed $?"
1736     sysctl -w lustre.fail_val=$((TIMEOUT * 3 / 2))
1737     sysctl -w lustre.fail_loc=0x80000312
1738     cp /etc/profile $DIR/${tfile}_2 || error "2nd cp failed $?"
1739     sysctl -w lustre.fail_loc=0
1740     echo $ENQ_MIN >> $ldlm_enqueue_min
1741     return 0
1742 }
1743 run_test 68 "AT: verify slowing locks"
1744
1745 if [ -n "$ATOLDBASE" ]; then
1746     at_history=$(do_facet mds "find /sys/ -name at_history")
1747     do_facet mds "echo $ATOLDBASE >> $at_history" || true
1748     do_facet ost1 "echo $ATOLDBASE >> $at_history" || true
1749 fi
1750
1751 if [ $AT_MAX_SET -ne 0 ]; then
1752     for facet in mds client ost; do
1753         var=AT_MAX_SAVE_${facet}
1754         echo restore AT on $facet to saved value ${!var}
1755         at_max_set ${!var} $facet
1756         AT_NEW=$(at_max_get $facet)
1757         echo Restored AT value on $facet $AT_NEW 
1758         [ $AT_NEW -ne ${!var} ] && \
1759             error "$facet : AT value was not restored SAVED ${!var} NEW $AT_NEW"
1760     done
1761 fi
1762
1763 # end of AT tests includes above lines
1764
1765
1766 # start multi-client tests
1767 test_70a () {
1768         [ -z "$CLIENTS" ] && \
1769                 { skip "Need two or more clients." && return; }
1770         [ $CLIENTCOUNT -lt 2 ] && \
1771                 { skip "Need two or more clients, have $CLIENTCOUNT" && return; }
1772
1773         echo "mount clients $CLIENTS ..."
1774         zconf_mount_clients $CLIENTS $DIR
1775
1776         local clients=${CLIENTS//,/ }
1777         echo "Write/read files on $DIR ; clients $CLIENTS ... "
1778         for CLIENT in $clients; do
1779                 do_node $CLIENT dd bs=1M count=10 if=/dev/zero \
1780                         of=$DIR/${tfile}_${CLIENT} 2>/dev/null || \
1781                                 error "dd failed on $CLIENT"
1782         done
1783
1784         local prev_client=$(echo $clients | sed 's/^.* \(.\+\)$/\1/') 
1785         for C in ${CLIENTS//,/ }; do
1786                 do_node $prev_client dd if=$DIR/${tfile}_${C} of=/dev/null 2>/dev/null || \
1787                         error "dd if=$DIR/${tfile}_${C} failed on $prev_client"
1788                 prev_client=$C
1789         done
1790         
1791         ls $DIR
1792 }
1793 run_test 70a "check multi client t-f"
1794
1795 test_70b () {
1796         [ -z "$CLIENTS" ] && \
1797                 { skip "Need two or more clients." && return; }
1798         [ $CLIENTCOUNT -lt 2 ] && \
1799                 { skip "Need two or more clients, have $CLIENTCOUNT" && return; }
1800
1801         zconf_mount_clients $CLIENTS $DIR
1802         
1803         local duration="-t 60"
1804         local cmd="rundbench 1 $duration "
1805         local PID=""
1806         for CLIENT in ${CLIENTS//,/ }; do
1807                 $PDSH $CLIENT "set -x; PATH=:$PATH:$LUSTRE/utils:$LUSTRE/tests/:${DBENCH_LIB} DBENCH_LIB=${DBENCH_LIB} $cmd" &
1808                 PID=$!
1809                 echo $PID >pid.$CLIENT
1810                 echo "Started load PID=`cat pid.$CLIENT`"
1811         done
1812
1813         replay_barrier $SINGLEMDS 
1814         sleep 3 # give clients a time to do operations
1815
1816         log "$TESTNAME fail mds 1"
1817         fail $SINGLEMDS
1818
1819 # wait for client to reconnect to MDS
1820         sleep $TIMEOUT
1821
1822         for CLIENT in ${CLIENTS//,/ }; do
1823                 PID=`cat pid.$CLIENT`
1824                 wait $PID
1825                 rc=$?
1826                 echo "load on ${CLIENT} returned $rc"
1827         done
1828
1829 }
1830 run_test 70b "mds recovery; $CLIENTCOUNT clients"
1831 # end multi-client tests
1832
1833 test_80a() {
1834     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1835
1836     mkdir -p $DIR/$tdir
1837     replay_barrier mds2
1838     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir $DIR/$tdir failed"
1839     rmdir $DIR/$tdir || error "rmdir $DIR/$tdir failed"
1840     fail mds2
1841     stat $DIR/$tdir
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
1854 }
1855 run_test 80b "CMD: unlink cross-node dir (fail mds with name)"
1856
1857 test_81a() {
1858     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1859
1860     mkdir -p $DIR/$tdir
1861     createmany -o $DIR/$tdir/f 3000 || error "createmany failed"
1862     sleep 10
1863     $CHECKSTAT -t dir $DIR/$tdir || error "$CHECKSTAT -t dir failed"
1864     $CHECKSTAT -t file $DIR/$tdir/f1002 || error "$CHECKSTAT -t file failed"
1865     replay_barrier mds1
1866     rm $DIR/$tdir/f1002 || error "rm $DIR/$tdir/f1002 failed"
1867     fail mds1
1868     stat $DIR/$tdir/f1002
1869 }
1870 run_test 81a "CMD: unlink cross-node file (fail mds with name)"
1871
1872 test_82a() {
1873     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1874
1875     local dir=$DIR/d82a
1876     replay_barrier mds2
1877     mkdir $dir || error "mkdir $dir failed"
1878     log "FAILOVER mds2"
1879     fail mds2
1880     stat $DIR
1881     $CHECKSTAT -t dir $dir || error "$CHECKSTAT -t dir $dir failed"
1882 }
1883 run_test 82a "CMD: mkdir cross-node dir (fail mds with inode)"
1884
1885 test_82b() {
1886     [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
1887
1888     local dir=$DIR/d82b
1889     replay_barrier mds1
1890     mkdir $dir || error "mkdir $dir failed"
1891     log "FAILOVER mds1"
1892     fail mds1
1893     stat $DIR
1894     $CHECKSTAT -t dir $dir || error "$CHECKSTAT -t dir $dir failed"
1895 }
1896 run_test 82b "CMD: mkdir cross-node dir (fail mds with name)"
1897
1898 equals_msg `basename $0`: test complete, cleaning up
1899 check_and_cleanup_lustre
1900 [ -f "$TESTSUITELOG" ] && cat $TESTSUITELOG || true