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))"
94 if large_xattr_enabled &&
95 setfattr -n user.foo -v $val $tgt 2>/dev/null; then
98 setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
106 local changelog_file=$(generate_logname "changelog")
108 if [ -e $1 -o -e $2 ]; then
109 diff -rq -x "dev1" $1 $2
111 if [ $RC -ne 0 ]; then
112 $LFS changelog $MDT0 > $changelog_file
113 error "Failure in replication; differences found."
118 procs_are_stopped() {
122 for state in $(ps -p "$pids" -o state=); do
123 if [[ "$state" != T ]]; then
131 # Send SIGSTOP to PIDs and wait up to 60 seconds for them to show a
132 # stopped process state.
138 end=$((SECONDS + 60))
139 while ((SECONDS < end)); do
140 if procs_are_stopped $pids; then
150 # Test 1A - test basic operations
151 test_1A() { # was test_1
154 local xattr=$(check_xattr $TGT/foo)
161 touch $DIR/$tdir/file1
162 cp /etc/hosts $DIR/$tdir/d1/
163 touch $DIR/$tdir/d1/"space in filename"
164 touch $DIR/$tdir/d1/file2
167 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
169 # File and directory delete
170 touch $DIR/$tdir/d1/file4
171 mkdir $DIR/$tdir/d1/del
172 touch $DIR/$tdir/d1/del/del1
173 touch $DIR/$tdir/d1/del/del2
174 rm -rf $DIR/$tdir/d1/del
175 rm $DIR/$tdir/d1/file4
178 cat /etc/hosts > $DIR/$tdir/d1/link1
179 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
180 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
183 #mknod $DIR/$tdir/dev1 b 8 1
186 local LRSYNC_LOG=$(generate_logname "lrsync_log")
187 echo "Replication #1"
188 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
192 chmod 000 $DIR/$tdir/d2/file3
193 chown nobody:$GROUP $DIR/$tdir/d2/file3
196 if [[ "$xattr" != "no" ]]; then
198 touch $DIR/$tdir/file5
199 [[ "$xattr" = "large" ]] &&
200 value="$(generate_string $(max_xattr_size))" || value="bar"
201 setfattr -n user.foo -v $value $DIR/$tdir/file5
204 echo "Replication #2"
205 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
207 if [[ "$xattr" != "no" ]]; then
208 local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
209 local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
211 if [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
212 error "Error in replicating xattrs."
216 # Use diff to compare the source and the destination
217 check_diff $DIR/$tdir $TGT/$tdir
218 check_diff $DIR/$tdir $TGT2/$tdir
223 run_test 1A "Simple Replication"
225 # Test 1a - test create/delete operations in ROOT directory
226 test_1a() { # LU-5005
227 rm -rf $TGT/root-* 2> /dev/null
228 rm -rf $DIR/root-* 2> /dev/null
233 mkdir_on_mdt0 $DIR/root-dir
237 touch $DIR/root-file2
240 mv $DIR/root-file2 $DIR/root-file3
242 # File and directory delete
243 touch $DIR/root-file4
244 mkdir_on_mdt0 $DIR/root-dir1
246 rm -rf $DIR/root-dir1
249 local LRSYNC_LOG=$(generate_logname "lrsync_log")
251 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
255 stat $TGT/root-dir || error "Dir create not replicated"
256 stat $TGT/root-file || error "File create not replicated"
257 stat $TGT/root-file2 && error "Rename not replicated (src)"
258 stat $TGT/root-file3 || error "Rename not replicated (tgt)"
259 stat $TGT/root-dir1 && error "Dir delete not replicated"
260 stat $TGT/root-file4 && error "File delete not replicated"
268 run_test 1a "Replicate create/delete operations in ROOT directory"
270 # Test 2a - Replicate files created by dbench
276 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed"
278 local LRSYNC_LOG=$(generate_logname "lrsync_log")
279 # Replicate the changes to $TGT
280 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
283 # Use diff to compare the source and the destination
284 check_diff $DIR/$tdir $TGT/$tdir
285 check_diff $DIR/$tdir $TGT2/$tdir
291 run_test 2a "Replicate files created by dbench."
293 # Test 2b - Replicate files changed by dbench.
300 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
301 # wait for dbench to start
302 wait_for_function 'child_pid=$(pgrep dbench)' 360
303 # let dbench run for a bit
306 echo PIDs: $child_pid
308 stop_procs $child_pid
310 local LRSYNC_LOG=$(generate_logname "lrsync_log")
311 echo Starting replication
312 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
314 check_diff $DIR/$tdir $TGT/$tdir
317 $KILL -SIGCONT $child_pid
321 stop_procs $child_pid
323 echo Starting replication
324 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
325 check_diff $DIR/$tdir $TGT/$tdir
327 echo "Wait for dbench to finish"
328 $KILL -SIGCONT $child_pid
331 # Replicate the changes to $TGT
332 echo Starting replication
333 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
335 check_diff $DIR/$tdir $TGT/$tdir
336 check_diff $DIR/$tdir $TGT2/$tdir
342 run_test 2b "Replicate files changed by dbench."
344 # Test 2c - Replicate files while dbench is running
350 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
352 local LRSYNC_LOG=$(generate_logname "lrsync_log")
353 # Replicate the changes to $TGT
354 sleep 10 # give dbench a headstart
356 while [ $quit -le 1 ];
358 echo "Running lustre_rsync"
359 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
360 -l $LREPL_LOG -D $LRSYNC_LOG
363 if [ $? -ne 0 ]; then
364 quit=$(expr $quit + 1)
368 # Use diff to compare the source and the destination
369 check_diff $DIR/$tdir $TGT/$tdir
370 check_diff $DIR/$tdir $TGT2/$tdir
376 run_test 2c "Replicate files while dbench is running."
378 # Test 3a - Replicate files created by createmany
384 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
386 local LRSYNC_LOG=$(generate_logname "lrsync_log")
387 # Replicate the changes to $TGT
388 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
390 check_diff $DIR/$tdir $TGT/$tdir
391 check_diff $DIR/$tdir $TGT2/$tdir
397 run_test 3a "Replicate files created by createmany"
399 # Test 3b - Replicate files created by writemany
406 writemany -q -a $DIR/$tdir/$tfile $time $threads ||
407 error "writemany failed"
409 local LRSYNC_LOG=$(generate_logname "lrsync_log")
410 # Replicate the changes to $TGT
411 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
414 check_diff $DIR/$tdir $TGT/$tdir
415 check_diff $DIR/$tdir $TGT2/$tdir
421 run_test 3b "Replicate files created by writemany"
423 # Test 3c - Replicate files created by createmany/unlinkmany
429 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
430 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
432 local LRSYNC_LOG=$(generate_logname "lrsync_log")
433 # Replicate the changes to $TGT
434 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
436 check_diff $DIR/$tdir $TGT/$tdir
437 check_diff $DIR/$tdir $TGT2/$tdir
443 run_test 3c "Replicate files created by createmany/unlinkmany"
445 # Test 4 - Replicate files created by iozone
447 which iozone > /dev/null 2>&1
448 [ $? -ne 0 ] && skip "iozone not found"
453 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
454 MOUNT=${DIR}/$tdir run_iozone.sh &
456 child_pid=$(pgrep iozone)
457 stop_procs $child_pid
459 local LRSYNC_LOG=$(generate_logname "lrsync_log")
460 # Replicate the changes to $TGT
461 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
463 check_diff $DIR/$tdir $TGT/$tdir
464 check_diff $DIR/$tdir $TGT2/$tdir
466 $KILL -SIGCONT $child_pid
468 $KILL -SIGKILL $(pgrep run_iozone.sh)
469 $KILL -SIGKILL $(pgrep iozone)
471 # After killing 'run_iozone.sh', process 'iozone' becomes the
472 # child of PID 1. Hence 'wait' does not wait for it. Killing
473 # iozone first, means more iozone processes are spawned off which
474 # is not desirable. So, after sending a sigkill, the test goes
475 # into a wait loop for iozone to cleanup and exit.
477 while [ "$(pgrep "iozone")" != "" ];
479 ps -ef | grep iozone | grep -v grep
483 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
484 check_diff $DIR/$tdir $TGT/$tdir
485 check_diff $DIR/$tdir $TGT2/$tdir
491 run_test 4 "Replicate files created by iozone"
493 # Test 5a - Stop / start lustre_rsync
499 createmany -o $DIR/$tdir/$tfile $NUMTEST
501 # Replicate the changes to $TGT
502 local LRSYNC_LOG=$(generate_logname "lrsync_log")
503 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
507 $KILL -SIGHUP $child_pid
509 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
511 check_diff $DIR/$tdir $TGT/$tdir
512 check_diff $DIR/$tdir $TGT2/$tdir
518 run_test 5a "Stop / start lustre_rsync"
520 # Test 5b - Kill / restart lustre_rsync
526 createmany -o $DIR/$tdir/$tfile $NUMTEST
528 # Replicate the changes to $TGT
529 local LRSYNC_LOG=$(generate_logname "lrsync_log")
530 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
534 $KILL -SIGKILL $child_pid
536 $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
538 check_diff $DIR/$tdir $TGT/$tdir
539 check_diff $DIR/$tdir $TGT2/$tdir
545 run_test 5b "Kill / restart lustre_rsync"
547 # Test 6 - lustre_rsync large no of hard links
555 touch $DIR/$tdir/link0
556 for ((i = 1; i < num_links - 1; i++)); do
557 ln $DIR/$tdir/link0 $DIR/$tdir/link$i
559 # create an extra hard link of src name ending with dest name
560 ln $DIR/$tdir/link0 $DIR/$tdir/ink0
562 local LRSYNC_LOG=$(generate_logname "lrsync_log")
563 # Replicate the changes to $TGT
564 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
566 check_diff $DIR/$tdir $TGT/$tdir
567 check_diff $DIR/$tdir $TGT2/$tdir
569 local count1=$(stat --format=%h $TGT/$tdir/link0)
570 local count2=$(stat --format=%h $TGT2/$tdir/link0)
571 if ((count1 != num_links || count2 != num_links)); then
572 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
573 error "Incorrect no of hard links found $count1, $count2"
580 run_test 6 "lustre_rsync large no of hard links"
582 # Test 7 - lustre_rsync stripesize
587 mkdir -p ${DIR}/tgt/$tdir
590 $LFS setstripe -c $OSTCOUNT $DIR/$tdir ||
591 error "$LFS setstripe failed"
592 createmany -o $DIR/$tdir/$tfile $numfiles
594 # To simulate replication to another lustre filesystem, replicate
595 # the changes to $DIR/tgt. We can't turn off the changelogs
596 # while we are registered, so lustre_rsync better not try to
597 # replicate the replication steps. It seems ok :)
599 local LRSYNC_LOG=$(generate_logname "lrsync_log")
600 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
602 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
605 while [ $i -lt $numfiles ];
607 local count=$($LFS getstripe $DIR/tgt/$tdir/${tfile}$i |
608 awk '/stripe_count/ {print $2}')
609 if [ $count -ne $OSTCOUNT ]; then
610 error "Stripe size not replicated"
618 run_test 7 "lustre_rsync stripesize"
620 # Test 8 - Replicate multiple file/directory moves
625 for i in 1 2 3 4 5 6 7 8 9; do
627 for j in 1 2 3 4 5 6 7 8 9; do
628 mkdir $DIR/$tdir/d$i/d$i$j
629 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
631 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
632 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
634 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
636 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
639 local LRSYNC_LOG=$(generate_logname "lrsync_log")
640 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
643 check_diff ${DIR}/$tdir $TGT/$tdir
649 run_test 8 "Replicate multiple file/directory moves"
656 touch $DIR/$tdir/foo/a1
658 local LRSYNC_LOG=$(generate_logname "lrsync_log")
659 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
662 check_diff ${DIR}/$tdir $TGT/$tdir
664 rm -rf $DIR/$tdir/foo
666 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
669 check_diff ${DIR}/$tdir $TGT/$tdir
675 run_test 9 "Replicate recursive directory removal"
679 check_and_cleanup_lustre