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
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 # control the time of tests
56 DBENCH_TIME=${DBENCH_TIME:-60} # No of seconds to run dbench
59 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
60 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
63 CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
64 echo $MDT0: Registered changelog user $CL_USER
65 CL_USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
66 mdd.$MDT0.changelog_users | wc -l) - 2 ))
67 [ $CL_USERS -ne 1 ] && \
68 echo "Other changelog users present ($CL_USERS)"
72 rm -rf $TGT/$tdir $TGT/d*.lustre_rsync-test 2> /dev/null
73 rm -rf $TGT2/$tdir $TGT2/d*.lustre_rsync-test 2> /dev/null
74 rm -rf ${DIR}/$tdir $DIR/d*.lustre_rsync-test ${DIR}/tgt 2> /dev/null
78 mkdir -p ${TGT2}/$tdir
80 error "Failed to create target: " $TGT
91 $LFS changelog_clear $MDT0 $CL_USER 0
92 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
95 # Check whether the filesystem supports xattr or not.
97 # "large" - large xattr is supported
98 # "small" - large xattr is unsupported but small xattr is supported
99 # "no" - xattr is unsupported
106 local val="$(generate_string $(max_xattr_size))"
107 if large_xattr_enabled &&
108 setfattr -n user.foo -v $val $tgt 2>/dev/null; then
111 setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
119 local changelog_file=$(generate_logname "changelog")
121 if [ -e $1 -o -e $2 ]; then
122 diff -rq -x "dev1" $1 $2
124 if [ $RC -ne 0 ]; then
125 $LFS changelog $MDT0 > $changelog_file
126 error "Failure in replication; differences found."
131 procs_are_stopped() {
135 for state in $(ps -p "$pids" -o state=); do
136 if [[ "$state" != T ]]; then
144 # Send SIGSTOP to PIDs and wait up to 60 seconds for them to show a
145 # stopped process state.
151 end=$((SECONDS + 60))
152 while ((SECONDS < end)); do
153 if procs_are_stopped $pids; then
163 # Test 1 - test basic operations
164 test_1A() { # was test_1
167 local xattr=$(check_xattr $TGT/foo)
174 touch $DIR/$tdir/file1
175 cp /etc/hosts $DIR/$tdir/d1/
176 touch $DIR/$tdir/d1/"space in filename"
177 touch $DIR/$tdir/d1/file2
180 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
182 # File and directory delete
183 touch $DIR/$tdir/d1/file4
184 mkdir $DIR/$tdir/d1/del
185 touch $DIR/$tdir/d1/del/del1
186 touch $DIR/$tdir/d1/del/del2
187 rm -rf $DIR/$tdir/d1/del
188 rm $DIR/$tdir/d1/file4
191 cat /etc/hosts > $DIR/$tdir/d1/link1
192 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
193 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
196 #mknod $DIR/$tdir/dev1 b 8 1
199 local LRSYNC_LOG=$(generate_logname "lrsync_log")
200 echo "Replication #1"
201 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
205 chmod 000 $DIR/$tdir/d2/file3
206 chown nobody:$GROUP $DIR/$tdir/d2/file3
209 if [[ "$xattr" != "no" ]]; then
211 touch $DIR/$tdir/file5
212 [[ "$xattr" = "large" ]] &&
213 value="$(generate_string $(max_xattr_size))" || value="bar"
214 setfattr -n user.foo -v $value $DIR/$tdir/file5
217 echo "Replication #2"
218 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
220 if [[ "$xattr" != "no" ]]; then
221 local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
222 local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
227 # fid2path and path2fid aren't implemented for block devices
228 #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
229 # ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
230 # error "Error replicating block devices"
233 if [[ "$xattr" != "no" ]] &&
234 [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
235 error "Error in replicating xattrs."
239 # Use diff to compare the source and the destination
240 check_diff $DIR/$tdir $TGT/$tdir
241 check_diff $DIR/$tdir $TGT2/$tdir
247 run_test 1A "Simple Replication"
249 # Test 1a - test create/delete operations in ROOT directory
250 test_1a() { # LU-5005
251 rm -rf $TGT/root-* 2> /dev/null
252 rm -rf $DIR/root-* 2> /dev/null
261 touch $DIR/root-file2
264 mv $DIR/root-file2 $DIR/root-file3
266 # File and directory delete
267 touch $DIR/root-file4
270 rm -rf $DIR/root-dir1
273 local LRSYNC_LOG=$(generate_logname "lrsync_log")
275 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
279 stat $TGT/root-dir || error "Dir create not replicated"
280 stat $TGT/root-file || error "File create not replicated"
281 stat $TGT/root-file2 && error "Rename not replicated (src)"
282 stat $TGT/root-file3 || error "Rename not replicated (tgt)"
283 stat $TGT/root-dir1 && error "Dir delete not replicated"
284 stat $TGT/root-file4 && error "File delete not replicated"
292 run_test 1a "Replicate create/delete operations in ROOT directory"
294 # Test 2a - Replicate files created by dbench
300 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed"
302 local LRSYNC_LOG=$(generate_logname "lrsync_log")
303 # Replicate the changes to $TGT
304 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
307 # Use diff to compare the source and the destination
308 check_diff $DIR/$tdir $TGT/$tdir
309 check_diff $DIR/$tdir $TGT2/$tdir
315 run_test 2a "Replicate files created by dbench."
318 # Test 2b - Replicate files changed by dbench.
325 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
326 # wait for dbench to start
327 wait_for_function 'child_pid=$(pgrep dbench)' 360
328 # let dbench run for a bit
331 echo PIDs: $child_pid
333 stop_procs $child_pid
335 local LRSYNC_LOG=$(generate_logname "lrsync_log")
336 echo Starting replication
337 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
339 check_diff $DIR/$tdir $TGT/$tdir
342 $KILL -SIGCONT $child_pid
346 stop_procs $child_pid
348 echo Starting replication
349 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
350 check_diff $DIR/$tdir $TGT/$tdir
352 echo "Wait for dbench to finish"
353 $KILL -SIGCONT $child_pid
356 # Replicate the changes to $TGT
357 echo Starting replication
358 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
360 check_diff $DIR/$tdir $TGT/$tdir
361 check_diff $DIR/$tdir $TGT2/$tdir
367 run_test 2b "Replicate files changed by dbench."
369 # Test 2c - Replicate files while dbench is running
375 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
377 local LRSYNC_LOG=$(generate_logname "lrsync_log")
378 # Replicate the changes to $TGT
379 sleep 10 # give dbench a headstart
381 while [ $quit -le 1 ];
383 echo "Running lustre_rsync"
384 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
385 -l $LREPL_LOG -D $LRSYNC_LOG
388 if [ $? -ne 0 ]; then
389 quit=$(expr $quit + 1)
393 # Use diff to compare the source and the destination
394 check_diff $DIR/$tdir $TGT/$tdir
395 check_diff $DIR/$tdir $TGT2/$tdir
401 run_test 2c "Replicate files while dbench is running."
403 # Test 3a - Replicate files created by createmany
409 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
411 local LRSYNC_LOG=$(generate_logname "lrsync_log")
412 # Replicate the changes to $TGT
413 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
415 check_diff $DIR/$tdir $TGT/$tdir
416 check_diff $DIR/$tdir $TGT2/$tdir
422 run_test 3a "Replicate files created by createmany"
425 # Test 3b - Replicate files created by writemany
432 writemany -q -a $DIR/$tdir/$tfile $time $threads ||
433 error "writemany failed"
435 local LRSYNC_LOG=$(generate_logname "lrsync_log")
436 # Replicate the changes to $TGT
437 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
440 check_diff $DIR/$tdir $TGT/$tdir
441 check_diff $DIR/$tdir $TGT2/$tdir
447 run_test 3b "Replicate files created by writemany"
449 # Test 3c - Replicate files created by createmany/unlinkmany
455 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
456 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
458 local LRSYNC_LOG=$(generate_logname "lrsync_log")
459 # Replicate the changes to $TGT
460 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
462 check_diff $DIR/$tdir $TGT/$tdir
463 check_diff $DIR/$tdir $TGT2/$tdir
469 run_test 3c "Replicate files created by createmany/unlinkmany"
471 # Test 4 - Replicate files created by iozone
473 which iozone > /dev/null 2>&1
474 if [ $? -ne 0 ]; then
475 skip "iozone not found. Skipping test"
482 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
483 MOUNT=${DIR}/$tdir run_iozone.sh &
485 child_pid=$(pgrep iozone)
486 stop_procs $child_pid
488 local LRSYNC_LOG=$(generate_logname "lrsync_log")
489 # Replicate the changes to $TGT
490 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
492 check_diff $DIR/$tdir $TGT/$tdir
493 check_diff $DIR/$tdir $TGT2/$tdir
495 $KILL -SIGCONT $child_pid
497 $KILL -SIGKILL $(pgrep run_iozone.sh)
498 $KILL -SIGKILL $(pgrep iozone)
500 # After killing 'run_iozone.sh', process 'iozone' becomes the
501 # child of PID 1. Hence 'wait' does not wait for it. Killing
502 # iozone first, means more iozone processes are spawned off which
503 # is not desirable. So, after sending a sigkill, the test goes
504 # into a wait loop for iozone to cleanup and exit.
506 while [ "$(pgrep "iozone")" != "" ];
508 ps -ef | grep iozone | grep -v grep
512 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
513 check_diff $DIR/$tdir $TGT/$tdir
514 check_diff $DIR/$tdir $TGT2/$tdir
520 run_test 4 "Replicate files created by iozone"
522 # Test 5a - Stop / start lustre_rsync
528 createmany -o $DIR/$tdir/$tfile $NUMTEST
530 # Replicate the changes to $TGT
531 local LRSYNC_LOG=$(generate_logname "lrsync_log")
532 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
536 $KILL -SIGHUP $child_pid
538 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
540 check_diff $DIR/$tdir $TGT/$tdir
541 check_diff $DIR/$tdir $TGT2/$tdir
547 run_test 5a "Stop / start lustre_rsync"
549 # Test 5b - Kill / restart lustre_rsync
555 createmany -o $DIR/$tdir/$tfile $NUMTEST
557 # Replicate the changes to $TGT
558 local LRSYNC_LOG=$(generate_logname "lrsync_log")
559 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
563 $KILL -SIGKILL $child_pid
565 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
567 check_diff $DIR/$tdir $TGT/$tdir
568 check_diff $DIR/$tdir $TGT2/$tdir
574 run_test 5b "Kill / restart lustre_rsync"
576 # Test 6 - lustre_rsync large no of hard links
584 touch $DIR/$tdir/link0
585 for ((i = 1; i < num_links - 1; i++)); do
586 ln $DIR/$tdir/link0 $DIR/$tdir/link$i
588 # create an extra hard link of src name ending with dest name
589 ln $DIR/$tdir/link0 $DIR/$tdir/ink0
591 local LRSYNC_LOG=$(generate_logname "lrsync_log")
592 # Replicate the changes to $TGT
593 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
595 check_diff $DIR/$tdir $TGT/$tdir
596 check_diff $DIR/$tdir $TGT2/$tdir
598 local count1=$(stat --format=%h $TGT/$tdir/link0)
599 local count2=$(stat --format=%h $TGT2/$tdir/link0)
600 if ((count1 != num_links || count2 != num_links)); then
601 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
602 error "Incorrect no of hard links found $count1, $count2"
609 run_test 6 "lustre_rsync large no of hard links"
611 # Test 7 - lustre_rsync stripesize
614 mkdir -p ${DIR}/tgt/$tdir
618 lfs setstripe -c $OSTCOUNT $DIR/$tdir
619 createmany -o $DIR/$tdir/$tfile $NUMFILES
621 # To simulate replication to another lustre filesystem, replicate
622 # the changes to $DIR/tgt. We can't turn off the changelogs
623 # while we are registered, so lustre_rsync better not try to
624 # replicate the replication steps. It seems ok :)
626 local LRSYNC_LOG=$(generate_logname "lrsync_log")
627 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
629 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
632 while [ $i -lt $NUMFILES ];
634 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | \
635 awk '/stripe_count/ {print $2}')
636 if [ $count -ne $OSTCOUNT ]; then
637 error "Stripe size not replicated"
645 run_test 7 "lustre_rsync stripesize"
647 # Test 8 - Replicate multiple file/directory moves
652 for i in 1 2 3 4 5 6 7 8 9; do
654 for j in 1 2 3 4 5 6 7 8 9; do
655 mkdir $DIR/$tdir/d$i/d$i$j
656 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
658 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
659 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
661 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
663 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
666 local LRSYNC_LOG=$(generate_logname "lrsync_log")
667 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
670 check_diff ${DIR}/$tdir $TGT/$tdir
676 run_test 8 "Replicate multiple file/directory moves"
683 touch $DIR/$tdir/foo/a1
685 local LRSYNC_LOG=$(generate_logname "lrsync_log")
686 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
689 check_diff ${DIR}/$tdir $TGT/$tdir
691 rm -rf $DIR/$tdir/foo
693 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
696 check_diff ${DIR}/$tdir $TGT/$tdir
702 run_test 9 "Replicate recursive directory removal"
706 check_and_cleanup_lustre