Whamcloud - gitweb
LU-2012 tests: disable replay-dual test_14b
[fs/lustre-release.git] / lustre / tests / lustre-rsync-test.sh
1 #!/bin/bash
2 # -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
3 # vim:shiftwidth=4:softtabstop=4:tabstop=4:
4 #
5 # Run select tests by setting ONLY, or as arguments to the script.
6 # Skip specific tests by setting EXCEPT.
7 #
8 # Run test by setting NOSETUP=true when ltest has setup env for us
9 set -e
10
11 SRCDIR=`dirname $0`
12 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
13
14 ONLY=${ONLY:-"$*"}
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!
19
20 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
21         echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
22
23 KILL=/bin/kill
24
25 TMP=${TMP:-/tmp}
26 LREPL_LOG=$TMP/lustre_rsync.log
27 ORIG_PWD=${PWD}
28
29 LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
30 . $LUSTRE/tests/test-framework.sh
31 init_test_env $@
32 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
33 init_logging
34
35 check_and_setup_lustre
36
37 DIR=${DIR:-$MOUNT}
38 assert_DIR
39
40
41 build_test_filter
42
43 export LRSYNC=${LRSYNC:-"$LUSTRE/utils/lustre_rsync"}
44 [ ! -f "$LRSYNC" ] && export LRSYNC=$(which lustre_rsync)
45 export LRSYNC="$LRSYNC -v -c no -d 2"
46
47 # control the time of tests
48 DBENCH_TIME=${DBENCH_TIME:-60}  # No of seconds to run dbench
49 TGT=$TMP/target
50 TGT2=$TMP/target2
51 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
52     awk '{gsub(/_UUID/,""); print $1}' | head -1)
53
54 init_changelog() {
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)"
61 }
62
63 init_src() {
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
67     rm -f $LREPL_LOG
68     mkdir -p ${DIR}/$tdir
69     mkdir -p ${TGT}/$tdir
70     mkdir -p ${TGT2}/$tdir
71     if [ $? -ne 0 ]; then
72         error "Failed to create target: " $TGT
73     fi
74 }
75
76 cleanup_src_tgt() {
77     rm -rf $TGT/$tdir
78     rm -rf $DIR/$tdir
79     rm -rf $DIR/tgt
80 }
81
82 fini_changelog() {
83     $LFS changelog_clear $MDT0 $CL_USER 0
84     do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
85 }
86
87 # Check whether the filesystem supports xattr or not.
88 # Return value:
89 # "large" - large xattr is supported
90 # "small" - large xattr is unsupported but small xattr is supported
91 # "no"    - xattr is unsupported
92 check_xattr() {
93     local tgt=$1
94     local xattr="no"
95
96     touch $tgt
97
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
101             xattr="large"
102     else
103         setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
104     fi
105
106     rm -f $tgt
107     echo $xattr
108 }
109
110 check_diff() {
111         local changelog_file=$(generate_logname "changelog")
112
113         if [ -e $1 -o -e $2 ]; then
114                 diff -rq -x "dev1" $1 $2
115                 local RC=$?
116                 if [ $RC -ne 0 ]; then
117                         $LFS changelog $MDT0 > $changelog_file
118                         error "Failure in replication; differences found."
119                 fi
120         fi
121 }
122
123 # Test 1 - test basic operations
124 test_1() {
125     init_src
126     init_changelog
127     local xattr=$(check_xattr $TGT/foo)
128
129     # Directory create
130     mkdir $DIR/$tdir/d1
131     mkdir $DIR/$tdir/d2
132
133     # File create
134     touch $DIR/$tdir/file1
135     cp /etc/hosts  $DIR/$tdir/d1/
136     touch  $DIR/$tdir/d1/"space in filename"
137     touch  $DIR/$tdir/d1/file2
138
139     # File rename
140     mv $DIR/$tdir/d1/file2 $DIR/$tdir/d2/file3
141
142     # File and directory delete
143     touch $DIR/$tdir/d1/file4
144     mkdir $DIR/$tdir/d1/del
145     touch  $DIR/$tdir/d1/del/del1
146     touch  $DIR/$tdir/d1/del/del2
147     rm -rf $DIR/$tdir/d1/del
148     rm $DIR/$tdir/d1/file4
149
150     #hard and soft links
151     cat /etc/hosts > $DIR/$tdir/d1/link1
152     ln  $DIR/$tdir/d1/link1  $DIR/$tdir/d1/link2
153     ln -s $DIR/$tdir/d1/link1  $DIR/$tdir/d1/link3
154
155     # Device files
156     #mknod $DIR/$tdir/dev1 b 8 1
157
158         # Replicate
159         local LRSYNC_LOG=$(generate_logname "lrsync_log")
160         echo "Replication #1"
161         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
162                 -D $LRSYNC_LOG
163
164     # Set attributes
165     chmod 000 $DIR/$tdir/d2/file3
166     chown nobody:nobody $DIR/$tdir/d2/file3
167
168     # Set xattrs
169     if [[ "$xattr" != "no" ]]; then
170         local value
171         touch $DIR/$tdir/file5
172         [[ "$xattr" = "large" ]] &&
173             value="$(generate_string $(max_xattr_size))" || value="bar"
174         setfattr -n user.foo -v $value $DIR/$tdir/file5
175     fi
176
177         echo "Replication #2"
178         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
179
180     if [[ "$xattr" != "no" ]]; then
181         local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
182         local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
183     fi
184
185     RC=0
186
187     # fid2path and path2fid aren't implemented for block devices
188     #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
189     #   ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
190     #   error "Error replicating block devices"
191     #   RC=1
192
193     if [[ "$xattr" != "no" ]] &&
194        [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
195         error "Error in replicating xattrs."
196         RC=1
197     fi
198
199         # Use diff to compare the source and the destination
200         check_diff $DIR/$tdir $TGT/$tdir
201         check_diff $DIR/$tdir $TGT2/$tdir
202
203     fini_changelog
204     cleanup_src_tgt
205     return $RC
206 }
207 run_test 1 "Simple Replication"
208
209 # Test 2a - Replicate files created by dbench
210 test_2a() {
211     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
212     init_src
213     init_changelog
214
215     # Run dbench
216     sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed!"
217
218         local LRSYNC_LOG=$(generate_logname "lrsync_log")
219         # Replicate the changes to $TGT
220         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
221                 -D $LRSYNC_LOG
222
223         # Use diff to compare the source and the destination
224         check_diff $DIR/$tdir $TGT/$tdir
225         check_diff $DIR/$tdir $TGT2/$tdir
226
227     fini_changelog
228     cleanup_src_tgt
229     return 0
230 }
231 run_test 2a "Replicate files created by dbench."
232
233
234 # Test 2b - Replicate files changed by dbench.
235 test_2b() {
236     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
237
238     init_src
239     init_changelog
240
241     # Run dbench
242     sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
243     sleep 20
244
245     local child_pid=$(pgrep dbench)
246     echo PIDs: $child_pid
247     echo Stopping dbench
248     $KILL -SIGSTOP $child_pid
249
250         local LRSYNC_LOG=$(generate_logname "lrsync_log")
251         echo Starting replication
252         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
253                 -D $LRSYNC_LOG
254         check_diff $DIR/$tdir $TGT/$tdir
255
256     echo Resuming dbench
257     $KILL -SIGCONT $child_pid
258     sleep 10
259
260     echo Stopping dbench
261     $KILL -SIGSTOP $child_pid
262
263         echo Starting replication
264         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
265         check_diff $DIR/$tdir $TGT/$tdir
266
267     echo "Wait for dbench to finish"
268     $KILL -SIGCONT $child_pid
269     wait
270
271         # Replicate the changes to $TGT
272         echo Starting replication
273         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
274
275         check_diff $DIR/$tdir $TGT/$tdir
276         check_diff $DIR/$tdir $TGT2/$tdir
277
278     fini_changelog
279     cleanup_src_tgt
280     return 0
281 }
282 run_test 2b "Replicate files changed by dbench."
283
284 # Test 2c - Replicate files while dbench is running
285 test_2c() {
286     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
287     init_src
288     init_changelog
289
290     # Run dbench
291     sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
292
293         local LRSYNC_LOG=$(generate_logname "lrsync_log")
294         # Replicate the changes to $TGT
295         sleep 10 # give dbench a headstart
296         local quit=0
297         while [ $quit -le 1 ];
298         do
299                 echo "Running lustre_rsync"
300                 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
301                         -l $LREPL_LOG -D $LRSYNC_LOG
302                 sleep 5
303                 pgrep dbench
304                 if [ $? -ne 0 ]; then
305                         quit=$(expr $quit + 1)
306                 fi
307         done
308
309         # Use diff to compare the source and the destination
310         check_diff $DIR/$tdir $TGT/$tdir
311         check_diff $DIR/$tdir $TGT2/$tdir
312
313     fini_changelog
314     cleanup_src_tgt
315     return 0
316 }
317 run_test 2c "Replicate files while dbench is running."
318
319 # Test 3a - Replicate files created by createmany
320 test_3a() {
321     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
322
323     init_src
324     init_changelog
325
326     local numfiles=1000
327     createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
328
329         local LRSYNC_LOG=$(generate_logname "lrsync_log")
330         # Replicate the changes to $TGT
331         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
332                 -D $LRSYNC_LOG
333         check_diff $DIR/$tdir $TGT/$tdir
334         check_diff $DIR/$tdir $TGT2/$tdir
335
336     fini_changelog
337     cleanup_src_tgt
338     return 0
339 }
340 run_test 3a "Replicate files created by createmany"
341
342
343 # Test 3b - Replicate files created by writemany
344 test_3b() {
345     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
346
347     init_src
348     init_changelog
349
350     local time=60
351     local threads=5
352     writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
353
354         local LRSYNC_LOG=$(generate_logname "lrsync_log")
355         # Replicate the changes to $TGT
356         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
357                 -D $LRSYNC_LOG
358
359         check_diff $DIR/$tdir $TGT/$tdir
360         check_diff $DIR/$tdir $TGT2/$tdir
361
362     fini_changelog
363     cleanup_src_tgt
364     return 0
365 }
366 run_test 3b "Replicate files created by writemany"
367
368 # Test 3c - Replicate files created by createmany/unlinkmany
369 test_3c() {
370     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
371
372     init_src
373     init_changelog
374
375     local numfiles=1000
376     createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
377     unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
378
379         local LRSYNC_LOG=$(generate_logname "lrsync_log")
380         # Replicate the changes to $TGT
381         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0  -u $CL_USER -l $LREPL_LOG \
382                 -D $LRSYNC_LOG
383         check_diff $DIR/$tdir $TGT/$tdir
384         check_diff $DIR/$tdir $TGT2/$tdir
385
386     fini_changelog
387     cleanup_src_tgt
388     return 0
389 }
390 run_test 3c "Replicate files created by createmany/unlinkmany"
391
392 # Test 4 - Replicate files created by iozone
393 test_4() {
394     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
395
396     which iozone > /dev/null 2>&1
397     if [ $? -ne 0 ]; then
398         skip "iozone not found. Skipping test"
399         return
400     fi
401
402     init_src
403     init_changelog
404
405     END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
406         MOUNT=${DIR}/$tdir run_iozone.sh &
407     sleep 30
408     child_pid=$(pgrep iozone)
409     $KILL -SIGSTOP $child_pid
410
411         local LRSYNC_LOG=$(generate_logname "lrsync_log")
412         # Replicate the changes to $TGT
413         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0  -u $CL_USER -l $LREPL_LOG \
414                 -D $LRSYNC_LOG
415         check_diff $DIR/$tdir $TGT/$tdir
416         check_diff $DIR/$tdir $TGT2/$tdir
417
418     $KILL -SIGCONT $child_pid
419     sleep 60
420     $KILL -SIGKILL $(pgrep run_iozone.sh)
421     $KILL -SIGKILL $(pgrep iozone)
422
423     # After killing 'run_iozone.sh', process 'iozone' becomes the
424     # child of PID 1. Hence 'wait' does not wait for it. Killing
425     # iozone first, means more iozone processes are spawned off which
426     # is not desirable. So, after sending a sigkill, the test goes
427     # into a wait loop for iozone to cleanup and exit.
428     wait
429     while [ "$(pgrep "iozone")" != "" ];
430     do
431       ps -ef | grep iozone | grep -v grep
432       sleep 1;
433     done
434
435         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
436         check_diff $DIR/$tdir $TGT/$tdir
437         check_diff $DIR/$tdir $TGT2/$tdir
438
439     fini_changelog
440     cleanup_src_tgt
441     return 0
442 }
443 run_test 4 "Replicate files created by iozone"
444
445 # Test 5a - Stop / start lustre_rsync
446 test_5a() {
447     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
448
449     init_src
450     init_changelog
451
452     NUMTEST=2000
453     createmany -o $DIR/$tdir/$tfile $NUMTEST
454
455         # Replicate the changes to $TGT
456         local LRSYNC_LOG=$(generate_logname "lrsync_log")
457         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
458                 -D $LRSYNC_LOG &
459         local child_pid=$!
460         sleep 30
461         $KILL -SIGHUP $child_pid
462         wait
463         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
464
465         check_diff $DIR/$tdir $TGT/$tdir
466         check_diff $DIR/$tdir $TGT2/$tdir
467
468     fini_changelog
469     cleanup_src_tgt
470     return 0
471 }
472 run_test 5a "Stop / start lustre_rsync"
473
474 # Test 5b - Kill / restart lustre_rsync
475 test_5b() {
476     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
477
478     init_src
479     init_changelog
480
481     NUMTEST=2000
482     createmany -o $DIR/$tdir/$tfile $NUMTEST
483
484         # Replicate the changes to $TGT
485         local LRSYNC_LOG=$(generate_logname "lrsync_log")
486         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
487                 -D $LRSYNC_LOG &
488         local child_pid=$!
489         sleep 30
490         $KILL -SIGKILL $child_pid
491         wait
492         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
493
494         check_diff $DIR/$tdir $TGT/$tdir
495         check_diff $DIR/$tdir $TGT2/$tdir
496
497     fini_changelog
498     cleanup_src_tgt
499     return 0
500 }
501 run_test 5b "Kill / restart lustre_rsync"
502
503 # Test 6 - lustre_rsync large no of hard links
504 test_6() {
505     init_src
506     init_changelog
507
508     local NUMLINKS=128
509     touch $DIR/$tdir/link0
510     local i=1
511     while [ $i -lt $NUMLINKS ];
512     do
513       ln $DIR/$tdir/link0  $DIR/$tdir/link${i}
514       i=$(expr $i + 1)
515     done
516
517         local LRSYNC_LOG=$(generate_logname "lrsync_log")
518         # Replicate the changes to $TGT
519         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
520                 -D $LRSYNC_LOG
521         check_diff $DIR/$tdir $TGT/$tdir
522         check_diff $DIR/$tdir $TGT2/$tdir
523
524     local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
525     local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
526     if [[ $count1 -ne $NUMLINKS ]] ||  [[ $count2 -ne $NUMLINKS ]]; then
527         ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
528         error "Incorrect no of hard links found $count1, $count2"
529     fi
530     fini_changelog
531     cleanup_src_tgt
532     return 0
533 }
534 run_test 6 "lustre_rsync large no of hard links"
535
536 # Test 7 - lustre_rsync stripesize
537 test_7() {
538     init_src
539     mkdir -p ${DIR}/tgt/$tdir
540     init_changelog
541
542     local NUMFILES=100
543     lfs setstripe -c $OSTCOUNT $DIR/$tdir
544     createmany -o $DIR/$tdir/$tfile $NUMFILES
545
546         # To simulate replication to another lustre filesystem, replicate
547         # the changes to $DIR/tgt. We can't turn off the changelogs
548         # while we are registered, so lustre_rsync better not try to
549         # replicate the replication steps.  It seems ok :)
550
551         local LRSYNC_LOG=$(generate_logname "lrsync_log")
552         $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
553                 -D $LRSYNC_LOG
554         check_diff ${DIR}/$tdir $DIR/tgt/$tdir
555
556         local i=0
557         while [ $i -lt $NUMFILES ];
558         do
559                 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | \
560                               awk '/stripe_count/ {print $2}')
561                 if [ $count -ne $OSTCOUNT ]; then
562                         error "Stripe size not replicated"
563                 fi
564                 i=$(expr $i + 1)
565         done
566         fini_changelog
567         cleanup_src_tgt
568         return 0
569 }
570 run_test 7 "lustre_rsync stripesize"
571
572 # Test 8 - Replicate multiple file/directory moves
573 test_8() {
574     init_src
575     init_changelog
576
577     for i in 1 2 3 4 5 6 7 8 9; do
578         mkdir $DIR/$tdir/d$i
579             for j in 1 2 3 4 5 6 7 8 9; do
580                 mkdir $DIR/$tdir/d$i/d$i$j
581                 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
582                     > /dev/null
583                 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
584                 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
585                     > /dev/null
586                 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
587             done
588             mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
589     done
590
591         local LRSYNC_LOG=$(generate_logname "lrsync_log")
592         $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
593                 -D $LRSYNC_LOG
594
595         check_diff ${DIR}/$tdir $TGT/$tdir
596
597     fini_changelog
598     cleanup_src_tgt
599     return 0
600 }
601 run_test 8 "Replicate multiple file/directory moves"
602
603 test_9() {
604     init_src
605     init_changelog
606
607     mkdir $DIR/$tdir/foo
608     touch $DIR/$tdir/foo/a1
609
610         local LRSYNC_LOG=$(generate_logname "lrsync_log")
611         $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
612                 -D $LRSYNC_LOG
613
614         check_diff ${DIR}/$tdir $TGT/$tdir
615
616         rm -rf $DIR/$tdir/foo
617
618         $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
619                 -D $LRSYNC_LOG
620
621         check_diff ${DIR}/$tdir $TGT/$tdir
622
623     fini_changelog
624     cleanup_src_tgt
625     return 0
626 }
627 run_test 9 "Replicate recursive directory removal"
628
629 cd $ORIG_PWD
630 complete $SECONDS
631 check_and_cleanup_lustre
632 exit_status