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