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