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
70 mkdir -p ${DIR}/$tdir || error "Failed to create target: " $DIR/$tdir
71 mkdir -p ${TGT}/$tdir || error "Failed to create target: " $TGT/$tdir
72 mkdir -p ${TGT2}/$tdir || error "Failed to create target: " $TGT2/$tdir
81 # Check whether the filesystem supports xattr or not.
83 # "large" - large xattr is supported
84 # "small" - large xattr is unsupported but small xattr is supported
85 # "no" - xattr is unsupported
92 local val="$(generate_string $(max_xattr_size))"
93 if large_xattr_enabled &&
94 setfattr -n user.foo -v $val $tgt 2>/dev/null; then
97 setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
105 local changelog_file=$(generate_logname "changelog")
107 if [ -e $1 -o -e $2 ]; then
108 diff -rq -x "dev1" $1 $2
110 if [ $RC -ne 0 ]; then
111 $LFS changelog $MDT0 > $changelog_file
112 error "Failure in replication; differences found."
117 procs_are_stopped() {
121 for state in $(ps -p "$pids" -o state=); do
122 if [[ "$state" != T ]]; then
130 # Send SIGSTOP to PIDs and wait up to 60 seconds for them to show a
131 # stopped process state.
137 end=$((SECONDS + 60))
138 while ((SECONDS < end)); do
139 if procs_are_stopped $pids; then
149 # Test 1A - test basic operations
150 test_1A() { # was test_1
153 local xattr=$(check_xattr $TGT/foo)
160 touch $DIR/$tdir/file1
161 cp /etc/hosts $DIR/$tdir/d1/
162 touch $DIR/$tdir/d1/"space in filename"
163 touch $DIR/$tdir/d1/file2
166 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
168 # File and directory delete
169 touch $DIR/$tdir/d1/file4
170 mkdir $DIR/$tdir/d1/del
171 touch $DIR/$tdir/d1/del/del1
172 touch $DIR/$tdir/d1/del/del2
173 rm -rf $DIR/$tdir/d1/del
174 rm $DIR/$tdir/d1/file4
177 cat /etc/hosts > $DIR/$tdir/d1/link1
178 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
179 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
182 #mknod $DIR/$tdir/dev1 b 8 1
185 local LRSYNC_LOG=$(generate_logname "lrsync_log")
186 echo "Replication #1"
187 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
191 chmod 000 $DIR/$tdir/d2/file3
192 chown nobody:$GROUP $DIR/$tdir/d2/file3
195 if [[ "$xattr" != "no" ]]; then
197 touch $DIR/$tdir/file5
198 [[ "$xattr" = "large" ]] &&
199 value="$(generate_string $(max_xattr_size))" || value="bar"
200 setfattr -n user.foo -v $value $DIR/$tdir/file5
203 echo "Replication #2"
204 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
206 if [[ "$xattr" != "no" ]]; then
207 local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
208 local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
210 if [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
211 error "Error in replicating xattrs."
215 # Use diff to compare the source and the destination
216 check_diff $DIR/$tdir $TGT/$tdir
217 check_diff $DIR/$tdir $TGT2/$tdir
222 run_test 1A "Simple Replication"
224 # Test 1a - test create/delete operations in ROOT directory
225 test_1a() { # LU-5005
226 rm -rf $TGT/root-* 2> /dev/null
227 rm -rf $DIR/root-* 2> /dev/null
236 touch $DIR/root-file2
239 mv $DIR/root-file2 $DIR/root-file3
241 # File and directory delete
242 touch $DIR/root-file4
245 rm -rf $DIR/root-dir1
248 local LRSYNC_LOG=$(generate_logname "lrsync_log")
250 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
254 stat $TGT/root-dir || error "Dir create not replicated"
255 stat $TGT/root-file || error "File create not replicated"
256 stat $TGT/root-file2 && error "Rename not replicated (src)"
257 stat $TGT/root-file3 || error "Rename not replicated (tgt)"
258 stat $TGT/root-dir1 && error "Dir delete not replicated"
259 stat $TGT/root-file4 && error "File delete not replicated"
267 run_test 1a "Replicate create/delete operations in ROOT directory"
269 # Test 2a - Replicate files created by dbench
275 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed"
277 local LRSYNC_LOG=$(generate_logname "lrsync_log")
278 # Replicate the changes to $TGT
279 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
282 # Use diff to compare the source and the destination
283 check_diff $DIR/$tdir $TGT/$tdir
284 check_diff $DIR/$tdir $TGT2/$tdir
290 run_test 2a "Replicate files created by dbench."
292 # Test 2b - Replicate files changed by dbench.
299 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
300 # wait for dbench to start
301 wait_for_function 'child_pid=$(pgrep dbench)' 360
302 # let dbench run for a bit
305 echo PIDs: $child_pid
307 stop_procs $child_pid
309 local LRSYNC_LOG=$(generate_logname "lrsync_log")
310 echo Starting replication
311 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
313 check_diff $DIR/$tdir $TGT/$tdir
316 $KILL -SIGCONT $child_pid
320 stop_procs $child_pid
322 echo Starting replication
323 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
324 check_diff $DIR/$tdir $TGT/$tdir
326 echo "Wait for dbench to finish"
327 $KILL -SIGCONT $child_pid
330 # Replicate the changes to $TGT
331 echo Starting replication
332 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
334 check_diff $DIR/$tdir $TGT/$tdir
335 check_diff $DIR/$tdir $TGT2/$tdir
341 run_test 2b "Replicate files changed by dbench."
343 # Test 2c - Replicate files while dbench is running
349 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
351 local LRSYNC_LOG=$(generate_logname "lrsync_log")
352 # Replicate the changes to $TGT
353 sleep 10 # give dbench a headstart
355 while [ $quit -le 1 ];
357 echo "Running lustre_rsync"
358 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
359 -l $LREPL_LOG -D $LRSYNC_LOG
362 if [ $? -ne 0 ]; then
363 quit=$(expr $quit + 1)
367 # Use diff to compare the source and the destination
368 check_diff $DIR/$tdir $TGT/$tdir
369 check_diff $DIR/$tdir $TGT2/$tdir
375 run_test 2c "Replicate files while dbench is running."
377 # Test 3a - Replicate files created by createmany
383 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
385 local LRSYNC_LOG=$(generate_logname "lrsync_log")
386 # Replicate the changes to $TGT
387 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
389 check_diff $DIR/$tdir $TGT/$tdir
390 check_diff $DIR/$tdir $TGT2/$tdir
396 run_test 3a "Replicate files created by createmany"
398 # Test 3b - Replicate files created by writemany
405 writemany -q -a $DIR/$tdir/$tfile $time $threads ||
406 error "writemany failed"
408 local LRSYNC_LOG=$(generate_logname "lrsync_log")
409 # Replicate the changes to $TGT
410 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
413 check_diff $DIR/$tdir $TGT/$tdir
414 check_diff $DIR/$tdir $TGT2/$tdir
420 run_test 3b "Replicate files created by writemany"
422 # Test 3c - Replicate files created by createmany/unlinkmany
428 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
429 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
431 local LRSYNC_LOG=$(generate_logname "lrsync_log")
432 # Replicate the changes to $TGT
433 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
435 check_diff $DIR/$tdir $TGT/$tdir
436 check_diff $DIR/$tdir $TGT2/$tdir
442 run_test 3c "Replicate files created by createmany/unlinkmany"
444 # Test 4 - Replicate files created by iozone
446 which iozone > /dev/null 2>&1
447 [ $? -ne 0 ] && skip "iozone not found"
452 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
453 MOUNT=${DIR}/$tdir run_iozone.sh &
455 child_pid=$(pgrep iozone)
456 stop_procs $child_pid
458 local LRSYNC_LOG=$(generate_logname "lrsync_log")
459 # Replicate the changes to $TGT
460 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
462 check_diff $DIR/$tdir $TGT/$tdir
463 check_diff $DIR/$tdir $TGT2/$tdir
465 $KILL -SIGCONT $child_pid
467 $KILL -SIGKILL $(pgrep run_iozone.sh)
468 $KILL -SIGKILL $(pgrep iozone)
470 # After killing 'run_iozone.sh', process 'iozone' becomes the
471 # child of PID 1. Hence 'wait' does not wait for it. Killing
472 # iozone first, means more iozone processes are spawned off which
473 # is not desirable. So, after sending a sigkill, the test goes
474 # into a wait loop for iozone to cleanup and exit.
476 while [ "$(pgrep "iozone")" != "" ];
478 ps -ef | grep iozone | grep -v grep
482 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
483 check_diff $DIR/$tdir $TGT/$tdir
484 check_diff $DIR/$tdir $TGT2/$tdir
490 run_test 4 "Replicate files created by iozone"
492 # Test 5a - Stop / start lustre_rsync
498 createmany -o $DIR/$tdir/$tfile $NUMTEST
500 # Replicate the changes to $TGT
501 local LRSYNC_LOG=$(generate_logname "lrsync_log")
502 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
506 $KILL -SIGHUP $child_pid
508 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
510 check_diff $DIR/$tdir $TGT/$tdir
511 check_diff $DIR/$tdir $TGT2/$tdir
517 run_test 5a "Stop / start lustre_rsync"
519 # Test 5b - Kill / restart lustre_rsync
525 createmany -o $DIR/$tdir/$tfile $NUMTEST
527 # Replicate the changes to $TGT
528 local LRSYNC_LOG=$(generate_logname "lrsync_log")
529 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
533 $KILL -SIGKILL $child_pid
535 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
537 check_diff $DIR/$tdir $TGT/$tdir
538 check_diff $DIR/$tdir $TGT2/$tdir
544 run_test 5b "Kill / restart lustre_rsync"
546 # Test 6 - lustre_rsync large no of hard links
554 touch $DIR/$tdir/link0
555 for ((i = 1; i < num_links - 1; i++)); do
556 ln $DIR/$tdir/link0 $DIR/$tdir/link$i
558 # create an extra hard link of src name ending with dest name
559 ln $DIR/$tdir/link0 $DIR/$tdir/ink0
561 local LRSYNC_LOG=$(generate_logname "lrsync_log")
562 # Replicate the changes to $TGT
563 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
565 check_diff $DIR/$tdir $TGT/$tdir
566 check_diff $DIR/$tdir $TGT2/$tdir
568 local count1=$(stat --format=%h $TGT/$tdir/link0)
569 local count2=$(stat --format=%h $TGT2/$tdir/link0)
570 if ((count1 != num_links || count2 != num_links)); then
571 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
572 error "Incorrect no of hard links found $count1, $count2"
579 run_test 6 "lustre_rsync large no of hard links"
581 # Test 7 - lustre_rsync stripesize
586 mkdir -p ${DIR}/tgt/$tdir
589 $LFS setstripe -c $OSTCOUNT $DIR/$tdir ||
590 error "$LFS setstripe failed"
591 createmany -o $DIR/$tdir/$tfile $numfiles
593 # To simulate replication to another lustre filesystem, replicate
594 # the changes to $DIR/tgt. We can't turn off the changelogs
595 # while we are registered, so lustre_rsync better not try to
596 # replicate the replication steps. It seems ok :)
598 local LRSYNC_LOG=$(generate_logname "lrsync_log")
599 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
601 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
604 while [ $i -lt $numfiles ];
606 local count=$($LFS getstripe $DIR/tgt/$tdir/${tfile}$i |
607 awk '/stripe_count/ {print $2}')
608 if [ $count -ne $OSTCOUNT ]; then
609 error "Stripe size not replicated"
617 run_test 7 "lustre_rsync stripesize"
619 # Test 8 - Replicate multiple file/directory moves
624 for i in 1 2 3 4 5 6 7 8 9; do
626 for j in 1 2 3 4 5 6 7 8 9; do
627 mkdir $DIR/$tdir/d$i/d$i$j
628 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
630 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
631 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
633 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
635 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
638 local LRSYNC_LOG=$(generate_logname "lrsync_log")
639 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
642 check_diff ${DIR}/$tdir $TGT/$tdir
648 run_test 8 "Replicate multiple file/directory moves"
655 touch $DIR/$tdir/foo/a1
657 local LRSYNC_LOG=$(generate_logname "lrsync_log")
658 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
661 check_diff ${DIR}/$tdir $TGT/$tdir
663 rm -rf $DIR/$tdir/foo
665 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
668 check_diff ${DIR}/$tdir $TGT/$tdir
674 run_test 9 "Replicate recursive directory removal"
678 check_and_cleanup_lustre