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