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