+test_58() { # bug 11546
+#define OBD_FAIL_MDC_ENQUEUE_PAUSE 0x801
+ touch $DIR/$tfile
+ ls -la $DIR/$tfile
+ lctl set_param fail_loc=0x80000801
+ cp $DIR/$tfile /dev/null &
+ pid=$!
+ sleep 1
+ lctl set_param fail_loc=0
+ drop_bl_callback_once rm -f $DIR/$tfile
+ wait $pid
+ # the first 'df' could tigger the eviction caused by
+ # 'drop_bl_callback_once', and it's normal case.
+ # but the next 'df' should return successfully.
+ do_facet client "df $DIR" || do_facet client "df $DIR"
+}
+run_test 58 "Eviction in the middle of open RPC reply processing"
+
+test_59() { # bug 10589
+ zconf_mount `hostname` $MOUNT2 || error "Failed to mount $MOUNT2"
+ echo $DIR2 | grep -q $MOUNT2 || error "DIR2 is not set properly: $DIR2"
+#define OBD_FAIL_LDLM_CANCEL_EVICT_RACE 0x311
+ lctl set_param fail_loc=0x311
+ writes=$(LANG=C dd if=/dev/zero of=$DIR2/$tfile count=1 2>&1)
+ [ $? = 0 ] || error "dd write failed"
+ writes=$(echo $writes | awk -F '+' '/out/ {print $1}')
+ lctl set_param fail_loc=0
+ sync
+ zconf_umount `hostname` $MOUNT2 -f
+ reads=$(LANG=C dd if=$DIR/$tfile of=/dev/null 2>&1)
+ [ $? = 0 ] || error "dd read failed"
+ reads=$(echo $reads | awk -F '+' '/in/ {print $1}')
+ [ "$reads" -eq "$writes" ] || error "read" $reads "blocks, must be" $writes
+}
+run_test 59 "Read cancel race on client eviction"
+
+err17935 () {
+ # we assume that all md changes are in the MDT0 changelog
+ if [ $MDSCOUNT -gt 1 ]; then
+ error_ignore bz17935 $*
+ else
+ error $*
+ fi
+}
+
+test_60() {
+ MDT0=$($LCTL get_param -n mdc.*.mds_server_uuid |
+ awk '{ gsub(/_UUID/,""); print $1 }' | head -n1)
+
+ NUM_FILES=15000
+ mkdir -p $DIR/$tdir
+
+ # Register (and start) changelog
+ USER=$(do_facet $SINGLEMDS lctl --device $MDT0 changelog_register -n)
+ echo "Registered as $MDT0 changelog user $USER"
+
+ # Generate a large number of changelog entries
+ createmany -o $DIR/$tdir/$tfile $NUM_FILES
+ sync
+ sleep 5
+
+ # Unlink files in the background
+ unlinkmany $DIR/$tdir/$tfile $NUM_FILES &
+ CLIENT_PID=$!
+ sleep 1
+
+ # Failover the MDS while unlinks are happening
+ facet_failover $SINGLEMDS
+
+ # Wait for unlinkmany to finish
+ wait $CLIENT_PID
+
+ # Check if all the create/unlink events were recorded
+ # in the changelog
+ $LFS changelog $MDT0 >> $DIR/$tdir/changelog
+ local cl_count=$(grep UNLNK $DIR/$tdir/changelog | wc -l)
+ echo "$cl_count unlinks in $MDT0 changelog"
+
+ do_facet $SINGLEMDS lctl --device $MDT0 changelog_deregister $USER
+ USERS=$(( $(do_facet $SINGLEMDS lctl get_param -n \
+ mdd.$MDT0.changelog_users | wc -l) - 2 ))
+ if [ $USERS -eq 0 ]; then
+ [ $cl_count -eq $NUM_FILES ] || \
+ err17935 "Recorded ${cl_count} unlinks out of $NUM_FILES"
+ # Also make sure we can clear large changelogs
+ cl_count=$($LFS changelog $FSNAME | wc -l)
+ [ $cl_count -le 2 ] || \
+ error "Changelog not empty: $cl_count entries"
+ else
+ # If there are other users, there may be other unlinks in the log
+ [ $cl_count -ge $NUM_FILES ] || \
+ err17935 "Recorded ${cl_count} unlinks out of $NUM_FILES"
+ echo "$USERS other changelog users; can't verify clear"
+ fi
+}
+run_test 60 "Add Changelog entries during MDS failover"
+
+test_61()
+{
+ local mdtosc=$(get_mdtosc_proc_path $SINGLEMDS $FSNAME-OST0000)
+ mdtosc=${mdtosc/-MDT*/-MDT\*}
+ local cflags="osc.$mdtosc.connect_flags"
+ do_facet $SINGLEMDS "lctl get_param -n $cflags" |grep -q skip_orphan
+ [ $? -ne 0 ] && skip "don't have skip orphan feature" && return
+
+ mkdir -p $DIR/$tdir || error "mkdir dir $DIR/$tdir failed"
+ # Set the default stripe of $DIR/$tdir to put the files to ost1
+ $LFS setstripe -c 1 -i 0 $DIR/$tdir
+
+ replay_barrier $SINGLEMDS
+ createmany -o $DIR/$tdir/$tfile-%d 10
+ local oid=$(do_facet ost1 "lctl get_param -n \
+ obdfilter.${ost1_svc}.last_id" | sed -e 's/.*://')
+
+ fail_abort $SINGLEMDS
+
+ touch $DIR/$tdir/$tfile
+ local id=$($LFS getstripe $DIR/$tdir/$tfile |
+ awk '$1 == 0 { print $2 }')
+ [ $id -le $oid ] && error "the orphan objid was reused, failed"
+
+ # Cleanup
+ rm -rf $DIR/$tdir
+}
+run_test 61 "Verify to not reuse orphan objects - bug 17025"
+
+# test_62 as seen it b2_1 please do not reuse test_62
+#test_62()
+#{
+# zconf_umount `hostname` $DIR
+# #define OBD_FAIL_PTLRPC_DELAY_IMP_FULL 0x516
+# lctl set_param fail_loc=0x516
+# mount_client $DIR
+#}
+#run_test 62 "Verify connection flags race - bug LU-1716"
+
+test_66()
+{
+ [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.7.51) ]] ||
+ { skip "Need MDS version at least 2.7.51"; return 0; }
+
+ local list=$(comma_list $(osts_nodes))
+
+ # modify dir so that next revalidate would not obtain UPDATE lock
+ touch $DIR
+
+ # drop 1 reply with UPDATE lock
+ mcreate $DIR/$tfile || error "mcreate failed: $?"
+ drop_ldlm_reply_once "stat $DIR/$tfile" &
+ sleep 2
+
+ # make the re-sent lock to sleep
+#define OBD_FAIL_MDS_RESEND 0x136
+ do_nodes $list $LCTL set_param fail_loc=0x80000136
+
+ #initiate the re-connect & re-send
+ local mdccli=$($LCTL dl | awk '/-mdc-/ {print $4;}')
+ local conn_uuid=$($LCTL get_param -n mdc.${mdccli}.mds_conn_uuid)
+ $LCTL set_param "mdc.${mdccli}.import=connection=${conn_uuid}"
+ sleep 2
+
+ #initiate the client eviction while enqueue re-send is in progress
+ mds_evict_client
+
+ client_reconnect
+ wait
+}
+run_test 66 "lock enqueue re-send vs client eviction"
+
+test_65() {
+ mount_client $DIR2
+
+ #grant lock1, export2
+ $SETSTRIPE -i -0 $DIR2/$tfile || return 1
+ $MULTIOP $DIR2/$tfile Ow || return 2
+
+#define OBD_FAIL_LDLM_BL_EVICT 0x31e
+ do_facet ost $LCTL set_param fail_loc=0x31e
+ #get waiting lock2, export1
+ $MULTIOP $DIR/$tfile Ow &
+ PID1=$!
+ # let enqueue to get asleep
+ sleep 2
+
+ #get lock2 blocked
+ $MULTIOP $DIR2/$tfile Ow &
+ PID2=$!
+ sleep 2
+
+ #evict export1
+ ost_evict_client
+
+ sleep 2
+ do_facet ost $LCTL set_param fail_loc=0
+
+ wait $PID1
+ wait $PID2
+
+ umount_client $DIR2
+}
+run_test 65 "lock enqueue for destroyed export"
+
+check_cli_ir_state()
+{
+ local NODE=${1:-$HOSTNAME}
+ local st
+ st=$(do_node $NODE "lctl get_param mgc.*.ir_state |
+ awk '/imperative_recovery:/ { print \\\$2}'")
+ [ $st != ON -o $st != OFF -o $st != ENABLED -o $st != DISABLED ] ||
+ error "Error state $st, must be ENABLED or DISABLED"
+ echo -n $st
+}
+
+check_target_ir_state()
+{
+ local target=${1}
+ local name=${target}_svc
+ local recovery_proc=obdfilter.${!name}.recovery_status
+ local st
+
+ st=$(do_facet $target "lctl get_param -n $recovery_proc |
+ awk '/IR:/{ print \\\$2}'")
+ [ $st != ON -o $st != OFF -o $st != ENABLED -o $st != DISABLED ] ||
+ error "Error state $st, must be ENABLED or DISABLED"
+ echo -n $st
+}
+
+set_ir_status()
+{
+ do_facet mgs lctl set_param -n mgs.MGS.live.$FSNAME="state=$1"
+}
+
+get_ir_status()
+{
+ local state=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
+ awk '/state:/{ print \\\$2 }'")
+ echo -n ${state/,/}
+}
+
+nidtbl_version_mgs()
+{
+ local ver=$(do_facet mgs "lctl get_param -n mgs.MGS.live.$FSNAME |
+ awk '/nidtbl_version:/{ print \\\$2 }'")
+ echo -n $ver
+}
+
+# nidtbl_version_client <mds1|client> [node]
+nidtbl_version_client()
+{
+ local cli=$1
+ local node=${2:-$HOSTNAME}
+
+ if [ X$cli = Xclient ]; then
+ cli=$FSNAME-client
+ else
+ local obdtype=${cli/%[0-9]*/}
+ [ $obdtype != mds ] && error "wrong parameters $cli"
+
+ node=$(facet_active_host $cli)
+ local t=${cli}_svc
+ cli=${!t}
+ fi
+
+ local vers=$(do_node $node "lctl get_param -n mgc.*.ir_state" |
+ awk "/$cli/{print \$6}" |sort -u)
+
+ # in case there are multiple mounts on the client node
+ local arr=($vers)
+ [ ${#arr[@]} -ne 1 ] && error "versions on client node mismatch"
+ echo -n $vers
+}
+
+nidtbl_versions_match()
+{
+ [ $(nidtbl_version_mgs) -eq $(nidtbl_version_client ${1:-client}) ]
+}
+
+target_instance_match()
+{
+ local srv=$1
+ local obdtype
+ local cliname
+
+ obdtype=${srv/%[0-9]*/}
+ case $obdtype in
+ mds)
+ obdname="mdt"
+ cliname="mdc"
+ ;;
+ ost)
+ obdname="obdfilter"
+ cliname="osc"
+ ;;
+ *)
+ error "invalid target type" $srv
+ return 1
+ ;;
+ esac
+
+ local target=${srv}_svc
+ local si=$(do_facet $srv lctl get_param -n $obdname.${!target}.instance)
+ local ci=$(lctl get_param -n $cliname.${!target}-${cliname}-*.import |
+ awk '/instance/{ print $2 }' | head -n1)
+
+ return $([ $si -eq $ci ])
+}
+
+test_100()
+{
+ do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
+ { skip "MGS without IR support"; return 0; }
+
+ # MDT was just restarted in the previous test, make sure everything
+ # is all set.
+ local cnt=30
+ while [ $cnt -gt 0 ]; do
+ nidtbl_versions_match && break
+ sleep 1
+ cnt=$((cnt - 1))
+ done
+
+ # disable IR
+ set_ir_status disabled
+
+ local prev_ver=$(nidtbl_version_client client)
+
+ local saved_FAILURE_MODE=$FAILURE_MODE
+ [ $(facet_host mgs) = $(facet_host ost1) ] && FAILURE_MODE="SOFT"
+ fail ost1
+
+ # valid check
+ [ $(nidtbl_version_client client) -eq $prev_ver ] ||
+ error "version must not change due to IR disabled"
+ target_instance_match ost1 || error "instance mismatch"
+
+ # restore env
+ set_ir_status full
+ FAILURE_MODE=$saved_FAILURE_MODE
+}
+run_test 100 "IR: Make sure normal recovery still works w/o IR"
+
+test_101()
+{
+ do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
+ { skip "MGS without IR support"; return 0; }
+
+ set_ir_status full
+
+ local OST1_IMP=$(get_osc_import_name client ost1)
+
+ # disable pinger recovery
+ lctl set_param -n osc.$OST1_IMP.pinger_recov=0
+
+ fail ost1
+
+ target_instance_match ost1 || error "instance mismatch"
+ nidtbl_versions_match || error "version must match"
+
+ lctl set_param -n osc.$OST1_IMP.pinger_recov=1
+}
+run_test 101 "IR: Make sure IR works w/o normal recovery"
+
+test_102()
+{
+ do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
+ { skip "MGS without IR support"; return 0; }
+
+ local clients=${CLIENTS:-$HOSTNAME}
+ local old_version
+ local new_version
+ local mgsdev=mgs
+
+ set_ir_status full
+
+ # let's have a new nidtbl version
+ fail ost1
+
+ # sleep for a while so that clients can see the failure of ost
+ # it must be MGC_TIMEOUT_MIN_SECONDS + MGC_TIMEOUT_RAND_CENTISEC.
+ # int mgc_request.c:
+ # define MGC_TIMEOUT_MIN_SECONDS 5
+ # define MGC_TIMEOUT_RAND_CENTISEC 0x1ff /* ~500 *
+ local count=30 # 20 seconds at most
+ while [ $count -gt 0 ]; do
+ nidtbl_versions_match && break
+ sleep 1
+ count=$((count-1))
+ done
+
+ nidtbl_versions_match || error "nidtbl mismatch"
+
+ # get the version #
+ old_version=$(nidtbl_version_client client)
+
+ zconf_umount_clients $clients $MOUNT || error "Cannot umount client"
+
+ # restart mgs
+ combined_mgs_mds && mgsdev=mds1
+ remount_facet $mgsdev
+ fail ost1
+
+ zconf_mount_clients $clients $MOUNT || error "Cannot mount client"
+
+ # check new version
+ new_version=$(nidtbl_version_client client)
+ [ $new_version -lt $old_version ] &&
+ error "nidtbl version wrong after mgs restarts"
+ return 0
+}
+run_test 102 "IR: New client gets updated nidtbl after MGS restart"
+
+test_103()
+{
+ do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
+ { skip "MGS without IR support"; return 0; }
+
+ combined_mgs_mds && skip "mgs and mds on the same target" && return 0
+
+ # workaround solution to generate config log on the mds
+ remount_facet mds1
+
+ stop mgs
+ stop mds1
+
+ # We need this test because mds is like a client in IR context.
+ start mds1 $(mdsdevname 1) $MDS_MOUNT_OPTS ||
+ error "MDS should start w/o mgs"
+
+ # start mgs and remount mds w/ ir
+ start mgs $(mgsdevname) $MGS_MOUNT_OPTS
+ clients_up
+
+ # remount client so that fsdb will be created on the MGS
+ umount_client $MOUNT || error "umount failed"
+ mount_client $MOUNT || error "mount failed"
+
+ # sleep 30 seconds so the MDS has a chance to detect MGS restarting
+ local count=30
+ while [ $count -gt 0 ]; do
+ [ $(nidtbl_version_client mds1) -ne 0 ] && break
+ sleep 1
+ count=$((count-1))
+ done
+
+ # after a while, mds should be able to reconnect to mgs and fetch
+ # up-to-date nidtbl version
+ nidtbl_versions_match mds1 || error "mds nidtbl mismatch"
+
+ # reset everything
+ set_ir_status full
+}
+run_test 103 "IR: MDS can start w/o MGS and get updated nidtbl later"
+
+test_104()
+{
+ do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
+ { skip "MGS without IR support"; return 0; }
+
+ set_ir_status full
+
+ stop ost1
+ start ost1 $(ostdevname 1) "$OST_MOUNT_OPTS -onoir" ||
+ error "OST1 cannot start"
+ clients_up
+
+ local ir_state=$(check_target_ir_state ost1)
+ [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
+ error "ir status on ost1 should be DISABLED"
+}
+run_test 104 "IR: ost can disable IR voluntarily"
+
+test_105()
+{
+ [ -z "$RCLIENTS" ] && skip "Needs multiple clients" && return 0
+ do_facet mgs $LCTL list_param mgs.*.ir_timeout ||
+ { skip "MGS without IR support"; return 0; }
+
+ set_ir_status full
+
+ # get one of the clients from client list
+ local rcli=$(echo $RCLIENTS |cut -d' ' -f 1)
+
+ local mount_opts=${MOUNT_OPTS:+$MOUNT_OPTS,}noir
+ zconf_umount $rcli $MOUNT || error "umount failed"
+ zconf_mount $rcli $MOUNT $mount_opts || error "mount failed"
+
+ # make sure lustre mount at $rcli disabling IR
+ local ir_state=$(check_cli_ir_state $rcli)
+ [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
+ error "IR state must be DISABLED at $rcli"
+
+ # Since the client just mounted, its last_rcvd entry is not on disk.
+ # Send an RPC so exp_need_sync forces last_rcvd to commit this export
+ # so the client can reconnect during OST recovery (LU-924, LU-1582)
+ $SETSTRIPE -i 0 $DIR/$tfile
+ dd if=/dev/zero of=$DIR/$tfile bs=1M count=1 conv=sync
+
+ # make sure MGS's state is Partial
+ [ $(get_ir_status) = "partial" ] || error "MGS IR state must be partial"
+
+ fail ost1
+ # make sure IR on ost1 is DISABLED
+ local ir_state=$(check_target_ir_state ost1)
+ [ $ir_state = "DISABLED" -o $ir_state = "OFF" ] ||
+ error "IR status on ost1 should be DISABLED"
+
+ # remount with the default MOUNT_OPTS
+ zconf_umount $rcli $MOUNT || error "umount failed"
+ zconf_mount $rcli $MOUNT || error "mount failed"
+
+ # make sure MGS's state is full
+ [ $(get_ir_status) = "full" ] || error "MGS IR status must be full"
+
+ fail ost1
+ # make sure IR on ost1 is ENABLED
+ local ir_state=$(check_target_ir_state ost1)
+ [ $ir_state = "ENABLED" -o $ir_state = "ON" ] ||
+ error "IR status on ost1 should be ENABLED"
+
+ return 0
+}
+run_test 105 "IR: NON IR clients support"
+
+cleanup_106() {
+ trap 0
+ umount_client $DIR2
+ debugrestore
+}
+
+test_106() { # LU-1789
+ [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.50) ]] ||
+ { skip "Need MDS version at least 2.3.50"; return 0; }
+
+#define OBD_FAIL_MDC_LIGHTWEIGHT 0x805
+ $LCTL set_param fail_loc=0x805
+
+ debugsave
+ trap cleanup_106 EXIT
+
+ # enable lightweight flag on mdc connection
+ mount_client $DIR2
+
+ local MDS_NEXP=$(do_facet $SINGLEMDS \
+ lctl get_param -n mdt.${mds1_svc}.num_exports |
+ cut -d' ' -f2)
+ $LCTL set_param fail_loc=0
+
+ touch $DIR2/$tfile || error "failed to create empty file"
+ replay_barrier $SINGLEMDS
+
+ $LCTL set_param debug=console
+ $LCTL clear
+ facet_failover $SINGLEMDS
+
+ # lightweight connection must be evicted
+ touch -c $DIR2/$tfile || true
+ $LCTL dk $TMP/lustre-log-$TESTNAME.log
+ evicted=`awk '/This client was evicted by .*MDT0000/ {
+ print;
+ }' $TMP/lustre-log-$TESTNAME.log`
+ [ -z "$evicted" ] && error "lightweight client not evicted by mds"
+
+ # and all operations performed by lightweight client should be
+ # synchronous, so the file created before mds restart should be there
+ $CHECKSTAT -t file $DIR/$tfile || error "file not present"
+ rm -f $DIR/$tfile
+
+ cleanup_106
+}
+run_test 106 "lightweight connection support"
+
+test_107 () {
+ local CLIENT_PID
+ local close_pid
+
+ mkdir -p $DIR/$tdir
+ # OBD_FAIL_MDS_REINT_NET_REP 0x119
+ do_facet $SINGLEMDS lctl set_param fail_loc=0x119
+ multiop $DIR/$tdir D_c &
+ close_pid=$!
+ mkdir $DIR/$tdir/dir_106 &
+ CLIENT_PID=$!
+ do_facet $SINGLEMDS lctl set_param fail_loc=0
+ fail $SINGLEMDS
+
+ wait $CLIENT_PID || rc=$?
+ checkstat -t dir $DIR/$tdir/dir_106 || return 1
+
+ kill -USR1 $close_pid
+ wait $close_pid || return 2
+
+ return $rc
+}
+run_test 107 "drop reint reply, then restart MDT"
+
+test_108() {
+ mkdir -p $DIR/$tdir
+ $SETSTRIPE -c 1 -i 0 $DIR/$tdir
+
+ dd if=/dev/zero of=$DIR/$tdir/$tfile bs=1M count=256 &
+ local dd_pid=$!
+ sleep 0.1
+
+ ost_evict_client
+
+ wait $dd_pid
+
+ client_up || error "reconnect failed"
+ rm -f $DIR/$tdir/$tfile
+}
+run_test 108 "client eviction don't crash"
+
+test_110a () {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+ local remote_dir=$DIR/$tdir/remote_dir
+ local MDTIDX=1
+ local num
+
+ #prepare for 110 test, which need set striped dir on remote MDT.
+ for num in $(seq $MDSCOUNT); do
+ do_facet mds$num \
+ lctl set_param -n mdt.${FSNAME}*.enable_remote_dir=1 \
+ 2>/dev/null
+ done
+
+ mkdir -p $DIR/$tdir
+ drop_request "$LFS mkdir -i $MDTIDX -c2 $remote_dir" ||
+ error "lfs mkdir failed"
+ local diridx=$($GETSTRIPE -M $remote_dir)
+ [ $diridx -eq $MDTIDX ] || error "$diridx != $MDTIDX"
+
+ rm -rf $DIR/$tdir || error "rmdir failed"
+}
+run_test 110a "create remote directory: drop client req"
+
+test_110b () {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+ local remote_dir=$DIR/$tdir/remote_dir
+ local MDTIDX=1
+
+ mkdir -p $DIR/$tdir
+ drop_reint_reply "$LFS mkdir -i $MDTIDX -c2 $remote_dir" ||
+ error "lfs mkdir failed"
+
+ diridx=$($GETSTRIPE -M $remote_dir)
+ [ $diridx -eq $MDTIDX ] || error "$diridx != $MDTIDX"
+
+ rm -rf $DIR/$tdir || error "rmdir failed"
+}
+run_test 110b "create remote directory: drop Master rep"
+
+test_110c () {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+ local remote_dir=$DIR/$tdir/remote_dir
+ local MDTIDX=1
+
+ mkdir -p $DIR/$tdir
+ drop_update_reply $MDTIDX "$LFS mkdir -i $MDTIDX -c2 $remote_dir" ||
+ error "lfs mkdir failed"
+
+ diridx=$($GETSTRIPE -M $remote_dir)
+ [ $diridx -eq $MDTIDX ] || error "$diridx != $MDTIDX"
+
+ rm -rf $DIR/$tdir || error "rmdir failed"
+}
+run_test 110c "create remote directory: drop update rep on slave MDT"
+
+test_110d () {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+ local remote_dir=$DIR/$tdir/remote_dir
+ local MDTIDX=1
+
+ mkdir -p $DIR/$tdir
+ $LFS mkdir -i $MDTIDX -c2 $remote_dir || error "lfs mkdir failed"
+
+ drop_request "rm -rf $remote_dir" || error "rm remote dir failed"
+
+ rm -rf $DIR/$tdir || error "rmdir failed"
+
+ return 0
+}
+run_test 110d "remove remote directory: drop client req"
+
+test_110e () {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+ local remote_dir=$DIR/$tdir/remote_dir
+ local MDTIDX=1
+
+ mkdir -p $DIR/$tdir
+ $LFS mkdir -i $MDTIDX -c2 $remote_dir || error "lfs mkdir failed"
+ drop_reint_reply "rm -rf $remote_dir" || error "rm remote dir failed"
+
+ rm -rf $DIR/$tdir || error "rmdir failed"
+
+ return 0
+}
+run_test 110e "remove remote directory: drop master rep"
+
+test_110f () {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+ local remote_dir=$DIR/$tdir/remote_dir
+ local MDTIDX=1
+
+ mkdir -p $DIR/$tdir
+ $LFS mkdir -i $MDTIDX -c2 $remote_dir || error "lfs mkdir failed"
+ drop_update_reply $MDTIDX "rm -rf $remote_dir" ||
+ error "rm remote dir failed"
+
+ rm -rf $DIR/$tdir || error "rmdir failed"
+}
+run_test 110f "remove remote directory: drop slave rep"
+
+test_110g () {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+ local remote_dir=$DIR/$tdir/remote_dir
+ local MDTIDX=1
+
+ mkdir -p $remote_dir
+
+ createmany -o $remote_dir/f 100
+
+ #define OBD_FAIL_MIGRATE_NET_REP 0x1702
+ do_facet mds$MDTIDX lctl set_param fail_loc=0x1702
+ $LFS migrate -m $MDTIDX $remote_dir || error "migrate failed"
+ do_facet mds$MDTIDX lctl set_param fail_loc=0x0
+
+ for file in $(find $remote_dir); do
+ mdt_index=$($LFS getstripe -M $file)
+ [ $mdt_index == $MDTIDX ] ||
+ error "$file is not on MDT${MDTIDX}"
+ done
+
+ rm -rf $DIR/$tdir || error "rmdir failed"
+}
+run_test 110g "drop reply during migration"
+
+test_110h () {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+ local src_dir=$DIR/$tdir/source_dir
+ local tgt_dir=$DIR/$tdir/target_dir
+ local MDTIDX=1
+
+ mkdir -p $src_dir
+ $LFS mkdir -i $MDTIDX $tgt_dir
+
+ dd if=/etc/hosts of=$src_dir/src_file
+ touch $tgt_dir/tgt_file
+ drop_update_reply $MDTIDX \
+ "mrename $src_dir/src_file $tgt_dir/tgt_file" ||
+ error "mrename failed"
+
+ $CHECKSTAT -t file $src_dir/src_file &&
+ error "src_file present after rename"
+
+ diff /etc/hosts $tgt_dir/tgt_file ||
+ error "file changed after rename"
+
+}
+run_test 110h "drop update reply during cross-MDT file rename"
+
+test_110i () {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+ local src_dir=$DIR/$tdir/source_dir
+ local tgt_dir=$DIR/$tdir/target_dir
+ local MDTIDX=1
+
+ mkdir -p $src_dir
+ $LFS mkdir -i $MDTIDX $tgt_dir
+
+ mkdir $src_dir/src_dir
+ touch $src_dir/src_dir/a
+ mkdir $tgt_dir/tgt_dir
+ drop_update_reply $MDTIDX \
+ "mrename $src_dir/src_dir $tgt_dir/tgt_dir" ||
+ error "mrename failed"
+
+ $CHECKSTAT -t dir $src_dir/src_dir &&
+ error "src_dir present after rename"
+
+ $CHECKSTAT -t dir $tgt_dir/tgt_dir ||
+ error "tgt_dir not present after rename"
+
+ $CHECKSTAT -t file $tgt_dir/tgt_dir/a ||
+ error "a not present after rename"
+}
+run_test 110i "drop update reply during cross-MDT dir rename"
+
+test_110j () {
+ [ $MDSCOUNT -lt 2 ] && skip "needs >= 2 MDTs" && return 0
+ local remote_dir=$DIR/$tdir/remote_dir
+ local local_dir=$DIR/$tdir/local_dir
+ local MDTIDX=1
+
+ mkdir -p $DIR/$tdir
+ mkdir $DIR/$tdir/local_dir
+ $LFS mkdir -i $MDTIDX $remote_dir
+
+ touch $local_dir/local_file
+ drop_update_reply $MDTIDX \
+ "ln $local_dir/local_file $remote_dir/remote_file" ||
+ error "ln failed"
+
+ $CHECKSTAT -t file $remote_dir/remote_file ||
+ error "remote not present after ln"
+}
+run_test 110j "drop update reply during cross-MDT ln"
+
+# LU-2844 mdt prepare fail should not cause umount oops
+test_111 ()
+{
+ [[ $(lustre_version_code $SINGLEMDS) -ge $(version_code 2.3.62) ]] ||
+ { skip "Need MDS version at least 2.3.62"; return 0; }
+
+ local mdsdev=$(mdsdevname ${SINGLEMDS//mds/})
+#define OBD_FAIL_MDS_CHANGELOG_INIT 0x151
+ do_facet $SINGLEMDS lctl set_param fail_loc=0x151
+ stop $SINGLEMDS || error "stop MDS failed"
+ start $SINGLEMDS $mdsdev && error "start MDS should fail"
+ do_facet $SINGLEMDS lctl set_param fail_loc=0
+ start $SINGLEMDS $mdsdev || error "start MDS failed"
+}
+run_test 111 "mdd setup fail should not cause umount oops"
+
+# LU-793
+test_112a() {
+ remote_ost_nodsh && skip "remote OST with nodsh" && return 0
+
+ do_facet_random_file client $TMP/$tfile 100K ||
+ error_noexit "Create random file $TMP/$tfile"
+
+ pause_bulk "cp $TMP/$tfile $DIR/$tfile" $TIMEOUT ||
+ error_noexit "Can't pause_bulk copy"
+
+ df $DIR
+ # expect cmp to succeed, client resent bulk
+ cmp $TMP/$tfile $DIR/$tfile ||
+ error_noexit "Wrong data has been written"
+ rm $DIR/$tfile ||
+ error_noexit "Can't remove file"
+ rm $TMP/$tfile
+}
+run_test 112a "bulk resend while orignal request is in progress"
+
+# parameters: fail_loc CMD RC
+test_120_reply() {
+ local PID
+ local PID2
+ local rc=5
+ local fail
+
+ #define OBD_FAIL_LDLM_CP_CB_WAIT2 0x320
+ #define OBD_FAIL_LDLM_CP_CB_WAIT3 0x321
+ #define OBD_FAIL_LDLM_CP_CB_WAIT4 0x322
+ #define OBD_FAIL_LDLM_CP_CB_WAIT5 0x323
+
+ echo
+ echo -n "** FLOCK REPLY vs. EVICTION race, lock $2"
+ [ "$1" = "CLEANUP" ] &&
+ fail=0x80000320 && echo ", $1 cp first"
+ [ "$1" = "REPLY" ] &&
+ fail=0x80000321 && echo ", $1 cp first"
+ [ "$1" = "DEADLOCK CLEANUP" ] &&
+ fail=0x80000322 && echo " DEADLOCK, CLEANUP cp first"
+ [ "$1" = "DEADLOCK REPLY" ] &&
+ fail=0x80000323 && echo " DEADLOCK, REPLY cp first"
+
+ if [ x"$2" = x"get" ]; then
+ #for TEST lock, take a conflict in advance
+ # sleep longer than evictor to not confuse fail_loc: 2+2+4
+ echo "** Taking conflict **"
+ flocks_test 5 set read sleep 10 $DIR/$tfile &
+ PID2=$!
+
+ sleep 2
+ fi
+
+ $LCTL set_param fail_loc=$fail
+
+ flocks_test 5 $2 write $DIR/$tfile &
+ PID=$!
+
+ sleep 2
+ echo "** Evicting and re-connecting client **"
+ mds_evict_client
+
+ client_reconnect
+
+ if [ x"$2" = x"get" ]; then
+ wait $PID2
+ fi
+
+ wait $PID
+ rc=$?
+
+ # check if the return value is allowed
+ [ $rc -eq $3 ] && rc=0
+
+ $LCTL set_param fail_loc=0
+ return $rc
+}
+
+# a lock is taken, unlock vs. cleanup_resource() race for destroying
+# the ORIGINAL lock.
+test_120_destroy()
+{
+ local PID
+
+ flocks_test 5 set write sleep 4 $DIR/$tfile &
+ PID=$!
+ sleep 2
+
+ # let unlock to sleep in CP CB
+ $LCTL set_param fail_loc=$1
+ sleep 4
+
+ # let cleanup to cleep in CP CB
+ mds_evict_client
+
+ client_reconnect
+
+ wait $PID
+ rc=$?
+
+ $LCTL set_param fail_loc=0
+ return $rc
+}
+
+test_120() {
+ flock_is_enabled || { skip "mount w/o flock enabled" && return; }
+ touch $DIR/$tfile
+
+ test_120_reply "CLEANUP" set 5 || error "SET race failed"
+ test_120_reply "CLEANUP" get 5 || error "GET race failed"
+ test_120_reply "CLEANUP" unlock 5 || error "UNLOCK race failed"
+
+ test_120_reply "REPLY" set 5 || error "SET race failed"
+ test_120_reply "REPLY" get 5 || error "GET race failed"
+ test_120_reply "REPLY" unlock 5 || error "UNLOCK race failed"
+
+ # DEADLOCK tests
+ test_120_reply "DEADLOCK CLEANUP" set 5 || error "DEADLOCK race failed"
+ test_120_reply "DEADLOCK REPLY" set 35 || error "DEADLOCK race failed"
+
+ test_120_destroy 0x320 || error "unlock-cleanup race failed"
+}
+run_test 120 "flock race: completion vs. evict"
+
+test_113() {
+ local BEFORE=$(date +%s)
+ local EVICT
+
+ # modify dir so that next revalidate would not obtain UPDATE lock
+ touch $DIR
+
+ # drop 1 reply with UPDATE lock,
+ # resend should not create 2nd lock on server
+ mcreate $DIR/$tfile || error "mcreate failed: $?"
+ drop_ldlm_reply_once "stat $DIR/$tfile" || error "stat failed: $?"
+
+ # 2 BL AST will be sent to client, both must find the same lock,
+ # race them to not get EINVAL for 2nd BL AST
+ #define OBD_FAIL_LDLM_PAUSE_CANCEL2 0x31f
+ $LCTL set_param fail_loc=0x8000031f
+
+ $LCTL set_param ldlm.namespaces.*.early_lock_cancel=0 > /dev/null
+ chmod 0777 $DIR/$tfile || error "chmod failed: $?"
+ $LCTL set_param ldlm.namespaces.*.early_lock_cancel=1 > /dev/null
+
+ # let the client reconnect
+ client_reconnect
+ EVICT=$($LCTL get_param mdc.$FSNAME-MDT*.state |
+ awk -F"[ [,]" '/EVICTED ]$/ { if (mx<$5) {mx=$5;} } END { print mx }')
+
+ [ -z "$EVICT" ] || [[ $EVICT -le $BEFORE ]] || error "eviction happened"
+}
+run_test 113 "ldlm enqueue dropped reply should not cause deadlocks"
+
+complete $SECONDS
+check_and_cleanup_lustre
+exit_status