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