2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
5 # Run select tests by setting ONLY, or as arguments to the script.
6 # Skip specific tests by setting EXCEPT.
8 # Run test by setting NOSETUP=true when ltest has setup env for us
12 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
15 ALWAYS_EXCEPT="$LRSYNC_EXCEPT"
16 # bug number for skipped test:
17 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
19 [ "$SLOW" = "no" ] && EXCEPT_SLOW=""
21 [ "$ALWAYS_EXCEPT$EXCEPT" ] &&
22 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
27 LREPL_LOG=$TMP/lustre_rsync.log
30 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
31 . $LUSTRE/tests/test-framework.sh
33 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
36 check_and_setup_lustre
44 export LRSYNC=${LRSYNC:-"$LUSTRE/utils/lustre_rsync"}
45 [ ! -f "$LRSYNC" ] && export LRSYNC=$(which lustre_rsync)
46 export LRSYNC="$LRSYNC -v -c no -d 2"
48 # control the time of tests
49 DBENCH_TIME=${DBENCH_TIME:-60} # No of seconds to run dbench
52 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
53 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
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)"
65 rm -rf $TGT/$tdir $TGT/d*.lustre_rsync-test 2> /dev/null
66 rm -rf $TGT2/$tdir $TGT2/d*.lustre_rsync-test 2> /dev/null
67 rm -rf ${DIR}/$tdir $DIR/d*.lustre_rsync-test ${DIR}/tgt 2> /dev/null
71 mkdir -p ${TGT2}/$tdir
73 error "Failed to create target: " $TGT
84 $LFS changelog_clear $MDT0 $CL_USER 0
85 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
88 # Check whether the filesystem supports xattr or not.
90 # "large" - large xattr is supported
91 # "small" - large xattr is unsupported but small xattr is supported
92 # "no" - xattr is unsupported
99 local val="$(generate_string $(max_xattr_size))"
100 if large_xattr_enabled &&
101 setfattr -n user.foo -v $val $tgt 2>/dev/null; then
104 setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
112 local changelog_file=$(generate_logname "changelog")
114 if [ -e $1 -o -e $2 ]; then
115 diff -rq -x "dev1" $1 $2
117 if [ $RC -ne 0 ]; then
118 $LFS changelog $MDT0 > $changelog_file
119 error "Failure in replication; differences found."
124 # Test 1 - test basic operations
128 local xattr=$(check_xattr $TGT/foo)
135 touch $DIR/$tdir/file1
136 cp /etc/hosts $DIR/$tdir/d1/
137 touch $DIR/$tdir/d1/"space in filename"
138 touch $DIR/$tdir/d1/file2
141 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
143 # File and directory delete
144 touch $DIR/$tdir/d1/file4
145 mkdir $DIR/$tdir/d1/del
146 touch $DIR/$tdir/d1/del/del1
147 touch $DIR/$tdir/d1/del/del2
148 rm -rf $DIR/$tdir/d1/del
149 rm $DIR/$tdir/d1/file4
152 cat /etc/hosts > $DIR/$tdir/d1/link1
153 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
154 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
157 #mknod $DIR/$tdir/dev1 b 8 1
160 local LRSYNC_LOG=$(generate_logname "lrsync_log")
161 echo "Replication #1"
162 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
166 chmod 000 $DIR/$tdir/d2/file3
167 chown nobody:nobody $DIR/$tdir/d2/file3
170 if [[ "$xattr" != "no" ]]; then
172 touch $DIR/$tdir/file5
173 [[ "$xattr" = "large" ]] &&
174 value="$(generate_string $(max_xattr_size))" || value="bar"
175 setfattr -n user.foo -v $value $DIR/$tdir/file5
178 echo "Replication #2"
179 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
181 if [[ "$xattr" != "no" ]]; then
182 local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
183 local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
188 # fid2path and path2fid aren't implemented for block devices
189 #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
190 # ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
191 # error "Error replicating block devices"
194 if [[ "$xattr" != "no" ]] &&
195 [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
196 error "Error in replicating xattrs."
200 # Use diff to compare the source and the destination
201 check_diff $DIR/$tdir $TGT/$tdir
202 check_diff $DIR/$tdir $TGT2/$tdir
208 run_test 1 "Simple Replication"
210 # Test 1a - test create/delete operations in ROOT directory
211 test_1a() { # LU-5005
212 rm -rf $TGT/root-* 2> /dev/null
213 rm -rf $DIR/root-* 2> /dev/null
221 touch $DIR/root-file2
224 mv $DIR/root-file2 $DIR/root-file3
226 # File and directory delete
227 touch $DIR/root-file4
230 rm -rf $DIR/root-dir1
233 local LRSYNC_LOG=$(generate_logname "lrsync_log")
235 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
239 stat $TGT/root-dir || error "Dir create not replicated"
240 stat $TGT/root-file || error "File create not replicated"
241 stat $TGT/root-file2 && error "Rename not replicated (src)"
242 stat $TGT/root-file3 || error "Rename not replicated (tgt)"
243 stat $TGT/root-dir1 && error "Dir delete not replicated"
244 stat $TGT/root-file4 && error "File delete not replicated"
251 run_test 1a "Replicate create/delete operations in ROOT directory"
253 # Test 2a - Replicate files created by dbench
259 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed"
261 local LRSYNC_LOG=$(generate_logname "lrsync_log")
262 # Replicate the changes to $TGT
263 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
266 # Use diff to compare the source and the destination
267 check_diff $DIR/$tdir $TGT/$tdir
268 check_diff $DIR/$tdir $TGT2/$tdir
274 run_test 2a "Replicate files created by dbench."
277 # Test 2b - Replicate files changed by dbench.
284 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
285 # wait for dbench to start
286 wait_for_function 'child_pid=$(pgrep dbench)' 360
287 # let dbench run for a bit
290 echo PIDs: $child_pid
292 $KILL -SIGSTOP $child_pid
294 local LRSYNC_LOG=$(generate_logname "lrsync_log")
295 echo Starting replication
296 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
298 check_diff $DIR/$tdir $TGT/$tdir
301 $KILL -SIGCONT $child_pid
305 $KILL -SIGSTOP $child_pid
307 echo Starting replication
308 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
309 check_diff $DIR/$tdir $TGT/$tdir
311 echo "Wait for dbench to finish"
312 $KILL -SIGCONT $child_pid
315 # Replicate the changes to $TGT
316 echo Starting replication
317 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
319 check_diff $DIR/$tdir $TGT/$tdir
320 check_diff $DIR/$tdir $TGT2/$tdir
326 run_test 2b "Replicate files changed by dbench."
328 # Test 2c - Replicate files while dbench is running
334 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
336 local LRSYNC_LOG=$(generate_logname "lrsync_log")
337 # Replicate the changes to $TGT
338 sleep 10 # give dbench a headstart
340 while [ $quit -le 1 ];
342 echo "Running lustre_rsync"
343 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
344 -l $LREPL_LOG -D $LRSYNC_LOG
347 if [ $? -ne 0 ]; then
348 quit=$(expr $quit + 1)
352 # Use diff to compare the source and the destination
353 check_diff $DIR/$tdir $TGT/$tdir
354 check_diff $DIR/$tdir $TGT2/$tdir
360 run_test 2c "Replicate files while dbench is running."
362 # Test 3a - Replicate files created by createmany
368 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
370 local LRSYNC_LOG=$(generate_logname "lrsync_log")
371 # Replicate the changes to $TGT
372 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
374 check_diff $DIR/$tdir $TGT/$tdir
375 check_diff $DIR/$tdir $TGT2/$tdir
381 run_test 3a "Replicate files created by createmany"
384 # Test 3b - Replicate files created by writemany
391 writemany -q -a $DIR/$tdir/$tfile $time $threads ||
392 error "writemany failed"
394 local LRSYNC_LOG=$(generate_logname "lrsync_log")
395 # Replicate the changes to $TGT
396 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
399 check_diff $DIR/$tdir $TGT/$tdir
400 check_diff $DIR/$tdir $TGT2/$tdir
406 run_test 3b "Replicate files created by writemany"
408 # Test 3c - Replicate files created by createmany/unlinkmany
414 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
415 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
417 local LRSYNC_LOG=$(generate_logname "lrsync_log")
418 # Replicate the changes to $TGT
419 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
421 check_diff $DIR/$tdir $TGT/$tdir
422 check_diff $DIR/$tdir $TGT2/$tdir
428 run_test 3c "Replicate files created by createmany/unlinkmany"
430 # Test 4 - Replicate files created by iozone
432 which iozone > /dev/null 2>&1
433 if [ $? -ne 0 ]; then
434 skip "iozone not found. Skipping test"
441 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
442 MOUNT=${DIR}/$tdir run_iozone.sh &
444 child_pid=$(pgrep iozone)
445 $KILL -SIGSTOP $child_pid
447 local LRSYNC_LOG=$(generate_logname "lrsync_log")
448 # Replicate the changes to $TGT
449 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
451 check_diff $DIR/$tdir $TGT/$tdir
452 check_diff $DIR/$tdir $TGT2/$tdir
454 $KILL -SIGCONT $child_pid
456 $KILL -SIGKILL $(pgrep run_iozone.sh)
457 $KILL -SIGKILL $(pgrep iozone)
459 # After killing 'run_iozone.sh', process 'iozone' becomes the
460 # child of PID 1. Hence 'wait' does not wait for it. Killing
461 # iozone first, means more iozone processes are spawned off which
462 # is not desirable. So, after sending a sigkill, the test goes
463 # into a wait loop for iozone to cleanup and exit.
465 while [ "$(pgrep "iozone")" != "" ];
467 ps -ef | grep iozone | grep -v grep
471 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
472 check_diff $DIR/$tdir $TGT/$tdir
473 check_diff $DIR/$tdir $TGT2/$tdir
479 run_test 4 "Replicate files created by iozone"
481 # Test 5a - Stop / start lustre_rsync
487 createmany -o $DIR/$tdir/$tfile $NUMTEST
489 # Replicate the changes to $TGT
490 local LRSYNC_LOG=$(generate_logname "lrsync_log")
491 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
495 $KILL -SIGHUP $child_pid
497 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
499 check_diff $DIR/$tdir $TGT/$tdir
500 check_diff $DIR/$tdir $TGT2/$tdir
506 run_test 5a "Stop / start lustre_rsync"
508 # Test 5b - Kill / restart lustre_rsync
514 createmany -o $DIR/$tdir/$tfile $NUMTEST
516 # Replicate the changes to $TGT
517 local LRSYNC_LOG=$(generate_logname "lrsync_log")
518 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
522 $KILL -SIGKILL $child_pid
524 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
526 check_diff $DIR/$tdir $TGT/$tdir
527 check_diff $DIR/$tdir $TGT2/$tdir
533 run_test 5b "Kill / restart lustre_rsync"
535 # Test 6 - lustre_rsync large no of hard links
543 touch $DIR/$tdir/link0
544 for ((i = 1; i < num_links - 1; i++)); do
545 ln $DIR/$tdir/link0 $DIR/$tdir/link$i
547 # create an extra hard link of src name ending with dest name
548 ln $DIR/$tdir/link0 $DIR/$tdir/ink0
550 local LRSYNC_LOG=$(generate_logname "lrsync_log")
551 # Replicate the changes to $TGT
552 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
554 check_diff $DIR/$tdir $TGT/$tdir
555 check_diff $DIR/$tdir $TGT2/$tdir
557 local count1=$(stat --format=%h $TGT/$tdir/link0)
558 local count2=$(stat --format=%h $TGT2/$tdir/link0)
559 if ((count1 != num_links || count2 != num_links)); then
560 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
561 error "Incorrect no of hard links found $count1, $count2"
568 run_test 6 "lustre_rsync large no of hard links"
570 # Test 7 - lustre_rsync stripesize
573 mkdir -p ${DIR}/tgt/$tdir
577 lfs setstripe -c $OSTCOUNT $DIR/$tdir
578 createmany -o $DIR/$tdir/$tfile $NUMFILES
580 # To simulate replication to another lustre filesystem, replicate
581 # the changes to $DIR/tgt. We can't turn off the changelogs
582 # while we are registered, so lustre_rsync better not try to
583 # replicate the replication steps. It seems ok :)
585 local LRSYNC_LOG=$(generate_logname "lrsync_log")
586 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
588 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
591 while [ $i -lt $NUMFILES ];
593 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | \
594 awk '/stripe_count/ {print $2}')
595 if [ $count -ne $OSTCOUNT ]; then
596 error "Stripe size not replicated"
604 run_test 7 "lustre_rsync stripesize"
606 # Test 8 - Replicate multiple file/directory moves
611 for i in 1 2 3 4 5 6 7 8 9; do
613 for j in 1 2 3 4 5 6 7 8 9; do
614 mkdir $DIR/$tdir/d$i/d$i$j
615 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
617 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
618 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
620 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
622 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
625 local LRSYNC_LOG=$(generate_logname "lrsync_log")
626 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
629 check_diff ${DIR}/$tdir $TGT/$tdir
635 run_test 8 "Replicate multiple file/directory moves"
642 touch $DIR/$tdir/foo/a1
644 local LRSYNC_LOG=$(generate_logname "lrsync_log")
645 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
648 check_diff ${DIR}/$tdir $TGT/$tdir
650 rm -rf $DIR/$tdir/foo
652 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
655 check_diff ${DIR}/$tdir $TGT/$tdir
661 run_test 9 "Replicate recursive directory removal"
665 check_and_cleanup_lustre