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 2a - Replicate files created by dbench
216 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed"
218 local LRSYNC_LOG=$(generate_logname "lrsync_log")
219 # Replicate the changes to $TGT
220 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
223 # Use diff to compare the source and the destination
224 check_diff $DIR/$tdir $TGT/$tdir
225 check_diff $DIR/$tdir $TGT2/$tdir
231 run_test 2a "Replicate files created by dbench."
234 # Test 2b - Replicate files changed by dbench.
241 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
242 # wait for dbench to start
243 wait_for_function 'child_pid=$(pgrep dbench)' 360
244 # let dbench run for a bit
247 echo PIDs: $child_pid
249 $KILL -SIGSTOP $child_pid
251 local LRSYNC_LOG=$(generate_logname "lrsync_log")
252 echo Starting replication
253 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
255 check_diff $DIR/$tdir $TGT/$tdir
258 $KILL -SIGCONT $child_pid
262 $KILL -SIGSTOP $child_pid
264 echo Starting replication
265 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
266 check_diff $DIR/$tdir $TGT/$tdir
268 echo "Wait for dbench to finish"
269 $KILL -SIGCONT $child_pid
272 # Replicate the changes to $TGT
273 echo Starting replication
274 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
276 check_diff $DIR/$tdir $TGT/$tdir
277 check_diff $DIR/$tdir $TGT2/$tdir
283 run_test 2b "Replicate files changed by dbench."
285 # Test 2c - Replicate files while dbench is running
291 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
293 local LRSYNC_LOG=$(generate_logname "lrsync_log")
294 # Replicate the changes to $TGT
295 sleep 10 # give dbench a headstart
297 while [ $quit -le 1 ];
299 echo "Running lustre_rsync"
300 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
301 -l $LREPL_LOG -D $LRSYNC_LOG
304 if [ $? -ne 0 ]; then
305 quit=$(expr $quit + 1)
309 # Use diff to compare the source and the destination
310 check_diff $DIR/$tdir $TGT/$tdir
311 check_diff $DIR/$tdir $TGT2/$tdir
317 run_test 2c "Replicate files while dbench is running."
319 # Test 3a - Replicate files created by createmany
325 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
327 local LRSYNC_LOG=$(generate_logname "lrsync_log")
328 # Replicate the changes to $TGT
329 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
331 check_diff $DIR/$tdir $TGT/$tdir
332 check_diff $DIR/$tdir $TGT2/$tdir
338 run_test 3a "Replicate files created by createmany"
341 # Test 3b - Replicate files created by writemany
348 writemany -q -a $DIR/$tdir/$tfile $time $threads ||
349 error "writemany failed"
351 local LRSYNC_LOG=$(generate_logname "lrsync_log")
352 # Replicate the changes to $TGT
353 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
356 check_diff $DIR/$tdir $TGT/$tdir
357 check_diff $DIR/$tdir $TGT2/$tdir
363 run_test 3b "Replicate files created by writemany"
365 # Test 3c - Replicate files created by createmany/unlinkmany
371 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
372 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
374 local LRSYNC_LOG=$(generate_logname "lrsync_log")
375 # Replicate the changes to $TGT
376 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
378 check_diff $DIR/$tdir $TGT/$tdir
379 check_diff $DIR/$tdir $TGT2/$tdir
385 run_test 3c "Replicate files created by createmany/unlinkmany"
387 # Test 4 - Replicate files created by iozone
389 which iozone > /dev/null 2>&1
390 if [ $? -ne 0 ]; then
391 skip "iozone not found. Skipping test"
398 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
399 MOUNT=${DIR}/$tdir run_iozone.sh &
401 child_pid=$(pgrep iozone)
402 $KILL -SIGSTOP $child_pid
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
411 $KILL -SIGCONT $child_pid
413 $KILL -SIGKILL $(pgrep run_iozone.sh)
414 $KILL -SIGKILL $(pgrep iozone)
416 # After killing 'run_iozone.sh', process 'iozone' becomes the
417 # child of PID 1. Hence 'wait' does not wait for it. Killing
418 # iozone first, means more iozone processes are spawned off which
419 # is not desirable. So, after sending a sigkill, the test goes
420 # into a wait loop for iozone to cleanup and exit.
422 while [ "$(pgrep "iozone")" != "" ];
424 ps -ef | grep iozone | grep -v grep
428 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
429 check_diff $DIR/$tdir $TGT/$tdir
430 check_diff $DIR/$tdir $TGT2/$tdir
436 run_test 4 "Replicate files created by iozone"
438 # Test 5a - Stop / start lustre_rsync
444 createmany -o $DIR/$tdir/$tfile $NUMTEST
446 # Replicate the changes to $TGT
447 local LRSYNC_LOG=$(generate_logname "lrsync_log")
448 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
452 $KILL -SIGHUP $child_pid
454 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
456 check_diff $DIR/$tdir $TGT/$tdir
457 check_diff $DIR/$tdir $TGT2/$tdir
463 run_test 5a "Stop / start lustre_rsync"
465 # Test 5b - Kill / restart lustre_rsync
471 createmany -o $DIR/$tdir/$tfile $NUMTEST
473 # Replicate the changes to $TGT
474 local LRSYNC_LOG=$(generate_logname "lrsync_log")
475 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
479 $KILL -SIGKILL $child_pid
481 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
483 check_diff $DIR/$tdir $TGT/$tdir
484 check_diff $DIR/$tdir $TGT2/$tdir
490 run_test 5b "Kill / restart lustre_rsync"
492 # Test 6 - lustre_rsync large no of hard links
498 touch $DIR/$tdir/link0
500 while [ $i -lt $NUMLINKS ];
502 ln $DIR/$tdir/link0 $DIR/$tdir/link${i}
506 local LRSYNC_LOG=$(generate_logname "lrsync_log")
507 # Replicate the changes to $TGT
508 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
510 check_diff $DIR/$tdir $TGT/$tdir
511 check_diff $DIR/$tdir $TGT2/$tdir
513 local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
514 local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
515 if [[ $count1 -ne $NUMLINKS ]] || [[ $count2 -ne $NUMLINKS ]]; then
516 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
517 error "Incorrect no of hard links found $count1, $count2"
523 run_test 6 "lustre_rsync large no of hard links"
525 # Test 7 - lustre_rsync stripesize
528 mkdir -p ${DIR}/tgt/$tdir
532 lfs setstripe -c $OSTCOUNT $DIR/$tdir
533 createmany -o $DIR/$tdir/$tfile $NUMFILES
535 # To simulate replication to another lustre filesystem, replicate
536 # the changes to $DIR/tgt. We can't turn off the changelogs
537 # while we are registered, so lustre_rsync better not try to
538 # replicate the replication steps. It seems ok :)
540 local LRSYNC_LOG=$(generate_logname "lrsync_log")
541 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
543 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
546 while [ $i -lt $NUMFILES ];
548 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | \
549 awk '/stripe_count/ {print $2}')
550 if [ $count -ne $OSTCOUNT ]; then
551 error "Stripe size not replicated"
559 run_test 7 "lustre_rsync stripesize"
561 # Test 8 - Replicate multiple file/directory moves
566 for i in 1 2 3 4 5 6 7 8 9; do
568 for j in 1 2 3 4 5 6 7 8 9; do
569 mkdir $DIR/$tdir/d$i/d$i$j
570 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
572 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
573 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
575 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
577 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
580 local LRSYNC_LOG=$(generate_logname "lrsync_log")
581 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
584 check_diff ${DIR}/$tdir $TGT/$tdir
590 run_test 8 "Replicate multiple file/directory moves"
597 touch $DIR/$tdir/foo/a1
599 local LRSYNC_LOG=$(generate_logname "lrsync_log")
600 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
603 check_diff ${DIR}/$tdir $TGT/$tdir
605 rm -rf $DIR/$tdir/foo
607 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
610 check_diff ${DIR}/$tdir $TGT/$tdir
616 run_test 9 "Replicate recursive directory removal"
620 check_and_cleanup_lustre