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
89 setfattr -n user.foo -v 'bar' $tgt 2> /dev/null
98 if [ -e $1 -o -e $2 ]; then
99 diff -rq -x "dev1" $1 $2
101 if [ $RC -ne 0 ]; then
102 error "Failure in replication; differences found."
107 # Test 1 - test basic operations
111 local xattr=`check_xattr $TGT/foo`
118 touch $DIR/$tdir/file1
119 cp /etc/hosts $DIR/$tdir/d1/
120 touch $DIR/$tdir/d1/"space in filename"
121 touch $DIR/$tdir/d1/file2
124 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
126 # File and directory delete
127 touch $DIR/$tdir/d1/file4
128 mkdir $DIR/$tdir/d1/del
129 touch $DIR/$tdir/d1/del/del1
130 touch $DIR/$tdir/d1/del/del2
131 rm -rf $DIR/$tdir/d1/del
132 rm $DIR/$tdir/d1/file4
135 cat /etc/hosts > $DIR/$tdir/d1/link1
136 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
137 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
140 #mknod $DIR/$tdir/dev1 b 8 1
143 echo "Replication #1"
144 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
147 chmod 000 $DIR/$tdir/d2/file3
148 chown nobody:nobody $DIR/$tdir/d2/file3
151 if [ "$xattr" == "yes" ]; then
152 touch $DIR/$tdir/file5
153 setfattr -n user.foo -v 'bar' $DIR/$tdir/file5
156 echo "Replication #2"
157 $LRSYNC -l $LREPL_LOG
159 if [ "$xattr" == "yes" ]; then
160 local xval1=$(getfattr -n user.foo --absolute-names --only-values \
162 local xval2=$(getfattr -n user.foo --absolute-names --only-values \
168 # fid2path and path2fid aren't implemented for block devices
169 #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
170 # ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
171 # error "Error replicating block devices"
174 if [[ "$xattr" == "yes" ]] &&
175 [[ "$xval1" != "bar" || "$xval2" != "bar" ]]; then
176 error "Error in replicating xattrs. $xval1, $xval2"
180 # Use diff to compare the source and the destination
181 check_diff $DIR/$tdir $TGT/$tdir
182 check_diff $DIR/$tdir $TGT2/$tdir
188 run_test 1 "Simple Replication"
190 # Test 2a - Replicate files created by dbench
192 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
197 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed!"
199 # Replicate the changes to $TGT
200 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
202 # Use diff to compare the source and the destination
203 check_diff $DIR/$tdir $TGT/$tdir
204 check_diff $DIR/$tdir $TGT2/$tdir
210 run_test 2a "Replicate files created by dbench."
213 # Test 2b - Replicate files changed by dbench.
215 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
221 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
224 local child_pid=$(pgrep dbench)
225 echo PIDs: $child_pid
227 $KILL -SIGSTOP $child_pid
229 echo Starting replication
230 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
231 check_diff $DIR/$tdir $TGT/$tdir
234 $KILL -SIGCONT $child_pid
238 $KILL -SIGSTOP $child_pid
240 echo Starting replication
241 $LRSYNC -l $LREPL_LOG
242 check_diff $DIR/$tdir $TGT/$tdir
244 echo "Wait for dbench to finish"
245 $KILL -SIGCONT $child_pid
248 # Replicate the changes to $TGT
249 echo Starting replication
250 $LRSYNC -l $LREPL_LOG
252 check_diff $DIR/$tdir $TGT/$tdir
253 check_diff $DIR/$tdir $TGT2/$tdir
259 run_test 2b "Replicate files changed by dbench."
261 # Test 2c - Replicate files while dbench is running
263 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
268 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
270 # Replicate the changes to $TGT
271 sleep 10 # give dbench a headstart
273 while [ $quit -le 1 ];
275 echo "Running lustre_rsync"
276 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER -l $LREPL_LOG
279 if [ $? -ne 0 ]; then
280 quit=$(expr $quit + 1)
284 # Use diff to compare the source and the destination
285 check_diff $DIR/$tdir $TGT/$tdir
286 check_diff $DIR/$tdir $TGT2/$tdir
292 run_test 2c "Replicate files while dbench is running."
294 # Test 3a - Replicate files created by createmany
296 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
302 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
304 # Replicate the changes to $TGT
305 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
306 check_diff $DIR/$tdir $TGT/$tdir
307 check_diff $DIR/$tdir $TGT2/$tdir
313 run_test 3a "Replicate files created by createmany"
316 # Test 3b - Replicate files created by writemany
318 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
325 writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
327 # Replicate the changes to $TGT
328 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
330 check_diff $DIR/$tdir $TGT/$tdir
331 check_diff $DIR/$tdir $TGT2/$tdir
337 run_test 3b "Replicate files created by writemany"
339 # Test 3c - Replicate files created by createmany/unlinkmany
341 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
347 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
348 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
350 # Replicate the changes to $TGT
351 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
352 check_diff $DIR/$tdir $TGT/$tdir
353 check_diff $DIR/$tdir $TGT2/$tdir
359 run_test 3c "Replicate files created by createmany/unlinkmany"
361 # Test 4 - Replicate files created by iozone
363 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
365 which iozone > /dev/null 2>&1
366 if [ $? -ne 0 ]; then
367 skip "iozone not found. Skipping test"
374 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
375 MOUNT=${DIR}/$tdir run_iozone.sh &
377 child_pid=$(pgrep iozone)
378 $KILL -SIGSTOP $child_pid
380 # Replicate the changes to $TGT
381 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
382 check_diff $DIR/$tdir $TGT/$tdir
383 check_diff $DIR/$tdir $TGT2/$tdir
385 $KILL -SIGCONT $child_pid
387 $KILL -SIGKILL $(pgrep run_iozone.sh)
388 $KILL -SIGKILL $(pgrep iozone)
390 # After killing 'run_iozone.sh', process 'iozone' becomes the
391 # child of PID 1. Hence 'wait' does not wait for it. Killing
392 # iozone first, means more iozone processes are spawned off which
393 # is not desirable. So, after sending a sigkill, the test goes
394 # into a wait loop for iozone to cleanup and exit.
396 while [ "$(pgrep "iozone")" != "" ];
398 ps -ef | grep iozone | grep -v grep
402 $LRSYNC -l $LREPL_LOG
403 check_diff $DIR/$tdir $TGT/$tdir
404 check_diff $DIR/$tdir $TGT2/$tdir
410 run_test 4 "Replicate files created by iozone"
412 # Test 5a - Stop / start lustre_rsync
414 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
420 createmany -o $DIR/$tdir/$tfile $NUMTEST
422 # Replicate the changes to $TGT
424 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
427 $KILL -SIGHUP $child_pid
429 $LRSYNC -l $LREPL_LOG
431 check_diff $DIR/$tdir $TGT/$tdir
432 check_diff $DIR/$tdir $TGT2/$tdir
438 run_test 5a "Stop / start lustre_rsync"
440 # Test 5b - Kill / restart lustre_rsync
442 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
448 createmany -o $DIR/$tdir/$tfile $NUMTEST
450 # Replicate the changes to $TGT
452 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
455 $KILL -SIGKILL $child_pid
457 $LRSYNC -l $LREPL_LOG
459 check_diff $DIR/$tdir $TGT/$tdir
460 check_diff $DIR/$tdir $TGT2/$tdir
466 run_test 5b "Kill / restart lustre_rsync"
468 # Test 6 - lustre_rsync large no of hard links
474 touch $DIR/$tdir/link0
476 while [ $i -lt $NUMLINKS ];
478 ln $DIR/$tdir/link0 $DIR/$tdir/link${i}
482 # Replicate the changes to $TGT
483 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
484 check_diff $DIR/$tdir $TGT/$tdir
485 check_diff $DIR/$tdir $TGT2/$tdir
487 local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
488 local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
489 if [[ $count1 -ne $NUMLINKS ]] || [[ $count2 -ne $NUMLINKS ]]; then
490 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
491 error "Incorrect no of hard links found $count1, $count2"
497 run_test 6 "lustre_rsync large no of hard links"
499 # Test 7 - lustre_rsync stripesize
502 mkdir -p ${DIR}/tgt/$tdir
506 lfs setstripe -c 2 ${DIR}/$tdir
507 createmany -o $DIR/$tdir/$tfile $NUMFILES
509 # To simulate replication to another lustre filesystem, replicate
510 # the changes to $DIR/tgt. We can't turn off the changelogs
511 # while we are registered, so lustre_rsync better not try to
512 # replicate the replication steps. It seems ok :)
514 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG
515 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
518 while [ $i -lt $NUMFILES ];
520 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | awk '/stripe_count/ {print $2}')
521 if [ $count -ne 2 ]; then
522 error "Stripe size not replicated"
530 run_test 7 "lustre_rsync stripesize"
532 # Test 8 - Replicate multiple file/directory moves
537 for i in 1 2 3 4 5 6 7 8 9; do
539 for j in 1 2 3 4 5 6 7 8 9; do
540 mkdir $DIR/$tdir/d$i/d$i$j
541 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
543 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
544 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
546 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
548 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
551 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
553 check_diff ${DIR}/$tdir $TGT/$tdir
559 run_test 8 "Replicate multiple file/directory moves"
566 touch $DIR/$tdir/foo/a1
568 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
570 check_diff ${DIR}/$tdir $TGT/$tdir
572 rm -rf $DIR/$tdir/foo
574 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
576 check_diff ${DIR}/$tdir $TGT/$tdir
582 run_test 9 "Replicate recursive directory removal"
585 complete $(basename $0) $SECONDS
586 check_and_cleanup_lustre