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 # bug number for skipped test: LU-4256
16 ALWAYS_EXCEPT="$LRSYNC_EXCEPT 2b"
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
41 if getent group nobody; then
43 elif getent group nogroup; then
46 error "No generic nobody group"
51 export LRSYNC=${LRSYNC:-"$LUSTRE/utils/lustre_rsync"}
52 [ ! -f "$LRSYNC" ] && export LRSYNC=$(which lustre_rsync)
53 export LRSYNC="$LRSYNC -v -c no -d 2"
55 # Number of seconds to run dbench
56 DBENCH_TIME=${DBENCH_TIME:-60}
59 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
60 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
63 changelog_register || error "changelog_register failed"
64 CL_USER=(${CL_USERS[$SINGLEMDS]})
65 echo $MDT0: Registered changelog user $CL_USER
67 echo "No changelog users present on $SINGLEMDS"
76 rm -rf $TGT/$tdir $TGT/d*.lustre_rsync-test 2> /dev/null
77 rm -rf $TGT2/$tdir $TGT2/d*.lustre_rsync-test 2> /dev/null
78 rm -rf ${DIR}/$tdir $DIR/d*.lustre_rsync-test ${DIR}/tgt 2> /dev/null
80 mkdir -p ${DIR}/$tdir || error "Failed to create target: " $DIR/$tdir
81 mkdir -p ${TGT}/$tdir || error "Failed to create target: " $TGT/$tdir
82 mkdir -p ${TGT2}/$tdir || error "Failed to create target: " $TGT2/$tdir
91 # Check whether the filesystem supports xattr or not.
93 # "large" - large xattr is supported
94 # "small" - large xattr is unsupported but small xattr is supported
95 # "no" - xattr is unsupported
102 local val="$(generate_string $(max_xattr_size))"
103 if large_xattr_enabled &&
104 setfattr -n user.foo -v $val $tgt 2>/dev/null; then
107 setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
115 local changelog_file=$(generate_logname "changelog")
117 if [ -e $1 -o -e $2 ]; then
118 diff -rq -x "dev1" $1 $2
120 if [ $RC -ne 0 ]; then
121 $LFS changelog $MDT0 > $changelog_file
122 error "Failure in replication; differences found."
127 procs_are_stopped() {
131 for state in $(ps -p "$pids" -o state=); do
132 if [[ "$state" != T ]]; then
140 # Send SIGSTOP to PIDs and wait up to 60 seconds for them to show a
141 # stopped process state.
147 end=$((SECONDS + 60))
148 while ((SECONDS < end)); do
149 if procs_are_stopped $pids; then
159 # Test 1A - test basic operations
160 test_1A() { # was test_1
163 local xattr=$(check_xattr $TGT/foo)
170 touch $DIR/$tdir/file1
171 cp /etc/hosts $DIR/$tdir/d1/
172 touch $DIR/$tdir/d1/"space in filename"
173 touch $DIR/$tdir/d1/file2
176 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
178 # File and directory delete
179 touch $DIR/$tdir/d1/file4
180 mkdir $DIR/$tdir/d1/del
181 touch $DIR/$tdir/d1/del/del1
182 touch $DIR/$tdir/d1/del/del2
183 rm -rf $DIR/$tdir/d1/del
184 rm $DIR/$tdir/d1/file4
187 cat /etc/hosts > $DIR/$tdir/d1/link1
188 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
189 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
192 #mknod $DIR/$tdir/dev1 b 8 1
195 local LRSYNC_LOG=$(generate_logname "lrsync_log")
196 echo "Replication #1"
197 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
201 chmod 000 $DIR/$tdir/d2/file3
202 chown nobody:$GROUP $DIR/$tdir/d2/file3
205 if [[ "$xattr" != "no" ]]; then
207 touch $DIR/$tdir/file5
208 [[ "$xattr" = "large" ]] &&
209 value="$(generate_string $(max_xattr_size))" || value="bar"
210 setfattr -n user.foo -v $value $DIR/$tdir/file5
213 echo "Replication #2"
214 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
216 if [[ "$xattr" != "no" ]]; then
217 local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
218 local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
220 if [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
221 error "Error in replicating xattrs."
225 # Use diff to compare the source and the destination
226 check_diff $DIR/$tdir $TGT/$tdir
227 check_diff $DIR/$tdir $TGT2/$tdir
232 run_test 1A "Simple Replication"
234 # Test 1a - test create/delete operations in ROOT directory
235 test_1a() { # LU-5005
236 rm -rf $TGT/root-* 2> /dev/null
237 rm -rf $DIR/root-* 2> /dev/null
246 touch $DIR/root-file2
249 mv $DIR/root-file2 $DIR/root-file3
251 # File and directory delete
252 touch $DIR/root-file4
255 rm -rf $DIR/root-dir1
258 local LRSYNC_LOG=$(generate_logname "lrsync_log")
260 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
264 stat $TGT/root-dir || error "Dir create not replicated"
265 stat $TGT/root-file || error "File create not replicated"
266 stat $TGT/root-file2 && error "Rename not replicated (src)"
267 stat $TGT/root-file3 || error "Rename not replicated (tgt)"
268 stat $TGT/root-dir1 && error "Dir delete not replicated"
269 stat $TGT/root-file4 && error "File delete not replicated"
277 run_test 1a "Replicate create/delete operations in ROOT directory"
279 # Test 2a - Replicate files created by dbench
285 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed"
287 local LRSYNC_LOG=$(generate_logname "lrsync_log")
288 # Replicate the changes to $TGT
289 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
292 # Use diff to compare the source and the destination
293 check_diff $DIR/$tdir $TGT/$tdir
294 check_diff $DIR/$tdir $TGT2/$tdir
300 run_test 2a "Replicate files created by dbench."
302 # Test 2b - Replicate files changed by dbench.
309 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
310 # wait for dbench to start
311 wait_for_function 'child_pid=$(pgrep dbench)' 360
312 # let dbench run for a bit
315 echo PIDs: $child_pid
317 stop_procs $child_pid
319 local LRSYNC_LOG=$(generate_logname "lrsync_log")
320 echo Starting replication
321 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
323 check_diff $DIR/$tdir $TGT/$tdir
326 $KILL -SIGCONT $child_pid
330 stop_procs $child_pid
332 echo Starting replication
333 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
334 check_diff $DIR/$tdir $TGT/$tdir
336 echo "Wait for dbench to finish"
337 $KILL -SIGCONT $child_pid
340 # Replicate the changes to $TGT
341 echo Starting replication
342 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
344 check_diff $DIR/$tdir $TGT/$tdir
345 check_diff $DIR/$tdir $TGT2/$tdir
351 run_test 2b "Replicate files changed by dbench."
353 # Test 2c - Replicate files while dbench is running
359 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
361 local LRSYNC_LOG=$(generate_logname "lrsync_log")
362 # Replicate the changes to $TGT
363 sleep 10 # give dbench a headstart
365 while [ $quit -le 1 ];
367 echo "Running lustre_rsync"
368 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
369 -l $LREPL_LOG -D $LRSYNC_LOG
372 if [ $? -ne 0 ]; then
373 quit=$(expr $quit + 1)
377 # Use diff to compare the source and the destination
378 check_diff $DIR/$tdir $TGT/$tdir
379 check_diff $DIR/$tdir $TGT2/$tdir
385 run_test 2c "Replicate files while dbench is running."
387 # Test 3a - Replicate files created by createmany
393 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
395 local LRSYNC_LOG=$(generate_logname "lrsync_log")
396 # Replicate the changes to $TGT
397 $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 3a "Replicate files created by createmany"
408 # Test 3b - Replicate files created by writemany
415 writemany -q -a $DIR/$tdir/$tfile $time $threads ||
416 error "writemany failed"
418 local LRSYNC_LOG=$(generate_logname "lrsync_log")
419 # Replicate the changes to $TGT
420 $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 3b "Replicate files created by writemany"
432 # Test 3c - Replicate files created by createmany/unlinkmany
438 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
439 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
441 local LRSYNC_LOG=$(generate_logname "lrsync_log")
442 # Replicate the changes to $TGT
443 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
445 check_diff $DIR/$tdir $TGT/$tdir
446 check_diff $DIR/$tdir $TGT2/$tdir
452 run_test 3c "Replicate files created by createmany/unlinkmany"
454 # Test 4 - Replicate files created by iozone
456 which iozone > /dev/null 2>&1
457 [ $? -ne 0 ] && skip "iozone not found"
462 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
463 MOUNT=${DIR}/$tdir run_iozone.sh &
465 child_pid=$(pgrep iozone)
466 stop_procs $child_pid
468 local LRSYNC_LOG=$(generate_logname "lrsync_log")
469 # Replicate the changes to $TGT
470 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
472 check_diff $DIR/$tdir $TGT/$tdir
473 check_diff $DIR/$tdir $TGT2/$tdir
475 $KILL -SIGCONT $child_pid
477 $KILL -SIGKILL $(pgrep run_iozone.sh)
478 $KILL -SIGKILL $(pgrep iozone)
480 # After killing 'run_iozone.sh', process 'iozone' becomes the
481 # child of PID 1. Hence 'wait' does not wait for it. Killing
482 # iozone first, means more iozone processes are spawned off which
483 # is not desirable. So, after sending a sigkill, the test goes
484 # into a wait loop for iozone to cleanup and exit.
486 while [ "$(pgrep "iozone")" != "" ];
488 ps -ef | grep iozone | grep -v grep
492 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
493 check_diff $DIR/$tdir $TGT/$tdir
494 check_diff $DIR/$tdir $TGT2/$tdir
500 run_test 4 "Replicate files created by iozone"
502 # Test 5a - Stop / start lustre_rsync
508 createmany -o $DIR/$tdir/$tfile $NUMTEST
510 # Replicate the changes to $TGT
511 local LRSYNC_LOG=$(generate_logname "lrsync_log")
512 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
516 $KILL -SIGHUP $child_pid
518 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
520 check_diff $DIR/$tdir $TGT/$tdir
521 check_diff $DIR/$tdir $TGT2/$tdir
527 run_test 5a "Stop / start lustre_rsync"
529 # Test 5b - Kill / restart lustre_rsync
535 createmany -o $DIR/$tdir/$tfile $NUMTEST
537 # Replicate the changes to $TGT
538 local LRSYNC_LOG=$(generate_logname "lrsync_log")
539 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
543 $KILL -SIGKILL $child_pid
545 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
547 check_diff $DIR/$tdir $TGT/$tdir
548 check_diff $DIR/$tdir $TGT2/$tdir
554 run_test 5b "Kill / restart lustre_rsync"
556 # Test 6 - lustre_rsync large no of hard links
564 touch $DIR/$tdir/link0
565 for ((i = 1; i < num_links - 1; i++)); do
566 ln $DIR/$tdir/link0 $DIR/$tdir/link$i
568 # create an extra hard link of src name ending with dest name
569 ln $DIR/$tdir/link0 $DIR/$tdir/ink0
571 local LRSYNC_LOG=$(generate_logname "lrsync_log")
572 # Replicate the changes to $TGT
573 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
575 check_diff $DIR/$tdir $TGT/$tdir
576 check_diff $DIR/$tdir $TGT2/$tdir
578 local count1=$(stat --format=%h $TGT/$tdir/link0)
579 local count2=$(stat --format=%h $TGT2/$tdir/link0)
580 if ((count1 != num_links || count2 != num_links)); then
581 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
582 error "Incorrect no of hard links found $count1, $count2"
589 run_test 6 "lustre_rsync large no of hard links"
591 # Test 7 - lustre_rsync stripesize
596 mkdir -p ${DIR}/tgt/$tdir
599 $LFS setstripe -c $OSTCOUNT $DIR/$tdir ||
600 error "$LFS setstripe failed"
601 createmany -o $DIR/$tdir/$tfile $numfiles
603 # To simulate replication to another lustre filesystem, replicate
604 # the changes to $DIR/tgt. We can't turn off the changelogs
605 # while we are registered, so lustre_rsync better not try to
606 # replicate the replication steps. It seems ok :)
608 local LRSYNC_LOG=$(generate_logname "lrsync_log")
609 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
611 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
614 while [ $i -lt $numfiles ];
616 local count=$($LFS getstripe $DIR/tgt/$tdir/${tfile}$i |
617 awk '/stripe_count/ {print $2}')
618 if [ $count -ne $OSTCOUNT ]; then
619 error "Stripe size not replicated"
627 run_test 7 "lustre_rsync stripesize"
629 # Test 8 - Replicate multiple file/directory moves
634 for i in 1 2 3 4 5 6 7 8 9; do
636 for j in 1 2 3 4 5 6 7 8 9; do
637 mkdir $DIR/$tdir/d$i/d$i$j
638 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
640 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
641 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
643 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
645 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
648 local LRSYNC_LOG=$(generate_logname "lrsync_log")
649 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
652 check_diff ${DIR}/$tdir $TGT/$tdir
658 run_test 8 "Replicate multiple file/directory moves"
665 touch $DIR/$tdir/foo/a1
667 local LRSYNC_LOG=$(generate_logname "lrsync_log")
668 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
671 check_diff ${DIR}/$tdir $TGT/$tdir
673 rm -rf $DIR/$tdir/foo
675 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
678 check_diff ${DIR}/$tdir $TGT/$tdir
684 run_test 9 "Replicate recursive directory removal"
688 check_and_cleanup_lustre