Whamcloud - gitweb
LU-2903 tests: calculation of available space
[fs/lustre-release.git] / lustre / tests / replay-ost-single.sh
index 0861045..e0b8204 100755 (executable)
-#!/bin/sh
+#!/bin/bash
+# -*- mode: Bash; tab-width: 4; indent-tabs-mode: t; -*-
+# vim:shiftwidth=4:softtabstop=4:tabstop=4:
 
 set -e
 
-LUSTRE=${LUSTRE:-`dirname $0`/..}
+LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
+SETUP=${SETUP:-""}
+CLEANUP=${CLEANUP:-""}
 . $LUSTRE/tests/test-framework.sh
-
 init_test_env $@
+. ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
+init_logging
 
-. ${CONFIG:=$LUSTRE/tests/cfg/local.sh}
+# While we do not use OSTCOUNT=1 setup anymore,
+# ost1failover_HOST is used
+#ostfailover_HOST=${ostfailover_HOST:-$ost_HOST}
+#failover= must be defined in OST_MKFS_OPTIONS if ostfailover_HOST != ost_HOST
 
-ostfailover_HOST=${ostfailover_HOST:-$ost_HOST}
+require_dsh_ost || exit 0
 
 # Skip these tests
-ALWAYS_EXCEPT="5"
-# test 5 needs a larger fs than what local normally has
-
-gen_config() {
-    rm -f $XMLCONFIG
-    add_mds mds --dev $MDSDEV --size $MDSSIZE
-    add_lov lov1 mds --stripe_sz $STRIPE_BYTES\
-       --stripe_cnt $STRIPES_PER_OBJ --stripe_pattern 0
-    add_ost ost --lov lov1 --dev $OSTDEV --size $OSTSIZE --failover
-    if [ ! -z "$ostfailover_HOST" ]; then
-        add_ostfailover ost --dev $OSTDEV --size $OSTSIZE
-    fi
-    add_client client mds --lov lov1 --path $MOUNT
-}
+# BUG NUMBER: 
+ALWAYS_EXCEPT="$REPLAY_OST_SINGLE_EXCEPT"
 
-cleanup() {
-    # make sure we are using the primary MDS, so the config log will
-    # be able to clean up properly.
-    activeost=`facet_active ost`
-    if [ $activeost != "ost" ]; then
-        fail ost
-    fi
-    zconf_umount `hostname` $MOUNT
-    stop mds ${FORCE} $MDSLCONFARGS
-    stop ost ${FORCE} --dump cleanup.log
-}
+#                                      
+[ "$SLOW" = "no" ] && EXCEPT_SLOW="5"
 
-if [ "$ONLY" == "cleanup" ]; then
-    sysctl -w portals.debug=0
-    cleanup
-    exit
+if [ $(facet_fstype $SINGLEMDS) = "zfs" ]; then
+# bug number for skipped test:      LU-2285
+       ALWAYS_EXCEPT="$ALWAYS_EXCEPT 3"
+# bug number for slowed tests:                          LU-2874
+       [ "$SLOW" = "no" ] && EXCEPT_SLOW="$EXCEPT_SLOW 8a"
 fi
 
 build_test_filter
 
-rm -f ostactive
-
-gen_config
-
-start ost --reformat $OSTLCONFARGS
+check_and_setup_lustre
+assert_DIR
+rm -rf $DIR/[df][0-9]*
 
-[ "$DAEMONFILE" ] && $LCTL debug_daemon start $DAEMONFILE $DAEMONSIZE
-start mds --reformat $MDSLCONFARGS
-zconf_mount `hostname` $MOUNT
+TDIR=$DIR/d0.${TESTSUITE}
+mkdir -p $TDIR
+$LFS setstripe $TDIR -i 0 -c 1
+$LFS getstripe $TDIR
 
-mkdir -p $DIR
+test_0a() {
+    zconf_umount `hostname` $MOUNT -f
+    # needs to run during initial client->OST connection
+    #define OBD_FAIL_OST_ALL_REPLY_NET       0x211
+    do_facet ost1 "lctl set_param fail_loc=0x80000211"
+    zconf_mount `hostname` $MOUNT && df $MOUNT || error "0a mount fail"
+}
+run_test 0a "target handle mismatch (bug 5317) `date +%H:%M:%S`"
 
-test_0() {
-    fail ost
-    cp /etc/profile  $DIR/$tfile
+test_0b() {
+    fail ost1
+    cp /etc/profile  $TDIR/$tfile
     sync
-    diff /etc/profile $DIR/$tfile
+    diff /etc/profile $TDIR/$tfile
+    rm -f $TDIR/$tfile
 }
-run_test 0 "empty replay"
+run_test 0b "empty replay"
 
 test_1() {
-    date > $DIR/$tfile
-    fail ost
-    $CHECKSTAT -t file $DIR/$tfile || return 1
+    date > $TDIR/$tfile || error "error creating $TDIR/$tfile"
+    fail ost1
+    $CHECKSTAT -t file $TDIR/$tfile || return 1
+    rm -f $TDIR/$tfile
 }
 run_test 1 "touch"
 
 test_2() {
     for i in `seq 10`; do
-        echo "tag-$i" > $DIR/$tfile-$i
+        echo "tag-$i" > $TDIR/$tfile-$i || error "create $TDIR/$tfile-$i"
     done 
-    fail ost
+    fail ost1
     for i in `seq 10`; do
-      grep -q "tag-$i" $DIR/$tfile-$i || error "f2-$i"
+      grep -q "tag-$i" $TDIR/$tfile-$i || error "grep $TDIR/$tfile-$i"
     done 
+    rm -f $TDIR/$tfile-*
 }
 run_test 2 "|x| 10 open(O_CREAT)s"
 
 test_3() {
     verify=$ROOT/tmp/verify-$$
-    dd if=/dev/urandom bs=1024 count=5120 | tee $verify > $DIR/$tfile &
+    dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile &
     ddpid=$!
     sync &
-    fail ost
+    fail ost1
     wait $ddpid || return 1
-    cmp $verify $DIR/$tfile || return 2
-    rm -f $verify $DIR/$tfile
+    cmp $verify $TDIR/$tfile || return 2
+    rm -f $verify $TDIR/$tfile
 }
 run_test 3 "Fail OST during write, with verification"
 
 test_4() {
     verify=$ROOT/tmp/verify-$$
-    dd if=/dev/urandom bs=1024 count=5120 | tee $verify > $DIR/$tfile
+    dd if=/dev/urandom bs=4096 count=1280 | tee $verify > $TDIR/$tfile
     # invalidate cache, so that we're reading over the wire
-    for i in /proc/fs/lustre/ldlm/namespaces/OSC_*MNT*; do
-        echo -n clear > $i/lru_size
-    done
-    cmp $verify $DIR/$tfile &
+    cancel_lru_locks osc
+    cmp $verify $TDIR/$tfile &
     cmppid=$!
-    fail ost
+    fail ost1
     wait $cmppid || return 1
-    rm -f $verify $DIR/$tfile
+    rm -f $verify $TDIR/$tfile
 }
 run_test 4 "Fail OST during read, with verification"
 
+iozone_bg () {
+    local args=$@
+
+    local tmppipe=$TMP/${TESTSUITE}.${TESTNAME}.pipe
+    mkfifo $tmppipe
+
+    echo "+ iozone $args"
+    iozone $args > $tmppipe &
+
+    local pid=$!
+
+    echo "tmppipe=$tmppipe"
+    echo iozone pid=$pid
+
+    # iozone exit code is 0 even if iozone is not completed
+    # need to check iozone output  on "complete"
+    local iozonelog=$TMP/${TESTSUITE}.iozone.log
+    rm -f $iozonelog
+    cat $tmppipe | while read line ; do
+        echo "$line"
+        echo "$line" >>$iozonelog
+    done;
+
+    local rc=0
+    wait $pid
+    rc=$?
+    if ! $(tail -1 $iozonelog | grep -q complete); then
+        echo iozone failed!
+        rc=1
+    fi
+    rm -f $tmppipe
+    rm -f $iozonelog
+    return $rc
+}
+
 test_5() {
-    IOZONE_OPTS="-i 0 -i 1 -i 2 -+d -r 64 -s 1g"
-    iozone $IOZONE_OPTS -f $DIR/$tfile &
-    PID=$!
-    
-    sleep 10
-    fail ost
-    wait $PID || return 1
+    [ -z "`which iozone 2> /dev/null`" ] && skip_env "iozone missing" && return 0
+
+    # striping is -c 1, get min of available
+    local minavail=$(lctl get_param -n osc.*[oO][sS][cC][-_]*.kbytesavail | sort -n | head -1)
+    local size=$(( minavail * 3/4 ))
+    local GB=1048576  # 1048576KB == 1GB
+
+    if (( size > GB )); then
+        size=$GB
+    fi
+    local iozone_opts="-i 0 -i 1 -i 2 -+d -r 4 -s $size -f $TDIR/$tfile"
+
+    iozone_bg $iozone_opts &
+    local pid=$!
+
+    echo iozone bg pid=$pid
+
+    sleep 8
+    fail ost1
+    local rc=0
+    wait $pid
+    rc=$?
+    log "iozone rc=$rc"
+    rm -f $TDIR/$tfile
+    wait_delete_completed_mds
+    [ $rc -eq 0 ] || error "iozone failed"
+    return $rc
 }
 run_test 5 "Fail OST during iozone"
 
-equals_msg test complete, cleaning up
-cleanup
+kbytesfree() {
+   calc_osc_kbytes kbytesfree
+}
+
+test_6() {
+       remote_mds_nodsh && skip "remote MDS with nodsh" && return 0
+
+       local f=$TDIR/$tfile
+       rm -f $f
+       sync && sleep 2 && sync  # wait for delete thread
+
+       # wait till space is returned, following
+       # (( $before > $after_dd)) test counting on that
+       wait_mds_ost_sync || return 4
+       wait_destroy_complete || return 5
+
+       local before=$(kbytesfree)
+       dd if=/dev/urandom bs=4096 count=1280 of=$f || return 28
+       lfs getstripe $f
+       local stripe_index=$(lfs getstripe -i $f)
+
+       sync
+       sleep 4 # ensure we have a fresh statfs and changes have stablalized
+       sync
+
+       #define OBD_FAIL_MDS_REINT_NET_REP       0x119
+       do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
+       local after_dd=$(kbytesfree)
+       log "before: $before after_dd: $after_dd"
+       (( $before > $after_dd )) ||
+               error "space grew after dd: before:$before after_dd:$after_dd"
+       rm -f $f
+       fail ost$((stripe_index + 1))
+       wait_recovery_complete ost$((stripe_index + 1)) ||
+               error "OST$((stripe_index + 1)) recovery not completed"
+       $CHECKSTAT -t file $f && return 2 || true
+       sync
+       # let the delete happen
+       wait_mds_ost_sync || return 4
+       wait_delete_completed || return 5
+       local after=$(kbytesfree)
+       log "before: $before after: $after"
+       (( $before <= $after + $(fs_log_size) )) ||
+               error "$before > $after + logsize $(fs_log_size)"
+}
+run_test 6 "Fail OST before obd_destroy"
+
+test_7() {
+       local f=$TDIR/$tfile
+       rm -f $f
+       sync && sleep 5 && sync # wait for delete thread
+
+       # wait till space is returned, following
+       # (( $before > $after_dd)) test counting on that
+       wait_mds_ost_sync || return 4
+       wait_destroy_complete || return 5
+
+       local before=$(kbytesfree)
+       dd if=/dev/urandom bs=4096 count=1280 of=$f || error "dd to file failed: $?"
+
+       sync
+       local after_dd=$(kbytesfree)
+       while (( $before <= $after_dd && $i < 10 )); do
+               sync
+               sleep 1
+               let ++i
+               after_dd=$(kbytesfree)
+       done
+
+       log "before: $before after_dd: $after_dd took $i seconds"
+       (( $before > $after_dd )) ||
+               error "space grew after dd: before:$before after_dd:$after_dd"
+       replay_barrier ost1
+       rm -f $f
+       fail ost1
+       wait_recovery_complete ost1 || error "OST recovery not done"
+       $CHECKSTAT -t file $f && return 2 || true
+       sync
+       # let the delete happen
+       wait_mds_ost_sync || return 4
+       wait_delete_completed || return 5
+       local after=$(kbytesfree)
+       log "before: $before after: $after"
+       (( $before <= $after + $(fs_log_size) )) ||
+                error "$before > $after + logsize $(fs_log_size)"
+}
+run_test 7 "Fail OST before obd_destroy"
+
+test_8a() {
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
+               { skip "Need MDS version at least 2.3.0"; return; }
+       verify=$ROOT/tmp/verify-$$
+       dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
+               error "Create verify file failed"
+#define OBD_FAIL_OST_DQACQ_NET 0x230
+       do_facet ost1 "lctl set_param fail_loc=0x230"
+       dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
+       ddpid=$!
+       sleep $TIMEOUT  # wait for the io to become redo io
+       if ! ps -p $ddpid  > /dev/null 2>&1; then
+               error "redo io finished incorrectly"
+               return 1
+       fi
+       do_facet ost1 "lctl set_param fail_loc=0"
+       wait $ddpid || true
+       cancel_lru_locks osc
+       cmp $verify $TDIR/$tfile || return 2
+       rm -f $verify $TDIR/$tfile
+       message=`dmesg | grep "redo for recoverable error -115"`
+       [ -z "$message" ] || error "redo error messages found in dmesg"
+}
+run_test 8a "Verify redo io: redo io when get -EINPROGRESS error"
+
+test_8b() {
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
+               { skip "Need MDS version at least 2.3.0"; return; }
+       verify=$ROOT/tmp/verify-$$
+       dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
+               error "Create verify file failed"
+#define OBD_FAIL_OST_DQACQ_NET 0x230
+       do_facet ost1 "lctl set_param fail_loc=0x230"
+       dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
+       ddpid=$!
+       sleep $TIMEOUT  # wait for the io to become redo io
+       fail ost1
+       do_facet ost1 "lctl set_param fail_loc=0"
+       wait $ddpid || return 1
+       cancel_lru_locks osc
+       cmp $verify $TDIR/$tfile || return 2
+       rm -f $verify $TDIR/$tfile
+}
+run_test 8b "Verify redo io: redo io should success after recovery"
+
+test_8c() {
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
+               { skip "Need MDS version at least 2.3.0"; return; }
+       verify=$ROOT/tmp/verify-$$
+       dd if=/dev/urandom of=$verify bs=4096 count=1280 ||
+               error "Create verify file failed"
+#define OBD_FAIL_OST_DQACQ_NET 0x230
+       do_facet ost1 "lctl set_param fail_loc=0x230"
+       dd if=$verify of=$TDIR/$tfile bs=4096 count=1280 oflag=sync &
+       ddpid=$!
+       sleep $TIMEOUT  # wait for the io to become redo io
+       ost_evict_client
+       # allow recovery to complete
+       sleep $((TIMEOUT + 2))
+       do_facet ost1 "lctl set_param fail_loc=0"
+       wait $ddpid
+       cancel_lru_locks osc
+       cmp $verify $TDIR/$tfile && return 2
+       rm -f $verify $TDIR/$tfile
+}
+run_test 8c "Verify redo io: redo io should fail after eviction"
+
+test_8d() {
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
+               { skip "Need MDS version at least 2.3.0"; return; }
+#define OBD_FAIL_MDS_DQACQ_NET 0x187
+       do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
+       # test the non-intent create path
+       mcreate $TDIR/$tfile &
+       cpid=$!
+       sleep $TIMEOUT
+       if ! ps -p $cpid  > /dev/null 2>&1; then
+               error "mknod finished incorrectly"
+               return 1
+       fi
+       do_facet $SINGLEMDS "lctl set_param fail_loc=0"
+       wait $cpid || return 2
+       stat $TDIR/$tfile || error "mknod failed"
+
+       rm $TDIR/$tfile
+
+#define OBD_FAIL_MDS_DQACQ_NET 0x187
+       do_facet $SINGLEMDS "lctl set_param fail_loc=0x187"
+       # test the intent create path
+       openfile -f O_RDWR:O_CREAT $TDIR/$tfile &
+       cpid=$!
+       sleep $TIMEOUT
+       if ! ps -p $cpid > /dev/null 2>&1; then
+               error "open finished incorrectly"
+               return 3
+       fi
+       do_facet $SINGLEMDS "lctl set_param fail_loc=0"
+       wait $cpid || return 4
+       stat $TDIR/$tfile || error "open failed"
+}
+run_test 8d "Verify redo creation on -EINPROGRESS"
+
+test_8e() {
+       [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.0) ]] ||
+               { skip "Need MDS version at least 2.3.0"; return; }
+       sleep 1 # ensure we have a fresh statfs
+#define OBD_FAIL_OST_STATFS_EINPROGRESS 0x231
+       do_facet ost1 "lctl set_param fail_loc=0x231"
+       df $MOUNT &
+       dfpid=$!
+       sleep $TIMEOUT
+       if ! ps -p $dfpid  > /dev/null 2>&1; then
+                       do_facet ost1 "lctl set_param fail_loc=0"
+                       error "df shouldn't have completed!"
+                       return 1
+       fi
+       do_facet ost1 "lctl set_param fail_loc=0"
+}
+run_test 8e "Verify that ptlrpc resends request on -EINPROGRESS"
+
+complete $SECONDS
+check_and_cleanup_lustre
+exit_status