Commit cf78502e authored by James Simmons's avatar James Simmons Committed by Oleg Drokin
Browse files

LU-10756 ptlrpc: change IMPORT_SET_* macros into real functions



Make the IMPORT_SET_STATE_NOLOCK and IMPORT_SET_STATE macros into
normal functions. Since import_set_state_nolock() is basically a
wrapper around __import_set_state() we can merge both functions.

Change-Id: Idaa6aeb81ff2282e2f83d758a267129e686bd794
Signed-off-by: default avatarJames Simmons <uja.ornl@yahoo.com>
Reviewed-on: https://review.whamcloud.com/35463

Tested-by: default avatarjenkins <devops@whamcloud.com>
Reviewed-by: default avatarNeil Brown <neilb@suse.com>
Tested-by: default avatarMaloo <maloo@whamcloud.com>
Reviewed-by: default avatarBen Evans <bevans@cray.com>
Reviewed-by: default avatarOleg Drokin <green@whamcloud.com>
parent 43d5806f
......@@ -56,10 +56,10 @@ struct ptlrpc_connect_async_args {
/**
* Updates import \a imp current state to provided \a state value
* Helper function. Must be called under imp_lock.
* Helper function.
*/
static void __import_set_state(struct obd_import *imp,
enum lustre_imp_state state)
static void import_set_state_nolock(struct obd_import *imp,
enum lustre_imp_state state)
{
switch (state) {
case LUSTRE_IMP_CLOSED:
......@@ -72,7 +72,20 @@ static void __import_set_state(struct obd_import *imp,
break;
default:
imp->imp_replay_state = LUSTRE_IMP_REPLAY;
break;
}
/* A CLOSED import should remain so. */
if (state == LUSTRE_IMP_CLOSED)
return;
if (imp->imp_state != LUSTRE_IMP_NEW) {
CDEBUG(D_HA, "%p %s: changing import state from %s to %s\n",
imp, obd2cli_tgt(imp->imp_obd),
ptlrpc_import_state_name(imp->imp_state),
ptlrpc_import_state_name(state));
}
imp->imp_state = state;
imp->imp_state_hist[imp->imp_state_hist_idx].ish_state = state;
imp->imp_state_hist[imp->imp_state_hist_idx].ish_time =
......@@ -81,28 +94,17 @@ static void __import_set_state(struct obd_import *imp,
IMP_STATE_HIST_LEN;
}
/* A CLOSED import should remain so. */
#define IMPORT_SET_STATE_NOLOCK(imp, state) \
do { \
if (imp->imp_state != LUSTRE_IMP_CLOSED) { \
CDEBUG(D_HA, "%p %s: changing import state from %s to %s\n", \
imp, obd2cli_tgt(imp->imp_obd), \
ptlrpc_import_state_name(imp->imp_state), \
ptlrpc_import_state_name(state)); \
__import_set_state(imp, state); \
} \
} while(0)
#define IMPORT_SET_STATE(imp, state) \
do { \
spin_lock(&imp->imp_lock); \
IMPORT_SET_STATE_NOLOCK(imp, state); \
spin_unlock(&imp->imp_lock); \
} while(0)
static void import_set_state(struct obd_import *imp,
enum lustre_imp_state new_state)
{
spin_lock(&imp->imp_lock);
import_set_state_nolock(imp, new_state);
spin_unlock(&imp->imp_lock);
}
void ptlrpc_import_enter_resend(struct obd_import *imp)
{
IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
import_set_state(imp, LUSTRE_IMP_RECOVER);
}
EXPORT_SYMBOL(ptlrpc_import_enter_resend);
......@@ -184,7 +186,7 @@ int ptlrpc_set_import_discon(struct obd_import *imp, __u32 conn_cnt)
imp->imp_obd->obd_name, target_len, target_start,
obd_import_nid2str(imp));
}
IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON);
import_set_state_nolock(imp, LUSTRE_IMP_DISCON);
spin_unlock(&imp->imp_lock);
if (obd_dump_on_timeout)
......@@ -682,7 +684,7 @@ int ptlrpc_connect_import(struct obd_import *imp)
RETURN(-EALREADY);
}
IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CONNECTING);
import_set_state_nolock(imp, LUSTRE_IMP_CONNECTING);
imp->imp_conn_cnt++;
imp->imp_resend_replay = 0;
......@@ -789,7 +791,7 @@ int ptlrpc_connect_import(struct obd_import *imp)
rc = 0;
out:
if (rc != 0)
IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON);
import_set_state(imp, LUSTRE_IMP_DISCON);
RETURN(rc);
}
......@@ -1154,9 +1156,9 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
if (msg_flags & MSG_CONNECT_RECOVERING) {
CDEBUG(D_HA, "connect to %s during recovery\n",
obd2cli_tgt(imp->imp_obd));
IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS);
import_set_state(imp, LUSTRE_IMP_REPLAY_LOCKS);
} else {
IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
import_set_state(imp, LUSTRE_IMP_FULL);
ptlrpc_activate_import(imp);
}
......@@ -1215,7 +1217,7 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
*lustre_msg_get_handle(request->rq_repmsg);
if (!(MSG_CONNECT_RECOVERING & msg_flags)) {
IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
import_set_state(imp, LUSTRE_IMP_EVICTED);
GOTO(finish, rc = 0);
}
......@@ -1228,7 +1230,7 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
if (imp->imp_invalid) {
CDEBUG(D_HA, "%s: reconnected but import is invalid; "
"marking evicted\n", imp->imp_obd->obd_name);
IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
import_set_state(imp, LUSTRE_IMP_EVICTED);
} else if (MSG_CONNECT_RECOVERING & msg_flags) {
CDEBUG(D_HA, "%s: reconnected to %s during replay\n",
imp->imp_obd->obd_name,
......@@ -1238,9 +1240,9 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
imp->imp_resend_replay = 1;
spin_unlock(&imp->imp_lock);
IMPORT_SET_STATE(imp, imp->imp_replay_state);
import_set_state(imp, imp->imp_replay_state);
} else {
IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
import_set_state(imp, LUSTRE_IMP_RECOVER);
}
} else if ((MSG_CONNECT_RECOVERING & msg_flags) && !imp->imp_invalid) {
LASSERT(imp->imp_replayable);
......@@ -1248,7 +1250,7 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
*lustre_msg_get_handle(request->rq_repmsg);
imp->imp_last_replay_transno = 0;
imp->imp_replay_cursor = &imp->imp_committed_list;
IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY);
import_set_state(imp, LUSTRE_IMP_REPLAY);
} else if ((ocd->ocd_connect_flags & OBD_CONNECT_LIGHTWEIGHT) != 0 &&
!imp->imp_invalid) {
......@@ -1257,13 +1259,13 @@ static int ptlrpc_connect_interpret(const struct lu_env *env,
imp->imp_obd->obd_name);
imp->imp_remote_handle =
*lustre_msg_get_handle(request->rq_repmsg);
IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
import_set_state(imp, LUSTRE_IMP_RECOVER);
} else {
DEBUG_REQ(D_HA, request, "%s: evicting (reconnect/recover flags"
" not set: %x)", imp->imp_obd->obd_name, msg_flags);
imp->imp_remote_handle =
*lustre_msg_get_handle(request->rq_repmsg);
IMPORT_SET_STATE(imp, LUSTRE_IMP_EVICTED);
import_set_state(imp, LUSTRE_IMP_EVICTED);
}
/* Sanity checks for a reconnected import. */
......@@ -1309,7 +1311,7 @@ out:
class_export_put(exp);
if (rc != 0) {
IMPORT_SET_STATE(imp, LUSTRE_IMP_DISCON);
import_set_state(imp, LUSTRE_IMP_DISCON);
if (rc == -EACCES) {
/*
* Give up trying to reconnect
......@@ -1347,7 +1349,7 @@ out:
OBD_OCD_VERSION_FIX(ocd->ocd_version),
LUSTRE_VERSION_STRING);
ptlrpc_deactivate_import(imp);
IMPORT_SET_STATE(imp, LUSTRE_IMP_CLOSED);
import_set_state(imp, LUSTRE_IMP_CLOSED);
}
RETURN(-EPROTO);
}
......@@ -1450,7 +1452,7 @@ static int ptlrpc_invalidate_import_thread(void *data)
libcfs_debug_dumplog();
}
IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
import_set_state(imp, LUSTRE_IMP_RECOVER);
ptlrpc_import_recovery_state_machine(imp);
class_import_put(imp);
......@@ -1532,7 +1534,7 @@ int ptlrpc_import_recovery_state_machine(struct obd_import *imp)
rc = ptlrpc_replay_next(imp, &inflight);
if (inflight == 0 &&
atomic_read(&imp->imp_replay_inflight) == 0) {
IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_LOCKS);
import_set_state(imp, LUSTRE_IMP_REPLAY_LOCKS);
rc = ldlm_replay_locks(imp);
if (rc)
GOTO(out, rc);
......@@ -1542,7 +1544,7 @@ int ptlrpc_import_recovery_state_machine(struct obd_import *imp)
if (imp->imp_state == LUSTRE_IMP_REPLAY_LOCKS) {
if (atomic_read(&imp->imp_replay_inflight) == 0) {
IMPORT_SET_STATE(imp, LUSTRE_IMP_REPLAY_WAIT);
import_set_state(imp, LUSTRE_IMP_REPLAY_WAIT);
rc = signal_completed_replay(imp);
if (rc)
GOTO(out, rc);
......@@ -1551,7 +1553,7 @@ int ptlrpc_import_recovery_state_machine(struct obd_import *imp)
if (imp->imp_state == LUSTRE_IMP_REPLAY_WAIT) {
if (atomic_read(&imp->imp_replay_inflight) == 0) {
IMPORT_SET_STATE(imp, LUSTRE_IMP_RECOVER);
import_set_state(imp, LUSTRE_IMP_RECOVER);
}
}
......@@ -1561,7 +1563,7 @@ int ptlrpc_import_recovery_state_machine(struct obd_import *imp)
rc = ptlrpc_resend(imp);
if (rc)
GOTO(out, rc);
IMPORT_SET_STATE(imp, LUSTRE_IMP_FULL);
import_set_state(imp, LUSTRE_IMP_FULL);
ptlrpc_activate_import(imp);
LCONSOLE_INFO("%s: Connection restored to %s (at %s)\n",
......@@ -1619,7 +1621,7 @@ static struct ptlrpc_request *ptlrpc_disconnect_prep_req(struct obd_import *imp)
req->rq_timeout = min_t(int, req->rq_timeout,
INITIAL_CONNECT_TIMEOUT);
IMPORT_SET_STATE(imp, LUSTRE_IMP_CONNECTING);
import_set_state(imp, LUSTRE_IMP_CONNECTING);
req->rq_send_state = LUSTRE_IMP_CONNECTING;
ptlrpc_request_set_replen(req);
......@@ -1683,9 +1685,9 @@ set_state:
spin_lock(&imp->imp_lock);
out:
if (noclose)
IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_DISCON);
import_set_state_nolock(imp, LUSTRE_IMP_DISCON);
else
IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CLOSED);
import_set_state_nolock(imp, LUSTRE_IMP_CLOSED);
memset(&imp->imp_remote_handle, 0, sizeof(imp->imp_remote_handle));
spin_unlock(&imp->imp_lock);
......@@ -1736,7 +1738,7 @@ static int ptlrpc_disconnect_idle_interpret(const struct lu_env *env,
if (atomic_read(&imp->imp_inflight) > 1) {
imp->imp_generation++;
imp->imp_initiated_at = imp->imp_generation;
IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_NEW);
import_set_state_nolock(imp, LUSTRE_IMP_NEW);
ptlrpc_reset_reqs_generation(imp);
connect = 1;
}
......@@ -1789,7 +1791,7 @@ void ptlrpc_cleanup_imp(struct obd_import *imp)
ENTRY;
spin_lock(&imp->imp_lock);
IMPORT_SET_STATE_NOLOCK(imp, LUSTRE_IMP_CLOSED);
import_set_state_nolock(imp, LUSTRE_IMP_CLOSED);
imp->imp_generation++;
spin_unlock(&imp->imp_lock);
ptlrpc_abort_inflight(imp);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment