3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 [ -n "$ONLY" ] && SLOW=yes
14 ALWAYS_EXCEPT="$LRSYNC_EXCEPT"
15 # bug number for skipped test:
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
19 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
24 LREPL_LOG=$TMP/lustre_rsync.log
27 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
28 . $LUSTRE/tests/test-framework.sh
30 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
33 REPLLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
35 [ "$REPLLOG" ] && rm -f $REPLLOG || true
37 check_and_setup_lustre
45 export LRSYNC=${LRSYNC:-"$LUSTRE/utils/lustre_rsync"}
46 [ ! -f "$LRSYNC" ] && export LRSYNC=$(which lustre_rsync)
47 export LRSYNC="$LRSYNC -v" # -a
49 # control the time of tests
50 DBENCH_TIME=${DBENCH_TIME:-60} # No of seconds to run dbench
53 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
54 awk '{gsub(/_UUID/,""); print $1}' | head -1)
57 CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
58 echo $MDT0: Registered changelog user $CL_USER
59 CL_USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
60 mdd.$MDT0.changelog_users | wc -l) - 2 ))
61 [ $CL_USERS -ne 1 ] && \
62 echo "Other changelog users present ($CL_USERS)"
66 rm -rf $TGT/$tdir $TGT/d*.lustre_rsync-test 2> /dev/null
67 rm -rf $TGT2/$tdir $TGT2/d*.lustre_rsync-test 2> /dev/null
68 rm -rf ${DIR}/$tdir $DIR/d*.lustre_rsync-test ${DIR}/tgt 2> /dev/null
72 mkdir -p ${TGT2}/$tdir
74 error "Failed to create target: " $TGT
85 $LFS changelog_clear $MDT0 $CL_USER 0
86 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
93 setfattr -n user.foo -v 'bar' $tgt 2> /dev/null
102 if [ -e $1 -o -e $2 ]; then
103 diff -rq -x "dev1" $1 $2
105 if [ $RC -ne 0 ]; then
106 error "Failure in replication; differences found."
111 # Test 1 - test basic operations
115 local xattr=`check_xattr $TGT/foo`
122 touch $DIR/$tdir/file1
123 cp /etc/hosts $DIR/$tdir/d1/
124 touch $DIR/$tdir/d1/"space in filename"
125 touch $DIR/$tdir/d1/file2
128 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
130 # File and directory delete
131 touch $DIR/$tdir/d1/file4
132 mkdir $DIR/$tdir/d1/del
133 touch $DIR/$tdir/d1/del/del1
134 touch $DIR/$tdir/d1/del/del2
135 rm -rf $DIR/$tdir/d1/del
136 rm $DIR/$tdir/d1/file4
139 cat /etc/hosts > $DIR/$tdir/d1/link1
140 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
141 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
144 #mknod $DIR/$tdir/dev1 b 8 1
147 echo "Replication #1"
148 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
151 chmod 000 $DIR/$tdir/d2/file3
152 chown nobody:nobody $DIR/$tdir/d2/file3
155 if [ "$xattr" == "yes" ]; then
156 touch $DIR/$tdir/file5
157 setfattr -n user.foo -v 'bar' $DIR/$tdir/file5
160 echo "Replication #2"
161 $LRSYNC -l $LREPL_LOG
163 if [ "$xattr" == "yes" ]; then
164 local xval1=$(getfattr -n user.foo --absolute-names --only-values \
166 local xval2=$(getfattr -n user.foo --absolute-names --only-values \
172 # fid2path and path2fid aren't implemented for block devices
173 #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
174 # ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
175 # error "Error replicating block devices"
178 if [[ "$xattr" == "yes" ]] &&
179 [[ "$xval1" != "bar" || "$xval2" != "bar" ]]; then
180 error "Error in replicating xattrs. $xval1, $xval2"
184 # Use diff to compare the source and the destination
185 check_diff $DIR/$tdir $TGT/$tdir
186 check_diff $DIR/$tdir $TGT2/$tdir
192 run_test 1 "Simple Replication"
194 # Test 2a - Replicate files created by dbench
196 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
201 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed!"
203 # Replicate the changes to $TGT
204 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
206 # Use diff to compare the source and the destination
207 check_diff $DIR/$tdir $TGT/$tdir
208 check_diff $DIR/$tdir $TGT2/$tdir
214 run_test 2a "Replicate files created by dbench."
217 # Test 2b - Replicate files changed by dbench.
219 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
225 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
228 local child_pid=$(pgrep dbench)
229 echo PIDs: $child_pid
231 $KILL -SIGSTOP $child_pid
233 echo Starting replication
234 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
235 check_diff $DIR/$tdir $TGT/$tdir
238 $KILL -SIGCONT $child_pid
242 $KILL -SIGSTOP $child_pid
244 echo Starting replication
245 $LRSYNC -l $LREPL_LOG
246 check_diff $DIR/$tdir $TGT/$tdir
248 echo "Wait for dbench to finish"
249 $KILL -SIGCONT $child_pid
252 # Replicate the changes to $TGT
253 echo Starting replication
254 $LRSYNC -l $LREPL_LOG
256 check_diff $DIR/$tdir $TGT/$tdir
257 check_diff $DIR/$tdir $TGT2/$tdir
263 run_test 2b "Replicate files changed by dbench."
265 # Test 2c - Replicate files while dbench is running
267 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
272 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
274 # Replicate the changes to $TGT
275 sleep 10 # give dbench a headstart
277 while [ $quit -le 1 ];
279 echo "Running lustre_rsync"
280 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER -l $LREPL_LOG
283 if [ $? -ne 0 ]; then
284 quit=$(expr $quit + 1)
288 # Use diff to compare the source and the destination
289 check_diff $DIR/$tdir $TGT/$tdir
290 check_diff $DIR/$tdir $TGT2/$tdir
296 run_test 2c "Replicate files while dbench is running."
298 # Test 3a - Replicate files created by createmany
300 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
306 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
308 # Replicate the changes to $TGT
309 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
310 check_diff $DIR/$tdir $TGT/$tdir
311 check_diff $DIR/$tdir $TGT2/$tdir
317 run_test 3a "Replicate files created by createmany"
320 # Test 3b - Replicate files created by writemany
322 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
329 writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
331 # Replicate the changes to $TGT
332 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
334 check_diff $DIR/$tdir $TGT/$tdir
335 check_diff $DIR/$tdir $TGT2/$tdir
341 run_test 3b "Replicate files created by writemany"
343 # Test 3c - Replicate files created by createmany/unlinkmany
345 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
351 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
352 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
354 # Replicate the changes to $TGT
355 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
356 check_diff $DIR/$tdir $TGT/$tdir
357 check_diff $DIR/$tdir $TGT2/$tdir
363 run_test 3c "Replicate files created by createmany/unlinkmany"
365 # Test 4 - Replicate files created by iozone
367 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
369 which iozone > /dev/null 2>&1
370 if [ $? -ne 0 ]; then
371 skip "iozone not found. Skipping test"
378 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
379 MOUNT=${DIR}/$tdir run_iozone.sh &
381 child_pid=$(pgrep iozone)
382 $KILL -SIGSTOP $child_pid
384 # Replicate the changes to $TGT
385 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
386 check_diff $DIR/$tdir $TGT/$tdir
387 check_diff $DIR/$tdir $TGT2/$tdir
389 $KILL -SIGCONT $child_pid
391 $KILL -SIGKILL $(pgrep run_iozone.sh)
392 $KILL -SIGKILL $(pgrep iozone)
394 # After killing 'run_iozone.sh', process 'iozone' becomes the
395 # child of PID 1. Hence 'wait' does not wait for it. Killing
396 # iozone first, means more iozone processes are spawned off which
397 # is not desirable. So, after sending a sigkill, the test goes
398 # into a wait loop for iozone to cleanup and exit.
400 while [ "$(pgrep "iozone")" != "" ];
402 ps -ef | grep iozone | grep -v grep
406 $LRSYNC -l $LREPL_LOG
407 check_diff $DIR/$tdir $TGT/$tdir
408 check_diff $DIR/$tdir $TGT2/$tdir
414 run_test 4 "Replicate files created by iozone"
416 # Test 5a - Stop / start lustre_rsync
418 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
424 createmany -o $DIR/$tdir/$tfile $NUMTEST
426 # Replicate the changes to $TGT
428 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
431 $KILL -SIGHUP $child_pid
433 $LRSYNC -l $LREPL_LOG
435 check_diff $DIR/$tdir $TGT/$tdir
436 check_diff $DIR/$tdir $TGT2/$tdir
442 run_test 5a "Stop / start lustre_rsync"
444 # Test 5b - Kill / restart lustre_rsync
446 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
452 createmany -o $DIR/$tdir/$tfile $NUMTEST
454 # Replicate the changes to $TGT
456 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
459 $KILL -SIGKILL $child_pid
461 $LRSYNC -l $LREPL_LOG
463 check_diff $DIR/$tdir $TGT/$tdir
464 check_diff $DIR/$tdir $TGT2/$tdir
470 run_test 5b "Kill / restart lustre_rsync"
472 # Test 6 - lustre_rsync large no of hard links
478 touch $DIR/$tdir/link0
480 while [ $i -lt $NUMLINKS ];
482 ln $DIR/$tdir/link0 $DIR/$tdir/link${i}
486 # Replicate the changes to $TGT
487 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
488 check_diff $DIR/$tdir $TGT/$tdir
489 check_diff $DIR/$tdir $TGT2/$tdir
491 local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
492 local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
493 if [[ $count1 -ne $NUMLINKS ]] || [[ $count2 -ne $NUMLINKS ]]; then
494 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
495 error "Incorrect no of hard links found $count1, $count2"
501 run_test 6 "lustre_rsync large no of hard links"
503 # Test 7 - lustre_rsync stripesize
506 mkdir -p ${DIR}/tgt/$tdir
510 lfs setstripe -c 2 ${DIR}/$tdir
511 createmany -o $DIR/$tdir/$tfile $NUMFILES
513 # To simulate replication to another lustre filesystem, replicate
514 # the changes to $DIR/tgt. We can't turn off the changelogs
515 # while we are registered, so lustre_rsync better not try to
516 # replicate the replication steps. It seems ok :)
518 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG
519 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
522 while [ $i -lt $NUMFILES ];
524 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | awk '/stripe_count/ {print $2}')
525 if [ $count -ne 2 ]; then
526 error "Stripe size not replicated"
534 run_test 7 "lustre_rsync stripesize"
536 # Test 8 - Replicate multiple file/directory moves
541 for i in 1 2 3 4 5 6 7 8 9; do
543 for j in 1 2 3 4 5 6 7 8 9; do
544 mkdir $DIR/$tdir/d$i/d$i$j
545 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
547 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
548 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
550 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
552 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
555 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
557 check_diff ${DIR}/$tdir $TGT/$tdir
563 run_test 8 "Replicate multiple file/directory moves"
570 touch $DIR/$tdir/foo/a1
572 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
574 check_diff ${DIR}/$tdir $TGT/$tdir
576 rm -rf $DIR/$tdir/foo
578 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
580 check_diff ${DIR}/$tdir $TGT/$tdir
586 run_test 9 "Replicate recursive directory removal"
588 log "cleanup: ======================================================"
590 check_and_cleanup_lustre
591 echo '=========================== finished ==============================='
592 [ -f "$REPLLOG" ] && cat $REPLLOG && grep -q FAIL $REPLLOG && exit 1 || true