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