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