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