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