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