3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
6 # Run test by setting NOSETUP=true when ltest has setup env for us
10 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13 [ -n "$ONLY" ] && SLOW=yes
14 ALWAYS_EXCEPT="$LRSYNC_EXCEPT"
15 # bug number for skipped test:
16 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
18 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
19 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
24 LREPL_LOG=$TMP/lustre_rsync.log
27 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
28 . $LUSTRE/tests/test-framework.sh
30 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
33 check_and_setup_lustre
41 export LRSYNC=${LRSYNC:-"$LUSTRE/utils/lustre_rsync"}
42 [ ! -f "$LRSYNC" ] && export LRSYNC=$(which lustre_rsync)
43 export LRSYNC="$LRSYNC -v" # -a
45 # control the time of tests
46 DBENCH_TIME=${DBENCH_TIME:-60} # No of seconds to run dbench
49 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
50 awk '{gsub(/_UUID/,""); print $1}' | head -1)
53 CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
54 echo $MDT0: Registered changelog user $CL_USER
55 CL_USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
56 mdd.$MDT0.changelog_users | wc -l) - 2 ))
57 [ $CL_USERS -ne 1 ] && \
58 echo "Other changelog users present ($CL_USERS)"
62 rm -rf $TGT/$tdir $TGT/d*.lustre_rsync-test 2> /dev/null
63 rm -rf $TGT2/$tdir $TGT2/d*.lustre_rsync-test 2> /dev/null
64 rm -rf ${DIR}/$tdir $DIR/d*.lustre_rsync-test ${DIR}/tgt 2> /dev/null
68 mkdir -p ${TGT2}/$tdir
70 error "Failed to create target: " $TGT
81 $LFS changelog_clear $MDT0 $CL_USER 0
82 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
85 # Check whether the filesystem supports xattr or not.
87 # "large" - large xattr is supported
88 # "small" - large xattr is unsupported but small xattr is supported
89 # "no" - xattr is unsupported
96 local val="$(generate_string $(max_xattr_size))"
97 if large_xattr_enabled &&
98 setfattr -n user.foo -v $val $tgt 2>/dev/null; then
101 setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
109 if [ -e $1 -o -e $2 ]; then
110 diff -rq -x "dev1" $1 $2
112 if [ $RC -ne 0 ]; then
113 error "Failure in replication; differences found."
118 # Test 1 - test basic operations
122 local xattr=$(check_xattr $TGT/foo)
129 touch $DIR/$tdir/file1
130 cp /etc/hosts $DIR/$tdir/d1/
131 touch $DIR/$tdir/d1/"space in filename"
132 touch $DIR/$tdir/d1/file2
135 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
137 # File and directory delete
138 touch $DIR/$tdir/d1/file4
139 mkdir $DIR/$tdir/d1/del
140 touch $DIR/$tdir/d1/del/del1
141 touch $DIR/$tdir/d1/del/del2
142 rm -rf $DIR/$tdir/d1/del
143 rm $DIR/$tdir/d1/file4
146 cat /etc/hosts > $DIR/$tdir/d1/link1
147 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
148 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
151 #mknod $DIR/$tdir/dev1 b 8 1
154 echo "Replication #1"
155 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
158 chmod 000 $DIR/$tdir/d2/file3
159 chown nobody:nobody $DIR/$tdir/d2/file3
162 if [[ "$xattr" != "no" ]]; then
164 touch $DIR/$tdir/file5
165 [[ "$xattr" = "large" ]] &&
166 value="$(generate_string $(max_xattr_size))" || value="bar"
167 setfattr -n user.foo -v $value $DIR/$tdir/file5
170 echo "Replication #2"
171 $LRSYNC -l $LREPL_LOG
173 if [[ "$xattr" != "no" ]]; then
174 local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
175 local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
180 # fid2path and path2fid aren't implemented for block devices
181 #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
182 # ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
183 # error "Error replicating block devices"
186 if [[ "$xattr" != "no" ]] &&
187 [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
188 error "Error in replicating xattrs."
192 # Use diff to compare the source and the destination
193 check_diff $DIR/$tdir $TGT/$tdir
194 check_diff $DIR/$tdir $TGT2/$tdir
200 run_test 1 "Simple Replication"
202 # Test 2a - Replicate files created by dbench
204 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
209 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed!"
211 # Replicate the changes to $TGT
212 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
214 # Use diff to compare the source and the destination
215 check_diff $DIR/$tdir $TGT/$tdir
216 check_diff $DIR/$tdir $TGT2/$tdir
222 run_test 2a "Replicate files created by dbench."
225 # Test 2b - Replicate files changed by dbench.
227 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
233 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
236 local child_pid=$(pgrep dbench)
237 echo PIDs: $child_pid
239 $KILL -SIGSTOP $child_pid
241 echo Starting replication
242 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
243 check_diff $DIR/$tdir $TGT/$tdir
246 $KILL -SIGCONT $child_pid
250 $KILL -SIGSTOP $child_pid
252 echo Starting replication
253 $LRSYNC -l $LREPL_LOG
254 check_diff $DIR/$tdir $TGT/$tdir
256 echo "Wait for dbench to finish"
257 $KILL -SIGCONT $child_pid
260 # Replicate the changes to $TGT
261 echo Starting replication
262 $LRSYNC -l $LREPL_LOG
264 check_diff $DIR/$tdir $TGT/$tdir
265 check_diff $DIR/$tdir $TGT2/$tdir
271 run_test 2b "Replicate files changed by dbench."
273 # Test 2c - Replicate files while dbench is running
275 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
280 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
282 # Replicate the changes to $TGT
283 sleep 10 # give dbench a headstart
285 while [ $quit -le 1 ];
287 echo "Running lustre_rsync"
288 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER -l $LREPL_LOG
291 if [ $? -ne 0 ]; then
292 quit=$(expr $quit + 1)
296 # Use diff to compare the source and the destination
297 check_diff $DIR/$tdir $TGT/$tdir
298 check_diff $DIR/$tdir $TGT2/$tdir
304 run_test 2c "Replicate files while dbench is running."
306 # Test 3a - Replicate files created by createmany
308 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
314 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
316 # Replicate the changes to $TGT
317 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
318 check_diff $DIR/$tdir $TGT/$tdir
319 check_diff $DIR/$tdir $TGT2/$tdir
325 run_test 3a "Replicate files created by createmany"
328 # Test 3b - Replicate files created by writemany
330 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
337 writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
339 # Replicate the changes to $TGT
340 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
342 check_diff $DIR/$tdir $TGT/$tdir
343 check_diff $DIR/$tdir $TGT2/$tdir
349 run_test 3b "Replicate files created by writemany"
351 # Test 3c - Replicate files created by createmany/unlinkmany
353 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
359 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
360 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
362 # Replicate the changes to $TGT
363 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
364 check_diff $DIR/$tdir $TGT/$tdir
365 check_diff $DIR/$tdir $TGT2/$tdir
371 run_test 3c "Replicate files created by createmany/unlinkmany"
373 # Test 4 - Replicate files created by iozone
375 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
377 which iozone > /dev/null 2>&1
378 if [ $? -ne 0 ]; then
379 skip "iozone not found. Skipping test"
386 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
387 MOUNT=${DIR}/$tdir run_iozone.sh &
389 child_pid=$(pgrep iozone)
390 $KILL -SIGSTOP $child_pid
392 # Replicate the changes to $TGT
393 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
394 check_diff $DIR/$tdir $TGT/$tdir
395 check_diff $DIR/$tdir $TGT2/$tdir
397 $KILL -SIGCONT $child_pid
399 $KILL -SIGKILL $(pgrep run_iozone.sh)
400 $KILL -SIGKILL $(pgrep iozone)
402 # After killing 'run_iozone.sh', process 'iozone' becomes the
403 # child of PID 1. Hence 'wait' does not wait for it. Killing
404 # iozone first, means more iozone processes are spawned off which
405 # is not desirable. So, after sending a sigkill, the test goes
406 # into a wait loop for iozone to cleanup and exit.
408 while [ "$(pgrep "iozone")" != "" ];
410 ps -ef | grep iozone | grep -v grep
414 $LRSYNC -l $LREPL_LOG
415 check_diff $DIR/$tdir $TGT/$tdir
416 check_diff $DIR/$tdir $TGT2/$tdir
422 run_test 4 "Replicate files created by iozone"
424 # Test 5a - Stop / start lustre_rsync
426 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
432 createmany -o $DIR/$tdir/$tfile $NUMTEST
434 # Replicate the changes to $TGT
436 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
439 $KILL -SIGHUP $child_pid
441 $LRSYNC -l $LREPL_LOG
443 check_diff $DIR/$tdir $TGT/$tdir
444 check_diff $DIR/$tdir $TGT2/$tdir
450 run_test 5a "Stop / start lustre_rsync"
452 # Test 5b - Kill / restart lustre_rsync
454 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
460 createmany -o $DIR/$tdir/$tfile $NUMTEST
462 # Replicate the changes to $TGT
464 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
467 $KILL -SIGKILL $child_pid
469 $LRSYNC -l $LREPL_LOG
471 check_diff $DIR/$tdir $TGT/$tdir
472 check_diff $DIR/$tdir $TGT2/$tdir
478 run_test 5b "Kill / restart lustre_rsync"
480 # Test 6 - lustre_rsync large no of hard links
486 touch $DIR/$tdir/link0
488 while [ $i -lt $NUMLINKS ];
490 ln $DIR/$tdir/link0 $DIR/$tdir/link${i}
494 # Replicate the changes to $TGT
495 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
496 check_diff $DIR/$tdir $TGT/$tdir
497 check_diff $DIR/$tdir $TGT2/$tdir
499 local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
500 local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
501 if [[ $count1 -ne $NUMLINKS ]] || [[ $count2 -ne $NUMLINKS ]]; then
502 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
503 error "Incorrect no of hard links found $count1, $count2"
509 run_test 6 "lustre_rsync large no of hard links"
511 # Test 7 - lustre_rsync stripesize
514 mkdir -p ${DIR}/tgt/$tdir
518 lfs setstripe -c $OSTCOUNT $DIR/$tdir
519 createmany -o $DIR/$tdir/$tfile $NUMFILES
521 # To simulate replication to another lustre filesystem, replicate
522 # the changes to $DIR/tgt. We can't turn off the changelogs
523 # while we are registered, so lustre_rsync better not try to
524 # replicate the replication steps. It seems ok :)
526 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG
527 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
530 while [ $i -lt $NUMFILES ];
532 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | awk '/stripe_count/ {print $2}')
533 if [ $count -ne $OSTCOUNT ]; then
534 error "Stripe size not replicated"
542 run_test 7 "lustre_rsync stripesize"
544 # Test 8 - Replicate multiple file/directory moves
549 for i in 1 2 3 4 5 6 7 8 9; do
551 for j in 1 2 3 4 5 6 7 8 9; do
552 mkdir $DIR/$tdir/d$i/d$i$j
553 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
555 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
556 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
558 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
560 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
563 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
565 check_diff ${DIR}/$tdir $TGT/$tdir
571 run_test 8 "Replicate multiple file/directory moves"
578 touch $DIR/$tdir/foo/a1
580 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
582 check_diff ${DIR}/$tdir $TGT/$tdir
584 rm -rf $DIR/$tdir/foo
586 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
588 check_diff ${DIR}/$tdir $TGT/$tdir
594 run_test 9 "Replicate recursive directory removal"
597 complete $(basename $0) $SECONDS
598 check_and_cleanup_lustre