Whamcloud - gitweb
b=21370 Double qos maxage timeout
[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 $TGT
70     mkdir -p $TGT2
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_xattr() {
88     local tgt=$1
89     local xattr="yes"
90     touch $tgt
91     setfattr -n user.foo -v 'bar' $tgt 2> /dev/null
92     if [ $? -ne 0 ]; then
93         xattr="no"
94     fi
95     rm -f $tgt
96     echo $xattr
97 }
98
99 check_diff() {
100     if [ -e $1 -o -e $2 ]; then 
101         diff -rq -x "dev1" $1 $2
102         local RC=$?
103         if [ $RC -ne 0 ]; then
104             error "Failure in replication; differences found."
105         fi
106     fi
107 }
108
109 # Test 1 - test basic operations
110 test_1() {
111     init_src
112     init_changelog
113     local xattr=`check_xattr $TGT/foo`
114
115     # Directory create
116     mkdir -p ${DIR}/$tdir
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     mkdir -p ${DIR}/$tdir
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     mkdir -p ${DIR}/$tdir
330     writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
331
332     # Replicate the changes to $TGT
333     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
334
335     check_diff $DIR/$tdir $TGT/$tdir   
336     check_diff $DIR/$tdir $TGT2/$tdir
337
338     fini_changelog
339     cleanup_src_tgt
340     return 0
341 }
342 run_test 3b "Replicate files created by writemany"
343
344 # Test 3c - Replicate files created by createmany/unlinkmany
345 test_3c() {
346     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
347
348     init_src
349     init_changelog
350
351     local numfiles=1000
352     mkdir -p ${DIR}/$tdir
353     createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
354     unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
355
356     # Replicate the changes to $TGT
357     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0  -u $CL_USER -l $LREPL_LOG
358     check_diff $DIR/$tdir $TGT/$tdir   
359     check_diff $DIR/$tdir $TGT2/$tdir
360
361     fini_changelog
362     cleanup_src_tgt
363     return 0
364 }
365 run_test 3c "Replicate files created by createmany/unlinkmany"
366
367 # Test 4 - Replicate files created by iozone
368 test_4() {
369     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
370
371     which iozone > /dev/null 2>&1
372     if [ $? -ne 0 ]; then
373         skip "iozone not found. Skipping test"
374         return
375     fi
376
377     init_src
378     init_changelog
379
380     mkdir -p ${DIR}/$tdir
381     END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
382         MOUNT=${DIR}/$tdir run_iozone.sh &
383     sleep 30
384     child_pid=$(pgrep iozone)
385     $KILL -SIGSTOP $child_pid
386
387     # Replicate the changes to $TGT
388     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0  -u $CL_USER -l $LREPL_LOG
389     check_diff $DIR/$tdir $TGT/$tdir
390     check_diff $DIR/$tdir $TGT2/$tdir
391
392     $KILL -SIGCONT $child_pid
393     sleep 60
394     $KILL -SIGKILL $(pgrep run_iozone.sh)
395     $KILL -SIGKILL $(pgrep iozone)
396
397     # After killing 'run_iozone.sh', process 'iozone' becomes the
398     # child of PID 1. Hence 'wait' does not wait for it. Killing
399     # iozone first, means more iozone processes are spawned off which
400     # is not desirable. So, after sending a sigkill, the test goes
401     # into a wait loop for iozone to cleanup and exit.
402     wait
403     while [ "$(pgrep "iozone")" != "" ];
404     do
405       ps -ef | grep iozone | grep -v grep
406       sleep 1;
407     done
408
409     $LRSYNC -l $LREPL_LOG
410     check_diff $DIR/$tdir $TGT/$tdir
411     check_diff $DIR/$tdir $TGT2/$tdir
412
413     fini_changelog
414     cleanup_src_tgt
415     return 0
416 }
417 run_test 4 "Replicate files created by iozone"
418
419 # Test 5a - Stop / start lustre_rsync
420 test_5a() {
421     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
422
423     init_src
424     init_changelog
425
426     NUMTEST=2000
427     mkdir -p ${DIR}/$tdir
428     createmany -o $DIR/$tdir/$tfile $NUMTEST
429
430     # Replicate the changes to $TGT
431     
432     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
433     local child_pid=$!
434     sleep 30
435     $KILL -SIGHUP $child_pid
436     wait
437     $LRSYNC -l $LREPL_LOG
438
439     check_diff $DIR/$tdir $TGT/$tdir   
440     check_diff $DIR/$tdir $TGT2/$tdir
441
442     fini_changelog
443     cleanup_src_tgt
444     return 0
445 }
446 run_test 5a "Stop / start lustre_rsync"
447
448 # Test 5b - Kill / restart lustre_rsync
449 test_5b() {
450     [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
451
452     init_src
453     init_changelog
454
455     NUMTEST=2000
456     mkdir -p ${DIR}/$tdir
457     createmany -o $DIR/$tdir/$tfile $NUMTEST
458
459     # Replicate the changes to $TGT
460     
461     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG &
462     local child_pid=$!
463     sleep 30
464     $KILL -SIGKILL $child_pid
465     wait
466     $LRSYNC -l $LREPL_LOG
467
468     check_diff $DIR/$tdir $TGT/$tdir   
469     check_diff $DIR/$tdir $TGT2/$tdir
470
471     fini_changelog
472     cleanup_src_tgt
473     return 0
474 }
475 run_test 5b "Kill / restart lustre_rsync"
476
477 # Test 6 - lustre_rsync large no of hard links
478 test_6() {
479     init_src
480     init_changelog
481
482     local NUMLINKS=128
483     mkdir -p ${DIR}/$tdir
484     touch $DIR/$tdir/link0
485     local i=1
486     while [ $i -lt $NUMLINKS ];
487     do
488       ln $DIR/$tdir/link0  $DIR/$tdir/link${i}
489       i=$(expr $i + 1)
490     done
491
492     # Replicate the changes to $TGT
493     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
494     check_diff $DIR/$tdir $TGT/$tdir
495     check_diff $DIR/$tdir $TGT2/$tdir
496
497     local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
498     local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
499     if [[ $count1 -ne $NUMLINKS ]] ||  [[ $count2 -ne $NUMLINKS ]]; then
500         ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
501         error "Incorrect no of hard links found $count1, $count2"
502     fi
503     fini_changelog
504     cleanup_src_tgt
505     return 0
506 }
507 run_test 6 "lustre_rsync large no of hard links"
508
509 # Test 7 - lustre_rsync stripesize
510 test_7() {
511     init_src
512     init_changelog
513
514     local NUMFILES=100
515     mkdir -p ${DIR}/$tdir
516     lfs setstripe -c 2 ${DIR}/$tdir
517     createmany -o $DIR/$tdir/$tfile $NUMFILES
518
519     # To simulate replication to another lustre filesystem, replicate
520     # the changes to $DIR/tgt. We can't turn off the changelogs
521     # while we are registered, so lustre_rsync better not try to 
522     # replicate the replication steps.  It seems ok :)
523     mkdir $DIR/tgt
524
525     $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG
526     check_diff ${DIR}/$tdir $DIR/tgt/$tdir
527
528     local i=0
529     while [ $i -lt $NUMFILES ];
530     do
531       local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | awk '/stripe_count/ {print $2}')
532       if [ $count -ne 2 ]; then
533           error "Stripe size not replicated" 
534       fi
535       i=$(expr $i + 1)
536     done
537     fini_changelog
538     cleanup_src_tgt
539     return 0
540 }
541 run_test 7 "lustre_rsync stripesize"
542
543 # Test 8 - Replicate multiple file/directory moves
544 test_8() {
545     init_src
546     init_changelog
547
548     mkdir -p ${DIR}/$tdir
549
550     for i in 1 2 3 4 5 6 7 8 9; do
551         mkdir $DIR/$tdir/d$i
552             for j in 1 2 3 4 5 6 7 8 9; do
553                 mkdir $DIR/$tdir/d$i/d$i$j
554                 createmany -o $DIR/$tdir/d$i/d$i$j/a 10 \
555                     > /dev/null
556                 mv $DIR/$tdir/d$i/d$i$j $DIR/$tdir/d$i/d0$i$j
557                 createmany -o $DIR/$tdir/d$i/d0$i$j/b 10 \
558                     > /dev/null
559                 mv $DIR/$tdir/d$i/d0$i$j/a0 $DIR/$tdir/d$i/d0$i$j/c0
560             done
561             mv $DIR/$tdir/d$i $DIR/$tdir/d0$i
562     done
563
564     $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
565
566     check_diff ${DIR}/$tdir $TGT/$tdir
567
568     fini_changelog
569     cleanup_src_tgt
570     return 0
571 }
572 run_test 8 "Replicate multiple file/directory moves"
573
574 log "cleanup: ======================================================"
575 cd $ORIG_PWD
576 check_and_cleanup_lustre
577 echo '=========================== finished ==============================='
578 [ -f "$REPLLOG" ] && cat $REPLLOG && grep -q FAIL $REPLLOG && exit 1 || true
579 echo "$0: completed"