Whamcloud - gitweb
LU-7117 osp: set ptlrpc_request::rq_allow_replay properly
[fs/lustre-release.git] / lustre / tests / lustre-rsync-test.sh
index 49918ae..b3fe03d 100644 (file)
@@ -12,13 +12,14 @@ SRCDIR=`dirname $0`
 export PATH=$PWD/$SRCDIR:$SRCDIR:$PWD/$SRCDIR/../utils:$PATH:/sbin
 
 ONLY=${ONLY:-"$*"}
-[ -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`"
+[ "$SLOW" = "no" ] && EXCEPT_SLOW=""
+
+[ "$ALWAYS_EXCEPT$EXCEPT" ] &&
+       echo "Skipping tests: `echo $ALWAYS_EXCEPT $EXCEPT`"
 
 KILL=/bin/kill
 
@@ -48,8 +49,8 @@ export LRSYNC="$LRSYNC -v -c no -d 2"
 DBENCH_TIME=${DBENCH_TIME:-60}  # No of seconds to run dbench
 TGT=$TMP/target
 TGT2=$TMP/target2
-MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid | \
-    awk '{gsub(/_UUID/,""); print $1}' | head -1)
+MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
+       awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
 
 init_changelog() {
     CL_USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
@@ -120,6 +121,38 @@ check_diff() {
        fi
 }
 
+procs_are_stopped() {
+       local pids="$*"
+       local state
+
+       for state in $(ps -p "$pids" -o state=); do
+               if [[ "$state" != T ]]; then
+                       return 1
+               fi
+       done
+
+       return 0
+}
+
+# Send SIGSTOP to PIDs and wait up to 60 seconds for them to show a
+# stopped process state.
+stop_procs() {
+       local pids="$*"
+       local end
+
+       $KILL -SIGSTOP $pids
+       end=$((SECONDS + 60))
+       while ((SECONDS < end)); do
+               if procs_are_stopped $pids; then
+                       return 0
+               fi
+
+               sleep 1
+       done
+
+       return 1
+}
+
 # Test 1 - test basic operations
 test_1() {
     init_src
@@ -206,14 +239,58 @@ test_1() {
 }
 run_test 1 "Simple Replication"
 
+# Test 1a - test create/delete operations in ROOT directory
+test_1a() { # LU-5005
+       rm -rf $TGT/root-* 2> /dev/null
+       rm -rf $DIR/root-* 2> /dev/null
+       init_src
+       init_changelog
+
+       # Directory create
+       mkdir $DIR/root-dir
+
+       # File create
+       touch $DIR/root-file
+       touch $DIR/root-file2
+
+       # File rename
+       mv $DIR/root-file2 $DIR/root-file3
+
+       # File and directory delete
+       touch $DIR/root-file4
+       mkdir $DIR/root-dir1
+       rm $DIR/root-file4
+       rm -rf $DIR/root-dir1
+
+       # Replicate
+       local LRSYNC_LOG=$(generate_logname "lrsync_log")
+       echo "Replication"
+       $LRSYNC -s $DIR -t $TGT -m $MDT0 -u $CL_USER -l $LREPL_LOG \
+               -D $LRSYNC_LOG
+
+       # Verify
+       stat $TGT/root-dir || error "Dir create not replicated"
+       stat $TGT/root-file || error "File create not replicated"
+       stat $TGT/root-file2 && error "Rename not replicated (src)"
+       stat $TGT/root-file3 || error "Rename not replicated (tgt)"
+       stat $TGT/root-dir1 && error "Dir delete not replicated"
+       stat $TGT/root-file4 && error "File delete not replicated"
+
+       cleanup_src_tgt
+       fini_changelog
+       rm -fr $TGT/root-*
+       rm -fr $DIR/root-*
+       return 0
+}
+run_test 1a "Replicate create/delete operations in ROOT directory"
+
 # Test 2a - Replicate files created by dbench
 test_2a() {
-    [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
-    init_src
-    init_changelog
+       init_src
+       init_changelog
 
-    # Run dbench
-    sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed!"
+       # Run dbench
+       sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME || error "dbench failed"
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        # Replicate the changes to $TGT
@@ -224,28 +301,29 @@ test_2a() {
        check_diff $DIR/$tdir $TGT/$tdir
        check_diff $DIR/$tdir $TGT2/$tdir
 
-    fini_changelog
-    cleanup_src_tgt
-    return 0
+       fini_changelog
+       cleanup_src_tgt
+       return 0
 }
 run_test 2a "Replicate files created by dbench."
 
 
 # Test 2b - Replicate files changed by dbench.
 test_2b() {
-    [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
+       local child_pid
+       init_src
+       init_changelog
 
-    init_src
-    init_changelog
-
-    # Run dbench
-    sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
-    sleep 20
+       # Run dbench
+       sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
+       # wait for dbench to start
+       wait_for_function 'child_pid=$(pgrep dbench)' 360
+       # let dbench run for a bit
+       sleep 10
 
-    local child_pid=$(pgrep dbench)
-    echo PIDs: $child_pid
-    echo Stopping dbench
-    $KILL -SIGSTOP $child_pid
+       echo PIDs: $child_pid
+       echo Stopping dbench
+       stop_procs $child_pid
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        echo Starting replication
@@ -258,7 +336,7 @@ test_2b() {
     sleep 10
 
     echo Stopping dbench
-    $KILL -SIGSTOP $child_pid
+       stop_procs $child_pid
 
        echo Starting replication
        $LRSYNC -l $LREPL_LOG -D $LRSYNC_LOG
@@ -283,12 +361,11 @@ run_test 2b "Replicate files changed by dbench."
 
 # Test 2c - Replicate files while dbench is running
 test_2c() {
-    [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
-    init_src
-    init_changelog
+       init_src
+       init_changelog
 
-    # Run dbench
-    sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
+       # Run dbench
+       sh rundbench -C -D $DIR/$tdir 2 -t $DBENCH_TIME &
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        # Replicate the changes to $TGT
@@ -310,21 +387,19 @@ test_2c() {
        check_diff $DIR/$tdir $TGT/$tdir
        check_diff $DIR/$tdir $TGT2/$tdir
 
-    fini_changelog
-    cleanup_src_tgt
-    return 0
+       fini_changelog
+       cleanup_src_tgt
+       return 0
 }
 run_test 2c "Replicate files while dbench is running."
 
 # Test 3a - Replicate files created by createmany
 test_3a() {
-    [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
-
-    init_src
-    init_changelog
+       init_src
+       init_changelog
 
-    local numfiles=1000
-    createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
+       local numfiles=1000
+       createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        # Replicate the changes to $TGT
@@ -333,23 +408,22 @@ test_3a() {
        check_diff $DIR/$tdir $TGT/$tdir
        check_diff $DIR/$tdir $TGT2/$tdir
 
-    fini_changelog
-    cleanup_src_tgt
-    return 0
+       fini_changelog
+       cleanup_src_tgt
+       return 0
 }
 run_test 3a "Replicate files created by createmany"
 
 
 # Test 3b - Replicate files created by writemany
 test_3b() {
-    [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
+       init_src
+       init_changelog
 
-    init_src
-    init_changelog
-
-    local time=60
-    local threads=5
-    writemany -q -a $DIR/$tdir/$tfile $time $threads || error "writemany failed!"
+       local time=60
+       local threads=5
+       writemany -q -a $DIR/$tdir/$tfile $time $threads ||
+               error "writemany failed"
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        # Replicate the changes to $TGT
@@ -359,22 +433,20 @@ test_3b() {
        check_diff $DIR/$tdir $TGT/$tdir
        check_diff $DIR/$tdir $TGT2/$tdir
 
-    fini_changelog
-    cleanup_src_tgt
-    return 0
+       fini_changelog
+       cleanup_src_tgt
+       return 0
 }
 run_test 3b "Replicate files created by writemany"
 
 # Test 3c - Replicate files created by createmany/unlinkmany
 test_3c() {
-    [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
-
-    init_src
-    init_changelog
+       init_src
+       init_changelog
 
-    local numfiles=1000
-    createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed!"
-    unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed!"
+       local numfiles=1000
+       createmany -o $DIR/$tdir/$tfile $numfiles || error "createmany failed"
+       unlinkmany $DIR/$tdir/$tfile $numfiles || error "unlinkmany failed"
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        # Replicate the changes to $TGT
@@ -383,16 +455,14 @@ test_3c() {
        check_diff $DIR/$tdir $TGT/$tdir
        check_diff $DIR/$tdir $TGT2/$tdir
 
-    fini_changelog
-    cleanup_src_tgt
-    return 0
+       fini_changelog
+       cleanup_src_tgt
+       return 0
 }
 run_test 3c "Replicate files created by createmany/unlinkmany"
 
 # Test 4 - Replicate files created by iozone
 test_4() {
-    [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
-
     which iozone > /dev/null 2>&1
     if [ $? -ne 0 ]; then
        skip "iozone not found. Skipping test"
@@ -406,7 +476,7 @@ test_4() {
         MOUNT=${DIR}/$tdir run_iozone.sh &
     sleep 30
     child_pid=$(pgrep iozone)
-    $KILL -SIGSTOP $child_pid
+       stop_procs $child_pid
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        # Replicate the changes to $TGT
@@ -444,13 +514,11 @@ run_test 4 "Replicate files created by iozone"
 
 # Test 5a - Stop / start lustre_rsync
 test_5a() {
-    [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
-
-    init_src
-    init_changelog
+       init_src
+       init_changelog
 
-    NUMTEST=2000
-    createmany -o $DIR/$tdir/$tfile $NUMTEST
+       NUMTEST=2000
+       createmany -o $DIR/$tdir/$tfile $NUMTEST
 
        # Replicate the changes to $TGT
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
@@ -465,21 +533,19 @@ test_5a() {
        check_diff $DIR/$tdir $TGT/$tdir
        check_diff $DIR/$tdir $TGT2/$tdir
 
-    fini_changelog
-    cleanup_src_tgt
-    return 0
+       fini_changelog
+       cleanup_src_tgt
+       return 0
 }
 run_test 5a "Stop / start lustre_rsync"
 
 # Test 5b - Kill / restart lustre_rsync
 test_5b() {
-    [ "$SLOW" = "no" ] && skip "Skipping slow test" && return
+       init_src
+       init_changelog
 
-    init_src
-    init_changelog
-
-    NUMTEST=2000
-    createmany -o $DIR/$tdir/$tfile $NUMTEST
+       NUMTEST=2000
+       createmany -o $DIR/$tdir/$tfile $NUMTEST
 
        # Replicate the changes to $TGT
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
@@ -494,25 +560,26 @@ test_5b() {
        check_diff $DIR/$tdir $TGT/$tdir
        check_diff $DIR/$tdir $TGT2/$tdir
 
-    fini_changelog
-    cleanup_src_tgt
-    return 0
+       fini_changelog
+       cleanup_src_tgt
+       return 0
 }
 run_test 5b "Kill / restart lustre_rsync"
 
 # Test 6 - lustre_rsync large no of hard links
 test_6() {
-    init_src
-    init_changelog
+       init_src
+       init_changelog
 
-    local NUMLINKS=128
-    touch $DIR/$tdir/link0
-    local i=1
-    while [ $i -lt $NUMLINKS ];
-    do
-      ln $DIR/$tdir/link0  $DIR/$tdir/link${i}
-      i=$(expr $i + 1)
-    done
+       local num_links=128
+       local i
+
+       touch $DIR/$tdir/link0
+       for ((i = 1; i < num_links - 1; i++)); do
+               ln $DIR/$tdir/link0 $DIR/$tdir/link$i
+       done
+       # create an extra hard link of src name ending with dest name
+       ln $DIR/$tdir/link0 $DIR/$tdir/ink0
 
        local LRSYNC_LOG=$(generate_logname "lrsync_log")
        # Replicate the changes to $TGT
@@ -521,15 +588,16 @@ test_6() {
        check_diff $DIR/$tdir $TGT/$tdir
        check_diff $DIR/$tdir $TGT2/$tdir
 
-    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 ' ')
-    if [[ $count1 -ne $NUMLINKS ]] ||  [[ $count2 -ne $NUMLINKS ]]; then
-       ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
-       error "Incorrect no of hard links found $count1, $count2"
-    fi
-    fini_changelog
-    cleanup_src_tgt
-    return 0
+       local count1=$(stat --format=%h $TGT/$tdir/link0)
+       local count2=$(stat --format=%h $TGT2/$tdir/link0)
+       if ((count1 != num_links || count2 != num_links)); then
+               ls -l $TGT/$tdir/link0 $TGT2/$tdir/link0
+               error "Incorrect no of hard links found $count1, $count2"
+       fi
+
+       fini_changelog
+       cleanup_src_tgt
+       return 0
 }
 run_test 6 "lustre_rsync large no of hard links"
 
@@ -627,6 +695,6 @@ test_9() {
 run_test 9 "Replicate recursive directory removal"
 
 cd $ORIG_PWD
-complete $(basename $0) $SECONDS
+complete $SECONDS
 check_and_cleanup_lustre
 exit_status