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