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