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`"
26 LREPL_LOG=$TMP/lustre_rsync.log
29 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
30 . $LUSTRE/tests/test-framework.sh
32 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
35 check_and_setup_lustre
43 export LRSYNC=${LRSYNC:-"$LUSTRE/utils/lustre_rsync"}
44 [ ! -f "$LRSYNC" ] && export LRSYNC=$(which lustre_rsync)
45 export LRSYNC="$LRSYNC -v" # -a
47 # control the time of tests
48 DBENCH_TIME=${DBENCH_TIME:-60} # No of seconds to run dbench
51 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
52 awk '{gsub(/_UUID/,""); print $1}' | head -1)
55 CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
56 echo $MDT0: Registered changelog user $CL_USER
57 CL_USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
58 mdd.$MDT0.changelog_users | wc -l) - 2 ))
59 [ $CL_USERS -ne 1 ] && \
60 echo "Other changelog users present ($CL_USERS)"
64 rm -rf $TGT/$tdir $TGT/d*.lustre_rsync-test 2> /dev/null
65 rm -rf $TGT2/$tdir $TGT2/d*.lustre_rsync-test 2> /dev/null
66 rm -rf ${DIR}/$tdir $DIR/d*.lustre_rsync-test ${DIR}/tgt 2> /dev/null
70 mkdir -p ${TGT2}/$tdir
72 error "Failed to create target: " $TGT
83 $LFS changelog_clear $MDT0 $CL_USER 0
84 do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
87 # Check whether the filesystem supports xattr or not.
89 # "large" - large xattr is supported
90 # "small" - large xattr is unsupported but small xattr is supported
91 # "no" - xattr is unsupported
98 local val="$(generate_string $(max_xattr_size))"
99 if large_xattr_enabled &&
100 setfattr -n user.foo -v $val $tgt 2>/dev/null; then
103 setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
111 if [ -e $1 -o -e $2 ]; then
112 diff -rq -x "dev1" $1 $2
114 if [ $RC -ne 0 ]; then
115 error "Failure in replication; differences found."
120 # Test 1 - test basic operations
124 local xattr=$(check_xattr $TGT/foo)
131 touch $DIR/$tdir/file1
132 cp /etc/hosts $DIR/$tdir/d1/
133 touch $DIR/$tdir/d1/"space in filename"
134 touch $DIR/$tdir/d1/file2
137 mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
139 # File and directory delete
140 touch $DIR/$tdir/d1/file4
141 mkdir $DIR/$tdir/d1/del
142 touch $DIR/$tdir/d1/del/del1
143 touch $DIR/$tdir/d1/del/del2
144 rm -rf $DIR/$tdir/d1/del
145 rm $DIR/$tdir/d1/file4
148 cat /etc/hosts > $DIR/$tdir/d1/link1
149 ln $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link2
150 ln -s $DIR/$tdir/d1/link1 $DIR/$tdir/d1/link3
153 #mknod $DIR/$tdir/dev1 b 8 1
156 echo "Replication #1"
157 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
160 chmod 000 $DIR/$tdir/d2/file3
161 chown nobody:nobody $DIR/$tdir/d2/file3
164 if [[ "$xattr" != "no" ]]; then
166 touch $DIR/$tdir/file5
167 [[ "$xattr" = "large" ]] &&
168 value="$(generate_string $(max_xattr_size))" || value="bar"
169 setfattr -n user.foo -v $value $DIR/$tdir/file5
172 echo "Replication #2"
173 $LRSYNC -l $LREPL_LOG
175 if [[ "$xattr" != "no" ]]; then
176 local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
177 local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
182 # fid2path and path2fid aren't implemented for block devices
183 #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
184 # ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
185 # error "Error replicating block devices"
188 if [[ "$xattr" != "no" ]] &&
189 [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
190 error "Error in replicating xattrs."
194 # Use diff to compare the source and the destination
195 check_diff $DIR/$tdir $TGT/$tdir
196 check_diff $DIR/$tdir $TGT2/$tdir
202 run_test 1 "Simple Replication"
204 # Test 2a - Replicate files created by dbench
206 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
211 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed!"
213 # Replicate the changes to $TGT
214 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
216 # Use diff to compare the source and the destination
217 check_diff $DIR/$tdir $TGT/$tdir
218 check_diff $DIR/$tdir $TGT2/$tdir
224 run_test 2a "Replicate files created by dbench."
227 # Test 2b - Replicate files changed by dbench.
229 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
235 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
238 local child_pid=$(pgrep dbench)
239 echo PIDs: $child_pid
241 $KILL -SIGSTOP $child_pid
243 echo Starting replication
244 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
245 check_diff $DIR/$tdir $TGT/$tdir
248 $KILL -SIGCONT $child_pid
252 $KILL -SIGSTOP $child_pid
254 echo Starting replication
255 $LRSYNC -l $LREPL_LOG
256 check_diff $DIR/$tdir $TGT/$tdir
258 echo "Wait for dbench to finish"
259 $KILL -SIGCONT $child_pid
262 # Replicate the changes to $TGT
263 echo Starting replication
264 $LRSYNC -l $LREPL_LOG
266 check_diff $DIR/$tdir $TGT/$tdir
267 check_diff $DIR/$tdir $TGT2/$tdir
273 run_test 2b "Replicate files changed by dbench."
275 # Test 2c - Replicate files while dbench is running
277 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
282 sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
284 # Replicate the changes to $TGT
285 sleep 10 # give dbench a headstart
287 while [ $quit -le 1 ];
289 echo "Running lustre_rsync"
290 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER -l $LREPL_LOG
293 if [ $? -ne 0 ]; then
294 quit=$(expr $quit + 1)
298 # Use diff to compare the source and the destination
299 check_diff $DIR/$tdir $TGT/$tdir
300 check_diff $DIR/$tdir $TGT2/$tdir
306 run_test 2c "Replicate files while dbench is running."
308 # Test 3a - Replicate files created by createmany
310 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
316 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
318 # Replicate the changes to $TGT
319 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
320 check_diff $DIR/$tdir $TGT/$tdir
321 check_diff $DIR/$tdir $TGT2/$tdir
327 run_test 3a "Replicate files created by createmany"
330 # Test 3b - Replicate files created by writemany
332 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
339 writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
341 # Replicate the changes to $TGT
342 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
344 check_diff $DIR/$tdir $TGT/$tdir
345 check_diff $DIR/$tdir $TGT2/$tdir
351 run_test 3b "Replicate files created by writemany"
353 # Test 3c - Replicate files created by createmany/unlinkmany
355 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
361 createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
362 unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
364 # Replicate the changes to $TGT
365 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
366 check_diff $DIR/$tdir $TGT/$tdir
367 check_diff $DIR/$tdir $TGT2/$tdir
373 run_test 3c "Replicate files created by createmany/unlinkmany"
375 # Test 4 - Replicate files created by iozone
377 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
379 which iozone > /dev/null 2>&1
380 if [ $? -ne 0 ]; then
381 skip "iozone not found. Skipping test"
388 END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
389 MOUNT=${DIR}/$tdir run_iozone.sh &
391 child_pid=$(pgrep iozone)
392 $KILL -SIGSTOP $child_pid
394 # Replicate the changes to $TGT
395 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
396 check_diff $DIR/$tdir $TGT/$tdir
397 check_diff $DIR/$tdir $TGT2/$tdir
399 $KILL -SIGCONT $child_pid
401 $KILL -SIGKILL $(pgrep run_iozone.sh)
402 $KILL -SIGKILL $(pgrep iozone)
404 # After killing 'run_iozone.sh', process 'iozone' becomes the
405 # child of PID 1. Hence 'wait' does not wait for it. Killing
406 # iozone first, means more iozone processes are spawned off which
407 # is not desirable. So, after sending a sigkill, the test goes
408 # into a wait loop for iozone to cleanup and exit.
410 while [ "$(pgrep "iozone")" != "" ];
412 ps -ef | grep iozone | grep -v grep
416 $LRSYNC -l $LREPL_LOG
417 check_diff $DIR/$tdir $TGT/$tdir
418 check_diff $DIR/$tdir $TGT2/$tdir
424 run_test 4 "Replicate files created by iozone"
426 # Test 5a - Stop / start lustre_rsync
428 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
434 createmany -o $DIR/$tdir/$tfile $NUMTEST
436 # Replicate the changes to $TGT
438 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
441 $KILL -SIGHUP $child_pid
443 $LRSYNC -l $LREPL_LOG
445 check_diff $DIR/$tdir $TGT/$tdir
446 check_diff $DIR/$tdir $TGT2/$tdir
452 run_test 5a "Stop / start lustre_rsync"
454 # Test 5b - Kill / restart lustre_rsync
456 [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
462 createmany -o $DIR/$tdir/$tfile $NUMTEST
464 # Replicate the changes to $TGT
466 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
469 $KILL -SIGKILL $child_pid
471 $LRSYNC -l $LREPL_LOG
473 check_diff $DIR/$tdir $TGT/$tdir
474 check_diff $DIR/$tdir $TGT2/$tdir
480 run_test 5b "Kill / restart lustre_rsync"
482 # Test 6 - lustre_rsync large no of hard links
488 touch $DIR/$tdir/link0
490 while [ $i -lt $NUMLINKS ];
492 ln $DIR/$tdir/link0 $DIR/$tdir/link${i}
496 # Replicate the changes to $TGT
497 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
498 check_diff $DIR/$tdir $TGT/$tdir
499 check_diff $DIR/$tdir $TGT2/$tdir
501 local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
502 local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
503 if [[ $count1 -ne $NUMLINKS ]] || [[ $count2 -ne $NUMLINKS ]]; then
504 ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
505 error "Incorrect no of hard links found $count1, $count2"
511 run_test 6 "lustre_rsync large no of hard links"
513 # Test 7 - lustre_rsync stripesize
516 mkdir -p ${DIR}/tgt/$tdir
520 lfs setstripe -c $OSTCOUNT $DIR/$tdir
521 createmany -o $DIR/$tdir/$tfile $NUMFILES
523 # To simulate replication to another lustre filesystem, replicate
524 # the changes to $DIR/tgt. We can't turn off the changelogs
525 # while we are registered, so lustre_rsync better not try to
526 # replicate the replication steps. It seems ok :)
528 $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG
529 check_diff ${DIR}/$tdir $DIR/tgt/$tdir
532 while [ $i -lt $NUMFILES ];
534 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | awk '/stripe_count/ {print $2}')
535 if [ $count -ne $OSTCOUNT ]; then
536 error "Stripe size not replicated"
544 run_test 7 "lustre_rsync stripesize"
546 # Test 8 - Replicate multiple file/directory moves
551 for i in 1 2 3 4 5 6 7 8 9; do
553 for j in 1 2 3 4 5 6 7 8 9; do
554 mkdir $DIR/$tdir/d$i/d$i$j
555 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
557 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
558 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
560 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
562 mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
565 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
567 check_diff ${DIR}/$tdir $TGT/$tdir
573 run_test 8 "Replicate multiple file/directory moves"
580 touch $DIR/$tdir/foo/a1
582 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
584 check_diff ${DIR}/$tdir $TGT/$tdir
586 rm -rf $DIR/$tdir/foo
588 $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
590 check_diff ${DIR}/$tdir $TGT/$tdir
596 run_test 9 "Replicate recursive directory removal"
599 complete $(basename $0) $SECONDS
600 check_and_cleanup_lustre