3 # Run select tests by setting ONLY, or as arguments to the script.
4 # Skip specific tests by setting EXCEPT.
11 LREPL_LOG=$TMP/lustre_rsync.log
14 LUSTRE=${LUSTRE:-$(dirname $0)/..}
15 . $LUSTRE/tests/test-framework.sh
19 ALWAYS_EXCEPT="$LRSYNC_EXCEPT "
20 # bug number for skipped test: LU-4256
22 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
26 [ -n "$FILESET" ] && skip "Not functional for FILESET set"
28 check_and_setup_lustre
33 if getent group nobody; then
35 elif getent group nogroup; then
38 error "No generic nobody group"
41 export LRSYNC=${LRSYNC:-"$LUSTRE/utils/lustre_rsync"}
42 [ ! -f "$LRSYNC" ] && export LRSYNC=$(which lustre_rsync)
43 export LRSYNC="$LRSYNC -v -c no -d 2"
45 # Number of seconds to run dbench
46 DBENCH_TIME=${DBENCH_TIME:-60}
49 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
50 awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
53 changelog_register || error "changelog_register failed"
54 CL_USER=(${CL_USERS[$SINGLEMDS]})
55 echo $MDT0: Registered changelog user $CL_USER
57 echo "No changelog users present on $SINGLEMDS"
66 rm -rf $TGT/$tdir $TGT/d*.lustre_rsync-test 2> /dev/null
67 rm -rf $TGT2/$tdir $TGT2/d*.lustre_rsync-test 2> /dev/null
68 rm -rf ${DIR}/$tdir $DIR/d*.lustre_rsync-test ${DIR}/tgt 2> /dev/null
71 mkdir_on_mdt0 $DIR/$tdir || error "Failed to create target: " $DIR/$tdir
72 mkdir -p ${TGT}/$tdir || error "Failed to create target: " $TGT/$tdir
73 mkdir -p ${TGT2}/$tdir || error "Failed to create target: " $TGT2/$tdir
82 # Check whether the filesystem supports xattr or not.
84 # "large" - large xattr is supported
85 # "small" - large xattr is unsupported but small xattr is supported
86 # "no" - xattr is unsupported
93 local val="$(generate_string $(max_xattr_size))"
95 if large_xattr_enabled &&
96 setfattr -n user.foo -v $val $tgt 2>/dev/null; then
99 setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
107 local changelog_file=$(generate_logname "changelog")
109 if [ -e $1 -o -e $2 ]; then
110 diff -rq -x "dev1" $1 $2
112 if [ $RC -ne 0 ]; then
113 $LFS changelog $MDT0 > $changelog_file
114 error "Failure in replication; differences found."
119 procs_are_stopped() {
123 for state in $(ps -p "$pids" -o state=); do
124 if [[ "$state" != T ]]; then
132 # Send SIGSTOP to PIDs and wait up to 60 seconds for them to show a
133 # stopped process state.
139 end=$((SECONDS + 60))
140 while ((SECONDS < end)); do
141 if procs_are_stopped $pids; then
151 # Test 1A - test basic operations
152 test_1A() { # was test_1
155 local xattr=$(check_xattr $TGT/foo)
162 touch $DIR/$tdir/file1
163 cp /etc/hosts $DIR/$tdir/d1/
164 touch $DIR/$tdir/d1/"space in filename"
165 touch $DIR/$tdir/d1/file2
168 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
170 # File and directory delete
171 touch $DIR/$tdir/d1/file4
172 mkdir $DIR/$tdir/d1/del
173 touch $DIR/$tdir/d1/del/del1
174 touch $DIR/$tdir/d1/del/del2
175 rm -rf $DIR/$tdir/d1/del
176 rm $DIR/$tdir/d1/file4
178 # Hard and soft links
179 cat /etc/hosts > $DIR/$tdir/d1/link1
180 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
181 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
184 #mknod $DIR/$tdir/dev1 b 8 1
187 local LRSYNC_LOG=$(generate_logname "lrsync_log")
188 echo "Replication #1"
189 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
193 chmod 000 $DIR/$tdir/d2/file3
194 chown nobody:$GROUP $DIR/$tdir/d2/file3
197 if [[ "$xattr" != "no" ]]; then
199 touch $DIR/$tdir/file5
200 [[ "$xattr" = "large" ]] &&
201 value="$(generate_string $(max_xattr_size))" || value="bar"
202 setfattr -n user.foo -v $value $DIR/$tdir/file5 ||
203 error "setfattr failed"
206 echo "Replication #2"
207 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
209 if [[ "$xattr" != "no" ]]; then
210 local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
211 local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
213 if [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
214 error "Error in replicating xattrs."
218 # Use diff to compare the source and the destination
219 check_diff $DIR/$tdir $TGT/$tdir
220 check_diff $DIR/$tdir $TGT2/$tdir
225 run_test 1A "Simple Replication"
227 # Test 1a - test create/delete operations in ROOT directory
228 test_1a() { # LU-5005
229 rm -rf $TGT/root-* 2> /dev/null
230 rm -rf $DIR/root-* 2> /dev/null
235 mkdir_on_mdt0 $DIR/root-dir
239 touch $DIR/root-file2
242 mv $DIR/root-file2 $DIR/root-file3
244 # File and directory delete
245 touch $DIR/root-file4
246 mkdir_on_mdt0 $DIR/root-dir1
248 rm -rf $DIR/root-dir1
251 local LRSYNC_LOG=$(generate_logname "lrsync_log")
253 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
257 stat $TGT/root-dir || error "Dir create not replicated"
258 stat $TGT/root-file || error "File create not replicated"
259 stat $TGT/root-file2 && error "Rename not replicated (src)"
260 stat $TGT/root-file3 || error "Rename not replicated (tgt)"
261 stat $TGT/root-dir1 && error "Dir delete not replicated"
262 stat $TGT/root-file4 && error "File delete not replicated"
270 run_test 1a "Replicate create/delete operations in ROOT directory"
272 # Test 2a - Replicate files created by dbench
278 bash rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME ||
279 error "dbench failed"
281 local LRSYNC_LOG=$(generate_logname "lrsync_log")
282 # Replicate the changes to $TGT
283 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
286 # Use diff to compare the source and the destination
287 check_diff $DIR/$tdir $TGT/$tdir
288 check_diff $DIR/$tdir $TGT2/$tdir
294 run_test 2a "Replicate files created by dbench."
296 # Test 2b - Replicate files changed by dbench.
303 bash rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
304 # wait for dbench to start
305 wait_for_function 'child_pid=$(pgrep dbench)' 360
306 # let dbench run for a bit
309 echo PIDs: $child_pid
311 stop_procs $child_pid
313 local LRSYNC_LOG=$(generate_logname "lrsync_log")
314 echo Starting replication
315 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
317 check_diff $DIR/$tdir $TGT/$tdir
320 $KILL -SIGCONT $child_pid
324 stop_procs $child_pid
326 echo Starting replication
327 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
328 check_diff $DIR/$tdir $TGT/$tdir
330 echo "Wait for dbench to finish"
331 $KILL -SIGCONT $child_pid
334 # Replicate the changes to $TGT
335 echo Starting replication
336 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
338 check_diff $DIR/$tdir $TGT/$tdir
339 check_diff $DIR/$tdir $TGT2/$tdir
345 run_test 2b "Replicate files changed by dbench."
347 # Test 2c - Replicate files while dbench is running
353 bash rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
355 local LRSYNC_LOG=$(generate_logname "lrsync_log")
356 # Replicate the changes to $TGT
357 sleep 10 # give dbench a headstart
359 while [ $quit -le 1 ];
361 echo "Running lustre_rsync"
362 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
363 -l $LREPL_LOG -D $LRSYNC_LOG
366 if [ $? -ne 0 ]; then
367 quit=$(expr $quit + 1)
371 # Use diff to compare the source and the destination
372 check_diff $DIR/$tdir $TGT/$tdir
373 check_diff $DIR/$tdir $TGT2/$tdir
379 run_test 2c "Replicate files while dbench is running."
381 # Test 3a - Replicate files created by createmany
387 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
389 local LRSYNC_LOG=$(generate_logname "lrsync_log")
390 # Replicate the changes to $TGT
391 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
393 check_diff $DIR/$tdir $TGT/$tdir
394 check_diff $DIR/$tdir $TGT2/$tdir
400 run_test 3a "Replicate files created by createmany"
402 # Test 3b - Replicate files created by writemany
409 writemany -q -a $DIR/$tdir/$tfile $time $threads ||
410 error "writemany failed"
412 local LRSYNC_LOG=$(generate_logname "lrsync_log")
413 # Replicate the changes to $TGT
414 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
417 check_diff $DIR/$tdir $TGT/$tdir
418 check_diff $DIR/$tdir $TGT2/$tdir
424 run_test 3b "Replicate files created by writemany"
426 # Test 3c - Replicate files created by createmany/unlinkmany
432 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
433 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
435 local LRSYNC_LOG=$(generate_logname "lrsync_log")
436 # Replicate the changes to $TGT
437 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
439 check_diff $DIR/$tdir $TGT/$tdir
440 check_diff $DIR/$tdir $TGT2/$tdir
446 run_test 3c "Replicate files created by createmany/unlinkmany"
448 # Test 4 - Replicate files created by iozone
450 which iozone > /dev/null 2>&1
451 [ $? -ne 0 ] && skip "iozone not found"
456 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
457 MOUNT=${DIR}/$tdir run_iozone.sh &
459 child_pid=$(pgrep iozone)
460 stop_procs $child_pid
462 local LRSYNC_LOG=$(generate_logname "lrsync_log")
463 # Replicate the changes to $TGT
464 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
466 check_diff $DIR/$tdir $TGT/$tdir
467 check_diff $DIR/$tdir $TGT2/$tdir
469 $KILL -SIGCONT $child_pid
471 $KILL -SIGKILL $(pgrep run_iozone.sh)
472 $KILL -SIGKILL $(pgrep iozone)
474 # After killing 'run_iozone.sh', process 'iozone' becomes the
475 # child of PID 1. Hence 'wait' does not wait for it. Killing
476 # iozone first, means more iozone processes are spawned off which
477 # is not desirable. So, after sending a sigkill, the test goes
478 # into a wait loop for iozone to cleanup and exit.
480 while [ "$(pgrep "iozone")" != "" ];
482 ps -ef | grep iozone | grep -v grep
486 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
487 check_diff $DIR/$tdir $TGT/$tdir
488 check_diff $DIR/$tdir $TGT2/$tdir
494 run_test 4 "Replicate files created by iozone"
496 # Test 5a - Stop / start lustre_rsync
502 createmany -o $DIR/$tdir/$tfile $NUMTEST
504 # Replicate the changes to $TGT
505 local LRSYNC_LOG=$(generate_logname "lrsync_log")
506 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
510 $KILL -SIGHUP $child_pid
512 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
514 check_diff $DIR/$tdir $TGT/$tdir
515 check_diff $DIR/$tdir $TGT2/$tdir
521 run_test 5a "Stop / start lustre_rsync"
523 # Test 5b - Kill / restart lustre_rsync
529 createmany -o $DIR/$tdir/$tfile $NUMTEST
531 # Replicate the changes to $TGT
532 local LRSYNC_LOG=$(generate_logname "lrsync_log")
533 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
537 $KILL -SIGKILL $child_pid
539 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
541 check_diff $DIR/$tdir $TGT/$tdir
542 check_diff $DIR/$tdir $TGT2/$tdir
548 run_test 5b "Kill / restart lustre_rsync"
550 # Test 6 - lustre_rsync large no of hard links
558 touch $DIR/$tdir/link0
559 for ((i = 1; i < num_links - 1; i++)); do
560 ln $DIR/$tdir/link0 $DIR/$tdir/link$i
562 # create an extra hard link of src name ending with dest name
563 ln $DIR/$tdir/link0 $DIR/$tdir/ink0
565 local LRSYNC_LOG=$(generate_logname "lrsync_log")
566 # Replicate the changes to $TGT
567 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
569 check_diff $DIR/$tdir $TGT/$tdir
570 check_diff $DIR/$tdir $TGT2/$tdir
572 local count1=$(stat --format=%h $TGT/$tdir/link0)
573 local count2=$(stat --format=%h $TGT2/$tdir/link0)
574 if ((count1 != num_links || count2 != num_links)); then
575 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
576 error "Incorrect no of hard links found $count1, $count2"
583 run_test 6 "lustre_rsync large no of hard links"
585 # Test 7 - lustre_rsync stripesize
590 mkdir -p ${DIR}/tgt/$tdir
593 $LFS setstripe -c $OSTCOUNT $DIR/$tdir ||
594 error "$LFS setstripe failed"
595 createmany -o $DIR/$tdir/$tfile $numfiles
597 # To simulate replication to another lustre filesystem, replicate
598 # the changes to $DIR/tgt. We can't turn off the changelogs
599 # while we are registered, so lustre_rsync better not try to
600 # replicate the replication steps. It seems ok :)
602 local LRSYNC_LOG=$(generate_logname "lrsync_log")
603 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
605 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
608 while [ $i -lt $numfiles ];
610 local count=$($LFS getstripe $DIR/tgt/$tdir/${tfile}$i |
611 awk '/stripe_count/ {print $2}')
612 if [ $count -ne $OSTCOUNT ]; then
613 error "Stripe size not replicated"
621 run_test 7 "lustre_rsync stripesize"
623 # Test 8 - Replicate multiple file/directory moves
628 for i in 1 2 3 4 5 6 7 8 9; do
630 for j in 1 2 3 4 5 6 7 8 9; do
631 mkdir $DIR/$tdir/d$i/d$i$j
632 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
634 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
635 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
637 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
639 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
642 local LRSYNC_LOG=$(generate_logname "lrsync_log")
643 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
646 check_diff ${DIR}/$tdir $TGT/$tdir
652 run_test 8 "Replicate multiple file/directory moves"
659 touch $DIR/$tdir/foo/a1
661 local LRSYNC_LOG=$(generate_logname "lrsync_log")
662 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
665 check_diff ${DIR}/$tdir $TGT/$tdir
667 rm -rf $DIR/$tdir/foo
669 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
672 check_diff ${DIR}/$tdir $TGT/$tdir
678 run_test 9 "Replicate recursive directory removal"
682 check_and_cleanup_lustre