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