Skip to content
Snippets Groups Projects
replay-single.sh 50.3 KiB
Newer Older
Nathan Rutman's avatar
Nathan Rutman committed
#!/bin/bash
Nathan Rutman's avatar
Nathan Rutman committed
#set -v
#
# This test needs to be run on the client
#
Elena Gryaznova's avatar
Elena Gryaznova committed
SAVE_PWD=$PWD
Robert Read's avatar
Robert Read committed
LUSTRE=${LUSTRE:-$(cd $(dirname $0)/..; echo $PWD)}
Elena Gryaznova's avatar
Elena Gryaznova committed
SETUP=${SETUP:-}
CLEANUP=${CLEANUP:-}
. $LUSTRE/tests/test-framework.sh
init_test_env $@
Nathan Rutman's avatar
Nathan Rutman committed
. ${CONFIG:=$LUSTRE/tests/cfg/$NAME.sh}
Elena Gryaznova's avatar
Elena Gryaznova committed
CHECK_GRANT=${CHECK_GRANT:-"yes"}
GRANT_CHECK_LIST=${GRANT_CHECK_LIST:-""}
Robert Read's avatar
 
Robert Read committed

Yury Umanets's avatar
Yury Umanets committed
# bug number:
ALWAYS_EXCEPT="$REPLAY_SINGLE_EXCEPT"
Elena Gryaznova's avatar
Elena Gryaznova committed
#                                                  63 min  7 min  AT AT AT AT"
[ "$SLOW" = "no" ] && EXCEPT_SLOW="1 2 3 4 6 12 16 44a      44b    65 66 67 68"
Elena Gryaznova's avatar
Elena Gryaznova committed

Elena Gryaznova's avatar
Elena Gryaznova committed
cleanup_and_setup_lustre
Elena Gryaznova's avatar
Elena Gryaznova committed
assert_DIR
Elena Gryaznova's avatar
Elena Gryaznova committed
rm -rf $DIR/[df][0-9]*

Elena Gryaznova's avatar
Elena Gryaznova committed
test_0a() {	# was test_0
    sleep 10
    mkdir $DIR/$tfile
    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
    rmdir $DIR/$tfile
Elena Gryaznova's avatar
Elena Gryaznova committed
run_test 0a "empty replay"
test_0b() {
Bobi Jam's avatar
Bobi Jam committed
    # this test attempts to trigger a race in the precreation code,
    # and must run before any other objects are created on the filesystem
Nathan Rutman's avatar
Nathan Rutman committed
    fail ost1
    createmany -o $DIR/$tfile 20 || return 1
    unlinkmany $DIR/$tfile 20 || return 2
}
run_test 0b "ensure object created after recover exists. (3284)"

seq_set_width()
{
    local mds=$1
    local width=$2
komaln's avatar
komaln committed
    lctl set_param -n seq.cli-srv-$mds-mdc-*.width=$width
seq_get_width()
{
    local mds=$1
komaln's avatar
komaln committed
    lctl get_param -n seq.cli-srv-$mds-mdc-*.width
Nathan Rutman's avatar
Nathan Rutman committed

# This test should pass for single-mds and multi-mds configs.
# But for different configurations it tests different things.
#
# single-mds
# ----------
# (1) fld_create replay should happen;
#
# (2) fld_create replay should not return -EEXISTS, if it does
Bobi Jam's avatar
Bobi Jam committed
# this means sequence manager recovery code is buggy and allocated
# same sequence two times after recovery.
#
# multi-mds
# ---------
Bobi Jam's avatar
Bobi Jam committed
# (1) fld_create replay may not happen, because its home MDS is
# MDS2 which is not involved to revovery;
#
Bobi Jam's avatar
Bobi Jam committed
# (2) as fld_create does not happen on MDS1, it does not make any
# problem.
test_0c() {
    local label=`mdsdevlabel 1`
    [ -z "$label" ] && echo "No label for mds1" && return 1

    replay_barrier $SINGLEMDS
    local sw=`seq_get_width $label`
Bobi Jam's avatar
Bobi Jam committed

    # make seq manager switch to next sequence each
    # time as new fid is needed.
    seq_set_width $label 1
Bobi Jam's avatar
Bobi Jam committed

    # make sure that fld has created at least one new
    # entry on server
    touch $DIR/$tfile || return 2
    seq_set_width $label $sw
Bobi Jam's avatar
Bobi Jam committed

    # fail $SINGLEMDS and start recovery, replay RPCs, etc.
    fail $SINGLEMDS
Bobi Jam's avatar
Bobi Jam committed

    # wait for recovery finish
    sleep 10
    df $MOUNT
Bobi Jam's avatar
Bobi Jam committed

    # flush fld cache and dentry cache to make it lookup
    # created entry instead of revalidating existent one
    umount $MOUNT
    zconf_mount `hostname` $MOUNT
Bobi Jam's avatar
Bobi Jam committed

    # issue lookup which should call fld lookup which
    # should fail if client did not replay fld create
    # correctly and server has no fld entry
    touch $DIR/$tfile || return 3
    rm $DIR/$tfile || return 4
Nathan Rutman's avatar
Nathan Rutman committed
}
run_test 0c "fld create"

test_1() {
    replay_barrier $SINGLEMDS
    mcreate $DIR/$tfile
    fail $SINGLEMDS
    $CHECKSTAT -t file $DIR/$tfile || return 1
    rm $DIR/$tfile
}
run_test 1 "simple create"
Nathan Rutman's avatar
Nathan Rutman committed

    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
    $CHECKSTAT -t file $DIR/$tfile || return 1
    rm $DIR/$tfile
Elena Gryaznova's avatar
Elena Gryaznova committed
    mcreate $DIR/$tfile
    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
    $CHECKSTAT -t file $DIR/$tfile || return 1
    rm $DIR/$tfile
    replay_barrier $SINGLEMDS
    mcreate $DIR/$tfile
    o_directory $DIR/$tfile
    fail $SINGLEMDS
    $CHECKSTAT -t file $DIR/$tfile || return 2
    rm $DIR/$tfile
run_test 3a "replay failed open(O_DIRECTORY)"

test_3b() {
    replay_barrier $SINGLEMDS
#define OBD_FAIL_MDS_OPEN_PACK | OBD_FAIL_ONCE
komaln's avatar
komaln committed
    do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000114"
    touch $DIR/$tfile
komaln's avatar
komaln committed
    do_facet $SINGLEMDS "lctl set_param fail_loc=0"
    fail $SINGLEMDS
    $CHECKSTAT -t file $DIR/$tfile && return 2
    return 0
}
run_test 3b "replay failed open -ENOMEM"

test_3c() {
    replay_barrier $SINGLEMDS
#define OBD_FAIL_MDS_ALLOC_OBDO | OBD_FAIL_ONCE
komaln's avatar
komaln committed
    do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000128"
    touch $DIR/$tfile
komaln's avatar
komaln committed
    do_facet $SINGLEMDS "lctl set_param fail_loc=0"
    fail $SINGLEMDS

    $CHECKSTAT -t file $DIR/$tfile && return 2
    return 0
}
run_test 3c "replay failed open -ENOMEM"
Elena Gryaznova's avatar
Elena Gryaznova committed
test_4a() {	# was test_4
    replay_barrier $SINGLEMDS
    for i in `seq 10`; do
        echo "tag-$i" > $DIR/$tfile-$i
Bobi Jam's avatar
Bobi Jam committed
    done
    fail $SINGLEMDS
    for i in `seq 10`; do
      grep -q "tag-$i" $DIR/$tfile-$i || error "$tfile-$i"
Bobi Jam's avatar
Bobi Jam committed
    done
Elena Gryaznova's avatar
Elena Gryaznova committed
run_test 4a "|x| 10 open(O_CREAT)s"
    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
    $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
}
run_test 4b "|x| rm 10 files"

Bobi Jam's avatar
Bobi Jam committed
# The idea is to get past the first block of precreated files on both
# osts, and then replay.
test_5() {
    replay_barrier $SINGLEMDS
    for i in `seq 220`; do
        echo "tag-$i" > $DIR/$tfile-$i
Bobi Jam's avatar
Bobi Jam committed
    done
    fail $SINGLEMDS
    for i in `seq 220`; do
      grep -q "tag-$i" $DIR/$tfile-$i || error "f1c-$i"
Bobi Jam's avatar
Bobi Jam committed
    done
    rm -rf $DIR/$tfile-*
    sleep 3
    # waiting for commitment of removal
}
run_test 5 "|x| 220 open(O_CREAT)"


Elena Gryaznova's avatar
Elena Gryaznova committed
test_6a() {	# was test_6
Elena Gryaznova's avatar
Elena Gryaznova committed
    mkdir -p $DIR/$tdir
    replay_barrier $SINGLEMDS
    mcreate $DIR/$tdir/$tfile
    fail $SINGLEMDS
    $CHECKSTAT -t dir $DIR/$tdir || return 1
    $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
    sleep 2
    # waiting for log process thread
}
Elena Gryaznova's avatar
Elena Gryaznova committed
run_test 6a "mkdir + contained create"
Elena Gryaznova's avatar
Elena Gryaznova committed
    mkdir -p $DIR/$tdir
    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
Bobi Jam's avatar
Bobi Jam committed
    $CHECKSTAT -t dir $DIR/$tdir && return 1 || true
}
run_test 6b "|X| rmdir"

test_7() {
Elena Gryaznova's avatar
Elena Gryaznova committed
    mkdir -p $DIR/$tdir
    replay_barrier $SINGLEMDS
    mcreate $DIR/$tdir/$tfile
    fail $SINGLEMDS
    $CHECKSTAT -t dir $DIR/$tdir || return 1
    $CHECKSTAT -t file $DIR/$tdir/$tfile || return 2
    rm -fr $DIR/$tdir
}
run_test 7 "mkdir |X| contained create"

test_8() {
    # make sure no side-effect from previous test.
    rm -f $DIR/$tfile
    replay_barrier $SINGLEMDS
    multiop_bg_pause $DIR/$tfile mo_c || return 4
    fail $SINGLEMDS
    ls $DIR/$tfile
    $CHECKSTAT -t file $DIR/$tfile || return 1
    kill -USR1 $MULTIPID || return 2
    wait $MULTIPID || return 3
    rm $DIR/$tfile
}
run_test 8 "creat open |X| close"

test_9() {
    replay_barrier $SINGLEMDS
    mcreate $DIR/$tfile
    local old_inum=`ls -i $DIR/$tfile | awk '{print $1}'`
    fail $SINGLEMDS
    local new_inum=`ls -i $DIR/$tfile | awk '{print $1}'`

    echo " old_inum == $old_inum, new_inum == $new_inum"
    if [ $old_inum -eq $new_inum  ] ;
    then
        echo " old_inum and new_inum match"
    else
        echo "!!!! old_inum and new_inum NOT match"
        return 1
    fi
    rm $DIR/$tfile
}
run_test 9  "|X| create (same inum/gen)"

test_10() {
    mcreate $DIR/$tfile
    replay_barrier $SINGLEMDS
    mv $DIR/$tfile $DIR/$tfile-2
    rm -f $DIR/$tfile
    fail $SINGLEMDS
    $CHECKSTAT $DIR/$tfile && return 1
Nathan Rutman's avatar
Nathan Rutman committed
    $CHECKSTAT $DIR/$tfile-2 ||return 2
    rm $DIR/$tfile-2
    return 0
}
run_test 10 "create |X| rename unlink"

test_11() {
    mcreate $DIR/$tfile
    echo "old" > $DIR/$tfile
    mv $DIR/$tfile $DIR/$tfile-2
    replay_barrier $SINGLEMDS
    echo "new" > $DIR/$tfile
Bobi Jam's avatar
Bobi Jam committed
    grep new $DIR/$tfile
    grep old $DIR/$tfile-2
    fail $SINGLEMDS
    grep new $DIR/$tfile || return 1
    grep old $DIR/$tfile-2 || return 2
}
run_test 11 "create open write rename |X| create-old-name read"

test_12() {
Bobi Jam's avatar
Bobi Jam committed
    mcreate $DIR/$tfile
    multiop_bg_pause $DIR/$tfile o_tSc || return 3
    replay_barrier $SINGLEMDS
    kill -USR1 $pid
    wait $pid || return 1

    fail $SINGLEMDS
    [ -e $DIR/$tfile ] && return 2
    return 0
}
run_test 12 "open, unlink |X| close"


# 1777 - replay open after committed chmod that would make
Bobi Jam's avatar
Bobi Jam committed
#        a regular open a failure
Bobi Jam's avatar
Bobi Jam committed
    mcreate $DIR/$tfile
    multiop_bg_pause $DIR/$tfile O_wc || return 3
    pid=$!
    chmod 0 $DIR/$tfile
    $CHECKSTAT -p 0 $DIR/$tfile
    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
    kill -USR1 $pid
    wait $pid || return 1

    $CHECKSTAT -s 1 -p 0 $DIR/$tfile || return 2
    return 0
}
run_test 13 "open chmod 0 |x| write close"

test_14() {
    multiop_bg_pause $DIR/$tfile O_tSc || return 4
    replay_barrier $SINGLEMDS
    kill -USR1 $pid || return 1
    wait $pid || return 2

    fail $SINGLEMDS
    [ -e $DIR/$tfile ] && return 3
    return 0
}
run_test 14 "open(O_CREAT), unlink |X| close"

test_15() {
    multiop_bg_pause $DIR/$tfile O_tSc || return 5
    replay_barrier $SINGLEMDS
    touch $DIR/g11 || return 1
    kill -USR1 $pid
    wait $pid || return 2

    fail $SINGLEMDS
    [ -e $DIR/$tfile ] && return 3
    touch $DIR/h11 || return 4
    return 0
}
run_test 15 "open(O_CREAT), unlink |X|  touch new, close"


test_16() {
    replay_barrier $SINGLEMDS
    mcreate $DIR/$tfile
    munlink $DIR/$tfile
    mcreate $DIR/$tfile-2
    fail $SINGLEMDS
    [ -e $DIR/$tfile ] && return 1
    [ -e $DIR/$tfile-2 ] || return 2
    munlink $DIR/$tfile-2 || return 3
}
run_test 16 "|X| open(O_CREAT), unlink, touch new,  unlink new"

test_17() {
    replay_barrier $SINGLEMDS
    multiop_bg_pause $DIR/$tfile O_c || return 4
    fail $SINGLEMDS
    kill -USR1 $pid || return 1
    wait $pid || return 2
    $CHECKSTAT -t file $DIR/$tfile || return 3
    rm $DIR/$tfile
}
run_test 17 "|X| open(O_CREAT), |replay| close"

test_18() {
    replay_barrier $SINGLEMDS
    multiop_bg_pause $DIR/$tfile O_tSc || return 8
    pid=$!
    rm -f $DIR/$tfile
    touch $DIR/$tfile-2 || return 1
    echo "pid: $pid will close"
    kill -USR1 $pid
    wait $pid || return 2
    fail $SINGLEMDS
    [ -e $DIR/$tfile ] && return 3
    [ -e $DIR/$tfile-2 ] || return 4
    # this touch frequently fails
    touch $DIR/$tfile-3 || return 5
    munlink $DIR/$tfile-2 || return 6
    munlink $DIR/$tfile-3 || return 7
    return 0
}
run_test 18 "|X| open(O_CREAT), unlink, touch new, close, touch, unlink"

# bug 1855 (a simpler form of test_11 above)
test_19() {
    replay_barrier $SINGLEMDS
    mcreate $DIR/$tfile
    echo "old" > $DIR/$tfile
    mv $DIR/$tfile $DIR/$tfile-2
    grep old $DIR/$tfile-2
    fail $SINGLEMDS
    grep old $DIR/$tfile-2 || return 2
}
run_test 19 "|X| mcreate, open, write, rename "

Elena Gryaznova's avatar
Elena Gryaznova committed
test_20a() {	# was test_20
    replay_barrier $SINGLEMDS
    multiop_bg_pause $DIR/$tfile O_tSc || return 3
    fail $SINGLEMDS
    kill -USR1 $pid
    wait $pid || return 1
    [ -e $DIR/$tfile ] && return 2
    return 0
}
Elena Gryaznova's avatar
Elena Gryaznova committed
run_test 20a "|X| open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"
Nathan Rutman's avatar
Nathan Rutman committed
test_20b() { # bug 10480
    BEFOREUSED=`df -P $DIR | tail -1 | awk '{ print $3 }'`

    dd if=/dev/zero of=$DIR/$tfile bs=4k count=10000 &
    pid=$!
    while [ ! -e $DIR/$tfile ] ; do
        usleep 60                           # give dd a chance to start
    done

    lfs getstripe $DIR/$tfile || return 1
    rm -f $DIR/$tfile || return 2       # make it an orphan
    mds_evict_client
    df -P $DIR || df -P $DIR || true    # reconnect

    fail $SINGLEMDS                            # start orphan recovery
Nathan Rutman's avatar
Nathan Rutman committed
    df -P $DIR || df -P $DIR || true    # reconnect
Elena Gryaznova's avatar
Elena Gryaznova committed
    wait_mds_recovery_done || error "MDS recovery not done"
Nathan Rutman's avatar
Nathan Rutman committed

Bobi Jam's avatar
Bobi Jam committed
    # FIXME just because recovery is done doesn't mean we've finished
Nathan Rutman's avatar
Nathan Rutman committed
    # orphan cleanup.  Fake it with a sleep for now...
    sleep 10
Nathan Rutman's avatar
Nathan Rutman committed
    AFTERUSED=`df -P $DIR | tail -1 | awk '{ print $3 }'`
    log "before $BEFOREUSED, after $AFTERUSED"
    [ $AFTERUSED -gt $((BEFOREUSED + 20)) ] && \
Nathan Rutman's avatar
Nathan Rutman committed
        error "after $AFTERUSED > before $BEFOREUSED"
Nathan Rutman's avatar
Nathan Rutman committed
    return 0
}
run_test 20b "write, unlink, eviction, replay, (test mds_cleanup_orphans)"

test_20c() { # bug 10480
    multiop_bg_pause $DIR/$tfile Ow_c || return 1
Elena Gryaznova's avatar
Elena Gryaznova committed
    pid=$!
Nathan Rutman's avatar
Nathan Rutman committed

    ls -la $DIR/$tfile

    mds_evict_client

    df -P $DIR || df -P $DIR || true    # reconnect

Elena Gryaznova's avatar
Elena Gryaznova committed
    kill -USR1 $pid
Nathan Rutman's avatar
Nathan Rutman committed
    test -s $DIR/$tfile || error "File was truncated"

Elena Gryaznova's avatar
Elena Gryaznova committed
    wait $pid || return 1
Nathan Rutman's avatar
Nathan Rutman committed
    return 0
}
run_test 20c "check that client eviction does not affect file content"

    replay_barrier $SINGLEMDS
    multiop_bg_pause $DIR/$tfile O_tSc || return 5
    pid=$!
    rm -f $DIR/$tfile
    touch $DIR/g11 || return 1

    fail $SINGLEMDS
    kill -USR1 $pid
    wait $pid || return 2
    [ -e $DIR/$tfile ] && return 3
    touch $DIR/h11 || return 4
    return 0
}
run_test 21 "|X| open(O_CREAT), unlink touch new, replay, close (test mds_cleanup_orphans)"

test_22() {
    multiop_bg_pause $DIR/$tfile O_tSc || return 3
    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
    kill -USR1 $pid
    wait $pid || return 1
    [ -e $DIR/$tfile ] && return 2
    return 0
}
run_test 22 "open(O_CREAT), |X| unlink, replay, close (test mds_cleanup_orphans)"

test_23() {
    multiop_bg_pause $DIR/$tfile O_tSc || return 5
    replay_barrier $SINGLEMDS
    rm -f $DIR/$tfile
    touch $DIR/g11 || return 1

    fail $SINGLEMDS
    kill -USR1 $pid
    wait $pid || return 2
    [ -e $DIR/$tfile ] && return 3
    touch $DIR/h11 || return 4
    return 0
}
run_test 23 "open(O_CREAT), |X| unlink touch new, replay, close (test mds_cleanup_orphans)"

test_24() {
    multiop_bg_pause $DIR/$tfile O_tSc || return 3
    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
    rm -f $DIR/$tfile
    kill -USR1 $pid
    wait $pid || return 1
    [ -e $DIR/$tfile ] && return 2
    return 0
}
run_test 24 "open(O_CREAT), replay, unlink, close (test mds_cleanup_orphans)"

test_25() {
    multiop_bg_pause $DIR/$tfile O_tSc || return 3
    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
    kill -USR1 $pid
    wait $pid || return 1
    [ -e $DIR/$tfile ] && return 2
    return 0
}
run_test 25 "open(O_CREAT), unlink, replay, close (test mds_cleanup_orphans)"

test_26() {
    replay_barrier $SINGLEMDS
    multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
    multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
    pid2=$!
    rm -f $DIR/$tfile-1
    rm -f $DIR/$tfile-2
    kill -USR1 $pid2
    wait $pid2 || return 1

    fail $SINGLEMDS
    kill -USR1 $pid1
    wait $pid1 || return 2
    [ -e $DIR/$tfile-1 ] && return 3
    [ -e $DIR/$tfile-2 ] && return 4
    return 0
}
run_test 26 "|X| open(O_CREAT), unlink two, close one, replay, close one (test mds_cleanup_orphans)"

test_27() {
    replay_barrier $SINGLEMDS
    multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
    multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
    pid2=$!
    rm -f $DIR/$tfile-1
    rm -f $DIR/$tfile-2

    fail $SINGLEMDS
    kill -USR1 $pid1
    wait $pid1 || return 1
    kill -USR1 $pid2
    wait $pid2 || return 2
    [ -e $DIR/$tfile-1 ] && return 3
    [ -e $DIR/$tfile-2 ] && return 4
    return 0
}
run_test 27 "|X| open(O_CREAT), unlink two, replay, close two (test mds_cleanup_orphans)"

test_28() {
    multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
    multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
    replay_barrier $SINGLEMDS
    rm -f $DIR/$tfile-1
    rm -f $DIR/$tfile-2
    kill -USR1 $pid2
    wait $pid2 || return 1

    fail $SINGLEMDS
    kill -USR1 $pid1
    wait $pid1 || return 2
    [ -e $DIR/$tfile-1 ] && return 3
    [ -e $DIR/$tfile-2 ] && return 4
    return 0
}
run_test 28 "open(O_CREAT), |X| unlink two, close one, replay, close one (test mds_cleanup_orphans)"

test_29() {
    multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
    multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
    replay_barrier $SINGLEMDS
    rm -f $DIR/$tfile-1
    rm -f $DIR/$tfile-2

    fail $SINGLEMDS
    kill -USR1 $pid1
    wait $pid1 || return 1
    kill -USR1 $pid2
    wait $pid2 || return 2
    [ -e $DIR/$tfile-1 ] && return 3
    [ -e $DIR/$tfile-2 ] && return 4
    return 0
}
run_test 29 "open(O_CREAT), |X| unlink two, replay, close two (test mds_cleanup_orphans)"

test_30() {
    multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
    multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
    pid2=$!
    rm -f $DIR/$tfile-1
    rm -f $DIR/$tfile-2

    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
    kill -USR1 $pid1
    wait $pid1 || return 1
    kill -USR1 $pid2
    wait $pid2 || return 2
    [ -e $DIR/$tfile-1 ] && return 3
    [ -e $DIR/$tfile-2 ] && return 4
    return 0
}
run_test 30 "open(O_CREAT) two, unlink two, replay, close two (test mds_cleanup_orphans)"

test_31() {
    multiop_bg_pause $DIR/$tfile-1 O_tSc || return 5
    multiop_bg_pause $DIR/$tfile-2 O_tSc || return 6
    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
    kill -USR1 $pid1
    wait $pid1 || return 1
    kill -USR1 $pid2
    wait $pid2 || return 2
    [ -e $DIR/$tfile-1 ] && return 3
    [ -e $DIR/$tfile-2 ] && return 4
    return 0
}
run_test 31 "open(O_CREAT) two, unlink one, |X| unlink one, close two (test mds_cleanup_orphans)"

# tests for bug 2104; completion without crashing is success.  The close is
# stale, but we always return 0 for close, so the app never sees it.
test_32() {
    multiop_bg_pause $DIR/$tfile O_c || return 2
    multiop_bg_pause $DIR/$tfile O_c || return 3
    df $MOUNT || sleep 1 && df $MOUNT || return 1
    kill -USR1 $pid1
    kill -USR1 $pid2
Elena Gryaznova's avatar
Elena Gryaznova committed
    wait $pid1 || return 4
    wait $pid2 || return 5
    return 0
}
run_test 32 "close() notices client eviction; close() after client eviction"

# Abort recovery before client complete
Elena Gryaznova's avatar
Elena Gryaznova committed
test_33a() {	# was test_33
    replay_barrier $SINGLEMDS
    createmany -o $DIR/$tfile-%d 100
    fail_abort $SINGLEMDS
    # this file should be gone, because the replay was aborted
Bobi Jam's avatar
Bobi Jam committed
    $CHECKSTAT -t file $DIR/$tfile-* && return 3
    unlinkmany $DIR/$tfile-%d 0 100
Elena Gryaznova's avatar
Elena Gryaznova committed
run_test 33a "abort recovery before client does replay"
Bobi Jam's avatar
Bobi Jam committed
# Stale FID sequence
Elena Gryaznova's avatar
Elena Gryaznova committed
test_33b() {	# was test_33a
    replay_barrier $SINGLEMDS
    createmany -o $DIR/$tfile-%d 10
    fail_abort $SINGLEMDS
    unlinkmany $DIR/$tfile-%d 0 10
    # recreate shouldn't fail
    createmany -o $DIR/$tfile-%d 10 || return 3
    unlinkmany $DIR/$tfile-%d 0 10
    return 0
}
Elena Gryaznova's avatar
Elena Gryaznova committed
run_test 33b "fid shouldn't be reused after abort recovery"
    multiop_bg_pause $DIR/$tfile O_c || return 2
    replay_barrier $SINGLEMDS
    fail_abort $SINGLEMDS
Elena Gryaznova's avatar
Elena Gryaznova committed
    wait $pid || return 3
    [ -e $DIR/$tfile ] && return 1
jacob's avatar
jacob committed
    sync
    return 0
}
run_test 34 "abort recovery before client does replay (test mds_cleanup_orphans)"

Bobi Jam's avatar
Bobi Jam committed
# bug 2278 - generate one orphan on OST, then destroy it during recovery from llog
Robert Read's avatar
Robert Read committed
#define OBD_FAIL_MDS_REINT_NET_REP       0x119
komaln's avatar
komaln committed
    do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000119"
    rm -f $DIR/$tfile &
    sleep 1
Robert Read's avatar
Robert Read committed
    sync
    sleep 1
    # give a chance to remove from MDS
    fail_abort $SINGLEMDS
    $CHECKSTAT -t file $DIR/$tfile && return 1 || true
}
run_test 35 "test recovery from llog for unlink op"
Robert Read's avatar
Robert Read committed
# b=2432 resent cancel after replay uses wrong cookie,
# so don't resend cancels
test_36() {
    replay_barrier $SINGLEMDS
Robert Read's avatar
Robert Read committed
    touch $DIR/$tfile
    checkstat $DIR/$tfile
    facet_failover $SINGLEMDS
Nathan Rutman's avatar
Nathan Rutman committed
    cancel_lru_locks mdc
Bobi Jam's avatar
Bobi Jam committed
    if dmesg | grep "unknown lock cookie"; then
Robert Read's avatar
Robert Read committed
	echo "cancel after replay failed"
	return 1
    fi
}
run_test 36 "don't resend cancel"

jacob's avatar
jacob committed
# b=2368
# directory orphans can't be unlinked from PENDING directory
test_37() {
    rmdir $DIR/$tfile 2>/dev/null
    multiop_bg_pause $DIR/$tfile dD_c || return 2
jacob's avatar
jacob committed
    pid=$!
    rmdir $DIR/$tfile

    replay_barrier $SINGLEMDS
jacob's avatar
jacob committed
    # clear the dmesg buffer so we only see errors from this recovery
    dmesg -c >/dev/null
    fail_abort $SINGLEMDS
jacob's avatar
jacob committed
    kill -USR1 $pid
    dmesg | grep  "mds_unlink_orphan.*error .* unlinking orphan" && return 1
Elena Gryaznova's avatar
Elena Gryaznova committed
    wait $pid || return 3
jacob's avatar
jacob committed
    sync
    return 0
}
run_test 37 "abort recovery before client does replay (test mds_cleanup_orphans for directories)"

Robert Read's avatar
Robert Read committed
    createmany -o $DIR/$tfile-%d 800
    unlinkmany $DIR/$tfile-%d 0 400
    replay_barrier $SINGLEMDS
    fail $SINGLEMDS
Robert Read's avatar
Robert Read committed
    unlinkmany $DIR/$tfile-%d 400 400
    sleep 2
    $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
}
run_test 38 "test recovery from unlink llog (test llog_gen_rec) "

Nathan Rutman's avatar
Nathan Rutman committed
test_39() { # bug 4176
Robert Read's avatar
Robert Read committed
    createmany -o $DIR/$tfile-%d 800
    replay_barrier $SINGLEMDS
Robert Read's avatar
Robert Read committed
    unlinkmany $DIR/$tfile-%d 0 400
    fail $SINGLEMDS
Robert Read's avatar
Robert Read committed
    unlinkmany $DIR/$tfile-%d 400 400
    sleep 2
    $CHECKSTAT -t file $DIR/$tfile-* && return 1 || true
}
run_test 39 "test recovery from unlink llog (test llog_gen_rec) "

Robert Read's avatar
Robert Read committed
count_ost_writes() {
komaln's avatar
komaln committed
    lctl get_param -n osc.*.stats | awk -vwrites=0 '/ost_write/ { writes += $2 } END { print writes; }'
Robert Read's avatar
Robert Read committed
}

#b=2477,2532
test_40(){
Bobi Jam's avatar
Bobi Jam committed
    $LCTL mark multiop $MOUNT/$tfile OS_c
Robert Read's avatar
Robert Read committed
    multiop $MOUNT/$tfile OS_c  &
    PID=$!
    writeme -s $MOUNT/${tfile}-2 &
    WRITE_PID=$!
    sleep 1
    facet_failover $SINGLEMDS
Robert Read's avatar
Robert Read committed
#define OBD_FAIL_MDS_CONNECT_NET         0x117
komaln's avatar
komaln committed
    do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000117"
Robert Read's avatar
Robert Read committed
    kill -USR1 $PID
    stat1=`count_ost_writes`
    sleep $TIMEOUT
    stat2=`count_ost_writes`
    echo "$stat1, $stat2"
Bobi Jam's avatar
Bobi Jam committed
    if [ $stat1 -lt $stat2 ]; then
Robert Read's avatar
Robert Read committed
       echo "writes continuing during recovery"
       RC=0
    else
       echo "writes not continuing during recovery, bug 2477"
       RC=4
    fi
    echo "waiting for writeme $WRITE_PID"
    kill $WRITE_PID
Bobi Jam's avatar
Bobi Jam committed
    wait $WRITE_PID
Robert Read's avatar
Robert Read committed

    echo "waiting for multiop $PID"
    wait $PID || return 2
    do_facet client munlink $MOUNT/$tfile  || return 3
    do_facet client munlink $MOUNT/${tfile}-2  || return 3
    return $RC
}
run_test 40 "cause recovery in ptlrpc, ensure IO continues"


#b=2814
# make sure that a read to one osc doesn't try to double-unlock its page just
# because another osc is invalid.  trigger_group_io used to mistakenly return
# an error if any oscs were invalid even after having successfully put rpcs
# on valid oscs.  This was fatal if the caller was ll_readpage who unlocked
# the page, guarnateeing that the unlock from the RPC completion would
# assert on trying to unlock the unlocked page.
test_41() {
Elena Gryaznova's avatar
Elena Gryaznova committed
    [ $OSTCOUNT -lt 2 ] && \
	skip "skipping test 41: we don't have a second OST to test with" && \
	return

    local f=$MOUNT/$tfile
    # make sure the start of the file is ost1
Bobi Jam's avatar
Bobi Jam committed
    lfs setstripe $f -s $((128 * 1024)) -i 0
    do_facet client dd if=/dev/zero of=$f bs=4k count=1 || return 3
Nathan Rutman's avatar
Nathan Rutman committed
    cancel_lru_locks osc
    # fail ost2 and read from ost1
komaln's avatar
komaln committed
    local osc2dev=`do_facet mds "lctl get_param -n devices | grep ${ost2_svc}-osc-MDT0000" | awk '{print $1}'`
    [ -z "$osc2dev" ] && echo "OST: $ost2_svc" && lctl get_param -n devices && return 4
Elena Gryaznova's avatar
Elena Gryaznova committed
    do_facet mds $LCTL --device $osc2dev deactivate || return 1
    do_facet client dd if=$f of=/dev/null bs=4k count=1 || return 3
Elena Gryaznova's avatar
Elena Gryaznova committed
    do_facet mds $LCTL --device $osc2dev activate || return 2
    return 0
}
run_test 41 "read from a valid osc while other oscs are invalid"

# test MDS recovery after ost failure
test_42() {
Nathan Rutman's avatar
Nathan Rutman committed
    blocks=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
    createmany -o $DIR/$tfile-%d 800
Nathan Rutman's avatar
Nathan Rutman committed
    replay_barrier ost1
    unlinkmany $DIR/$tfile-%d 0 400
Elena Gryaznova's avatar
Elena Gryaznova committed
    debugsave
komaln's avatar
komaln committed
    lctl set_param debug=-1
Nathan Rutman's avatar
Nathan Rutman committed
    facet_failover ost1
Bobi Jam's avatar
Bobi Jam committed

Nathan Rutman's avatar
Nathan Rutman committed
    # osc is evicted, fs is smaller (but only with failout OSTs (bug 7287)
    #blocks_after=`df -P $MOUNT | tail -n 1 | awk '{ print $2 }'`
    #[ $blocks_after -lt $blocks ] || return 1
    echo wait for MDS to timeout and recover
    sleep $((TIMEOUT * 2))
Elena Gryaznova's avatar
Elena Gryaznova committed
    debugrestore
    unlinkmany $DIR/$tfile-%d 400 400
    $CHECKSTAT -t file $DIR/$tfile-* && return 2 || true
Andreas Dilger's avatar
Andreas Dilger committed
run_test 42 "recovery after ost failure"
# timeout in MDS/OST recovery RPC will LBUG MDS
Nathan Rutman's avatar
Nathan Rutman committed
test_43() { # bug 2530
    replay_barrier $SINGLEMDS
komaln's avatar
komaln committed
    do_facet ost1 "lctl set_param fail_loc=0x80000204"
    fail $SINGLEMDS
komaln's avatar
komaln committed
    do_facet ost1 "lctl set_param fail_loc=0"

    return 0
}
run_test 43 "mds osc import failure during recovery; don't LBUG"

Elena Gryaznova's avatar
Elena Gryaznova committed
test_44a() {	# was test_44
Eric Mei's avatar
Eric Mei committed
    local at_max_saved=0

komaln's avatar
komaln committed
    mdcdev=`lctl get_param -n devices | awk '/MDT0000-mdc-/ {print $1}'`
Nathan Rutman's avatar
Nathan Rutman committed
    [ "$mdcdev" ] || exit 2
Eric Mei's avatar
Eric Mei committed

    # adaptive timeouts slow this way down
    if at_is_valid && at_is_enabled; then
        at_max_saved=$(at_max_get mds)
        at_max_set 40 mds
    fi

Nathan Rutman's avatar
Nathan Rutman committed
    for i in `seq 1 10`; do
Eric Mei's avatar
Eric Mei committed
	echo "$i of 10 ($(date +%s))"
	do_facet mds "grep service $LPROC/mdt/MDS/mds/timeouts"
Nathan Rutman's avatar
Nathan Rutman committed
	#define OBD_FAIL_TGT_CONN_RACE     0x701
komaln's avatar
komaln committed
	do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000701"
Nathan Rutman's avatar
Nathan Rutman committed
	$LCTL --device $mdcdev recover
	df $MOUNT
    done
komaln's avatar
komaln committed
    do_facet $SINGLEMDS "lctl set_param fail_loc=0"
Eric Mei's avatar
Eric Mei committed
    [ $at_max_saved -ne 0 ] && at_max_set $at_max_saved mds
Robert Read's avatar
Robert Read committed
    return 0
}
Elena Gryaznova's avatar
Elena Gryaznova committed
run_test 44a "race in target handle connect"
Robert Read's avatar
Robert Read committed

Nathan Rutman's avatar
Nathan Rutman committed
test_44b() {
komaln's avatar
komaln committed
    mdcdev=`lctl get_param -n devices | awk '/MDT0000-mdc-/ {print $1}'`
Nathan Rutman's avatar
Nathan Rutman committed
    [ "$mdcdev" ] || exit 2
    for i in `seq 1 10`; do
Eric Mei's avatar
Eric Mei committed
        echo "$i of 10 ($(date +%s))"
	do_facet mds "grep service $LPROC/mdt/MDS/mds/timeouts"
Nathan Rutman's avatar
Nathan Rutman committed
	#define OBD_FAIL_TGT_DELAY_RECONNECT 0x704
komaln's avatar
komaln committed
	do_facet $SINGLEMDS "lctl set_param fail_loc=0x80000704"
Nathan Rutman's avatar
Nathan Rutman committed
	$LCTL --device $mdcdev recover
	df $MOUNT
    done
komaln's avatar
komaln committed
    do_facet $SINGLEMDS "lctl set_param fail_loc=0"
Nathan Rutman's avatar
Nathan Rutman committed
    return 0
}
run_test 44b "race in target handle connect"

# Handle failed close
test_45() {
komaln's avatar
komaln committed
    mdcdev=`lctl get_param -n devices | awk '/MDT0000-mdc-/ {print $1}'`
Nathan Rutman's avatar
Nathan Rutman committed
    [ "$mdcdev" ] || exit 2
    $LCTL --device $mdcdev recover

    multiop_bg_pause $DIR/$tfile O_c || return 1
Bobi Jam's avatar
Bobi Jam committed
    # This will cause the CLOSE to fail before even
    # allocating a reply buffer
Nathan Rutman's avatar
Nathan Rutman committed
    $LCTL --device $mdcdev deactivate || return 4

    # try the close
    kill -USR1 $pid
    wait $pid || return 1

Nathan Rutman's avatar
Nathan Rutman committed
    $LCTL --device $mdcdev activate || return 5
Yury Umanets's avatar
Yury Umanets committed
    sleep 1

    $CHECKSTAT -t file $DIR/$tfile || return 2
    return 0
}
run_test 45 "Handle failed close"

test_46() {
    dmesg -c >/dev/null
    drop_reply "touch $DIR/$tfile"
    fail $SINGLEMDS
    # ironically, the previous test, 45, will cause a real forced close,
    # so just look for one for this test
    dmesg | grep -i "force closing client file handle for $tfile" && return 1
    return 0