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 [ -n "$ONLY" ] && SLOW=yes
16 ALWAYS_EXCEPT="$LRSYNC_EXCEPT"
17 # bug number for skipped test:
18 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
20 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
21 echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
23 # disable till changelogs from orion landed (LU-2034)
24 ALWAYS_EXCEPT="1 2 3 4 5 6 7 8 9"
29 LREPL_LOG=$TMP/lustre_rsync.log
32 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
33 . $LUSTRE/tests/test-framework.sh
35 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
38 check_and_setup_lustre
46 export LRSYNC=${LRSYNC:-"$LUSTRE/utils/lustre_rsync"}
47 [ ! -f "$LRSYNC" ] && export LRSYNC=$(which lustre_rsync)
48 export LRSYNC="$LRSYNC -v -c no" # -a
50 # control the time of tests
51 DBENCH_TIME=${DBENCH_TIME:-60} # No of seconds to run dbench
54 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
55 awk '{gsub(/_UUID/,""); print $1}' | head -1)
58 CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
59 echo $MDT0: Registered changelog user $CL_USER
60 CL_USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
61 mdd.$MDT0.changelog_users | wc -l) - 2 ))
62 [ $CL_USERS -ne 1 ] && \
63 echo "Other changelog users present ($CL_USERS)"
67 rm -rf $TGT/$tdir $TGT/d*.lustre_rsync-test 2> /dev/null
68 rm -rf $TGT2/$tdir $TGT2/d*.lustre_rsync-test 2> /dev/null
69 rm -rf ${DIR}/$tdir $DIR/d*.lustre_rsync-test ${DIR}/tgt 2> /dev/null
73 mkdir -p ${TGT2}/$tdir
75 error "Failed to create target: " $TGT
86 $LFS changelog_clear $MDT0 $CL_USER 0
87 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
90 # Check whether the filesystem supports xattr or not.
92 # "large" - large xattr is supported
93 # "small" - large xattr is unsupported but small xattr is supported
94 # "no" - xattr is unsupported
101 local val="$(generate_string $(max_xattr_size))"
102 if large_xattr_enabled &&
103 setfattr -n user.foo -v $val $tgt 2>/dev/null; then
106 setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
114 local changelog_file=$LOGDIR/${TESTSUITE}.test_${3}.changelog
116 if [ -e $1 -o -e $2 ]; then
117 diff -rq -x "dev1" $1 $2
119 if [ $RC -ne 0 ]; then
120 $LFS changelog $MDT0 > $changelog_file
121 error "Failure in replication; differences found."
126 # Test 1 - test basic operations
130 local xattr=$(check_xattr $TGT/foo)
137 touch $DIR/$tdir/file1
138 cp /etc/hosts $DIR/$tdir/d1/
139 touch $DIR/$tdir/d1/"space in filename"
140 touch $DIR/$tdir/d1/file2
143 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
145 # File and directory delete
146 touch $DIR/$tdir/d1/file4
147 mkdir $DIR/$tdir/d1/del
148 touch $DIR/$tdir/d1/del/del1
149 touch $DIR/$tdir/d1/del/del2
150 rm -rf $DIR/$tdir/d1/del
151 rm $DIR/$tdir/d1/file4
154 cat /etc/hosts > $DIR/$tdir/d1/link1
155 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
156 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
159 #mknod $DIR/$tdir/dev1 b 8 1
162 echo "Replication #1"
163 $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
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 1
202 check_diff $DIR/$tdir $TGT2/$tdir 1
208 run_test 1 "Simple Replication"
210 # Test 2a - Replicate files created by dbench
212 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
217 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed!"
219 # Replicate the changes to $TGT
220 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
222 # Use diff to compare the source and the destination
223 check_diff $DIR/$tdir $TGT/$tdir 2a
224 check_diff $DIR/$tdir $TGT2/$tdir 2a
230 run_test 2a "Replicate files created by dbench."
233 # Test 2b - Replicate files changed by dbench.
235 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
241 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
244 local child_pid=$(pgrep dbench)
245 echo PIDs: $child_pid
247 $KILL -SIGSTOP $child_pid
249 echo Starting replication
250 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
251 check_diff $DIR/$tdir $TGT/$tdir 2b
254 $KILL -SIGCONT $child_pid
258 $KILL -SIGSTOP $child_pid
260 echo Starting replication
261 $LRSYNC -l $LREPL_LOG
262 check_diff $DIR/$tdir $TGT/$tdir 2b
264 echo "Wait for dbench to finish"
265 $KILL -SIGCONT $child_pid
268 # Replicate the changes to $TGT
269 echo Starting replication
270 $LRSYNC -l $LREPL_LOG
272 check_diff $DIR/$tdir $TGT/$tdir 2b
273 check_diff $DIR/$tdir $TGT2/$tdir 2b
279 run_test 2b "Replicate files changed by dbench."
281 # Test 2c - Replicate files while dbench is running
283 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
288 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
290 # Replicate the changes to $TGT
291 sleep 10 # give dbench a headstart
293 while [ $quit -le 1 ];
295 echo "Running lustre_rsync"
296 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER -l $LREPL_LOG
299 if [ $? -ne 0 ]; then
300 quit=$(expr $quit + 1)
304 # Use diff to compare the source and the destination
305 check_diff $DIR/$tdir $TGT/$tdir 2c
306 check_diff $DIR/$tdir $TGT2/$tdir 2c
312 run_test 2c "Replicate files while dbench is running."
314 # Test 3a - Replicate files created by createmany
316 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
322 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
324 # Replicate the changes to $TGT
325 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
326 check_diff $DIR/$tdir $TGT/$tdir 3a
327 check_diff $DIR/$tdir $TGT2/$tdir 3a
333 run_test 3a "Replicate files created by createmany"
336 # Test 3b - Replicate files created by writemany
338 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
345 writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
347 # Replicate the changes to $TGT
348 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
350 check_diff $DIR/$tdir $TGT/$tdir 3b
351 check_diff $DIR/$tdir $TGT2/$tdir 3b
357 run_test 3b "Replicate files created by writemany"
359 # Test 3c - Replicate files created by createmany/unlinkmany
361 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
367 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
368 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
370 # Replicate the changes to $TGT
371 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
372 check_diff $DIR/$tdir $TGT/$tdir 3c
373 check_diff $DIR/$tdir $TGT2/$tdir 3c
379 run_test 3c "Replicate files created by createmany/unlinkmany"
381 # Test 4 - Replicate files created by iozone
383 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
385 which iozone > /dev/null 2>&1
386 if [ $? -ne 0 ]; then
387 skip "iozone not found. Skipping test"
394 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
395 MOUNT=${DIR}/$tdir run_iozone.sh &
397 child_pid=$(pgrep iozone)
398 $KILL -SIGSTOP $child_pid
400 # Replicate the changes to $TGT
401 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
402 check_diff $DIR/$tdir $TGT/$tdir 4
403 check_diff $DIR/$tdir $TGT2/$tdir 4
405 $KILL -SIGCONT $child_pid
407 $KILL -SIGKILL $(pgrep run_iozone.sh)
408 $KILL -SIGKILL $(pgrep iozone)
410 # After killing 'run_iozone.sh', process 'iozone' becomes the
411 # child of PID 1. Hence 'wait' does not wait for it. Killing
412 # iozone first, means more iozone processes are spawned off which
413 # is not desirable. So, after sending a sigkill, the test goes
414 # into a wait loop for iozone to cleanup and exit.
416 while [ "$(pgrep "iozone")" != "" ];
418 ps -ef | grep iozone | grep -v grep
422 $LRSYNC -l $LREPL_LOG
423 check_diff $DIR/$tdir $TGT/$tdir 4
424 check_diff $DIR/$tdir $TGT2/$tdir 4
430 run_test 4 "Replicate files created by iozone"
432 # Test 5a - Stop / start lustre_rsync
434 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
440 createmany -o $DIR/$tdir/$tfile $NUMTEST
442 # Replicate the changes to $TGT
444 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
447 $KILL -SIGHUP $child_pid
449 $LRSYNC -l $LREPL_LOG
451 check_diff $DIR/$tdir $TGT/$tdir 5a
452 check_diff $DIR/$tdir $TGT2/$tdir 5a
458 run_test 5a "Stop / start lustre_rsync"
460 # Test 5b - Kill / restart lustre_rsync
462 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
468 createmany -o $DIR/$tdir/$tfile $NUMTEST
470 # Replicate the changes to $TGT
472 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
475 $KILL -SIGKILL $child_pid
477 $LRSYNC -l $LREPL_LOG
479 check_diff $DIR/$tdir $TGT/$tdir 5b
480 check_diff $DIR/$tdir $TGT2/$tdir 5b
486 run_test 5b "Kill / restart lustre_rsync"
488 # Test 6 - lustre_rsync large no of hard links
494 touch $DIR/$tdir/link0
496 while [ $i -lt $NUMLINKS ];
498 ln $DIR/$tdir/link0 $DIR/$tdir/link${i}
502 # Replicate the changes to $TGT
503 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
504 check_diff $DIR/$tdir $TGT/$tdir 6
505 check_diff $DIR/$tdir $TGT2/$tdir 6
507 local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
508 local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
509 if [[ $count1 -ne $NUMLINKS ]] || [[ $count2 -ne $NUMLINKS ]]; then
510 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
511 error "Incorrect no of hard links found $count1, $count2"
517 run_test 6 "lustre_rsync large no of hard links"
519 # Test 7 - lustre_rsync stripesize
522 mkdir -p ${DIR}/tgt/$tdir
526 lfs setstripe -c $OSTCOUNT $DIR/$tdir
527 createmany -o $DIR/$tdir/$tfile $NUMFILES
529 # To simulate replication to another lustre filesystem, replicate
530 # the changes to $DIR/tgt. We can't turn off the changelogs
531 # while we are registered, so lustre_rsync better not try to
532 # replicate the replication steps. It seems ok :)
534 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG
535 check_diff ${DIR}/$tdir $DIR/tgt/$tdir 7
538 while [ $i -lt $NUMFILES ];
540 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | awk '/stripe_count/ {print $2}')
541 if [ $count -ne $OSTCOUNT ]; then
542 error "Stripe size not replicated"
550 run_test 7 "lustre_rsync stripesize"
552 # Test 8 - Replicate multiple file/directory moves
557 for i in 1 2 3 4 5 6 7 8 9; do
559 for j in 1 2 3 4 5 6 7 8 9; do
560 mkdir $DIR/$tdir/d$i/d$i$j
561 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
563 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
564 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
566 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
568 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
571 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
573 check_diff ${DIR}/$tdir $TGT/$tdir 8
579 run_test 8 "Replicate multiple file/directory moves"
586 touch $DIR/$tdir/foo/a1
588 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
590 check_diff ${DIR}/$tdir $TGT/$tdir 9
592 rm -rf $DIR/$tdir/foo
594 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
596 check_diff ${DIR}/$tdir $TGT/$tdir 9
602 run_test 9 "Replicate recursive directory removal"
605 complete $(basename $0) $SECONDS
606 check_and_cleanup_lustre