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