Whamcloud - gitweb
41aabf360cd635190fd9a4086809c4728f742bcf
[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     sleep 1
707     mds_evict_client
708     df $MOUNT || sleep 1 && df $MOUNT || return 1
709     kill -USR1 $pid1
710     kill -USR1 $pid2
711     sleep 1
712     return 0
713 }
714 run_test 32 "close() notices client eviction; close() after client eviction"
715
716 # Abort recovery before client complete
717 test_33() {
718     replay_barrier $SINGLEMDS
719     touch $DIR/$tfile
720     fail_abort $SINGLEMDS
721     # this file should be gone, because the replay was aborted
722     $CHECKSTAT -t file $DIR/$tfile && return 1
723     return 0
724 }
725 run_test 33 "abort recovery before client does replay"
726
727 test_34() {
728     multiop $DIR/$tfile O_c &
729     pid=$!
730     # give multiop a chance to open
731     sleep 1 
732     rm -f $DIR/$tfile
733
734     replay_barrier $SINGLEMDS
735     fail_abort $SINGLEMDS
736     kill -USR1 $pid
737     [ -e $DIR/$tfile ] && return 1
738     sync
739     return 0
740 }
741 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
742
743 # bug 2278 - generate one orphan on OST, then destroy it during recovery from llog 
744 test_35() {
745     touch $DIR/$tfile
746
747 #define OBD_FAIL_MDS_REINT_NET_REP       0x119
748     do_facet mds "sysctl -w lustre.fail_loc=0x80000119"
749     rm -f $DIR/$tfile &
750     sleep 1
751     sync
752     sleep 1
753     # give a chance to remove from MDS
754     fail_abort $SINGLEMDS
755     $CHECKSTAT -t file $DIR/$tfile && return 1 || true
756 }
757 run_test 35 "test recovery from llog for unlink op"
758
759 # b=2432 resent cancel after replay uses wrong cookie,
760 # so don't resend cancels
761 test_36() {
762     replay_barrier $SINGLEMDS
763     touch $DIR/$tfile
764     checkstat $DIR/$tfile
765     facet_failover $SINGLEMDS
766     cancel_lru_locks MDC
767     if dmesg | grep "unknown lock cookie"; then 
768         echo "cancel after replay failed"
769         return 1
770     fi
771 }
772 run_test 36 "don't resend cancel"
773
774 # b=2368
775 # directory orphans can't be unlinked from PENDING directory
776 test_37() {
777     rmdir $DIR/$tfile 2>/dev/null
778     multiop $DIR/$tfile dD_c &
779     pid=$!
780     # give multiop a chance to open
781     sleep 1 
782     rmdir $DIR/$tfile
783
784     replay_barrier $SINGLEMDS
785     # clear the dmesg buffer so we only see errors from this recovery
786     dmesg -c >/dev/null
787     fail_abort $SINGLEMDS
788     kill -USR1 $pid
789     dmesg | grep  "mds_unlink_orphan.*error .* unlinking orphan" && return 1
790     sync
791     return 0
792 }
793 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
794
795 test_38() {
796     createmany -o $DIR/$tfile-%d 800
797     unlinkmany $DIR/$tfile-%d 0 400
798     replay_barrier $SINGLEMDS
799     fail $SINGLEMDS
800     unlinkmany $DIR/$tfile-%d 400 400
801     sleep 2
802     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
803 }
804 run_test 38 "test recovery from unlink llog (test llog_gen_rec) "
805
806 test_39() {
807     createmany -o $DIR/$tfile-%d 800
808     replay_barrier $SINGLEMDS
809     unlinkmany $DIR/$tfile-%d 0 400
810     fail $SINGLEMDS
811     unlinkmany $DIR/$tfile-%d 400 400
812     sleep 2
813     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
814 }
815 run_test 39 "test recovery from unlink llog (test llog_gen_rec) "
816
817 count_ost_writes() {
818         cat /proc/fs/lustre/osc/*/stats |
819             awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
820 }
821
822 #b=2477,2532
823 test_40(){
824     $LCTL mark multiop $MOUNT/$tfile OS_c 
825     multiop $MOUNT/$tfile OS_c  &
826     PID=$!
827     writeme -s $MOUNT/${tfile}-2 &
828     WRITE_PID=$!
829     sleep 1
830     facet_failover $SINGLEMDS
831 #define OBD_FAIL_MDS_CONNECT_NET         0x117
832     do_facet mds "sysctl -w lustre.fail_loc=0x80000117"
833     kill -USR1 $PID
834     stat1=`count_ost_writes`
835     sleep $TIMEOUT
836     stat2=`count_ost_writes`
837     echo "$stat1, $stat2"
838     if [ $stat1 -lt $stat2 ]; then 
839        echo "writes continuing during recovery"
840        RC=0
841     else
842        echo "writes not continuing during recovery, bug 2477"
843        RC=4
844     fi
845     echo "waiting for writeme $WRITE_PID"
846     kill $WRITE_PID
847     wait $WRITE_PID 
848
849     echo "waiting for multiop $PID"
850     wait $PID || return 2
851     do_facet client munlink $MOUNT/$tfile  || return 3
852     do_facet client munlink $MOUNT/${tfile}-2  || return 3
853     return $RC
854 }
855 run_test 40 "cause recovery in ptlrpc, ensure IO continues"
856
857
858 #b=2814
859 # make sure that a read to one osc doesn't try to double-unlock its page just
860 # because another osc is invalid.  trigger_group_io used to mistakenly return
861 # an error if any oscs were invalid even after having successfully put rpcs
862 # on valid oscs.  This was fatal if the caller was ll_readpage who unlocked
863 # the page, guarnateeing that the unlock from the RPC completion would
864 # assert on trying to unlock the unlocked page.
865 test_41() {
866     local f=$MOUNT/$tfile
867     # make sure the start of the file is ost1
868     lfs setstripe $f $((128 * 1024)) 0 0 
869     do_facet client dd if=/dev/zero of=$f bs=4k count=1 || return 3
870     cancel_lru_locks OSC
871     # fail ost2 and read from ost1
872     local osc2_dev=`$LCTL device_list | \
873                 awk '(/ost2.*client_facet/){print $4}' `
874     $LCTL --device %$osc2_dev deactivate
875     do_facet client dd if=$f of=/dev/null bs=4k count=1 || return 3
876     $LCTL --device %$osc2_dev activate
877     return 0
878 }
879 run_test 41 "read from a valid osc while other oscs are invalid"
880
881 # test MDS recovery after ost failure
882 test_42() {
883     blocks=`df $MOUNT | tail -n 1 | awk '{ print $1 }'`
884     createmany -o $DIR/$tfile-%d 800
885     replay_barrier ost
886     unlinkmany $DIR/$tfile-%d 0 400
887     facet_failover ost
888     
889     # osc is evicted, fs is smaller
890     blocks_after=`df $MOUNT | tail -n 1 | awk '{ print $1 }'`
891     [ $blocks_after -lt $blocks ] || return 1
892     echo wait for MDS to timeout and recover
893     sleep $((TIMEOUT * 2))
894     unlinkmany $DIR/$tfile-%d 400 400
895     $CHECKSTAT -t file $DIR/$tfile-* && return 2 || true
896 }
897 run_test 42 "recovery after ost failure"
898
899 # b=2530
900 # timeout in MDS/OST recovery RPC will LBUG MDS
901 test_43() {
902     replay_barrier $SINGLEMDS
903
904     # OBD_FAIL_OST_CREATE_NET 0x204
905     do_facet ost "sysctl -w lustre.fail_loc=0x80000204"
906     facet_failover $SINGLEMDS
907     df $MOUNT || return 1
908     sleep 10
909     do_facet ost "sysctl -w lustre.fail_loc=0"
910
911     return 0
912 }
913 run_test 43 "mds osc import failure during recovery; don't LBUG"
914
915 test_44() {
916     mdcdev=`awk '/mds_svc_MNT/ {print $1}' < /proc/fs/lustre/devices`
917     do_facet mds "sysctl -w lustre.fail_loc=0x80000701"
918     $LCTL --device $mdcdev recover
919     df $MOUNT
920     do_facet mds "sysctl -w lustre.fail_loc=0"
921     return 0
922 }
923 run_test 44 "race in target handle connect"
924
925 # Handle failed close
926 test_45() {
927     mdcdev=`awk '/mds_svc_MNT/ {print $1}' < /proc/fs/lustre/devices`
928     $LCTL --device $mdcdev recover
929
930     multiop $DIR/$tfile O_c &
931     pid=$!
932     sleep 1
933
934     # This will cause the CLOSE to fail before even 
935     # allocating a reply buffer
936     $LCTL --device $mdcdev deactivate
937
938     # try the close
939     kill -USR1 $pid
940     wait $pid || return 1
941
942     $LCTL --device $mdcdev activate
943     sleep 1
944
945     $CHECKSTAT -t file $DIR/$tfile || return 2
946     return 0
947 }
948 run_test 45 "Handle failed close"
949
950 test_46() {
951     dmesg -c >/dev/null
952     drop_reply "touch $DIR/$tfile"
953     fail $SINGLEMDS
954     # ironically, the previous test, 45, will cause a real forced close,
955     # so just look for one for this test
956     dmesg | grep -i "force closing client file handle for $tfile" && return 1
957     return 0
958 }
959 run_test 46 "Don't leak file handle after open resend (3325)"
960
961 # b=2824
962 test_47() {
963
964     # create some files to make sure precreate has been done on all 
965     # OSTs. (just in case this test is run independently)
966     createmany -o $DIR/$tfile 20  || return 1
967
968     # OBD_FAIL_OST_CREATE_NET 0x204
969     fail ost
970     do_facet ost "sysctl -w lustre.fail_loc=0x80000204"
971     df $MOUNT || return 2
972
973     # let the MDS discover the OST failure, attempt to recover, fail
974     # and recover again.  
975     sleep $((3 * TIMEOUT))
976
977     # Without 2824, this createmany would hang 
978     createmany -o $DIR/$tfile 20 || return 3
979     unlinkmany $DIR/$tfile 20 || return 4
980
981     do_facet ost "sysctl -w lustre.fail_loc=0"
982     return 0
983 }
984 run_test 47 "MDS->OSC failure during precreate cleanup (2824)"
985
986
987 test_48() {
988     createmany -o $DIR/${tfile}- 100
989     $CHECKSTAT $DIR/${tfile}-99 || return 1
990     mds_evict_client
991     df $MOUNT || echo "first df failed" 
992     sleep 1 
993     df $MOUNT || return 2
994     sleep 1
995     $CHECKSTAT $DIR/${tfile}-99 || return 3
996
997     dmesg -c >/dev/null
998     replay_barrier $SINGLEMDS
999     fail $SINGLEMDS
1000     unlinkmany $DIR/${tfile}- 100 || return 4
1001     if dmesg | grep "back in time"; then 
1002         echo "server went back in time!"
1003         return 5
1004     fi
1005     return 0
1006 }
1007 run_test 48 "Don't lose transno when client is evicted (2525)"
1008
1009 # b=3550 - replay of unlink
1010 test_49() {
1011     replay_barrier $SINGLEMDS
1012     createmany -o $DIR/$tfile-%d 400 || return 1
1013     unlinkmany $DIR/$tfile-%d 0 400 || return 2
1014     fail $SINGLEMDS
1015     $CHECKSTAT -t file $DIR/$tfile-* && return 3 || true
1016 }
1017 run_test 49 "re-write records to llog as written during fail"
1018
1019 test_50() {
1020     local osc_dev=`$LCTL device_list | \
1021                awk '(/ost_svc_$SINGLEMDS_svc/){print $4}' `
1022     $LCTL --device %$osc_dev recover &&  $LCTL --device %$osc_dev recover
1023     # give the mds_lov_sync threads a chance to run
1024     sleep 5
1025 }
1026 run_test 50 "Double OSC recovery, don't LASSERT (3812)"
1027
1028 # bug 3462 - simultaneous MDC requests
1029 test_51a() {
1030     replay_barrier_nodf $SINGLEMDS
1031     mkdir -p $DIR/${tdir}-1
1032     mkdir -p $DIR/${tdir}-2
1033     touch $DIR/${tdir}-2/f
1034     multiop $DIR/${tdir}-1/f O_c &
1035     pid=$!
1036     # give multiop a chance to open
1037     sleep 1
1038
1039     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000115"
1040     kill -USR1 $pid
1041     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1042     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 1
1043
1044     fail $SINGLEMDS
1045
1046     wait $pid || return 2
1047     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1048     rm -rf $DIR/${tdir}-*
1049 }
1050 run_test 51a "|X| close request while two MDC requests in flight"
1051
1052 test_51b() {
1053     replay_barrier_nodf $SINGLEMDS
1054     mkdir -p $DIR/$tdir-1
1055     mkdir -p $DIR/$tdir-2
1056     multiop $DIR/$tdir-1/f O_c &
1057     pid=$!
1058     # give multiop a chance to open
1059     sleep 1
1060
1061     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000107"
1062     touch $DIR/${tdir}-2/f &
1063     usleep 500
1064     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1065
1066     kill -USR1 $pid
1067     wait $pid || return 1
1068                                                                                                                              
1069     fail $SINGLEMDS
1070
1071     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 2
1072     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 3
1073     rm -rf $DIR/${tdir}-*
1074 }
1075 run_test 51b "|X| open request while two MDC requests in flight"
1076
1077 test_51c() {
1078     replay_barrier_nodf $SINGLEMDS
1079     mkdir -p $DIR/${tdir}-1
1080     mkdir -p $DIR/${tdir}-2
1081     multiop $DIR/${tdir}-1/f O_c &
1082     pid=$!
1083     # give multiop a chance to open
1084     sleep 1
1085
1086     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000107"
1087     touch $DIR/${tdir}-2/f &
1088     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1089
1090     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000115"
1091     kill -USR1 $pid
1092     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1093
1094     fail $SINGLEMDS
1095
1096     wait $pid || return 1
1097     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 2
1098     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 3
1099     rm -rf $DIR/${tdir}-*
1100 }
1101 run_test 51c "|X| open request and close request while two MDC requests in flight"
1102
1103 test_51d() {
1104     replay_barrier_nodf $SINGLEMDS
1105     mkdir -p $DIR/${tdir}-1
1106     mkdir -p $DIR/${tdir}-2
1107     touch $DIR/${tdir}-2/f
1108     multiop $DIR/${tdir}-1/f O_c &
1109     pid=$!
1110     # give multiop a chance to open
1111     sleep 1
1112
1113     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000122"
1114     kill -USR1 $pid
1115     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1116     #$CHECKSTAT -t file $DIR/${tdir}-2/f || return 1
1117
1118     fail $SINGLEMDS
1119
1120     wait $pid || return 2
1121     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 3
1122     rm -rf $DIR/${tdir}-*
1123 }
1124 run_test 51d "|X| close reply while two MDC requests in flight"
1125
1126 test_51e() {
1127     replay_barrier_nodf $SINGLEMDS
1128     mkdir -p $DIR/$tdir-1
1129     mkdir -p $DIR/$tdir-2
1130     multiop $DIR/$tdir-1/f O_c &
1131     pid=$!
1132     # give multiop a chance to open
1133     sleep 1
1134
1135     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000119"
1136     touch $DIR/${tdir}-2/f &
1137     usleep 500
1138     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1139
1140     kill -USR1 $pid
1141     wait $pid || return 1
1142
1143     fail $SINGLEMDS
1144
1145     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 2
1146     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 3
1147     rm -rf $DIR/${tdir}-*
1148 }
1149 run_test 51e "|X| open reply while two MDC requests in flight"
1150
1151 test_51f() {
1152     replay_barrier_nodf $SINGLEMDS
1153     mkdir -p $DIR/${tdir}-1
1154     mkdir -p $DIR/${tdir}-2
1155     multiop $DIR/${tdir}-1/f O_c &
1156     pid=$!
1157     # give multiop a chance to open
1158     sleep 1
1159
1160     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000119"
1161     touch $DIR/${tdir}-2/f &
1162     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1163
1164     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000122"
1165     kill -USR1 $pid
1166     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1167
1168     fail $SINGLEMDS
1169
1170     wait $pid || return 1
1171     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 2
1172     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 3
1173     rm -rf $DIR/${tdir}-*
1174 }
1175 run_test 51f "|X| open reply and close reply while two MDC requests in flight"
1176
1177 test_51g() {
1178     replay_barrier_nodf $SINGLEMDS
1179     mkdir -p $DIR/${tdir}-1
1180     mkdir -p $DIR/${tdir}-2
1181     multiop $DIR/${tdir}-1/f O_c &
1182     pid=$!
1183     # give multiop a chance to open
1184     sleep 1
1185
1186     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000119"
1187     touch $DIR/${tdir}-2/f &
1188     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1189
1190     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000115"
1191     kill -USR1 $pid
1192     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1193
1194     fail $SINGLEMDS
1195
1196     wait $pid || return 1
1197     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 2
1198     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 3
1199     rm -rf $DIR/${tdir}-*
1200 }
1201 run_test 51g "|X| open reply and close request while two MDC requests in flight"
1202
1203 test_51h() {
1204     replay_barrier_nodf $SINGLEMDS
1205     mkdir -p $DIR/${tdir}-1
1206     mkdir -p $DIR/${tdir}-2
1207     multiop $DIR/${tdir}-1/f O_c &
1208     pid=$!
1209     # give multio:wp a chance to open
1210     sleep 1
1211
1212     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000107"
1213     touch $DIR/${tdir}-2/f &
1214     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1215
1216     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000122"
1217     kill -USR1 $pid
1218     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1219
1220     fail $SINGLEMDS
1221
1222     wait $pid || return 1
1223     $CHECKSTAT -t file $DIR/${tdir}-1/f || return 2
1224     $CHECKSTAT -t file $DIR/${tdir}-2/f || return 3
1225     rm -rf $DIR/${tdir}-*
1226 }
1227 run_test 51h "|X| open request and close reply while two MDC requests in flight"
1228
1229 # b3764 timed out lock replay
1230 test_52() {
1231     touch $DIR/$tfile
1232     cancel_lru_locks MDC
1233
1234     multiop $DIR/$tfile s
1235     replay_barrier $SINGLEMDS
1236     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x8000030c"
1237     fail $SINGLEMDS
1238     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x0"
1239
1240     $CHECKSTAT -t file $DIR/$tfile-* && return 3 || true
1241 }
1242 run_test 52 "time out lock replay (3764)"
1243
1244 test_53() {
1245     replay_barrier_nodf $SINGLEMDS
1246     f1=$DIR/${tfile}-1
1247     cat <<EOF > $f1
1248 #!/bin/sh
1249 true
1250 EOF
1251     chmod +x $f1
1252     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x80000107"
1253     $f1 || return 1
1254     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0"
1255
1256     fail $SINGLEMDS
1257     rm -f $f1
1258 }
1259 run_test 53 "|X| open request and close reply while two MDC requests in flight"
1260
1261 test_54() {
1262     replay_barrier $SINGLEMDS
1263     createmany -o $DIR/$tfile 20
1264     unlinkmany $DIR/$tfile 20
1265     fail $SINGLEMDS
1266 }
1267 run_test 54 "|X| open request and close reply while two MDC requests in flight"
1268
1269 #b3440 ASSERTION(rec->ur_fid2->id) failed
1270 test_55() {
1271     sysctl -w portals.debug=-1 portals.debug_mb=25
1272     ln -s foo $DIR/$tfile
1273     replay_barrier $SINGLEMDS
1274     #drop_reply "cat $DIR/$tfile"
1275     fail $SINGLEMDS
1276     sleep 10
1277     lctl dk /r/tmp/debug
1278 }
1279 run_test 55 "don't replay a symlink open request (3440)"
1280
1281 #b3761 ASSERTION(hash != 0) failed
1282 test_56() {
1283 # OBD_FAIL_MDS_OPEN_CREATE | OBD_FAIL_ONCE
1284     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x8000012b"
1285     touch $DIR/$tfile
1286     pid=$!
1287     # give a chance for touch to run
1288     sleep 5
1289     do_facet $SINGLEMDS "sysctl -w lustre.fail_loc=0x0"
1290     wait $pid || return 1
1291     rm $DIR/$tfile
1292     return 0
1293 }
1294 run_test 56 "let MDS_CHECK_RESENT return the original return code instead of 0"
1295
1296 equals_msg test complete, cleaning up
1297 $CLEANUP
1298