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