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