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