Whamcloud - gitweb
LU-1303 mds: integration lod/osp into the stack
[fs/lustre-release.git] / lustre / tests / lustre-rsync-test.sh
index 576bc4c..b07d1e7 100644 (file)
@@ -1,4 +1,6 @@
 #!/bin/bash
+# -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
+# vim:shiftwidth=4:softtabstop=4:tabstop=4:
 #
 # Run select tests by setting ONLY, or as arguments to the script.
 # Skip specific tests by setting EXCEPT.
@@ -10,13 +12,17 @@ SRCDIR=`dirname $0`
 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
 
 ONLY=${ONLY:-"$*"}
-ALWAYS_EXCEPT="$LRSYNC_EXCEPT 5a 5b"
-# bug number for skipped test: -  20878
+[ -n "$ONLY" ] && SLOW=yes
+ALWAYS_EXCEPT="$LRSYNC_EXCEPT"
+# bug number for skipped test:
 # UPDATE THE COMMENT ABOVE WITH BUG NUMBERS WHEN CHANGING ALWAYS_EXCEPT!
 
 [ "$ALWAYS_EXCEPT$EXCEPT" ] && \
         echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
 
+# disable till changelogs from orion landed (LU-2034)
+ALWAYS_EXCEPT="1 2 3 4 5 6 7 8 9"
+
 KILL=/bin/kill
 
 TMP=${TMP:-/tmp}
@@ -29,10 +35,6 @@ init_test_env $@
 . ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
 init_logging
 
-REPLLOG=${TESTSUITELOG:-$TMP/$(basename $0 .sh).log}
-
-[ "$REPLLOG" ] && rm -f $REPLLOG || true
-
 check_and_setup_lustre
 
 DIR=${DIR:-$MOUNT}
@@ -43,12 +45,12 @@ build_test_filter
 
 export LRSYNC=${LRSYNC:-"$LUSTRE/utils/lustre_rsync"}
 [ ! -f "$LRSYNC" ] && export LRSYNC=$(which lustre_rsync)
-export LRSYNC="$LRSYNC -v" # -a
+export LRSYNC="$LRSYNC -v -c no" # -a
 
 # control the time of tests
 DBENCH_TIME=${DBENCH_TIME:-60}  # No of seconds to run dbench
-TGT=/tmp/target
-TGT2=/tmp/target2
+TGT=$TMP/target
+TGT2=$TMP/target2
 MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
     awk '{gsub(/_UUID/,""); print $1}' | head -1)
 
@@ -66,8 +68,9 @@ init_src() {
     rm -rf $TGT2/$tdir $TGT2/d*.lustre_rsync-test 2> /dev/null
     rm -rf ${DIR}/$tdir $DIR/d*.lustre_rsync-test ${DIR}/tgt 2> /dev/null
     rm -f $LREPL_LOG
-    mkdir -p $TGT
-    mkdir -p $TGT2
+    mkdir -p ${DIR}/$tdir
+    mkdir -p ${TGT}/$tdir
+    mkdir -p ${TGT2}/$tdir
     if [ $? -ne 0 ]; then
         error "Failed to create target: " $TGT
     fi
@@ -84,36 +87,49 @@ fini_changelog() {
     do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $CL_USER
 }
 
+# Check whether the filesystem supports xattr or not.
+# Return value:
+# "large" - large xattr is supported
+# "small" - large xattr is unsupported but small xattr is supported
+# "no"    - xattr is unsupported
 check_xattr() {
     local tgt=$1
-    local xattr="yes"
+    local xattr="no"
+
     touch $tgt
-    setfattr -n user.foo -v 'bar' $tgt 2> /dev/null
-    if [ $? -ne 0 ]; then
-       xattr="no"
+
+    local val="$(generate_string $(max_xattr_size))"
+    if large_xattr_enabled &&
+       setfattr -n user.foo -v $val $tgt 2>/dev/null; then
+            xattr="large"
+    else
+        setfattr -n user.foo -v bar $tgt 2>/dev/null && xattr="small"
     fi
+
     rm -f $tgt
     echo $xattr
 }
 
 check_diff() {
-    if [ -e $1 -o -e $2 ]; then 
-        diff -rq -x "dev1" $1 $2
-        local RC=$?
-        if [ $RC -ne 0 ]; then
-            error "Failure in replication; differences found."
-        fi
-    fi
+       local changelog_file=$LOGDIR/${TESTSUITE}.test_${3}.changelog
+
+       if [ -e $1 -o -e $2 ]; then
+               diff -rq -x "dev1" $1 $2
+               local RC=$?
+               if [ $RC -ne 0 ]; then
+                       $LFS changelog $MDT0 > $changelog_file
+                       error "Failure in replication; differences found."
+               fi
+       fi
 }
 
 # Test 1 - test basic operations
 test_1() {
     init_src
     init_changelog
-    local xattr=`check_xattr $TGT/foo`
+    local xattr=$(check_xattr $TGT/foo)
 
     # Directory create
-    mkdir -p ${DIR}/$tdir
     mkdir $DIR/$tdir/d1
     mkdir $DIR/$tdir/d2
 
@@ -151,38 +167,39 @@ test_1() {
     chown nobody:nobody $DIR/$tdir/d2/file3
 
     # Set xattrs
-    if [ "$xattr" == "yes" ]; then
-       touch $DIR/$tdir/file5
-       setfattr -n user.foo -v 'bar' $DIR/$tdir/file5
+    if [[ "$xattr" != "no" ]]; then
+        local value
+        touch $DIR/$tdir/file5
+        [[ "$xattr" = "large" ]] &&
+            value="$(generate_string $(max_xattr_size))" || value="bar"
+        setfattr -n user.foo -v $value $DIR/$tdir/file5
     fi
 
     echo "Replication #2"
     $LRSYNC -l $LREPL_LOG
 
-    if [ "$xattr" == "yes" ]; then
-       local xval1=$(getfattr -n user.foo --absolute-names --only-values \
-           $TGT/$tdir/file5)
-       local xval2=$(getfattr -n user.foo --absolute-names --only-values \
-           $TGT2/$tdir/file5)
+    if [[ "$xattr" != "no" ]]; then
+        local xval1=$(get_xattr_value user.foo $TGT/$tdir/file5)
+        local xval2=$(get_xattr_value user.foo $TGT2/$tdir/file5)
     fi
 
     RC=0
 
     # fid2path and path2fid aren't implemented for block devices
     #if [[ ! -b $TGT/$tdir/dev1 ]] || [[ ! -b $TGT2/$tdir/dev1 ]]; then
-    #  ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
+    #   ls -l $DIR/$tdir/dev1 $TGT/$tdir/dev1 $TGT2/$tdir/dev1
     #   error "Error replicating block devices"
     #   RC=1
 
-    if [[ "$xattr" == "yes" ]] &&
-       [[ "$xval1" != "bar" || "$xval2" != "bar" ]]; then
-        error "Error in replicating xattrs. $xval1, $xval2"
+    if [[ "$xattr" != "no" ]] &&
+       [[ "$xval1" != "$value" || "$xval2" != "$value" ]]; then
+        error "Error in replicating xattrs."
         RC=1
     fi
 
     # Use diff to compare the source and the destination
-    check_diff $DIR/$tdir $TGT/$tdir
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 1
+    check_diff $DIR/$tdir $TGT2/$tdir 1
 
     fini_changelog
     cleanup_src_tgt
@@ -203,8 +220,8 @@ test_2a() {
     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
 
     # Use diff to compare the source and the destination
-    check_diff $DIR/$tdir $TGT/$tdir
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 2a
+    check_diff $DIR/$tdir $TGT2/$tdir 2a
 
     fini_changelog
     cleanup_src_tgt
@@ -231,7 +248,7 @@ test_2b() {
 
     echo Starting replication
     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
-    check_diff $DIR/$tdir $TGT/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 2b
 
     echo Resuming dbench
     $KILL -SIGCONT $child_pid
@@ -242,7 +259,7 @@ test_2b() {
 
     echo Starting replication
     $LRSYNC -l $LREPL_LOG
-    check_diff $DIR/$tdir $TGT/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 2b
 
     echo "Wait for dbench to finish"
     $KILL -SIGCONT $child_pid
@@ -252,8 +269,8 @@ test_2b() {
     echo Starting replication
     $LRSYNC -l $LREPL_LOG
 
-    check_diff $DIR/$tdir $TGT/$tdir
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 2b
+    check_diff $DIR/$tdir $TGT2/$tdir 2b
 
     fini_changelog
     cleanup_src_tgt
@@ -285,8 +302,8 @@ test_2c() {
     done
 
     # Use diff to compare the source and the destination
-    check_diff $DIR/$tdir $TGT/$tdir
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 2c
+    check_diff $DIR/$tdir $TGT2/$tdir 2c
 
     fini_changelog
     cleanup_src_tgt
@@ -302,13 +319,12 @@ test_3a() {
     init_changelog
 
     local numfiles=1000
-    mkdir -p ${DIR}/$tdir
     createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
 
     # Replicate the changes to $TGT
     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
-    check_diff $DIR/$tdir $TGT/$tdir   
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 3a
+    check_diff $DIR/$tdir $TGT2/$tdir 3a
 
     fini_changelog
     cleanup_src_tgt
@@ -326,14 +342,13 @@ test_3b() {
 
     local time=60
     local threads=5
-    mkdir -p ${DIR}/$tdir
     writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
 
     # Replicate the changes to $TGT
     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
 
-    check_diff $DIR/$tdir $TGT/$tdir   
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 3b
+    check_diff $DIR/$tdir $TGT2/$tdir 3b
 
     fini_changelog
     cleanup_src_tgt
@@ -349,14 +364,13 @@ test_3c() {
     init_changelog
 
     local numfiles=1000
-    mkdir -p ${DIR}/$tdir
     createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
     unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
 
     # Replicate the changes to $TGT
     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0  -u $CL_USER -l $LREPL_LOG
-    check_diff $DIR/$tdir $TGT/$tdir   
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 3c
+    check_diff $DIR/$tdir $TGT2/$tdir 3c
 
     fini_changelog
     cleanup_src_tgt
@@ -377,7 +391,6 @@ test_4() {
     init_src
     init_changelog
 
-    mkdir -p ${DIR}/$tdir
     END_RUN_FILE=${DIR}/$tdir/run LOAD_PID_FILE=${DIR}/$tdir/pid \
         MOUNT=${DIR}/$tdir run_iozone.sh &
     sleep 30
@@ -386,8 +399,8 @@ test_4() {
 
     # Replicate the changes to $TGT
     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0  -u $CL_USER -l $LREPL_LOG
-    check_diff $DIR/$tdir $TGT/$tdir
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 4
+    check_diff $DIR/$tdir $TGT2/$tdir 4
 
     $KILL -SIGCONT $child_pid
     sleep 60
@@ -407,8 +420,8 @@ test_4() {
     done
 
     $LRSYNC -l $LREPL_LOG
-    check_diff $DIR/$tdir $TGT/$tdir
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 4
+    check_diff $DIR/$tdir $TGT2/$tdir 4
 
     fini_changelog
     cleanup_src_tgt
@@ -424,7 +437,6 @@ test_5a() {
     init_changelog
 
     NUMTEST=2000
-    mkdir -p ${DIR}/$tdir
     createmany -o $DIR/$tdir/$tfile $NUMTEST
 
     # Replicate the changes to $TGT
@@ -436,8 +448,8 @@ test_5a() {
     wait
     $LRSYNC -l $LREPL_LOG
 
-    check_diff $DIR/$tdir $TGT/$tdir   
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 5a
+    check_diff $DIR/$tdir $TGT2/$tdir 5a
 
     fini_changelog
     cleanup_src_tgt
@@ -453,7 +465,6 @@ test_5b() {
     init_changelog
 
     NUMTEST=2000
-    mkdir -p ${DIR}/$tdir
     createmany -o $DIR/$tdir/$tfile $NUMTEST
 
     # Replicate the changes to $TGT
@@ -465,8 +476,8 @@ test_5b() {
     wait
     $LRSYNC -l $LREPL_LOG
 
-    check_diff $DIR/$tdir $TGT/$tdir   
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 5b
+    check_diff $DIR/$tdir $TGT2/$tdir 5b
 
     fini_changelog
     cleanup_src_tgt
@@ -480,7 +491,6 @@ test_6() {
     init_changelog
 
     local NUMLINKS=128
-    mkdir -p ${DIR}/$tdir
     touch $DIR/$tdir/link0
     local i=1
     while [ $i -lt $NUMLINKS ];
@@ -491,8 +501,8 @@ test_6() {
 
     # Replicate the changes to $TGT
     $LRSYNC -s $DIR -t $TGT -t $TGT2 -m $MDT0 -u $CL_USER -l $LREPL_LOG
-    check_diff $DIR/$tdir $TGT/$tdir
-    check_diff $DIR/$tdir $TGT2/$tdir
+    check_diff $DIR/$tdir $TGT/$tdir 6
+    check_diff $DIR/$tdir $TGT2/$tdir 6
 
     local count1=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
     local count2=$(ls -l $TGT/$tdir/link0 | sed -r 's/ +/ /g' | cut -f 2 -d ' ')
@@ -509,27 +519,26 @@ run_test 6 "lustre_rsync large no of hard links"
 # Test 7 - lustre_rsync stripesize
 test_7() {
     init_src
+    mkdir -p ${DIR}/tgt/$tdir
     init_changelog
 
     local NUMFILES=100
-    mkdir -p ${DIR}/$tdir
-    lfs setstripe -c 2 ${DIR}/$tdir
+    lfs setstripe -c $OSTCOUNT $DIR/$tdir
     createmany -o $DIR/$tdir/$tfile $NUMFILES
 
     # To simulate replication to another lustre filesystem, replicate
     # the changes to $DIR/tgt. We can't turn off the changelogs
     # while we are registered, so lustre_rsync better not try to 
     # replicate the replication steps.  It seems ok :)
-    mkdir $DIR/tgt
 
     $LRSYNC -s $DIR -t $DIR/tgt -m $MDT0 -u $CL_USER -l $LREPL_LOG
-    check_diff ${DIR}/$tdir $DIR/tgt/$tdir
+    check_diff ${DIR}/$tdir $DIR/tgt/$tdir 7
 
     local i=0
     while [ $i -lt $NUMFILES ];
     do
       local count=$(lfs getstripe $DIR/tgt/$tdir/${tfile}$i | awk '/stripe_count/ {print $2}')
-      if [ $count -ne 2 ]; then
+      if [ $count -ne $OSTCOUNT ]; then
          error "Stripe size not replicated" 
       fi
       i=$(expr $i + 1)
@@ -545,8 +554,6 @@ test_8() {
     init_src
     init_changelog
 
-    mkdir -p ${DIR}/$tdir
-
     for i in 1 2 3 4 5 6 7 8 9; do
        mkdir $DIR/$tdir/d$i
            for j in 1 2 3 4 5 6 7 8 9; do
@@ -563,7 +570,7 @@ test_8() {
 
     $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
 
-    check_diff ${DIR}/$tdir $TGT/$tdir
+    check_diff ${DIR}/$tdir $TGT/$tdir 8
 
     fini_changelog
     cleanup_src_tgt
@@ -571,9 +578,30 @@ test_8() {
 }
 run_test 8 "Replicate multiple file/directory moves"
 
-log "cleanup: ======================================================"
+test_9() {
+    init_src
+    init_changelog
+
+    mkdir $DIR/$tdir/foo
+    touch $DIR/$tdir/foo/a1
+
+    $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
+
+    check_diff ${DIR}/$tdir $TGT/$tdir 9
+
+    rm -rf $DIR/$tdir/foo
+
+    $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG
+
+    check_diff ${DIR}/$tdir $TGT/$tdir 9
+
+    fini_changelog
+    cleanup_src_tgt
+    return 0
+}
+run_test 9 "Replicate recursive directory removal"
+
 cd $ORIG_PWD
+complete $(basename $0) $SECONDS
 check_and_cleanup_lustre
-echo '=========================== finished ==============================='
-[ -f "$REPLLOG" ] && cat $REPLLOG && grep -q FAIL $REPLLOG && exit 1 || true
-echo "$0: completed"
+exit_status