Whamcloud - gitweb
b=12499
[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
10 LUSTRE=${LUSTRE:-`dirname $0`/..}
11 . $LUSTRE/tests/test-framework.sh
12 init_test_env $@
13 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
14
15
16 # Skip these tests
17 # bug number:  4176 
18 ALWAYS_EXCEPT="39   $REPLAY_SINGLE_EXCEPT"
19
20 gen_config() {
21     rm -f $XMLCONFIG
22     add_mds mds --dev $MDSDEV --size $MDSSIZE
23     if [ ! -z "$mdsfailover_HOST" ]; then
24          add_mdsfailover mds --dev $MDSDEV --size $MDSSIZE
25     fi
26     
27     add_lov lov1 mds --stripe_sz $STRIPE_BYTES \
28         --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
29     add_ost ost --lov lov1 --dev `ostdevname 1` --size $OSTSIZE
30     add_ost ost2 --lov lov1 --dev `ostdevname 2` --size $OSTSIZE
31     add_client client mds --lov lov1 --path $MOUNT
32 }
33
34 build_test_filter
35
36 SETUP=${SETUP:-"setup"}
37 CLEANUP=${CLEANUP:-"cleanupall"}
38
39 if [ "$ONLY" == "cleanup" ]; then
40     sysctl -w lnet.debug=0 || true
41     $CLEANUP
42     exit 0
43 fi
44
45 setup() {
46     [ "$REFORMAT" ] && formatall
47     setupall
48 }
49
50 $SETUP
51
52 if [ "$ONLY" == "setup" ]; then
53     exit 0
54 fi
55
56 mkdir -p $DIR
57
58 test_0() {
59     replay_barrier mds
60     fail mds
61 }
62 run_test 0 "empty replay"
63
64 test_0b() {
65     # this test attempts to trigger a race in the precreation code, 
66     # and must run before any other objects are created on the filesystem
67     fail ost1
68     createmany -o $DIR/$tfile 20 || return 1
69     unlinkmany $DIR/$tfile 20 || return 2
70 }
71 run_test 0b "ensure object created after recover exists. (3284)"
72
73 test_1() {
74     replay_barrier mds
75     mcreate $DIR/$tfile
76     fail mds
77     $CHECKSTAT -t file $DIR/$tfile || return 1
78     rm $DIR/$tfile
79 }
80 run_test 1 "simple create"
81
82 test_1a() {
83     do_facet ost1 "sysctl -w lustre.fail_loc=0"
84
85     rm -fr $DIR/$tfile
86     local old_last_id=`cat $LPROC/obdfilter/*/last_id`
87     touch -o $DIR/$tfile 1
88     sync
89     local new_last_id=`cat $LPROC/obdfilter/*/last_id`
90     
91     test "$old_last_id" = "$new_last_id" || {
92         echo "OST object create is caused by MDS"
93         return 1
94     }
95     
96     old_last_id=`cat $LPROC/obdfilter/*/last_id`
97     echo "data" > $DIR/$tfile
98     sync
99     new_last_id=`cat $LPROC/obdfilter/*/last_id`
100     test "$old_last_id" = "$new_last_id "&& {
101         echo "CROW does not work on write"
102         return 1
103     }
104     
105     rm -fr $DIR/$tfile
106
107 #define OBD_FAIL_OST_CROW_EIO | OBD_FAIL_ONCE
108     do_facet ost1 "sysctl -w lustre.fail_loc=0x80000801"
109
110     rm -fr $DIR/1a1
111     old_last_id=`cat $LPROC/obdfilter/*/last_id`
112     echo "data" > $DIR/1a1
113     sync
114     new_last_id=`cat $LPROC/obdfilter/*/last_id`
115     test "$old_last_id" = "$new_last_id" || {
116         echo "CROW does work with fail_loc=0x80000801"
117         return 1
118     }
119     
120     rm -fr $DIR/1a1
121     
122     do_facet ost1 "sysctl -w lustre.fail_loc=0"
123 }
124 #CROW run_test 1a "CROW object create (check OST last_id)"
125
126 test_2a() {
127     replay_barrier mds
128     touch $DIR/$tfile
129     fail mds
130     $CHECKSTAT -t file $DIR/$tfile || return 1
131     rm $DIR/$tfile
132 }
133 run_test 2a "touch"
134
135 test_2b() {
136     ./mcreate $DIR/$tfile
137     replay_barrier mds
138     touch $DIR/$tfile
139     fail mds
140     $CHECKSTAT -t file $DIR/$tfile || return 1
141     rm $DIR/$tfile
142 }
143 run_test 2b "touch"
144
145 test_3a() {
146     replay_barrier mds
147     mcreate $DIR/$tfile
148     o_directory $DIR/$tfile
149     fail mds
150     $CHECKSTAT -t file $DIR/$tfile || return 2
151     rm $DIR/$tfile
152 }
153 run_test 3a "replay failed open(O_DIRECTORY)"
154
155 test_3b() {
156     replay_barrier mds
157 #define OBD_FAIL_MDS_OPEN_PACK | OBD_FAIL_ONCE
158     do_facet mds "sysctl -w lustre.fail_loc=0x80000114"
159     touch $DIR/$tfile
160     do_facet mds "sysctl -w lustre.fail_loc=0"
161     fail mds
162     $CHECKSTAT -t file $DIR/$tfile && return 2
163     return 0
164 }
165 run_test 3b "replay failed open -ENOMEM"
166
167 test_3c() {
168     replay_barrier mds
169 #define OBD_FAIL_MDS_ALLOC_OBDO | OBD_FAIL_ONCE
170     do_facet mds "sysctl -w lustre.fail_loc=0x80000128"
171     touch $DIR/$tfile
172     do_facet mds "sysctl -w lustre.fail_loc=0"
173     fail mds
174
175     $CHECKSTAT -t file $DIR/$tfile && return 2
176     return 0
177 }
178 run_test 3c "replay failed open -ENOMEM"
179
180 test_4() {
181     replay_barrier mds
182     for i in `seq 10`; do
183         echo "tag-$i" > $DIR/$tfile-$i
184     done 
185     fail mds
186     for i in `seq 10`; do
187       grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
188     done 
189 }
190 run_test 4 "|x| 10 open(O_CREAT)s"
191
192 test_4b() {
193     replay_barrier mds
194     rm -rf $DIR/$tfile-*
195     fail mds
196     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
197 }
198 run_test 4b "|x| rm 10 files"
199
200 # The idea is to get past the first block of precreated files on both 
201 # osts, and then replay.
202 test_5() {
203     replay_barrier mds
204     for i in `seq 220`; do
205         echo "tag-$i" > $DIR/$tfile-$i
206     done 
207     fail mds
208     for i in `seq 220`; do
209       grep -q "tag-$i" $DIR/$tfile-$i || error "f1c-$i"
210     done 
211     rm -rf $DIR/$tfile-*
212     sleep 3
213     # waiting for commitment of removal
214 }
215 run_test 5 "|x| 220 open(O_CREAT)"
216
217
218 test_6() {
219     replay_barrier mds
220     mkdir $DIR/$tdir
221     mcreate $DIR/$tdir/$tfile
222     fail mds
223     $CHECKSTAT -t dir $DIR/$tdir || return 1
224     $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
225     sleep 2
226     # waiting for log process thread
227 }
228 run_test 6 "mkdir + contained create"
229
230 test_6b() {
231     replay_barrier mds
232     rm -rf $DIR/$tdir
233     fail mds
234     $CHECKSTAT -t dir $DIR/$tdir && return 1 || true 
235 }
236 run_test 6b "|X| rmdir"
237
238 test_7() {
239     mkdir $DIR/$tdir
240     replay_barrier mds
241     mcreate $DIR/$tdir/$tfile
242     fail mds
243     $CHECKSTAT -t dir $DIR/$tdir || return 1
244     $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
245     rm -fr $DIR/$tdir
246 }
247 run_test 7 "mkdir |X| contained create"
248
249 test_8() {
250     replay_barrier mds
251     multiop $DIR/$tfile mo_c &
252     MULTIPID=$!
253     sleep 1
254     fail mds
255     ls $DIR/$tfile
256     $CHECKSTAT -t file $DIR/$tfile || return 1
257     kill -USR1 $MULTIPID || return 2
258     wait $MULTIPID || return 3
259     rm $DIR/$tfile
260 }
261 run_test 8 "creat open |X| close"
262
263 test_9() {
264     replay_barrier mds
265     mcreate $DIR/$tfile
266     local old_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
267     fail mds
268     local new_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
269
270     echo " old_inum == $old_inum, new_inum == $new_inum"
271     if [ $old_inum -eq $new_inum  ] ;
272     then
273         echo " old_inum and new_inum match"
274     else
275         echo "!!!! old_inum and new_inum NOT match"
276         return 1
277     fi
278     rm $DIR/$tfile
279 }
280 run_test 9  "|X| create (same inum/gen)"
281
282 test_10() {
283     mcreate $DIR/$tfile
284     replay_barrier mds
285     mv $DIR/$tfile $DIR/$tfile-2
286     rm -f $DIR/$tfile
287     fail mds
288     $CHECKSTAT $DIR/$tfile && return 1
289     $CHECKSTAT $DIR/$tfile-2 ||return 2
290     rm $DIR/$tfile-2
291     return 0
292 }
293 run_test 10 "create |X| rename unlink"
294
295 test_11() {
296     mcreate $DIR/$tfile
297     echo "old" > $DIR/$tfile
298     mv $DIR/$tfile $DIR/$tfile-2
299     replay_barrier mds
300     echo "new" > $DIR/$tfile
301     grep new $DIR/$tfile 
302     grep old $DIR/$tfile-2
303     fail mds
304     grep new $DIR/$tfile || return 1
305     grep old $DIR/$tfile-2 || return 2
306 }
307 run_test 11 "create open write rename |X| create-old-name read"
308
309 test_12() {
310     mcreate $DIR/$tfile 
311     multiop $DIR/$tfile o_tSc &
312     pid=$!
313     # give multiop a chance to open
314     sleep 1
315     rm -f $DIR/$tfile
316     replay_barrier mds
317     kill -USR1 $pid
318     wait $pid || return 1
319
320     fail mds
321     [ -e $DIR/$tfile ] && return 2
322     return 0
323 }
324 run_test 12 "open, unlink |X| close"
325
326
327 # 1777 - replay open after committed chmod that would make
328 #        a regular open a failure    
329 test_13() {
330     mcreate $DIR/$tfile 
331     multiop $DIR/$tfile O_wc &
332     pid=$!
333     # give multiop a chance to open
334     sleep 1 
335     chmod 0 $DIR/$tfile
336     $CHECKSTAT -p 0 $DIR/$tfile
337     replay_barrier mds
338     fail mds
339     kill -USR1 $pid
340     wait $pid || return 1
341
342     $CHECKSTAT -s 1 -p 0 $DIR/$tfile || return 2
343     return 0
344 }
345 run_test 13 "open chmod 0 |x| write close"
346
347 test_14() {
348     multiop $DIR/$tfile O_tSc &
349     pid=$!
350     # give multiop a chance to open
351     sleep 1 
352     rm -f $DIR/$tfile
353     replay_barrier mds
354     kill -USR1 $pid || return 1
355     wait $pid || return 2
356
357     fail mds
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 $DIR/$tfile O_tSc &
365     pid=$!
366     # give multiop a chance to open
367     sleep 1 
368     rm -f $DIR/$tfile
369     replay_barrier mds
370     touch $DIR/g11 || return 1
371     kill -USR1 $pid
372     wait $pid || return 2
373
374     fail mds
375     [ -e $DIR/$tfile ] && return 3
376     touch $DIR/h11 || return 4
377     return 0
378 }
379 run_test 15 "open(O_CREAT), unlink |X|  touch new, close"
380
381
382 test_16() {
383     replay_barrier mds
384     mcreate $DIR/$tfile
385     munlink $DIR/$tfile
386     mcreate $DIR/$tfile-2
387     fail mds
388     [ -e $DIR/$tfile ] && return 1
389     [ -e $DIR/$tfile-2 ] || return 2
390     munlink $DIR/$tfile-2 || return 3
391 }
392 run_test 16 "|X| open(O_CREAT), unlink, touch new,  unlink new"
393
394 test_17() {
395     replay_barrier mds
396     multiop $DIR/$tfile O_c &
397     pid=$!
398     # give multiop a chance to open
399     sleep 1 
400     fail mds
401     kill -USR1 $pid || return 1
402     wait $pid || return 2
403     $CHECKSTAT -t file $DIR/$tfile || return 3
404     rm $DIR/$tfile
405 }
406 run_test 17 "|X| open(O_CREAT), |replay| close"
407
408 test_18() {
409     replay_barrier mds
410     multiop $DIR/$tfile O_tSc &
411     pid=$!
412     # give multiop a chance to open
413     sleep 1 
414     rm -f $DIR/$tfile
415     touch $DIR/$tfile-2 || return 1
416     echo "pid: $pid will close"
417     kill -USR1 $pid
418     wait $pid || return 2
419
420     fail mds
421     [ -e $DIR/$tfile ] && return 3
422     [ -e $DIR/$tfile-2 ] || return 4
423     # this touch frequently fails
424     touch $DIR/$tfile-3 || return 5
425     munlink $DIR/$tfile-2 || return 6
426     munlink $DIR/$tfile-3 || return 7
427     return 0
428 }
429 run_test 18 "|X| open(O_CREAT), unlink, touch new, close, touch, unlink"
430
431 # bug 1855 (a simpler form of test_11 above)
432 test_19() {
433     replay_barrier mds
434     mcreate $DIR/$tfile
435     echo "old" > $DIR/$tfile
436     mv $DIR/$tfile $DIR/$tfile-2
437     grep old $DIR/$tfile-2
438     fail mds
439     grep old $DIR/$tfile-2 || return 2
440 }
441 run_test 19 "|X| mcreate, open, write, rename "
442
443 test_20() {
444     replay_barrier mds
445     multiop $DIR/$tfile O_tSc &
446     pid=$!
447     # give multiop a chance to open
448     sleep 1 
449     rm -f $DIR/$tfile
450
451     fail mds
452     kill -USR1 $pid
453     wait $pid || return 1
454     [ -e $DIR/$tfile ] && return 2
455     return 0
456 }
457 run_test 20 "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
458
459 test_20b() { # bug 10480
460     BEFOREUSED=`df -P $DIR | tail -1 | awk '{ print $3 }'`
461
462     dd if=/dev/zero of=$DIR/$tfile bs=4k count=10000 &
463     pid=$!
464     while [ ! -e $DIR/$tfile ] ; do
465         usleep 60                           # give dd a chance to start
466     done
467
468     lfs getstripe $DIR/$tfile || return 1
469     rm -f $DIR/$tfile || return 2       # make it an orphan
470     mds_evict_client
471     df -P $DIR || df -P $DIR || true    # reconnect
472
473     fail mds                            # start orphan recovery
474     df -P $DIR || df -P $DIR || true    # reconnect
475     sleep 2
476
477     AFTERUSED=`df -P $DIR | tail -1 | awk '{ print $3 }'`
478     log "before $BEFOREUSED, after $AFTERUSED"
479     [ $AFTERUSED -gt $((BEFOREUSED + 20)) ] && \
480         error "after $AFTERUSED > before $BEFOREUSED" && return 5
481     return 0
482 }
483 run_test 20b "write, unlink, eviction, replay, (test mds_cleanup_orphans)"
484
485 test_20c() { # bug 10480
486     dd if=/dev/zero of=$DIR/$tfile bs=4k count=10000
487
488     exec 100< $DIR/$tfile
489
490     ls -la $DIR/$tfile
491
492     mds_evict_client
493
494     df -P $DIR || df -P $DIR || true    # reconnect
495
496     exec 100<&-
497
498     test -s $DIR/$tfile || error "File was truncated"
499
500     return 0
501 }
502 run_test 20c "check that client eviction does not affect file content"
503
504 test_21() {
505     replay_barrier mds
506     multiop $DIR/$tfile O_tSc &
507     pid=$!
508     # give multiop a chance to open
509     sleep 1 
510     rm -f $DIR/$tfile
511     touch $DIR/g11 || return 1
512
513     fail mds
514     kill -USR1 $pid
515     wait $pid || return 2
516     [ -e $DIR/$tfile ] && return 3
517     touch $DIR/h11 || return 4
518     return 0
519 }
520 run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"
521
522 test_22() {
523     multiop $DIR/$tfile O_tSc &
524     pid=$!
525     # give multiop a chance to open
526     sleep 1 
527
528     replay_barrier mds
529     rm -f $DIR/$tfile
530
531     fail mds
532     kill -USR1 $pid
533     wait $pid || return 1
534     [ -e $DIR/$tfile ] && return 2
535     return 0
536 }
537 run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"
538
539 test_23() {
540     multiop $DIR/$tfile O_tSc &
541     pid=$!
542     # give multiop a chance to open
543     sleep 1 
544
545     replay_barrier mds
546     rm -f $DIR/$tfile
547     touch $DIR/g11 || return 1
548
549     fail mds
550     kill -USR1 $pid
551     wait $pid || return 2
552     [ -e $DIR/$tfile ] && return 3
553     touch $DIR/h11 || return 4
554     return 0
555 }
556 run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"
557
558 test_24() {
559     multiop $DIR/$tfile O_tSc &
560     pid=$!
561     # give multiop a chance to open
562     sleep 1 
563
564     replay_barrier mds
565     fail mds
566     rm -f $DIR/$tfile
567     kill -USR1 $pid
568     wait $pid || return 1
569     [ -e $DIR/$tfile ] && return 2
570     return 0
571 }
572 run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"
573
574 test_25() {
575     multiop $DIR/$tfile O_tSc &
576     pid=$!
577     # give multiop a chance to open
578     sleep 1 
579     rm -f $DIR/$tfile
580
581     replay_barrier mds
582     fail mds
583     kill -USR1 $pid
584     wait $pid || return 1
585     [ -e $DIR/$tfile ] && return 2
586     return 0
587 }
588 run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
589
590 test_26() {
591     replay_barrier mds
592     multiop $DIR/$tfile-1 O_tSc &
593     pid1=$!
594     multiop $DIR/$tfile-2 O_tSc &
595     pid2=$!
596     # give multiop a chance to open
597     sleep 1 
598     rm -f $DIR/$tfile-1
599     rm -f $DIR/$tfile-2
600     kill -USR1 $pid2
601     wait $pid2 || return 1
602
603     fail mds
604     kill -USR1 $pid1
605     wait $pid1 || return 2
606     [ -e $DIR/$tfile-1 ] && return 3
607     [ -e $DIR/$tfile-2 ] && return 4
608     return 0
609 }
610 run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"
611
612 test_27() {
613     replay_barrier mds
614     multiop $DIR/$tfile-1 O_tSc &
615     pid1=$!
616     multiop $DIR/$tfile-2 O_tSc &
617     pid2=$!
618     # give multiop a chance to open
619     sleep 1 
620     rm -f $DIR/$tfile-1
621     rm -f $DIR/$tfile-2
622
623     fail mds
624     kill -USR1 $pid1
625     wait $pid1 || return 1
626     kill -USR1 $pid2
627     wait $pid2 || return 2
628     [ -e $DIR/$tfile-1 ] && return 3
629     [ -e $DIR/$tfile-2 ] && return 4
630     return 0
631 }
632 run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"
633
634 test_28() {
635     multiop $DIR/$tfile-1 O_tSc &
636     pid1=$!
637     multiop $DIR/$tfile-2 O_tSc &
638     pid2=$!
639     # give multiop a chance to open
640     sleep 1 
641     replay_barrier mds
642     rm -f $DIR/$tfile-1
643     rm -f $DIR/$tfile-2
644     kill -USR1 $pid2
645     wait $pid2 || return 1
646
647     fail mds
648     kill -USR1 $pid1
649     wait $pid1 || return 2
650     [ -e $DIR/$tfile-1 ] && return 3
651     [ -e $DIR/$tfile-2 ] && return 4
652     return 0
653 }
654 run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"
655
656 test_29() {
657     multiop $DIR/$tfile-1 O_tSc &
658     pid1=$!
659     multiop $DIR/$tfile-2 O_tSc &
660     pid2=$!
661     # give multiop a chance to open
662     sleep 1 
663     replay_barrier mds
664     rm -f $DIR/$tfile-1
665     rm -f $DIR/$tfile-2
666
667     fail mds
668     kill -USR1 $pid1
669     wait $pid1 || return 1
670     kill -USR1 $pid2
671     wait $pid2 || return 2
672     [ -e $DIR/$tfile-1 ] && return 3
673     [ -e $DIR/$tfile-2 ] && return 4
674     return 0
675 }
676 run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"
677
678 test_30() {
679     multiop $DIR/$tfile-1 O_tSc &
680     pid1=$!
681     multiop $DIR/$tfile-2 O_tSc &
682     pid2=$!
683     # give multiop a chance to open
684     sleep 1 
685     rm -f $DIR/$tfile-1
686     rm -f $DIR/$tfile-2
687
688     replay_barrier mds
689     fail mds
690     kill -USR1 $pid1
691     wait $pid1 || return 1
692     kill -USR1 $pid2
693     wait $pid2 || return 2
694     [ -e $DIR/$tfile-1 ] && return 3
695     [ -e $DIR/$tfile-2 ] && return 4
696     return 0
697 }
698 run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"
699
700 test_31() {
701     multiop $DIR/$tfile-1 O_tSc &
702     pid1=$!
703     multiop $DIR/$tfile-2 O_tSc &
704     pid2=$!
705     # give multiop a chance to open
706     sleep 1 
707     rm -f $DIR/$tfile-1
708
709     replay_barrier mds
710     rm -f $DIR/$tfile-2
711     fail mds
712     kill -USR1 $pid1
713     wait $pid1 || return 1
714     kill -USR1 $pid2
715     wait $pid2 || return 2
716     [ -e $DIR/$tfile-1 ] && return 3
717     [ -e $DIR/$tfile-2 ] && return 4
718     return 0
719 }
720 run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"
721
722 # tests for bug 2104; completion without crashing is success.  The close is
723 # stale, but we always return 0 for close, so the app never sees it.
724 test_32() {
725     multiop $DIR/$tfile O_c &
726     pid1=$!
727     multiop $DIR/$tfile O_c &
728     pid2=$!
729     # give multiop a chance to open
730     sleep 1
731     mds_evict_client
732     df $MOUNT || sleep 1 && df $MOUNT || return 1
733     kill -USR1 $pid1
734     kill -USR1 $pid2
735     sleep 1
736     return 0
737 }
738 run_test 32 "close() notices client eviction; close() after client eviction"
739
740 # Abort recovery before client complete
741 test_33() {
742     replay_barrier mds
743     createmany -o $DIR/$tfile-%d 100 
744     fail_abort mds
745     # this file should be gone, because the replay was aborted
746     $CHECKSTAT -t file $DIR/$tfile-* && return 3 
747     unlinkmany $DIR/$tfile-%d 0 100
748     return 0
749 }
750 run_test 33 "abort recovery before client does replay"
751
752 test_34() {
753     multiop $DIR/$tfile O_c &
754     pid=$!
755     # give multiop a chance to open
756     sleep 1 
757     rm -f $DIR/$tfile
758
759     replay_barrier mds
760     fail_abort mds
761     kill -USR1 $pid
762     [ -e $DIR/$tfile ] && return 1
763     sync
764     return 0
765 }
766 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
767
768 # bug 2278 - generate one orphan on OST, then destroy it during recovery from llog 
769 test_35() {
770     touch $DIR/$tfile
771
772 #define OBD_FAIL_MDS_REINT_NET_REP       0x119
773     do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
774     rm -f $DIR/$tfile &
775     sleep 1
776     sync
777     sleep 1
778     # give a chance to remove from MDS
779     fail_abort mds
780     $CHECKSTAT -t file $DIR/$tfile && return 1 || true
781 }
782 run_test 35 "test recovery from llog for unlink op"
783
784 # b=2432 resent cancel after replay uses wrong cookie,
785 # so don't resend cancels
786 test_36() {
787     replay_barrier mds
788     touch $DIR/$tfile
789     checkstat $DIR/$tfile
790     facet_failover mds
791     cancel_lru_locks mdc
792     if dmesg | grep "unknown lock cookie"; then 
793         echo "cancel after replay failed"
794         return 1
795     fi
796 }
797 run_test 36 "don't resend cancel"
798
799 # b=2368
800 # directory orphans can't be unlinked from PENDING directory
801 test_37() {
802     rmdir $DIR/$tfile 2>/dev/null
803     multiop $DIR/$tfile dD_c &
804     pid=$!
805     # give multiop a chance to open
806     sleep 1 
807     rmdir $DIR/$tfile
808
809     replay_barrier mds
810     # clear the dmesg buffer so we only see errors from this recovery
811     dmesg -c >/dev/null
812     fail_abort mds
813     kill -USR1 $pid
814     dmesg | grep  "mds_unlink_orphan.*error .* unlinking orphan" && return 1
815     sync
816     return 0
817 }
818 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
819
820 test_38() {
821     createmany -o $DIR/$tfile-%d 800
822     unlinkmany $DIR/$tfile-%d 0 400
823     replay_barrier mds
824     fail mds
825     unlinkmany $DIR/$tfile-%d 400 400
826     sleep 2
827     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
828 }
829 run_test 38 "test recovery from unlink llog (test llog_gen_rec) "
830
831 test_39() { # bug 4176
832     createmany -o $DIR/$tfile-%d 800
833     replay_barrier mds
834     unlinkmany $DIR/$tfile-%d 0 400
835     fail mds
836     unlinkmany $DIR/$tfile-%d 400 400
837     sleep 2
838     ls -1f $DIR/$tfile-*
839     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
840 }
841 run_test 39 "test recovery from unlink llog (test llog_gen_rec) "
842
843 count_ost_writes() {
844     awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }' $LPROC/osc/*/stats
845 }
846
847 #b=2477,2532
848 test_40(){
849     $LCTL mark multiop $MOUNT/$tfile OS_c 
850     multiop $MOUNT/$tfile OS_c  &
851     PID=$!
852     writeme -s $MOUNT/${tfile}-2 &
853     WRITE_PID=$!
854     sleep 1
855     facet_failover mds
856 #define OBD_FAIL_MDS_CONNECT_NET         0x117
857     do_facet mds "sysctl -w lustre.fail_loc=0x80000117"
858     kill -USR1 $PID
859     stat1=`count_ost_writes`
860     sleep $TIMEOUT
861     stat2=`count_ost_writes`
862     echo "$stat1, $stat2"
863     if [ $stat1 -lt $stat2 ]; then 
864        echo "writes continuing during recovery"
865        RC=0
866     else
867        echo "writes not continuing during recovery, bug 2477"
868        RC=4
869     fi
870     echo "waiting for writeme $WRITE_PID"
871     kill $WRITE_PID
872     wait $WRITE_PID 
873
874     echo "waiting for multiop $PID"
875     wait $PID || return 2
876     do_facet client munlink $MOUNT/$tfile  || return 3
877     do_facet client munlink $MOUNT/${tfile}-2  || return 3
878     return $RC
879 }
880 run_test 40 "cause recovery in ptlrpc, ensure IO continues"
881
882
883 #b=2814
884 # make sure that a read to one osc doesn't try to double-unlock its page just
885 # because another osc is invalid.  trigger_group_io used to mistakenly return
886 # an error if any oscs were invalid even after having successfully put rpcs
887 # on valid oscs.  This was fatal if the caller was ll_readpage who unlocked
888 # the page, guarnateeing that the unlock from the RPC completion would
889 # assert on trying to unlock the unlocked page.
890 test_41() {
891     local f=$MOUNT/$tfile
892     # make sure the start of the file is ost1
893     lfs setstripe $f $((128 * 1024)) 0 0 
894     do_facet client dd if=/dev/zero of=$f bs=4k count=1 || return 3
895     cancel_lru_locks osc
896     # fail ost2 and read from ost1
897     local osc2dev=`grep ${ost2_svc}-osc- $LPROC/devices | awk '{print $1}'`
898     [ "$osc2dev" ] || return 4
899     $LCTL --device $osc2dev deactivate || return 1
900     do_facet client dd if=$f of=/dev/null bs=4k count=1 || return 3
901     $LCTL --device $osc2dev activate || return 2
902     return 0
903 }
904 run_test 41 "read from a valid osc while other oscs are invalid"
905
906 # test MDS recovery after ost failure
907 test_42() {
908     blocks=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
909     createmany -o $DIR/$tfile-%d 800
910     replay_barrier ost1
911     unlinkmany $DIR/$tfile-%d 0 400
912     debugsave
913     sysctl -w lnet.debug=-1
914     facet_failover ost1
915     
916     # osc is evicted, fs is smaller (but only with failout OSTs (bug 7287)
917     #blocks_after=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
918     #[ $blocks_after -lt $blocks ] || return 1
919     echo wait for MDS to timeout and recover
920     sleep $((TIMEOUT * 2))
921     debugrestore
922     unlinkmany $DIR/$tfile-%d 400 400
923     $CHECKSTAT -t file $DIR/$tfile-* && return 2 || true
924 }
925 run_test 42 "recovery after ost failure"
926
927 # timeout in MDS/OST recovery RPC will LBUG MDS
928 test_43() { # bug 2530
929     replay_barrier mds
930
931     # OBD_FAIL_OST_CREATE_NET 0x204
932     do_facet ost1 "sysctl -w lustre.fail_loc=0x80000204"
933     fail mds
934     sleep 10
935     do_facet ost1 "sysctl -w lustre.fail_loc=0"
936
937     return 0
938 }
939 run_test 43 "mds osc import failure during recovery; don't LBUG"
940
941 test_44() {
942     mdcdev=`awk '/-mdc-/ {print $1}' $LPROC/devices`
943     [ "$mdcdev" ] || exit 2
944     for i in `seq 1 10`; do
945         #define OBD_FAIL_TGT_CONN_RACE     0x701
946         do_facet mds "sysctl -w lustre.fail_loc=0x80000701"
947         $LCTL --device $mdcdev recover
948         df $MOUNT
949     done
950     do_facet mds "sysctl -w lustre.fail_loc=0"
951     return 0
952 }
953 run_test 44 "race in target handle connect"
954
955 test_44b() {
956     mdcdev=`awk '/-mdc-/ {print $1}' $LPROC/devices`
957     [ "$mdcdev" ] || exit 2
958     for i in `seq 1 10`; do
959         #define OBD_FAIL_TGT_DELAY_RECONNECT 0x704
960         do_facet mds "sysctl -w lustre.fail_loc=0x80000704"
961         $LCTL --device $mdcdev recover
962         df $MOUNT
963     done
964     do_facet mds "sysctl -w lustre.fail_loc=0"
965     return 0
966 }
967 run_test 44b "race in target handle connect"
968
969 # Handle failed close
970 test_45() {
971     mdcdev=`awk '/-mdc-/ {print $1}' $LPROC/devices`
972     [ "$mdcdev" ] || exit 2
973     $LCTL --device $mdcdev recover
974
975     multiop $DIR/$tfile O_c &
976     pid=$!
977     sleep 1
978
979     # This will cause the CLOSE to fail before even 
980     # allocating a reply buffer
981     $LCTL --device $mdcdev deactivate || return 4
982
983     # try the close
984     kill -USR1 $pid
985     wait $pid || return 1
986
987     $LCTL --device $mdcdev activate || return 5
988     sleep 1
989
990     $CHECKSTAT -t file $DIR/$tfile || return 2
991     return 0
992 }
993 run_test 45 "Handle failed close"
994
995 test_46() {
996     dmesg -c >/dev/null
997     drop_reply "touch $DIR/$tfile"
998     fail mds
999     # ironically, the previous test, 45, will cause a real forced close,
1000     # so just look for one for this test
1001     dmesg | grep -i "force closing client file handle for $tfile" && return 1
1002     return 0
1003 }
1004 run_test 46 "Don't leak file handle after open resend (3325)"
1005
1006 test_47() { # bug 2824
1007     # create some files to make sure precreate has been done on all 
1008     # OSTs. (just in case this test is run independently)
1009     createmany -o $DIR/$tfile 20  || return 1
1010
1011     # OBD_FAIL_OST_CREATE_NET 0x204
1012     fail ost1
1013     do_facet ost1 "sysctl -w lustre.fail_loc=0x80000204"
1014     df $MOUNT || return 2
1015
1016     # let the MDS discover the OST failure, attempt to recover, fail
1017     # and recover again.  
1018     sleep $((3 * TIMEOUT))
1019
1020     # Without 2824, this createmany would hang 
1021     createmany -o $DIR/$tfile 20 || return 3
1022     unlinkmany $DIR/$tfile 20 || return 4
1023
1024     do_facet ost1 "sysctl -w lustre.fail_loc=0"
1025     return 0
1026 }
1027 run_test 47 "MDS->OSC failure during precreate cleanup (2824)"
1028
1029 test_48() {
1030     replay_barrier mds
1031     createmany -o $DIR/$tfile 20  || return 1
1032     # OBD_FAIL_OST_EROFS 0x216
1033     fail mds
1034     do_facet ost1 "sysctl -w lustre.fail_loc=0x80000216"
1035     df $MOUNT || return 2
1036
1037     createmany -o $DIR/$tfile 20 20 || return 2
1038     unlinkmany $DIR/$tfile 40 || return 3
1039
1040     do_facet ost1 "sysctl -w lustre.fail_loc=0"
1041     return 0
1042 }
1043 run_test 48 "MDS->OSC failure during precreate cleanup (2824)"
1044
1045 test_50() {
1046     local oscdev=`grep ${ost1_svc}-osc- $LPROC/devices | awk '{print $1}'`
1047     [ "$oscdev" ] || return 1
1048     $LCTL --device $oscdev recover &&  $LCTL --device $oscdev recover
1049     # give the mds_lov_sync threads a chance to run
1050     sleep 5
1051 }
1052 run_test 50 "Double OSC recovery, don't LASSERT (3812)"
1053
1054 # b3764 timed out lock replay
1055 test_52() {
1056     touch $DIR/$tfile
1057     cancel_lru_locks mdc
1058
1059     multiop $DIR/$tfile s || return 1
1060     replay_barrier mds
1061 #define OBD_FAIL_LDLM_REPLY              0x30c
1062     do_facet mds "sysctl -w lustre.fail_loc=0x8000030c"
1063     fail mds || return 2
1064     do_facet mds "sysctl -w lustre.fail_loc=0x0"
1065
1066     $CHECKSTAT -t file $DIR/$tfile-* && return 3 || true
1067 }
1068 run_test 52 "time out lock replay (3764)"
1069
1070 #b_cray 53 "|X| open request and close reply while two MDC requests in flight"
1071 #b_cray 54 "|X| open request and close reply while two MDC requests in flight"
1072
1073 #b3761 ASSERTION(hash != 0) failed
1074 test_55() {
1075 # OBD_FAIL_MDS_OPEN_CREATE | OBD_FAIL_ONCE
1076     do_facet mds "sysctl -w lustre.fail_loc=0x8000012b"
1077     touch $DIR/$tfile &
1078     # give touch a chance to run
1079     sleep 5
1080     do_facet mds "sysctl -w lustre.fail_loc=0x0"
1081     rm $DIR/$tfile
1082     return 0
1083 }
1084 run_test 55 "let MDS_CHECK_RESENT return the original return code instead of 0"
1085
1086 #b3440 ASSERTION(rec->ur_fid2->id) failed
1087 test_56() {
1088     ln -s foo $DIR/$tfile
1089     replay_barrier mds
1090     #drop_reply "cat $DIR/$tfile"
1091     fail mds
1092     sleep 10
1093 }
1094 run_test 56 "don't replay a symlink open request (3440)"
1095
1096 #recovery one mds-ost setattr from llog
1097 test_57() {
1098 #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1099     do_facet mds "sysctl -w lustre.fail_loc=0x8000012c"
1100     touch $DIR/$tfile
1101     replay_barrier mds
1102     fail mds
1103     sleep 1
1104     $CHECKSTAT -t file $DIR/$tfile || return 1
1105     do_facet mds "sysctl -w lustre.fail_loc=0x0"
1106     rm $DIR/$tfile
1107 }
1108 run_test 57 "test recovery from llog for setattr op"
1109
1110 #recovery many mds-ost setattr from llog
1111 test_58() {
1112 #define OBD_FAIL_MDS_OST_SETATTR       0x12c
1113     do_facet mds "sysctl -w lustre.fail_loc=0x8000012c"
1114     mkdir $DIR/$tdir
1115     createmany -o $DIR/$tdir/$tfile-%d 2500
1116     replay_barrier mds
1117     fail mds
1118     sleep 2
1119     $CHECKSTAT -t file $DIR/$tdir/$tfile-* || return 1
1120     do_facet mds "sysctl -w lustre.fail_loc=0x0"
1121     unlinkmany $DIR/$tdir/$tfile-%d 2500
1122     rmdir $DIR/$tdir
1123 }
1124 run_test 58 "test recovery from llog for setattr op (test llog_gen_rec)"
1125
1126 # log_commit_thread vs filter_destroy race used to lead to import use after free
1127 # bug 11658
1128 test_59() {
1129     mkdir $DIR/$tdir
1130     createmany -o $DIR/$tdir/$tfile-%d 200
1131     sync
1132     unlinkmany $DIR/$tdir/$tfile-%d 200
1133 #define OBD_FAIL_PTLRPC_DELAY_RECOV       0x507
1134     do_facet ost1 "sysctl -w lustre.fail_loc=0x507"
1135     fail ost1
1136     fail mds
1137     do_facet ost1 "sysctl -w lustre.fail_loc=0x0"
1138     sleep 20
1139     rmdir $DIR/$tdir
1140 }
1141 run_test 59 "test log_commit_thread vs filter_destroy race"
1142
1143 # race between add unlink llog vs cat log init in post_recovery (only for b1_6)
1144 # bug 12086: should no oops and No ctxt error for this test
1145 test_60() {
1146     mkdir $DIR/$tdir
1147     createmany -o $DIR/$tdir/$tfile-%d 200
1148     replay_barrier mds
1149     unlinkmany $DIR/$tdir/$tfile-%d 0 100
1150     fail mds
1151     unlinkmany $DIR/$tdir/$tfile-%d 100 100
1152     local no_ctxt=`dmesg | grep "No ctxt"`
1153     [ -z "$no_ctxt" ] || error "ctxt is not initialized in recovery" 
1154 }
1155 run_test 60 "test llog post recovery init vs llog unlink"
1156
1157 equals_msg `basename $0`: test complete, cleaning up
1158 $CLEANUP