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
222 touch $DIR/root-file2
225 mv $DIR/root-file2 $DIR/root-file3
227 # File and directory delete
228 touch $DIR/root-file4
231 rm -rf $DIR/root-dir1
234 local LRSYNC_LOG=$(generate_logname "lrsync_log")
236 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
240 stat $TGT/root-dir || error "Dir create not replicated"
241 stat $TGT/root-file || error "File create not replicated"
242 stat $TGT/root-file2 && error "Rename not replicated (src)"
243 stat $TGT/root-file3 || error "Rename not replicated (tgt)"
244 stat $TGT/root-dir1 && error "Dir delete not replicated"
245 stat $TGT/root-file4 && error "File delete not replicated"
253 run_test 1a "Replicate create/delete operations in ROOT directory"
255 # Test 2a - Replicate files created by dbench
261 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed"
263 local LRSYNC_LOG=$(generate_logname "lrsync_log")
264 # Replicate the changes to $TGT
265 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
268 # Use diff to compare the source and the destination
269 check_diff $DIR/$tdir $TGT/$tdir
270 check_diff $DIR/$tdir $TGT2/$tdir
276 run_test 2a "Replicate files created by dbench."
279 # Test 2b - Replicate files changed by dbench.
286 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
287 # wait for dbench to start
288 wait_for_function 'child_pid=$(pgrep dbench)' 360
289 # let dbench run for a bit
292 echo PIDs: $child_pid
294 $KILL -SIGSTOP $child_pid
296 local LRSYNC_LOG=$(generate_logname "lrsync_log")
297 echo Starting replication
298 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
300 check_diff $DIR/$tdir $TGT/$tdir
303 $KILL -SIGCONT $child_pid
307 $KILL -SIGSTOP $child_pid
309 echo Starting replication
310 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
311 check_diff $DIR/$tdir $TGT/$tdir
313 echo "Wait for dbench to finish"
314 $KILL -SIGCONT $child_pid
317 # Replicate the changes to $TGT
318 echo Starting replication
319 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
321 check_diff $DIR/$tdir $TGT/$tdir
322 check_diff $DIR/$tdir $TGT2/$tdir
328 run_test 2b "Replicate files changed by dbench."
330 # Test 2c - Replicate files while dbench is running
336 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
338 local LRSYNC_LOG=$(generate_logname "lrsync_log")
339 # Replicate the changes to $TGT
340 sleep 10 # give dbench a headstart
342 while [ $quit -le 1 ];
344 echo "Running lustre_rsync"
345 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
346 -l $LREPL_LOG -D $LRSYNC_LOG
349 if [ $? -ne 0 ]; then
350 quit=$(expr $quit + 1)
354 # Use diff to compare the source and the destination
355 check_diff $DIR/$tdir $TGT/$tdir
356 check_diff $DIR/$tdir $TGT2/$tdir
362 run_test 2c "Replicate files while dbench is running."
364 # Test 3a - Replicate files created by createmany
370 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
372 local LRSYNC_LOG=$(generate_logname "lrsync_log")
373 # Replicate the changes to $TGT
374 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
376 check_diff $DIR/$tdir $TGT/$tdir
377 check_diff $DIR/$tdir $TGT2/$tdir
383 run_test 3a "Replicate files created by createmany"
386 # Test 3b - Replicate files created by writemany
393 writemany -q -a $DIR/$tdir/$tfile $time $threads ||
394 error "writemany failed"
396 local LRSYNC_LOG=$(generate_logname "lrsync_log")
397 # Replicate the changes to $TGT
398 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
401 check_diff $DIR/$tdir $TGT/$tdir
402 check_diff $DIR/$tdir $TGT2/$tdir
408 run_test 3b "Replicate files created by writemany"
410 # Test 3c - Replicate files created by createmany/unlinkmany
416 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
417 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
419 local LRSYNC_LOG=$(generate_logname "lrsync_log")
420 # Replicate the changes to $TGT
421 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
423 check_diff $DIR/$tdir $TGT/$tdir
424 check_diff $DIR/$tdir $TGT2/$tdir
430 run_test 3c "Replicate files created by createmany/unlinkmany"
432 # Test 4 - Replicate files created by iozone
434 which iozone > /dev/null 2>&1
435 if [ $? -ne 0 ]; then
436 skip "iozone not found. Skipping test"
443 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
444 MOUNT=${DIR}/$tdir run_iozone.sh &
446 child_pid=$(pgrep iozone)
447 $KILL -SIGSTOP $child_pid
449 local LRSYNC_LOG=$(generate_logname "lrsync_log")
450 # Replicate the changes to $TGT
451 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
453 check_diff $DIR/$tdir $TGT/$tdir
454 check_diff $DIR/$tdir $TGT2/$tdir
456 $KILL -SIGCONT $child_pid
458 $KILL -SIGKILL $(pgrep run_iozone.sh)
459 $KILL -SIGKILL $(pgrep iozone)
461 # After killing 'run_iozone.sh', process 'iozone' becomes the
462 # child of PID 1. Hence 'wait' does not wait for it. Killing
463 # iozone first, means more iozone processes are spawned off which
464 # is not desirable. So, after sending a sigkill, the test goes
465 # into a wait loop for iozone to cleanup and exit.
467 while [ "$(pgrep "iozone")" != "" ];
469 ps -ef | grep iozone | grep -v grep
473 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
474 check_diff $DIR/$tdir $TGT/$tdir
475 check_diff $DIR/$tdir $TGT2/$tdir
481 run_test 4 "Replicate files created by iozone"
483 # Test 5a - Stop / start lustre_rsync
489 createmany -o $DIR/$tdir/$tfile $NUMTEST
491 # Replicate the changes to $TGT
492 local LRSYNC_LOG=$(generate_logname "lrsync_log")
493 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
497 $KILL -SIGHUP $child_pid
499 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
501 check_diff $DIR/$tdir $TGT/$tdir
502 check_diff $DIR/$tdir $TGT2/$tdir
508 run_test 5a "Stop / start lustre_rsync"
510 # Test 5b - Kill / restart lustre_rsync
516 createmany -o $DIR/$tdir/$tfile $NUMTEST
518 # Replicate the changes to $TGT
519 local LRSYNC_LOG=$(generate_logname "lrsync_log")
520 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
524 $KILL -SIGKILL $child_pid
526 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
528 check_diff $DIR/$tdir $TGT/$tdir
529 check_diff $DIR/$tdir $TGT2/$tdir
535 run_test 5b "Kill / restart lustre_rsync"
537 # Test 6 - lustre_rsync large no of hard links
545 touch $DIR/$tdir/link0
546 for ((i = 1; i < num_links - 1; i++)); do
547 ln $DIR/$tdir/link0 $DIR/$tdir/link$i
549 # create an extra hard link of src name ending with dest name
550 ln $DIR/$tdir/link0 $DIR/$tdir/ink0
552 local LRSYNC_LOG=$(generate_logname "lrsync_log")
553 # Replicate the changes to $TGT
554 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
556 check_diff $DIR/$tdir $TGT/$tdir
557 check_diff $DIR/$tdir $TGT2/$tdir
559 local count1=$(stat --format=%h $TGT/$tdir/link0)
560 local count2=$(stat --format=%h $TGT2/$tdir/link0)
561 if ((count1 != num_links || count2 != num_links)); then
562 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
563 error "Incorrect no of hard links found $count1, $count2"
570 run_test 6 "lustre_rsync large no of hard links"
572 # Test 7 - lustre_rsync stripesize
575 mkdir -p ${DIR}/tgt/$tdir
579 lfs setstripe -c $OSTCOUNT $DIR/$tdir
580 createmany -o $DIR/$tdir/$tfile $NUMFILES
582 # To simulate replication to another lustre filesystem, replicate
583 # the changes to $DIR/tgt. We can't turn off the changelogs
584 # while we are registered, so lustre_rsync better not try to
585 # replicate the replication steps. It seems ok :)
587 local LRSYNC_LOG=$(generate_logname "lrsync_log")
588 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
590 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
593 while [ $i -lt $NUMFILES ];
595 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | \
596 awk '/stripe_count/ {print $2}')
597 if [ $count -ne $OSTCOUNT ]; then
598 error "Stripe size not replicated"
606 run_test 7 "lustre_rsync stripesize"
608 # Test 8 - Replicate multiple file/directory moves
613 for i in 1 2 3 4 5 6 7 8 9; do
615 for j in 1 2 3 4 5 6 7 8 9; do
616 mkdir $DIR/$tdir/d$i/d$i$j
617 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
619 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
620 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
622 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
624 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
627 local LRSYNC_LOG=$(generate_logname "lrsync_log")
628 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
631 check_diff ${DIR}/$tdir $TGT/$tdir
637 run_test 8 "Replicate multiple file/directory moves"
644 touch $DIR/$tdir/foo/a1
646 local LRSYNC_LOG=$(generate_logname "lrsync_log")
647 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
650 check_diff ${DIR}/$tdir $TGT/$tdir
652 rm -rf $DIR/$tdir/foo
654 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
657 check_diff ${DIR}/$tdir $TGT/$tdir
663 run_test 9 "Replicate recursive directory removal"
667 check_and_cleanup_lustre