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 [ -n "$ONLY" ] && SLOW=yes
16 ALWAYS_EXCEPT="$LRSYNC_EXCEPT"
17 # bug number for skipped test:
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
21 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
26 LREPL_LOG=$TMP/lustre_rsync.log
29 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
30 . $LUSTRE/tests/test-framework.sh
32 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
35 check_and_setup_lustre
43 export LRSYNC=${LRSYNC:-"$LUSTRE/utils/lustre_rsync"}
44 [ ! -f "$LRSYNC" ] && export LRSYNC=$(which lustre_rsync)
45 export LRSYNC="$LRSYNC -v -c no -d 2"
47 # control the time of tests
48 DBENCH_TIME=${DBENCH_TIME:-60} # No of seconds to run dbench
51 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
52 awk '{gsub(/_UUID/,""); print $1}' | head -1)
55 CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
56 echo $MDT0: Registered changelog user $CL_USER
57 CL_USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
58 mdd.$MDT0.changelog_users | wc -l) - 2 ))
59 [ $CL_USERS -ne 1 ] && \
60 echo "Other changelog users present ($CL_USERS)"
64 rm -rf $TGT/$tdir $TGT/d*.lustre_rsync-test 2> /dev/null
65 rm -rf $TGT2/$tdir $TGT2/d*.lustre_rsync-test 2> /dev/null
66 rm -rf ${DIR}/$tdir $DIR/d*.lustre_rsync-test ${DIR}/tgt 2> /dev/null
70 mkdir -p ${TGT2}/$tdir
72 error "Failed to create target: " $TGT
83 $LFS changelog_clear $MDT0 $CL_USER 0
84 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
87 # Check whether the filesystem supports xattr or not.
89 # "large" - large xattr is supported
90 # "small" - large xattr is unsupported but small xattr is supported
91 # "no" - xattr is unsupported
98 local val="$(generate_string $(max_xattr_size))"
99 if large_xattr_enabled &&
100 setfattr -n user.foo -v $val $tgt 2>/dev/null; then
103 setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
111 local changelog_file=$(generate_logname "changelog")
113 if [ -e $1 -o -e $2 ]; then
114 diff -rq -x "dev1" $1 $2
116 if [ $RC -ne 0 ]; then
117 $LFS changelog $MDT0 > $changelog_file
118 error "Failure in replication; differences found."
123 # Test 1 - test basic operations
127 local xattr=$(check_xattr $TGT/foo)
134 touch $DIR/$tdir/file1
135 cp /etc/hosts $DIR/$tdir/d1/
136 touch $DIR/$tdir/d1/"space in filename"
137 touch $DIR/$tdir/d1/file2
140 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
142 # File and directory delete
143 touch $DIR/$tdir/d1/file4
144 mkdir $DIR/$tdir/d1/del
145 touch $DIR/$tdir/d1/del/del1
146 touch $DIR/$tdir/d1/del/del2
147 rm -rf $DIR/$tdir/d1/del
148 rm $DIR/$tdir/d1/file4
151 cat /etc/hosts > $DIR/$tdir/d1/link1
152 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
153 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
156 #mknod $DIR/$tdir/dev1 b 8 1
159 local LRSYNC_LOG=$(generate_logname "lrsync_log")
160 echo "Replication #1"
161 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
165 chmod 000 $DIR/$tdir/d2/file3
166 chown nobody:nobody $DIR/$tdir/d2/file3
169 if [[ "$xattr" != "no" ]]; then
171 touch $DIR/$tdir/file5
172 [[ "$xattr" = "large" ]] &&
173 value="$(generate_string $(max_xattr_size))" || value="bar"
174 setfattr -n user.foo -v $value $DIR/$tdir/file5
177 echo "Replication #2"
178 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
180 if [[ "$xattr" != "no" ]]; then
181 local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
182 local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
187 # fid2path and path2fid aren't implemented for block devices
188 #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
189 # ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
190 # error "Error replicating block devices"
193 if [[ "$xattr" != "no" ]] &&
194 [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
195 error "Error in replicating xattrs."
199 # Use diff to compare the source and the destination
200 check_diff $DIR/$tdir $TGT/$tdir
201 check_diff $DIR/$tdir $TGT2/$tdir
207 run_test 1 "Simple Replication"
209 # Test 2a - Replicate files created by dbench
211 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
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.
236 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
242 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
245 local child_pid=$(pgrep dbench)
246 echo PIDs: $child_pid
248 $KILL -SIGSTOP $child_pid
250 local LRSYNC_LOG=$(generate_logname "lrsync_log")
251 echo Starting replication
252 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
254 check_diff $DIR/$tdir $TGT/$tdir
257 $KILL -SIGCONT $child_pid
261 $KILL -SIGSTOP $child_pid
263 echo Starting replication
264 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
265 check_diff $DIR/$tdir $TGT/$tdir
267 echo "Wait for dbench to finish"
268 $KILL -SIGCONT $child_pid
271 # Replicate the changes to $TGT
272 echo Starting replication
273 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
275 check_diff $DIR/$tdir $TGT/$tdir
276 check_diff $DIR/$tdir $TGT2/$tdir
282 run_test 2b "Replicate files changed by dbench."
284 # Test 2c - Replicate files while dbench is running
286 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
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
321 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
327 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
329 local LRSYNC_LOG=$(generate_logname "lrsync_log")
330 # Replicate the changes to $TGT
331 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
333 check_diff $DIR/$tdir $TGT/$tdir
334 check_diff $DIR/$tdir $TGT2/$tdir
340 run_test 3a "Replicate files created by createmany"
343 # Test 3b - Replicate files created by writemany
345 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
352 writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
354 local LRSYNC_LOG=$(generate_logname "lrsync_log")
355 # Replicate the changes to $TGT
356 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
359 check_diff $DIR/$tdir $TGT/$tdir
360 check_diff $DIR/$tdir $TGT2/$tdir
366 run_test 3b "Replicate files created by writemany"
368 # Test 3c - Replicate files created by createmany/unlinkmany
370 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
376 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
377 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
379 local LRSYNC_LOG=$(generate_logname "lrsync_log")
380 # Replicate the changes to $TGT
381 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
383 check_diff $DIR/$tdir $TGT/$tdir
384 check_diff $DIR/$tdir $TGT2/$tdir
390 run_test 3c "Replicate files created by createmany/unlinkmany"
392 # Test 4 - Replicate files created by iozone
394 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
396 which iozone > /dev/null 2>&1
397 if [ $? -ne 0 ]; then
398 skip "iozone not found. Skipping test"
405 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
406 MOUNT=${DIR}/$tdir run_iozone.sh &
408 child_pid=$(pgrep iozone)
409 $KILL -SIGSTOP $child_pid
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
418 $KILL -SIGCONT $child_pid
420 $KILL -SIGKILL $(pgrep run_iozone.sh)
421 $KILL -SIGKILL $(pgrep iozone)
423 # After killing 'run_iozone.sh', process 'iozone' becomes the
424 # child of PID 1. Hence 'wait' does not wait for it. Killing
425 # iozone first, means more iozone processes are spawned off which
426 # is not desirable. So, after sending a sigkill, the test goes
427 # into a wait loop for iozone to cleanup and exit.
429 while [ "$(pgrep "iozone")" != "" ];
431 ps -ef | grep iozone | grep -v grep
435 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
436 check_diff $DIR/$tdir $TGT/$tdir
437 check_diff $DIR/$tdir $TGT2/$tdir
443 run_test 4 "Replicate files created by iozone"
445 # Test 5a - Stop / start lustre_rsync
447 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
453 createmany -o $DIR/$tdir/$tfile $NUMTEST
455 # Replicate the changes to $TGT
456 local LRSYNC_LOG=$(generate_logname "lrsync_log")
457 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
461 $KILL -SIGHUP $child_pid
463 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
465 check_diff $DIR/$tdir $TGT/$tdir
466 check_diff $DIR/$tdir $TGT2/$tdir
472 run_test 5a "Stop / start lustre_rsync"
474 # Test 5b - Kill / restart lustre_rsync
476 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
482 createmany -o $DIR/$tdir/$tfile $NUMTEST
484 # Replicate the changes to $TGT
485 local LRSYNC_LOG=$(generate_logname "lrsync_log")
486 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
490 $KILL -SIGKILL $child_pid
492 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
494 check_diff $DIR/$tdir $TGT/$tdir
495 check_diff $DIR/$tdir $TGT2/$tdir
501 run_test 5b "Kill / restart lustre_rsync"
503 # Test 6 - lustre_rsync large no of hard links
509 touch $DIR/$tdir/link0
511 while [ $i -lt $NUMLINKS ];
513 ln $DIR/$tdir/link0 $DIR/$tdir/link${i}
517 local LRSYNC_LOG=$(generate_logname "lrsync_log")
518 # Replicate the changes to $TGT
519 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
521 check_diff $DIR/$tdir $TGT/$tdir
522 check_diff $DIR/$tdir $TGT2/$tdir
524 local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
525 local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
526 if [[ $count1 -ne $NUMLINKS ]] || [[ $count2 -ne $NUMLINKS ]]; then
527 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
528 error "Incorrect no of hard links found $count1, $count2"
534 run_test 6 "lustre_rsync large no of hard links"
536 # Test 7 - lustre_rsync stripesize
539 mkdir -p ${DIR}/tgt/$tdir
543 lfs setstripe -c $OSTCOUNT $DIR/$tdir
544 createmany -o $DIR/$tdir/$tfile $NUMFILES
546 # To simulate replication to another lustre filesystem, replicate
547 # the changes to $DIR/tgt. We can't turn off the changelogs
548 # while we are registered, so lustre_rsync better not try to
549 # replicate the replication steps. It seems ok :)
551 local LRSYNC_LOG=$(generate_logname "lrsync_log")
552 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
554 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
557 while [ $i -lt $NUMFILES ];
559 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | \
560 awk '/stripe_count/ {print $2}')
561 if [ $count -ne $OSTCOUNT ]; then
562 error "Stripe size not replicated"
570 run_test 7 "lustre_rsync stripesize"
572 # Test 8 - Replicate multiple file/directory moves
577 for i in 1 2 3 4 5 6 7 8 9; do
579 for j in 1 2 3 4 5 6 7 8 9; do
580 mkdir $DIR/$tdir/d$i/d$i$j
581 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
583 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
584 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
586 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
588 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
591 local LRSYNC_LOG=$(generate_logname "lrsync_log")
592 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
595 check_diff ${DIR}/$tdir $TGT/$tdir
601 run_test 8 "Replicate multiple file/directory moves"
608 touch $DIR/$tdir/foo/a1
610 local LRSYNC_LOG=$(generate_logname "lrsync_log")
611 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
614 check_diff ${DIR}/$tdir $TGT/$tdir
616 rm -rf $DIR/$tdir/foo
618 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
621 check_diff ${DIR}/$tdir $TGT/$tdir
627 run_test 9 "Replicate recursive directory removal"
631 check_and_cleanup_lustre