Whamcloud - gitweb
034ee8a351727f4ef5bb3d372097d9b25ccca881
[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/local.sh}
15
16 # Skip these tests
17 ALWAYS_EXCEPT="35"
18
19
20 gen_config() {
21     rm -f $XMLCONFIG
22     add_mds mds --dev $MDSDEV --size $MDSSIZE
23     if [ ! -z "$mdsfailover_HOST" ]; then
24          add_mdsfailover mds --dev $MDSDEV --size $MDSSIZE
25     fi
26     
27     add_lov lov1 mds --stripe_sz $STRIPE_BYTES\
28         --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
29     add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE
30     add_ost ost2 --lov lov1 --dev ${OSTDEV}-2 --size $OSTSIZE
31     add_client client mds --lov lov1 --path $MOUNT
32 }
33
34 build_test_filter
35
36 cleanup() {
37     # make sure we are using the primary MDS, so the config log will
38     # be able to clean up properly.
39     activemds=`facet_active mds`
40     if [ $activemds != "mds" ]; then
41         fail mds
42     fi
43     zconf_umount $MOUNT
44     stop mds ${FORCE} $MDSLCONFARGS
45     stop ost2 ${FORCE} --dump cleanup.log
46     stop ost ${FORCE} --dump cleanup.log
47 }
48
49 if [ "$ONLY" == "cleanup" ]; then
50     sysctl -w portals.debug=0 || true
51     cleanup
52     exit
53 fi
54
55 SETUP=${SETUP:-"setup"}
56 CLEANUP=${CLEANUP:-"cleanup"}
57
58 setup() {
59     gen_config
60
61     start ost --reformat $OSTLCONFARGS 
62     start ost2 --reformat $OSTLCONFARGS 
63     [ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
64     start mds $MDSLCONFARGS --reformat
65     zconf_mount $MOUNT
66 }
67
68 $SETUP
69
70 if [ "$ONLY" == "setup" ]; then
71     exit 0
72 fi
73
74 mkdir -p $DIR
75
76 test_0() {
77     replay_barrier mds
78     fail mds
79 }
80 run_test 0 "empty replay"
81
82 test_1() {
83     replay_barrier mds
84     mcreate $DIR/$tfile
85     fail mds
86     $CHECKSTAT -t file $DIR/$tfile || return 1
87     rm $DIR/$tfile
88 }
89 run_test 1 "simple create"
90
91 test_2a() {
92     replay_barrier mds
93     touch $DIR/$tfile
94     fail mds
95     $CHECKSTAT -t file $DIR/$tfile || return 1
96     rm $DIR/$tfile
97 }
98 run_test 2a "touch"
99
100 test_2b() {
101     ./mcreate $DIR/$tfile
102     replay_barrier mds
103     touch $DIR/$tfile
104     fail mds
105     $CHECKSTAT -t file $DIR/$tfile || return 1
106     rm $DIR/$tfile
107 }
108 run_test 2b "touch"
109
110 test_3() {
111     replay_barrier mds
112     mcreate $DIR/$tfile
113     o_directory $DIR/$tfile
114     fail mds
115     $CHECKSTAT -t file $DIR/$tfile || return 2
116     rm $DIR/$tfile
117 }
118 run_test 3 "replay failed open"
119
120 test_4() {
121     replay_barrier mds
122     for i in `seq 10`; do
123         echo "tag-$i" > $DIR/$tfile-$i
124     done 
125     fail mds
126     for i in `seq 10`; do
127       grep -q "tag-$i" $DIR/$tfile-$i || error "f1c-$i"
128     done 
129 }
130 run_test 4 "|x| 10 open(O_CREAT)s"
131
132 test_4b() {
133     replay_barrier mds
134     rm -rf $DIR/$tfile-*
135     fail mds
136     $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
137 }
138 run_test 4b "|x| rm 10 files"
139
140 # The idea is to get past the first block of precreated files on both 
141 # osts, and then replay.
142 test_5() {
143     replay_barrier mds
144     for i in `seq 220`; do
145         echo "tag-$i" > $DIR/$tfile-$i
146     done 
147     fail mds
148     for i in `seq 220`; do
149       grep -q "tag-$i" $DIR/$tfile-$i || error "f1c-$i"
150     done 
151     rm -rf $DIR/$tfile-*
152     sleep 3
153     # waiting for commitment of removal
154 }
155 run_test 5 "|x| 220 open(O_CREAT)"
156
157
158 test_6() {
159     replay_barrier mds
160     mkdir $DIR/$tdir
161     mcreate $DIR/$tdir/$tfile
162     fail mds
163     $CHECKSTAT -t dir $DIR/$tdir || return 1
164     $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
165     sleep 2
166     # waiting for log process thread
167 }
168 run_test 6 "mkdir + contained create"
169
170 test_6b() {
171     replay_barrier mds
172     rm -rf $DIR/$tdir
173     fail mds
174     $CHECKSTAT -t dir $DIR/$tdir && return 1 || true 
175 }
176 run_test 6b "|X| rmdir"
177
178 test_7() {
179     mkdir $DIR/$tdir
180     replay_barrier mds
181     mcreate $DIR/$tdir/$tfile
182     fail mds
183     $CHECKSTAT -t dir $DIR/$tdir || return 1
184     $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
185     rm -fr $DIR/$tdir
186 }
187 run_test 7 "mkdir |X| contained create"
188
189 test_8() {
190     replay_barrier mds
191     multiop $DIR/$tfile mo_c &
192     MULTIPID=$!
193     sleep 1
194     fail mds
195     ls $DIR/$tfile
196     $CHECKSTAT -t file $DIR/$tfile || return 1
197     kill -USR1 $MULTIPID || return 2
198     wait $MULTIPID || return 3
199     rm $DIR/$tfile
200 }
201 run_test 8 "creat open |X| close"
202
203 test_9() {
204     replay_barrier mds
205     mcreate $DIR/$tfile
206     local old_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
207     fail mds
208     local new_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
209
210     echo " old_inum == $old_inum, new_inum == $new_inum"
211     if [ $old_inum -eq $new_inum  ] ;
212     then
213         echo " old_inum and new_inum match"
214     else
215         echo "!!!! old_inum and new_inum NOT match"
216         return 1
217     fi
218     rm $DIR/$tfile
219 }
220 run_test 9  "|X| create (same inum/gen)"
221
222 test_10() {
223     mcreate $DIR/$tfile
224     replay_barrier mds
225     mv $DIR/$tfile $DIR/$tfile-2
226     rm -f $DIR/$tfile
227     fail mds
228     $CHECKSTAT $DIR/$tfile && return 1
229     $CHECKSTAT $DIR/$tfile-2 ||return 2
230     rm $DIR/$tfile-2
231     return 0
232 }
233 run_test 10 "create |X| rename unlink"
234
235 test_11() {
236     mcreate $DIR/$tfile
237     echo "old" > $DIR/$tfile
238     mv $DIR/$tfile $DIR/$tfile-2
239     replay_barrier mds
240     echo "new" > $DIR/$tfile
241     grep new $DIR/$tfile 
242     grep old $DIR/$tfile-2
243     fail mds
244     grep new $DIR/$tfile || return 1
245     grep old $DIR/$tfile-2 || return 2
246 }
247 run_test 11 "create open write rename |X| create-old-name read"
248
249 test_12() {
250     mcreate $DIR/$tfile 
251     multiop $DIR/$tfile o_tSc &
252     pid=$!
253     # give multiop a chance to open
254     sleep 1
255     rm -f $DIR/$tfile
256     replay_barrier mds
257     kill -USR1 $pid
258     wait $pid || return 1
259
260     fail mds
261     [ -e $DIR/$tfile ] && return 2
262     return 0
263 }
264 run_test 12 "open, unlink |X| close"
265
266
267 # 1777 - replay open after committed chmod that would make
268 #        a regular open a failure    
269 test_13() {
270     mcreate $DIR/$tfile 
271     multiop $DIR/$tfile O_wc &
272     pid=$!
273     # give multiop a chance to open
274     sleep 1 
275     chmod 0 $DIR/$tfile
276     $CHECKSTAT -p 0 $DIR/$tfile
277     replay_barrier mds
278     fail mds
279     kill -USR1 $pid
280     wait $pid || return 1
281
282     $CHECKSTAT -s 1 -p 0 $DIR/$tfile || return 2
283     return 0
284 }
285 run_test 13 "open chmod 0 |x| write close"
286
287 test_14() {
288     multiop $DIR/$tfile O_tSc &
289     pid=$!
290     # give multiop a chance to open
291     sleep 1 
292     rm -f $DIR/$tfile
293     replay_barrier mds
294     kill -USR1 $pid || return 1
295     wait $pid || return 2
296
297     fail mds
298     [ -e $DIR/$tfile ] && return 3
299     return 0
300 }
301 run_test 14 "open(O_CREAT), unlink |X| close"
302
303 test_15() {
304     multiop $DIR/$tfile O_tSc &
305     pid=$!
306     # give multiop a chance to open
307     sleep 1 
308     rm -f $DIR/$tfile
309     replay_barrier mds
310     touch $DIR/g11 || return 1
311     kill -USR1 $pid
312     wait $pid || return 2
313
314     fail mds
315     [ -e $DIR/$tfile ] && return 3
316     touch $DIR/h11 || return 4
317     return 0
318 }
319 run_test 15 "open(O_CREAT), unlink |X|  touch new, close"
320
321
322 test_16() {
323     replay_barrier mds
324     mcreate $DIR/$tfile
325     munlink $DIR/$tfile
326     mcreate $DIR/$tfile-2
327     fail mds
328     [ -e $DIR/$tfile ] && return 1
329     [ -e $DIR/$tfile-2 ] || return 2
330     munlink $DIR/$tfile-2 || return 3
331 }
332 run_test 16 "|X| open(O_CREAT), unlink, touch new,  unlink new"
333
334 test_17() {
335     replay_barrier mds
336     multiop $DIR/$tfile O_c &
337     pid=$!
338     # give multiop a chance to open
339     sleep 1 
340     fail mds
341     kill -USR1 $pid || return 1
342     wait $pid || return 2
343     $CHECKSTAT -t file $DIR/$tfile || return 3
344     rm $DIR/$tfile
345 }
346 run_test 17 "|X| open(O_CREAT), |replay| close"
347
348 test_18() {
349     replay_barrier mds
350     multiop $DIR/$tfile O_tSc &
351     pid=$!
352     # give multiop a chance to open
353     sleep 1 
354     rm -f $DIR/$tfile
355     touch $DIR/$tfile-2 || return 1
356     kill -USR1 $pid
357     wait $pid || return 2
358
359     fail mds
360     [ -e $DIR/$tfile ] && return 3
361     [ -e $DIR/$tfile-2 ] || return 4
362     # this touch frequently fails
363     touch $DIR/$tfile-3 || return 5
364     munlink $DIR/$tfile-2 || return 6
365     munlink $DIR/$tfile-3 || return 7
366     return 0
367 }
368 run_test 18 "|X| open(O_CREAT), unlink, touch new, close, touch, unlink"
369
370 # bug 1855 (a simpler form of test_11 above)
371 test_19() {
372     replay_barrier mds
373     mcreate $DIR/$tfile
374     echo "old" > $DIR/$tfile
375     mv $DIR/$tfile $DIR/$tfile-2
376     grep old $DIR/$tfile-2
377     fail mds
378     grep old $DIR/$tfile-2 || return 2
379 }
380 run_test 19 "|X| mcreate, open, write, rename "
381
382 test_20() {
383     replay_barrier mds
384     multiop $DIR/$tfile O_tSc &
385     pid=$!
386     # give multiop a chance to open
387     sleep 1 
388     rm -f $DIR/$tfile
389
390     fail mds
391     kill -USR1 $pid
392     wait $pid || return 1
393     [ -e $DIR/$tfile ] && return 2
394     return 0
395 }
396 run_test 20 "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
397
398 test_21() {
399     replay_barrier mds
400     multiop $DIR/$tfile O_tSc &
401     pid=$!
402     # give multiop a chance to open
403     sleep 1 
404     rm -f $DIR/$tfile
405     touch $DIR/g11 || return 1
406
407     fail mds
408     kill -USR1 $pid
409     wait $pid || return 2
410     [ -e $DIR/$tfile ] && return 3
411     touch $DIR/h11 || return 4
412     return 0
413 }
414 run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"
415
416 test_22() {
417     multiop $DIR/$tfile O_tSc &
418     pid=$!
419     # give multiop a chance to open
420     sleep 1 
421
422     replay_barrier mds
423     rm -f $DIR/$tfile
424
425     fail mds
426     kill -USR1 $pid
427     wait $pid || return 1
428     [ -e $DIR/$tfile ] && return 2
429     return 0
430 }
431 run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"
432
433 test_23() {
434     multiop $DIR/$tfile O_tSc &
435     pid=$!
436     # give multiop a chance to open
437     sleep 1 
438
439     replay_barrier mds
440     rm -f $DIR/$tfile
441     touch $DIR/g11 || return 1
442
443     fail mds
444     kill -USR1 $pid
445     wait $pid || return 2
446     [ -e $DIR/$tfile ] && return 3
447     touch $DIR/h11 || return 4
448     return 0
449 }
450 run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"
451
452 test_24() {
453     multiop $DIR/$tfile O_tSc &
454     pid=$!
455     # give multiop a chance to open
456     sleep 1 
457
458     replay_barrier mds
459     fail mds
460     rm -f $DIR/$tfile
461     kill -USR1 $pid
462     wait $pid || return 1
463     [ -e $DIR/$tfile ] && return 2
464     return 0
465 }
466 run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"
467
468 test_25() {
469     multiop $DIR/$tfile O_tSc &
470     pid=$!
471     # give multiop a chance to open
472     sleep 1 
473     rm -f $DIR/$tfile
474
475     replay_barrier mds
476     fail mds
477     kill -USR1 $pid
478     wait $pid || return 1
479     [ -e $DIR/$tfile ] && return 2
480     return 0
481 }
482 run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
483
484 test_26() {
485     replay_barrier mds
486     multiop $DIR/$tfile-1 O_tSc &
487     pid1=$!
488     multiop $DIR/$tfile-2 O_tSc &
489     pid2=$!
490     # give multiop a chance to open
491     sleep 1 
492     rm -f $DIR/$tfile-1
493     rm -f $DIR/$tfile-2
494     kill -USR1 $pid2
495     wait $pid2 || return 1
496
497     fail mds
498     kill -USR1 $pid1
499     wait $pid1 || return 2
500     [ -e $DIR/$tfile-1 ] && return 3
501     [ -e $DIR/$tfile-2 ] && return 4
502     return 0
503 }
504 run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"
505
506 test_27() {
507     replay_barrier mds
508     multiop $DIR/$tfile-1 O_tSc &
509     pid1=$!
510     multiop $DIR/$tfile-2 O_tSc &
511     pid2=$!
512     # give multiop a chance to open
513     sleep 1 
514     rm -f $DIR/$tfile-1
515     rm -f $DIR/$tfile-2
516
517     fail mds
518     kill -USR1 $pid1
519     wait $pid1 || return 1
520     kill -USR1 $pid2
521     wait $pid2 || return 2
522     [ -e $DIR/$tfile-1 ] && return 3
523     [ -e $DIR/$tfile-2 ] && return 4
524     return 0
525 }
526 run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"
527
528 test_28() {
529     multiop $DIR/$tfile-1 O_tSc &
530     pid1=$!
531     multiop $DIR/$tfile-2 O_tSc &
532     pid2=$!
533     # give multiop a chance to open
534     sleep 1 
535     replay_barrier mds
536     rm -f $DIR/$tfile-1
537     rm -f $DIR/$tfile-2
538     kill -USR1 $pid2
539     wait $pid2 || return 1
540
541     fail mds
542     kill -USR1 $pid1
543     wait $pid1 || return 2
544     [ -e $DIR/$tfile-1 ] && return 3
545     [ -e $DIR/$tfile-2 ] && return 4
546     return 0
547 }
548 run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"
549
550 test_29() {
551     multiop $DIR/$tfile-1 O_tSc &
552     pid1=$!
553     multiop $DIR/$tfile-2 O_tSc &
554     pid2=$!
555     # give multiop a chance to open
556     sleep 1 
557     replay_barrier mds
558     rm -f $DIR/$tfile-1
559     rm -f $DIR/$tfile-2
560
561     fail mds
562     kill -USR1 $pid1
563     wait $pid1 || return 1
564     kill -USR1 $pid2
565     wait $pid2 || return 2
566     [ -e $DIR/$tfile-1 ] && return 3
567     [ -e $DIR/$tfile-2 ] && return 4
568     return 0
569 }
570 run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"
571
572 test_30() {
573     multiop $DIR/$tfile-1 O_tSc &
574     pid1=$!
575     multiop $DIR/$tfile-2 O_tSc &
576     pid2=$!
577     # give multiop a chance to open
578     sleep 1 
579     rm -f $DIR/$tfile-1
580     rm -f $DIR/$tfile-2
581
582     replay_barrier mds
583     fail mds
584     kill -USR1 $pid1
585     wait $pid1 || return 1
586     kill -USR1 $pid2
587     wait $pid2 || return 2
588     [ -e $DIR/$tfile-1 ] && return 3
589     [ -e $DIR/$tfile-2 ] && return 4
590     return 0
591 }
592 run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"
593
594 test_31() {
595     multiop $DIR/$tfile-1 O_tSc &
596     pid1=$!
597     multiop $DIR/$tfile-2 O_tSc &
598     pid2=$!
599     # give multiop a chance to open
600     sleep 1 
601     rm -f $DIR/$tfile-1
602
603     replay_barrier mds
604     rm -f $DIR/$tfile-2
605     fail mds
606     kill -USR1 $pid1
607     wait $pid1 || return 1
608     kill -USR1 $pid2
609     wait $pid2 || return 2
610     [ -e $DIR/$tfile-1 ] && return 3
611     [ -e $DIR/$tfile-2 ] && return 4
612     return 0
613 }
614 run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"
615
616 # tests for bug 2104; completion without crashing is success.  The close is
617 # stale, but we always return 0 for close, so the app never sees it.
618 test_32() {
619     multiop $DIR/$tfile O_c &
620     pid1=$!
621     multiop $DIR/$tfile O_c &
622     pid2=$!
623     # give multiop a chance to open
624     sleep 1
625     mds_evict_client
626     df $MOUNT || df $MOUNT || return 1
627     kill -USR1 $pid1
628     kill -USR1 $pid2
629     sleep 1
630     return 0
631 }
632 run_test 32 "close() notices client eviction; close() after client eviction"
633
634 # Abort recovery before client complete
635 test_33() {
636     replay_barrier mds
637     touch $DIR/$tfile
638     fail_abort mds
639     # this file should be gone, because the replay was aborted
640     $CHECKSTAT -t file $DIR/$tfile && return 1
641     return 0
642 }
643 run_test 33 "abort recovery before client does replay"
644
645 test_34() {
646     multiop $DIR/$tfile O_c &
647     pid=$!
648     # give multiop a chance to open
649     sleep 1 
650     rm -f $DIR/$tfile
651
652     replay_barrier mds
653     fail_abort mds
654     kill -USR1 $pid
655     [ -e $DIR/$tfile ] && return 1
656     sync
657     return 0
658 }
659 run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"
660
661 # bug 2278 - generate one orphan on OST, then destroy it during recovery from llog 
662 test_35() {
663     touch $DIR/$tfile
664
665     echo 0x80000119 > /proc/sys/lustre/fail_loc
666     rm -f $DIR/$tfile &
667     sleep 1
668     # give a chance to remove from MDS
669     fail_abort mds
670     $CHECKSTAT -t file $DIR/$tfile && return 1 || true
671 }
672 run_test 35 "test recovery from llog for unlink op"
673
674 # b=2432 resent cancel after replay uses wrong cookie,
675 # so don't resend cancels
676 test_36() {
677     replay_barrier mds
678     touch $DIR/$tfile
679     checkstat $DIR/$tfile
680     facet_failover mds
681     cancel_lru_locks MDC
682     if dmesg | grep "unknown lock cookie"; then 
683         echo "cancel after replay failed"
684         return 1
685     fi
686 }
687 run_test 36 "don't resend cancel"
688
689 # b=2368
690 # directory orphans can't be unlinked from PENDING directory
691 test_37() {
692     rmdir $DIR/$tfile 2>/dev/null
693     multiop $DIR/$tfile dD_c &
694     pid=$!
695     # give multiop a chance to open
696     sleep 1 
697     rmdir $DIR/$tfile
698
699     replay_barrier mds
700     # clear the dmesg buffer so we only see errors from this recovery
701     dmesg -c >/dev/null
702     fail_abort mds
703     kill -USR1 $pid
704     dmesg | grep  "mds_unlink_orphan.*error .* unlinking orphan" && return 1
705     sync
706     return 0
707 }
708 run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"
709
710 equals_msg test complete, cleaning up
711 $CLEANUP