Whamcloud - gitweb
416ced331ca89423588467c014aa65335605b620
[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         init_src
237         init_changelog
238
239         # Run dbench
240         sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
241         sleep 20
242
243         local child_pid=$(pgrep dbench)
244         echo PIDs: $child_pid
245         echo Stopping dbench
246         $KILL -SIGSTOP $child_pid
247
248         local LRSYNC_LOG=$(generate_logname "lrsync_log")
249         echo Starting replication
250         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
251                 -D $LRSYNC_LOG
252         check_diff $DIR/$tdir $TGT/$tdir
253
254     echo Resuming dbench
255     $KILL -SIGCONT $child_pid
256     sleep 10
257
258     echo Stopping dbench
259     $KILL -SIGSTOP $child_pid
260
261         echo Starting replication
262         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
263         check_diff $DIR/$tdir $TGT/$tdir
264
265     echo "Wait for dbench to finish"
266     $KILL -SIGCONT $child_pid
267     wait
268
269         # Replicate the changes to $TGT
270         echo Starting replication
271         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
272
273         check_diff $DIR/$tdir $TGT/$tdir
274         check_diff $DIR/$tdir $TGT2/$tdir
275
276     fini_changelog
277     cleanup_src_tgt
278     return 0
279 }
280 run_test 2b "Replicate files changed by dbench."
281
282 # Test 2c - Replicate files while dbench is running
283 test_2c() {
284         init_src
285         init_changelog
286
287         # Run dbench
288         sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
289
290         local LRSYNC_LOG=$(generate_logname "lrsync_log")
291         # Replicate the changes to $TGT
292         sleep 10 # give dbench a headstart
293         local quit=0
294         while [ $quit -le 1 ];
295         do
296                 echo "Running lustre_rsync"
297                 $LRSYNC -s $DIR -t $TGT -t $TGT2 -m ${mds1_svc} -u $CL_USER \
298                         -l $LREPL_LOG -D $LRSYNC_LOG
299                 sleep 5
300                 pgrep dbench
301                 if [ $? -ne 0 ]; then
302                         quit=$(expr $quit + 1)
303                 fi
304         done
305
306         # Use diff to compare the source and the destination
307         check_diff $DIR/$tdir $TGT/$tdir
308         check_diff $DIR/$tdir $TGT2/$tdir
309
310         fini_changelog
311         cleanup_src_tgt
312         return 0
313 }
314 run_test 2c "Replicate files while dbench is running."
315
316 # Test 3a - Replicate files created by createmany
317 test_3a() {
318         init_src
319         init_changelog
320
321         local numfiles=1000
322         createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
323
324         local LRSYNC_LOG=$(generate_logname "lrsync_log")
325         # Replicate the changes to $TGT
326         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
327                 -D $LRSYNC_LOG
328         check_diff $DIR/$tdir $TGT/$tdir
329         check_diff $DIR/$tdir $TGT2/$tdir
330
331         fini_changelog
332         cleanup_src_tgt
333         return 0
334 }
335 run_test 3a "Replicate files created by createmany"
336
337
338 # Test 3b - Replicate files created by writemany
339 test_3b() {
340         init_src
341         init_changelog
342
343         local time=60
344         local threads=5
345         writemany -q -a $DIR/$tdir/$tfile $time $threads ||
346                 error "writemany failed"
347
348         local LRSYNC_LOG=$(generate_logname "lrsync_log")
349         # Replicate the changes to $TGT
350         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
351                 -D $LRSYNC_LOG
352
353         check_diff $DIR/$tdir $TGT/$tdir
354         check_diff $DIR/$tdir $TGT2/$tdir
355
356         fini_changelog
357         cleanup_src_tgt
358         return 0
359 }
360 run_test 3b "Replicate files created by writemany"
361
362 # Test 3c - Replicate files created by createmany/unlinkmany
363 test_3c() {
364         init_src
365         init_changelog
366
367         local numfiles=1000
368         createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
369         unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
370
371         local LRSYNC_LOG=$(generate_logname "lrsync_log")
372         # Replicate the changes to $TGT
373         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0  -u $CL_USER -l $LREPL_LOG \
374                 -D $LRSYNC_LOG
375         check_diff $DIR/$tdir $TGT/$tdir
376         check_diff $DIR/$tdir $TGT2/$tdir
377
378         fini_changelog
379         cleanup_src_tgt
380         return 0
381 }
382 run_test 3c "Replicate files created by createmany/unlinkmany"
383
384 # Test 4 - Replicate files created by iozone
385 test_4() {
386     which iozone > /dev/null 2>&1
387     if [ $? -ne 0 ]; then
388         skip "iozone not found. Skipping test"
389         return
390     fi
391
392     init_src
393     init_changelog
394
395     END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
396         MOUNT=${DIR}/$tdir run_iozone.sh &
397     sleep 30
398     child_pid=$(pgrep iozone)
399     $KILL -SIGSTOP $child_pid
400
401         local LRSYNC_LOG=$(generate_logname "lrsync_log")
402         # Replicate the changes to $TGT
403         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0  -u $CL_USER -l $LREPL_LOG \
404                 -D $LRSYNC_LOG
405         check_diff $DIR/$tdir $TGT/$tdir
406         check_diff $DIR/$tdir $TGT2/$tdir
407
408     $KILL -SIGCONT $child_pid
409     sleep 60
410     $KILL -SIGKILL $(pgrep run_iozone.sh)
411     $KILL -SIGKILL $(pgrep iozone)
412
413     # After killing 'run_iozone.sh', process 'iozone' becomes the
414     # child of PID 1. Hence 'wait' does not wait for it. Killing
415     # iozone first, means more iozone processes are spawned off which
416     # is not desirable. So, after sending a sigkill, the test goes
417     # into a wait loop for iozone to cleanup and exit.
418     wait
419     while [ "$(pgrep "iozone")" != "" ];
420     do
421       ps -ef | grep iozone | grep -v grep
422       sleep 1;
423     done
424
425         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
426         check_diff $DIR/$tdir $TGT/$tdir
427         check_diff $DIR/$tdir $TGT2/$tdir
428
429     fini_changelog
430     cleanup_src_tgt
431     return 0
432 }
433 run_test 4 "Replicate files created by iozone"
434
435 # Test 5a - Stop / start lustre_rsync
436 test_5a() {
437         init_src
438         init_changelog
439
440         NUMTEST=2000
441         createmany -o $DIR/$tdir/$tfile $NUMTEST
442
443         # Replicate the changes to $TGT
444         local LRSYNC_LOG=$(generate_logname "lrsync_log")
445         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
446                 -D $LRSYNC_LOG &
447         local child_pid=$!
448         sleep 30
449         $KILL -SIGHUP $child_pid
450         wait
451         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
452
453         check_diff $DIR/$tdir $TGT/$tdir
454         check_diff $DIR/$tdir $TGT2/$tdir
455
456         fini_changelog
457         cleanup_src_tgt
458         return 0
459 }
460 run_test 5a "Stop / start lustre_rsync"
461
462 # Test 5b - Kill / restart lustre_rsync
463 test_5b() {
464         init_src
465         init_changelog
466
467         NUMTEST=2000
468         createmany -o $DIR/$tdir/$tfile $NUMTEST
469
470         # Replicate the changes to $TGT
471         local LRSYNC_LOG=$(generate_logname "lrsync_log")
472         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
473                 -D $LRSYNC_LOG &
474         local child_pid=$!
475         sleep 30
476         $KILL -SIGKILL $child_pid
477         wait
478         $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
479
480         check_diff $DIR/$tdir $TGT/$tdir
481         check_diff $DIR/$tdir $TGT2/$tdir
482
483         fini_changelog
484         cleanup_src_tgt
485         return 0
486 }
487 run_test 5b "Kill / restart lustre_rsync"
488
489 # Test 6 - lustre_rsync large no of hard links
490 test_6() {
491     init_src
492     init_changelog
493
494     local NUMLINKS=128
495     touch $DIR/$tdir/link0
496     local i=1
497     while [ $i -lt $NUMLINKS ];
498     do
499       ln $DIR/$tdir/link0  $DIR/$tdir/link${i}
500       i=$(expr $i + 1)
501     done
502
503         local LRSYNC_LOG=$(generate_logname "lrsync_log")
504         # Replicate the changes to $TGT
505         $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG \
506                 -D $LRSYNC_LOG
507         check_diff $DIR/$tdir $TGT/$tdir
508         check_diff $DIR/$tdir $TGT2/$tdir
509
510     local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
511     local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
512     if [[ $count1 -ne $NUMLINKS ]] ||  [[ $count2 -ne $NUMLINKS ]]; then
513         ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
514         error "Incorrect no of hard links found $count1, $count2"
515     fi
516     fini_changelog
517     cleanup_src_tgt
518     return 0
519 }
520 run_test 6 "lustre_rsync large no of hard links"
521
522 # Test 7 - lustre_rsync stripesize
523 test_7() {
524     init_src
525     mkdir -p ${DIR}/tgt/$tdir
526     init_changelog
527
528     local NUMFILES=100
529     lfs setstripe -c $OSTCOUNT $DIR/$tdir
530     createmany -o $DIR/$tdir/$tfile $NUMFILES
531
532         # To simulate replication to another lustre filesystem, replicate
533         # the changes to $DIR/tgt. We can't turn off the changelogs
534         # while we are registered, so lustre_rsync better not try to
535         # replicate the replication steps.  It seems ok :)
536
537         local LRSYNC_LOG=$(generate_logname "lrsync_log")
538         $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG \
539                 -D $LRSYNC_LOG
540         check_diff ${DIR}/$tdir $DIR/tgt/$tdir
541
542         local i=0
543         while [ $i -lt $NUMFILES ];
544         do
545                 local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | \
546                               awk '/stripe_count/ {print $2}')
547                 if [ $count -ne $OSTCOUNT ]; then
548                         error "Stripe size not replicated"
549                 fi
550                 i=$(expr $i + 1)
551         done
552         fini_changelog
553         cleanup_src_tgt
554         return 0
555 }
556 run_test 7 "lustre_rsync stripesize"
557
558 # Test 8 - Replicate multiple file/directory moves
559 test_8() {
560     init_src
561     init_changelog
562
563     for i in 1 2 3 4 5 6 7 8 9; do
564         mkdir $DIR/$tdir/d$i
565             for j in 1 2 3 4 5 6 7 8 9; do
566                 mkdir $DIR/$tdir/d$i/d$i$j
567                 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
568                     > /dev/null
569                 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
570                 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
571                     > /dev/null
572                 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
573             done
574             mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
575     done
576
577         local LRSYNC_LOG=$(generate_logname "lrsync_log")
578         $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
579                 -D $LRSYNC_LOG
580
581         check_diff ${DIR}/$tdir $TGT/$tdir
582
583     fini_changelog
584     cleanup_src_tgt
585     return 0
586 }
587 run_test 8 "Replicate multiple file/directory moves"
588
589 test_9() {
590     init_src
591     init_changelog
592
593     mkdir $DIR/$tdir/foo
594     touch $DIR/$tdir/foo/a1
595
596         local LRSYNC_LOG=$(generate_logname "lrsync_log")
597         $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
598                 -D $LRSYNC_LOG
599
600         check_diff ${DIR}/$tdir $TGT/$tdir
601
602         rm -rf $DIR/$tdir/foo
603
604         $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
605                 -D $LRSYNC_LOG
606
607         check_diff ${DIR}/$tdir $TGT/$tdir
608
609     fini_changelog
610     cleanup_src_tgt
611     return 0
612 }
613 run_test 9 "Replicate recursive directory removal"
614
615 cd $ORIG_PWD
616 complete $SECONDS
617 check_and_cleanup_lustre
618 exit_status