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