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 -1)
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.
240 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
243 local child_pid=$(pgrep dbench)
244 echo PIDs: $child_pid
246 $KILL -SIGSTOP $child_pid
248 local LRSYNC_LOG=$(generate_logname "lrsync_log")
249 echo Starting replication
250 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
252 check_diff $DIR/$tdir $TGT/$tdir
255 $KILL -SIGCONT $child_pid
259 $KILL -SIGSTOP $child_pid
261 echo Starting replication
262 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
263 check_diff $DIR/$tdir $TGT/$tdir
265 echo "Wait for dbench to finish"
266 $KILL -SIGCONT $child_pid
269 # Replicate the changes to $TGT
270 echo Starting replication
271 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
273 check_diff $DIR/$tdir $TGT/$tdir
274 check_diff $DIR/$tdir $TGT2/$tdir
280 run_test 2b "Replicate files changed by dbench."
282 # Test 2c - Replicate files while dbench is running
288 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
290 local LRSYNC_LOG=$(generate_logname "lrsync_log")
291 # Replicate the changes to $TGT
292 sleep 10 # give dbench a headstart
294 while [ $quit -le 1 ];
296 echo "Running lustre_rsync"
297 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
298 -l $LREPL_LOG -D $LRSYNC_LOG
301 if [ $? -ne 0 ]; then
302 quit=$(expr $quit + 1)
306 # Use diff to compare the source and the destination
307 check_diff $DIR/$tdir $TGT/$tdir
308 check_diff $DIR/$tdir $TGT2/$tdir
314 run_test 2c "Replicate files while dbench is running."
316 # Test 3a - Replicate files created by createmany
322 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
324 local LRSYNC_LOG=$(generate_logname "lrsync_log")
325 # Replicate the changes to $TGT
326 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
328 check_diff $DIR/$tdir $TGT/$tdir
329 check_diff $DIR/$tdir $TGT2/$tdir
335 run_test 3a "Replicate files created by createmany"
338 # Test 3b - Replicate files created by writemany
345 writemany -q -a $DIR/$tdir/$tfile $time $threads ||
346 error "writemany failed"
348 local LRSYNC_LOG=$(generate_logname "lrsync_log")
349 # Replicate the changes to $TGT
350 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
353 check_diff $DIR/$tdir $TGT/$tdir
354 check_diff $DIR/$tdir $TGT2/$tdir
360 run_test 3b "Replicate files created by writemany"
362 # Test 3c - Replicate files created by createmany/unlinkmany
368 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
369 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
371 local LRSYNC_LOG=$(generate_logname "lrsync_log")
372 # Replicate the changes to $TGT
373 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
375 check_diff $DIR/$tdir $TGT/$tdir
376 check_diff $DIR/$tdir $TGT2/$tdir
382 run_test 3c "Replicate files created by createmany/unlinkmany"
384 # Test 4 - Replicate files created by iozone
386 which iozone > /dev/null 2>&1
387 if [ $? -ne 0 ]; then
388 skip "iozone not found. Skipping test"
395 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
396 MOUNT=${DIR}/$tdir run_iozone.sh &
398 child_pid=$(pgrep iozone)
399 $KILL -SIGSTOP $child_pid
401 local LRSYNC_LOG=$(generate_logname "lrsync_log")
402 # Replicate the changes to $TGT
403 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
405 check_diff $DIR/$tdir $TGT/$tdir
406 check_diff $DIR/$tdir $TGT2/$tdir
408 $KILL -SIGCONT $child_pid
410 $KILL -SIGKILL $(pgrep run_iozone.sh)
411 $KILL -SIGKILL $(pgrep iozone)
413 # After killing 'run_iozone.sh', process 'iozone' becomes the
414 # child of PID 1. Hence 'wait' does not wait for it. Killing
415 # iozone first, means more iozone processes are spawned off which
416 # is not desirable. So, after sending a sigkill, the test goes
417 # into a wait loop for iozone to cleanup and exit.
419 while [ "$(pgrep "iozone")" != "" ];
421 ps -ef | grep iozone | grep -v grep
425 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
426 check_diff $DIR/$tdir $TGT/$tdir
427 check_diff $DIR/$tdir $TGT2/$tdir
433 run_test 4 "Replicate files created by iozone"
435 # Test 5a - Stop / start lustre_rsync
441 createmany -o $DIR/$tdir/$tfile $NUMTEST
443 # Replicate the changes to $TGT
444 local LRSYNC_LOG=$(generate_logname "lrsync_log")
445 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
449 $KILL -SIGHUP $child_pid
451 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
453 check_diff $DIR/$tdir $TGT/$tdir
454 check_diff $DIR/$tdir $TGT2/$tdir
460 run_test 5a "Stop / start lustre_rsync"
462 # Test 5b - Kill / restart lustre_rsync
468 createmany -o $DIR/$tdir/$tfile $NUMTEST
470 # Replicate the changes to $TGT
471 local LRSYNC_LOG=$(generate_logname "lrsync_log")
472 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
476 $KILL -SIGKILL $child_pid
478 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
480 check_diff $DIR/$tdir $TGT/$tdir
481 check_diff $DIR/$tdir $TGT2/$tdir
487 run_test 5b "Kill / restart lustre_rsync"
489 # Test 6 - lustre_rsync large no of hard links
495 touch $DIR/$tdir/link0
497 while [ $i -lt $NUMLINKS ];
499 ln $DIR/$tdir/link0 $DIR/$tdir/link${i}
503 local LRSYNC_LOG=$(generate_logname "lrsync_log")
504 # Replicate the changes to $TGT
505 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
507 check_diff $DIR/$tdir $TGT/$tdir
508 check_diff $DIR/$tdir $TGT2/$tdir
510 local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
511 local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
512 if [[ $count1 -ne $NUMLINKS ]] || [[ $count2 -ne $NUMLINKS ]]; then
513 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
514 error "Incorrect no of hard links found $count1, $count2"
520 run_test 6 "lustre_rsync large no of hard links"
522 # Test 7 - lustre_rsync stripesize
525 mkdir -p ${DIR}/tgt/$tdir
529 lfs setstripe -c $OSTCOUNT $DIR/$tdir
530 createmany -o $DIR/$tdir/$tfile $NUMFILES
532 # To simulate replication to another lustre filesystem, replicate
533 # the changes to $DIR/tgt. We can't turn off the changelogs
534 # while we are registered, so lustre_rsync better not try to
535 # replicate the replication steps. It seems ok :)
537 local LRSYNC_LOG=$(generate_logname "lrsync_log")
538 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
540 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
543 while [ $i -lt $NUMFILES ];
545 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | \
546 awk '/stripe_count/ {print $2}')
547 if [ $count -ne $OSTCOUNT ]; then
548 error "Stripe size not replicated"
556 run_test 7 "lustre_rsync stripesize"
558 # Test 8 - Replicate multiple file/directory moves
563 for i in 1 2 3 4 5 6 7 8 9; do
565 for j in 1 2 3 4 5 6 7 8 9; do
566 mkdir $DIR/$tdir/d$i/d$i$j
567 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
569 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
570 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
572 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
574 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
577 local LRSYNC_LOG=$(generate_logname "lrsync_log")
578 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
581 check_diff ${DIR}/$tdir $TGT/$tdir
587 run_test 8 "Replicate multiple file/directory moves"
594 touch $DIR/$tdir/foo/a1
596 local LRSYNC_LOG=$(generate_logname "lrsync_log")
597 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
600 check_diff ${DIR}/$tdir $TGT/$tdir
602 rm -rf $DIR/$tdir/foo
604 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
607 check_diff ${DIR}/$tdir $TGT/$tdir
613 run_test 9 "Replicate recursive directory removal"
617 check_and_cleanup_lustre