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 procs_are_stopped() {
128 for state in $(ps -p "$pids" -o state=); do
129 if [[ "$state" != T ]]; then
137 # Send SIGSTOP to PIDs and wait up to 60 seconds for them to show a
138 # stopped process state.
144 end=$((SECONDS + 60))
145 while ((SECONDS < end)); do
146 if procs_are_stopped $pids; then
156 # Test 1 - test basic operations
160 local xattr=$(check_xattr $TGT/foo)
167 touch $DIR/$tdir/file1
168 cp /etc/hosts $DIR/$tdir/d1/
169 touch $DIR/$tdir/d1/"space in filename"
170 touch $DIR/$tdir/d1/file2
173 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
175 # File and directory delete
176 touch $DIR/$tdir/d1/file4
177 mkdir $DIR/$tdir/d1/del
178 touch $DIR/$tdir/d1/del/del1
179 touch $DIR/$tdir/d1/del/del2
180 rm -rf $DIR/$tdir/d1/del
181 rm $DIR/$tdir/d1/file4
184 cat /etc/hosts > $DIR/$tdir/d1/link1
185 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
186 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
189 #mknod $DIR/$tdir/dev1 b 8 1
192 local LRSYNC_LOG=$(generate_logname "lrsync_log")
193 echo "Replication #1"
194 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
198 chmod 000 $DIR/$tdir/d2/file3
199 chown nobody:nobody $DIR/$tdir/d2/file3
202 if [[ "$xattr" != "no" ]]; then
204 touch $DIR/$tdir/file5
205 [[ "$xattr" = "large" ]] &&
206 value="$(generate_string $(max_xattr_size))" || value="bar"
207 setfattr -n user.foo -v $value $DIR/$tdir/file5
210 echo "Replication #2"
211 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
213 if [[ "$xattr" != "no" ]]; then
214 local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
215 local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
220 # fid2path and path2fid aren't implemented for block devices
221 #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
222 # ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
223 # error "Error replicating block devices"
226 if [[ "$xattr" != "no" ]] &&
227 [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
228 error "Error in replicating xattrs."
232 # Use diff to compare the source and the destination
233 check_diff $DIR/$tdir $TGT/$tdir
234 check_diff $DIR/$tdir $TGT2/$tdir
240 run_test 1 "Simple Replication"
242 # Test 1a - test create/delete operations in ROOT directory
243 test_1a() { # LU-5005
244 rm -rf $TGT/root-* 2> /dev/null
245 rm -rf $DIR/root-* 2> /dev/null
254 touch $DIR/root-file2
257 mv $DIR/root-file2 $DIR/root-file3
259 # File and directory delete
260 touch $DIR/root-file4
263 rm -rf $DIR/root-dir1
266 local LRSYNC_LOG=$(generate_logname "lrsync_log")
268 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
272 stat $TGT/root-dir || error "Dir create not replicated"
273 stat $TGT/root-file || error "File create not replicated"
274 stat $TGT/root-file2 && error "Rename not replicated (src)"
275 stat $TGT/root-file3 || error "Rename not replicated (tgt)"
276 stat $TGT/root-dir1 && error "Dir delete not replicated"
277 stat $TGT/root-file4 && error "File delete not replicated"
285 run_test 1a "Replicate create/delete operations in ROOT directory"
287 # Test 2a - Replicate files created by dbench
293 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed"
295 local LRSYNC_LOG=$(generate_logname "lrsync_log")
296 # Replicate the changes to $TGT
297 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
300 # Use diff to compare the source and the destination
301 check_diff $DIR/$tdir $TGT/$tdir
302 check_diff $DIR/$tdir $TGT2/$tdir
308 run_test 2a "Replicate files created by dbench."
311 # Test 2b - Replicate files changed by dbench.
318 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
319 # wait for dbench to start
320 wait_for_function 'child_pid=$(pgrep dbench)' 360
321 # let dbench run for a bit
324 echo PIDs: $child_pid
326 stop_procs $child_pid
328 local LRSYNC_LOG=$(generate_logname "lrsync_log")
329 echo Starting replication
330 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
332 check_diff $DIR/$tdir $TGT/$tdir
335 $KILL -SIGCONT $child_pid
339 stop_procs $child_pid
341 echo Starting replication
342 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
343 check_diff $DIR/$tdir $TGT/$tdir
345 echo "Wait for dbench to finish"
346 $KILL -SIGCONT $child_pid
349 # Replicate the changes to $TGT
350 echo Starting replication
351 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
353 check_diff $DIR/$tdir $TGT/$tdir
354 check_diff $DIR/$tdir $TGT2/$tdir
360 run_test 2b "Replicate files changed by dbench."
362 # Test 2c - Replicate files while dbench is running
368 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
370 local LRSYNC_LOG=$(generate_logname "lrsync_log")
371 # Replicate the changes to $TGT
372 sleep 10 # give dbench a headstart
374 while [ $quit -le 1 ];
376 echo "Running lustre_rsync"
377 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
378 -l $LREPL_LOG -D $LRSYNC_LOG
381 if [ $? -ne 0 ]; then
382 quit=$(expr $quit + 1)
386 # Use diff to compare the source and the destination
387 check_diff $DIR/$tdir $TGT/$tdir
388 check_diff $DIR/$tdir $TGT2/$tdir
394 run_test 2c "Replicate files while dbench is running."
396 # Test 3a - Replicate files created by createmany
402 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
404 local LRSYNC_LOG=$(generate_logname "lrsync_log")
405 # Replicate the changes to $TGT
406 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
408 check_diff $DIR/$tdir $TGT/$tdir
409 check_diff $DIR/$tdir $TGT2/$tdir
415 run_test 3a "Replicate files created by createmany"
418 # Test 3b - Replicate files created by writemany
425 writemany -q -a $DIR/$tdir/$tfile $time $threads ||
426 error "writemany failed"
428 local LRSYNC_LOG=$(generate_logname "lrsync_log")
429 # Replicate the changes to $TGT
430 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
433 check_diff $DIR/$tdir $TGT/$tdir
434 check_diff $DIR/$tdir $TGT2/$tdir
440 run_test 3b "Replicate files created by writemany"
442 # Test 3c - Replicate files created by createmany/unlinkmany
448 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
449 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
451 local LRSYNC_LOG=$(generate_logname "lrsync_log")
452 # Replicate the changes to $TGT
453 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
455 check_diff $DIR/$tdir $TGT/$tdir
456 check_diff $DIR/$tdir $TGT2/$tdir
462 run_test 3c "Replicate files created by createmany/unlinkmany"
464 # Test 4 - Replicate files created by iozone
466 which iozone > /dev/null 2>&1
467 if [ $? -ne 0 ]; then
468 skip "iozone not found. Skipping test"
475 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
476 MOUNT=${DIR}/$tdir run_iozone.sh &
478 child_pid=$(pgrep iozone)
479 stop_procs $child_pid
481 local LRSYNC_LOG=$(generate_logname "lrsync_log")
482 # Replicate the changes to $TGT
483 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
485 check_diff $DIR/$tdir $TGT/$tdir
486 check_diff $DIR/$tdir $TGT2/$tdir
488 $KILL -SIGCONT $child_pid
490 $KILL -SIGKILL $(pgrep run_iozone.sh)
491 $KILL -SIGKILL $(pgrep iozone)
493 # After killing 'run_iozone.sh', process 'iozone' becomes the
494 # child of PID 1. Hence 'wait' does not wait for it. Killing
495 # iozone first, means more iozone processes are spawned off which
496 # is not desirable. So, after sending a sigkill, the test goes
497 # into a wait loop for iozone to cleanup and exit.
499 while [ "$(pgrep "iozone")" != "" ];
501 ps -ef | grep iozone | grep -v grep
505 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
506 check_diff $DIR/$tdir $TGT/$tdir
507 check_diff $DIR/$tdir $TGT2/$tdir
513 run_test 4 "Replicate files created by iozone"
515 # Test 5a - Stop / start lustre_rsync
521 createmany -o $DIR/$tdir/$tfile $NUMTEST
523 # Replicate the changes to $TGT
524 local LRSYNC_LOG=$(generate_logname "lrsync_log")
525 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
529 $KILL -SIGHUP $child_pid
531 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
533 check_diff $DIR/$tdir $TGT/$tdir
534 check_diff $DIR/$tdir $TGT2/$tdir
540 run_test 5a "Stop / start lustre_rsync"
542 # Test 5b - Kill / restart lustre_rsync
548 createmany -o $DIR/$tdir/$tfile $NUMTEST
550 # Replicate the changes to $TGT
551 local LRSYNC_LOG=$(generate_logname "lrsync_log")
552 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
556 $KILL -SIGKILL $child_pid
558 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
560 check_diff $DIR/$tdir $TGT/$tdir
561 check_diff $DIR/$tdir $TGT2/$tdir
567 run_test 5b "Kill / restart lustre_rsync"
569 # Test 6 - lustre_rsync large no of hard links
577 touch $DIR/$tdir/link0
578 for ((i = 1; i < num_links - 1; i++)); do
579 ln $DIR/$tdir/link0 $DIR/$tdir/link$i
581 # create an extra hard link of src name ending with dest name
582 ln $DIR/$tdir/link0 $DIR/$tdir/ink0
584 local LRSYNC_LOG=$(generate_logname "lrsync_log")
585 # Replicate the changes to $TGT
586 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
588 check_diff $DIR/$tdir $TGT/$tdir
589 check_diff $DIR/$tdir $TGT2/$tdir
591 local count1=$(stat --format=%h $TGT/$tdir/link0)
592 local count2=$(stat --format=%h $TGT2/$tdir/link0)
593 if ((count1 != num_links || count2 != num_links)); then
594 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
595 error "Incorrect no of hard links found $count1, $count2"
602 run_test 6 "lustre_rsync large no of hard links"
604 # Test 7 - lustre_rsync stripesize
607 mkdir -p ${DIR}/tgt/$tdir
611 lfs setstripe -c $OSTCOUNT $DIR/$tdir
612 createmany -o $DIR/$tdir/$tfile $NUMFILES
614 # To simulate replication to another lustre filesystem, replicate
615 # the changes to $DIR/tgt. We can't turn off the changelogs
616 # while we are registered, so lustre_rsync better not try to
617 # replicate the replication steps. It seems ok :)
619 local LRSYNC_LOG=$(generate_logname "lrsync_log")
620 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
622 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
625 while [ $i -lt $NUMFILES ];
627 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | \
628 awk '/stripe_count/ {print $2}')
629 if [ $count -ne $OSTCOUNT ]; then
630 error "Stripe size not replicated"
638 run_test 7 "lustre_rsync stripesize"
640 # Test 8 - Replicate multiple file/directory moves
645 for i in 1 2 3 4 5 6 7 8 9; do
647 for j in 1 2 3 4 5 6 7 8 9; do
648 mkdir $DIR/$tdir/d$i/d$i$j
649 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
651 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
652 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
654 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
656 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
659 local LRSYNC_LOG=$(generate_logname "lrsync_log")
660 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
663 check_diff ${DIR}/$tdir $TGT/$tdir
669 run_test 8 "Replicate multiple file/directory moves"
676 touch $DIR/$tdir/foo/a1
678 local LRSYNC_LOG=$(generate_logname "lrsync_log")
679 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
682 check_diff ${DIR}/$tdir $TGT/$tdir
684 rm -rf $DIR/$tdir/foo
686 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
689 check_diff ${DIR}/$tdir $TGT/$tdir
695 run_test 9 "Replicate recursive directory removal"
699 check_and_cleanup_lustre