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