Whamcloud - gitweb
b=19389
[fs/lustre-release.git] / lustre / tests / lreplicate-test.sh
1 #!/bin/bash
2 #
3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
5 #
6 # Run test by setting NOSETUP=true when ltest has setup env for us
7 set -e
8
9 SRCDIR=`dirname $0`
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
11
12 ONLY=${ONLY:-"$*"}
13 ALWAYS_EXCEPT="$LREPLICATE_EXCEPT"
14 # bug number for skipped test: -
15 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
16
17 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
18         echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
19
20 KILL=/bin/kill
21
22 TMP=${TMP:-/tmp}
23 LREPL_LOG=$TMP/lreplicate.log
24 ORIG_PWD=${PWD}
25
26 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
27 . $LUSTRE/tests/test-framework.sh
28 init_test_env $@
29 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
30
31
32 REPLLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
33
34 [ "$REPLLOG" ] && rm -f $REPLLOG || true
35
36 check_and_setup_lustre
37
38 DIR=${DIR:-$MOUNT}
39 assert_DIR
40
41
42 build_test_filter
43
44 export LREPLICATE=${LREPLICATE:-"$LUSTRE/utils/lreplicate"}
45 [ ! -f "$LREPLICATE" ] && export LREPLICATE=$(which lreplicate)
46 export LREPLICATE="$LREPLICATE -v" # -a
47
48 # control the time of tests
49 DBENCH_TIME=${DBENCH_TIME:-60}  # No of seconds to run dbench
50 TGT=/tmp/target
51 TGT2=/tmp/target2
52 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
53     awk '{gsub(/_UUID/,""); print $1}' | head -1)
54
55 init_changelog() {
56     CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
57     echo $MDT0: Registered changelog user $CL_USER
58     CL_USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
59         mdd.$MDT0.changelog_users | wc -l) - 2 ))
60     [ $CL_USERS -ne 1 ] && \
61         echo "Other changelog users present ($CL_USERS)"
62 }
63
64 init_src() {
65     rm -rf $TGT/$tdir $TGT/d*.lreplicate-test 2> /dev/null
66     rm -rf $TGT2/$tdir $TGT2/d*.lreplicate-test 2> /dev/null
67     rm -rf ${DIR}/$tdir $DIR/d*.lreplicate-test ${DIR}/tgt 2> /dev/null
68     rm -f $LREPL_LOG
69     mkdir -p $TGT
70     mkdir -p $TGT2
71     if [ $? -ne 0 ]; then
72         error "Failed to create target: " $TGT
73     fi
74 }
75
76 cleanup_src_tgt() {
77     rm -rf $TGT/$tdir
78     rm -rf $DIR/$tdir
79     rm -rf $DIR/tgt
80 }
81
82 fini_changelog() {
83     $LFS changelog_clear $MDT0 $CL_USER 0
84     do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
85 }
86
87 check_xattr() {
88     local tgt=$1
89     local xattr="yes"
90     touch $tgt
91     setfattr -n user.foo -v 'bar' $tgt 2> /dev/null
92     if [ $? -ne 0 ]; then
93         xattr="no"
94     fi
95     rm -f $tgt
96     echo $xattr
97 }
98
99 check_diff() {
100     if [ -e $1 -o -e $2 ]; then 
101         diff -rq -x "dev1" $1 $2
102         local RC=$?
103         if [ $RC -ne 0 ]; then
104             error "Failure in replication; differences found."
105         fi
106     fi
107 }
108
109 # Test 1 - test basic operations
110 test_1() {
111     init_src
112     init_changelog
113     local xattr=`check_xattr $TGT/foo`
114
115     # Directory create
116     mkdir -p ${DIR}/$tdir
117     mkdir $DIR/$tdir/d1
118     mkdir $DIR/$tdir/d2
119
120     # File create
121     touch $DIR/$tdir/file1
122     cp /etc/hosts  $DIR/$tdir/d1/
123     touch  $DIR/$tdir/d1/"space in filename"
124     touch  $DIR/$tdir/d1/file2
125
126     # File rename
127     mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
128
129     # File and directory delete
130     touch $DIR/$tdir/d1/file4
131     mkdir $DIR/$tdir/d1/del
132     touch  $DIR/$tdir/d1/del/del1
133     touch  $DIR/$tdir/d1/del/del2
134     rm -rf $DIR/$tdir/d1/del
135     rm $DIR/$tdir/d1/file4
136
137     #hard and soft links
138     cat /etc/hosts > $DIR/$tdir/d1/link1
139     ln  $DIR/$tdir/d1/link1  $DIR/$tdir/d1/link2
140     ln -s $DIR/$tdir/d1/link1  $DIR/$tdir/d1/link3
141
142     # Device files
143     #mknod $DIR/$tdir/dev1 b 8 1
144
145     # Replicate
146     echo "Replication #1"
147     $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
148
149     # Set attributes
150     chmod 000 $DIR/$tdir/d2/file3
151     chown nobody:nobody $DIR/$tdir/d2/file3
152
153     # Set xattrs
154     if [ "$xattr" == "yes" ]; then
155         touch $DIR/$tdir/file5
156         setfattr -n user.foo -v 'bar' $DIR/$tdir/file5
157     fi
158
159     echo "Replication #2"
160     $LREPLICATE -l $LREPL_LOG
161
162     if [ "$xattr" == "yes" ]; then
163         local xval1=$(getfattr -n user.foo --absolute-names --only-values \
164             $TGT/$tdir/file5)
165         local xval2=$(getfattr -n user.foo --absolute-names --only-values \
166             $TGT2/$tdir/file5)
167     fi
168
169     RC=0
170
171     # fid2path and path2fid aren't implemented for block devices
172     #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
173     #   ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
174     #   error "Error replicating block devices"
175     #   RC=1
176
177     if [[ "$xattr" == "yes" ]] &&
178        [[ "$xval1" != "bar" || "$xval2" != "bar" ]]; then
179         error "Error in replicating xattrs. $xval1, $xval2"
180         RC=1
181     fi
182
183     # Use diff to compare the source and the destination
184     check_diff $DIR/$tdir $TGT/$tdir
185     check_diff $DIR/$tdir $TGT2/$tdir
186
187     fini_changelog
188     cleanup_src_tgt
189     return $RC
190
191 }
192 run_test 1 "Simple Replication"
193
194 # Test 2a - Replicate files created by dbench 
195 test_2a() {
196     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
197     init_src
198     init_changelog
199
200     # Run dbench
201     sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed!"
202
203     # Replicate the changes to $TGT
204     $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
205
206     # Use diff to compare the source and the destination
207     check_diff $DIR/$tdir $TGT/$tdir
208     check_diff $DIR/$tdir $TGT2/$tdir
209
210     fini_changelog
211     cleanup_src_tgt
212     return 0
213 }
214 run_test 2a "Replicate files created by dbench."
215
216
217 # Test 2b - Replicate files changed by dbench.
218 test_2b() {
219     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
220
221     init_src
222     init_changelog
223
224     # Run dbench
225     sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
226     sleep 20
227
228     local child_pid=$(pgrep dbench)
229     echo PIDs: $child_pid
230     echo Stopping dbench
231     $KILL -SIGSTOP $child_pid
232
233     echo Starting replication
234     $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
235     check_diff $DIR/$tdir $TGT/$tdir
236
237     echo Resuming dbench
238     $KILL -SIGCONT $child_pid
239     sleep 10
240
241     echo Stopping dbench
242     $KILL -SIGSTOP $child_pid
243
244     echo Starting replication
245     $LREPLICATE -l $LREPL_LOG
246     check_diff $DIR/$tdir $TGT/$tdir
247
248     echo "Wait for dbench to finish"
249     $KILL -SIGCONT $child_pid
250     wait
251
252     # Replicate the changes to $TGT
253     echo Starting replication
254     $LREPLICATE -l $LREPL_LOG
255
256     check_diff $DIR/$tdir $TGT/$tdir
257     check_diff $DIR/$tdir $TGT2/$tdir
258
259     fini_changelog
260     cleanup_src_tgt
261     return 0
262 }
263 run_test 2b "Replicate files changed by dbench."
264
265 # Test 2c - Replicate files while dbench is running 
266 test_2c() {
267     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
268     init_src
269     init_changelog
270
271     # Run dbench
272     sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
273
274     # Replicate the changes to $TGT
275     sleep 10 # give dbench a headstart
276     local quit=0
277     while [ $quit -le 1 ];
278     do
279         echo "Running lreplicate"
280         $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER -l $LREPL_LOG
281         sleep 5
282         pgrep dbench
283         if [ $? -ne 0 ]; then
284             quit=$(expr $quit + 1)
285         fi
286     done
287
288     # Use diff to compare the source and the destination
289     check_diff $DIR/$tdir $TGT/$tdir
290     check_diff $DIR/$tdir $TGT2/$tdir
291
292     fini_changelog
293     cleanup_src_tgt
294     return 0
295 }
296 run_test 2c "Replicate files while dbench is running."
297
298 # Test 3a - Replicate files created by createmany
299 test_3a() {
300     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
301
302     init_src
303     init_changelog
304
305     local numfiles=1000
306     mkdir -p ${DIR}/$tdir
307     createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
308
309     # Replicate the changes to $TGT
310     $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
311     check_diff $DIR/$tdir $TGT/$tdir   
312     check_diff $DIR/$tdir $TGT2/$tdir
313
314     fini_changelog
315     cleanup_src_tgt
316     return 0
317 }
318 run_test 3a "Replicate files created by createmany"
319
320
321 # Test 3b - Replicate files created by writemany
322 test_3b() {
323     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
324
325     init_src
326     init_changelog
327
328     local time=60
329     local threads=5
330     mkdir -p ${DIR}/$tdir
331     writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
332
333     # Replicate the changes to $TGT
334     $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
335
336     check_diff $DIR/$tdir $TGT/$tdir   
337     check_diff $DIR/$tdir $TGT2/$tdir
338
339     fini_changelog
340     cleanup_src_tgt
341     return 0
342 }
343 run_test 3b "Replicate files created by writemany"
344
345 # Test 3c - Replicate files created by createmany/unlinkmany
346 test_3c() {
347     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
348
349     init_src
350     init_changelog
351
352     local numfiles=1000
353     mkdir -p ${DIR}/$tdir
354     createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
355     unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
356
357     # Replicate the changes to $TGT
358     $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m $MDT0  -u $CL_USER -l $LREPL_LOG
359     check_diff $DIR/$tdir $TGT/$tdir   
360     check_diff $DIR/$tdir $TGT2/$tdir
361
362     fini_changelog
363     cleanup_src_tgt
364     return 0
365 }
366 run_test 3c "Replicate files created by createmany/unlinkmany"
367
368 # Test 4 - Replicate files created by iozone
369 test_4() {
370     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
371
372     which iozone > /dev/null 2>&1
373     if [ $? -ne 0 ]; then
374         skip "iozone not found. Skipping test"
375         return
376     fi
377
378     init_src
379     init_changelog
380
381     mkdir -p ${DIR}/$tdir
382     END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
383         MOUNT=${DIR}/$tdir run_iozone.sh &
384     sleep 30
385     child_pid=$(pgrep iozone)
386     $KILL -SIGSTOP $child_pid
387
388     # Replicate the changes to $TGT
389     $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m $MDT0  -u $CL_USER -l $LREPL_LOG
390     check_diff $DIR/$tdir $TGT/$tdir
391     check_diff $DIR/$tdir $TGT2/$tdir
392
393     $KILL -SIGCONT $child_pid
394     sleep 60
395     $KILL -SIGKILL $child_pid
396
397     $LREPLICATE -l $LREPL_LOG
398     check_diff $DIR/$tdir $TGT/$tdir
399     check_diff $DIR/$tdir $TGT2/$tdir
400
401     fini_changelog
402     cleanup_src_tgt
403     return 0
404 }
405 run_test 4 "Replicate files created by iozone"
406
407 # Test 5a - Stop / start lreplicate
408 test_5a() {
409     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
410
411     init_src
412     init_changelog
413
414     NUMTEST=2000
415     mkdir -p ${DIR}/$tdir
416     createmany -o $DIR/$tdir/$tfile $NUMTEST
417
418     # Replicate the changes to $TGT
419     
420     $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
421     local child_pid=$!
422     sleep 30
423     $KILL -SIGHUP $child_pid
424     wait
425     $LREPLICATE -l $LREPL_LOG
426
427     check_diff $DIR/$tdir $TGT/$tdir   
428     check_diff $DIR/$tdir $TGT2/$tdir
429
430     fini_changelog
431     cleanup_src_tgt
432     return 0
433 }
434 run_test 5a "Stop / start lreplicate"
435
436 # Test 5b - Kill / restart lreplicate
437 test_5b() {
438     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
439
440     init_src
441     init_changelog
442
443     NUMTEST=2000
444     mkdir -p ${DIR}/$tdir
445     createmany -o $DIR/$tdir/$tfile $NUMTEST
446
447     # Replicate the changes to $TGT
448     
449     $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
450     local child_pid=$!
451     sleep 30
452     $KILL -SIGKILL $child_pid
453     wait
454     $LREPLICATE -l $LREPL_LOG
455
456     check_diff $DIR/$tdir $TGT/$tdir   
457     check_diff $DIR/$tdir $TGT2/$tdir
458
459     fini_changelog
460     cleanup_src_tgt
461     return 0
462 }
463 run_test 5b "Kill / restart lreplicate"
464
465 # Test 6 - lreplicate large no of hard links
466 test_6() {
467     init_src
468     init_changelog
469
470     local NUMLINKS=128
471     mkdir -p ${DIR}/$tdir
472     touch $DIR/$tdir/link0
473     local i=1
474     while [ $i -lt $NUMLINKS ];
475     do
476       ln $DIR/$tdir/link0  $DIR/$tdir/link${i}
477       i=$(expr $i + 1)
478     done
479
480     # Replicate the changes to $TGT
481     $LREPLICATE -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
482     check_diff $DIR/$tdir $TGT/$tdir
483     check_diff $DIR/$tdir $TGT2/$tdir
484
485     local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
486     local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
487     if [[ $count1 -ne $NUMLINKS ]] ||  [[ $count2 -ne $NUMLINKS ]]; then
488         ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
489         error "Incorrect no of hard links found $count1, $count2"
490     fi
491     fini_changelog
492     cleanup_src_tgt
493     return 0
494 }
495 run_test 6 "lreplicate large no of hard links"
496
497 # Test 7 - lreplicate stripesize
498 test_7() {
499     init_src
500     init_changelog
501
502     local NUMFILES=100
503     mkdir -p ${DIR}/$tdir
504     lfs setstripe -c 2 ${DIR}/$tdir
505     createmany -o $DIR/$tdir/$tfile $NUMFILES
506
507     # To simulate replication to another lustre filesystem, replicate
508     # the changes to $DIR/tgt. Disable changelogs before replication
509     # so that the files created as part of replication are not logged.
510     do_facet $SINGLEMDS lctl set_param -n mdd.$MDT0.changelog off
511     mkdir $DIR/tgt
512
513     $LREPLICATE -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG
514     check_diff ${DIR}/$tdir $DIR/tgt/$tdir
515
516     local i=0
517     while [ $i -lt $NUMFILES ];
518     do
519       local count=$(( $(lfs getstripe -q $DIR/tgt/$tdir/${tfile}$i | wc -l) - 1))
520       if [ $count -ne 2 ]; then
521           error "Stripe size not replicated" 
522       fi
523       i=$(expr $i + 1)
524     done
525     fini_changelog
526     cleanup_src_tgt
527     return 0
528 }
529 run_test 7 "lreplicate stripesize"
530
531 # Test 8 - Replicate multiple file/directory moves
532 test_8() {
533     init_src
534     init_changelog
535
536     mkdir -p ${DIR}/$tdir
537
538     for i in 1 2 3 4 5 6 7 8 9; do
539         mkdir $DIR/$tdir/d$i
540             for j in 1 2 3 4 5 6 7 8 9; do
541                 mkdir $DIR/$tdir/d$i/d$i$j
542                 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
543                     > /dev/null
544                 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
545                 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
546                     > /dev/null
547                 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
548             done
549             mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
550     done
551
552     $LREPLICATE -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
553
554     check_diff ${DIR}/$tdir $TGT/$tdir
555
556     fini_changelog
557     cleanup_src_tgt
558     return 0
559 }
560 run_test 8 "Replicate multiple file/directory moves"
561
562 log "cleanup: ======================================================"
563 cd $ORIG_PWD
564 check_and_cleanup_lustre
565 echo '=========================== finished ==============================='
566 [ -f "$REPLOG" ] && cat $REPLLOG && grep -q FAIL $REPLLOG && exit 1 || true
567 echo "$0: completed"