nvmf: Add states to spdk_nvmf_qpair

Change-Id: Ie37e0173f9c1b6fc766a154191df7d0bfa71042b
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.gerrithub.io/412077
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Changpeng Liu <changpeng.liu@intel.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Ben Walker 2018-05-22 10:07:43 -07:00 committed by Jim Harris
parent 4a8b3adb44
commit f14189b9a6
4 changed files with 40 additions and 3 deletions

View File

@ -426,6 +426,9 @@ _spdk_nvmf_qpair_destroy(void *ctx)
{ {
struct spdk_nvmf_qpair *qpair = ctx; struct spdk_nvmf_qpair *qpair = ctx;
assert(qpair->state == SPDK_NVMF_QPAIR_DEACTIVATING);
qpair->state = SPDK_NVMF_QPAIR_INACTIVE;
spdk_nvmf_transport_qpair_fini(qpair); spdk_nvmf_transport_qpair_fini(qpair);
} }
@ -452,17 +455,21 @@ _spdk_nvmf_ctrlr_remove_qpair(void *ctx)
} }
} }
void static void
spdk_nvmf_ctrlr_disconnect(struct spdk_nvmf_qpair *qpair) _spdk_nvmf_qpair_deactivate(void *ctx)
{ {
struct spdk_nvmf_qpair *qpair = ctx;
struct spdk_nvmf_ctrlr *ctrlr; struct spdk_nvmf_ctrlr *ctrlr;
assert(qpair->state == SPDK_NVMF_QPAIR_ACTIVE);
qpair->state = SPDK_NVMF_QPAIR_DEACTIVATING;
ctrlr = qpair->ctrlr; ctrlr = qpair->ctrlr;
if (ctrlr == NULL) { if (ctrlr == NULL) {
/* This qpair was never added to a controller. Skip a step /* This qpair was never added to a controller. Skip a step
* and destroy it immediately. */ * and destroy it immediately. */
spdk_thread_send_msg(qpair->group->thread, _spdk_nvmf_qpair_destroy, qpair); _spdk_nvmf_qpair_destroy(qpair);
return; return;
} }
@ -471,6 +478,13 @@ spdk_nvmf_ctrlr_disconnect(struct spdk_nvmf_qpair *qpair)
spdk_thread_send_msg(ctrlr->admin_qpair->group->thread, _spdk_nvmf_ctrlr_remove_qpair, qpair); spdk_thread_send_msg(ctrlr->admin_qpair->group->thread, _spdk_nvmf_ctrlr_remove_qpair, qpair);
} }
void
spdk_nvmf_ctrlr_disconnect(struct spdk_nvmf_qpair *qpair)
{
/* Send a message to the thread that owns this qpair */
spdk_thread_send_msg(qpair->group->thread, _spdk_nvmf_qpair_deactivate, qpair);
}
struct spdk_nvmf_qpair * struct spdk_nvmf_qpair *
spdk_nvmf_ctrlr_get_qpair(struct spdk_nvmf_ctrlr *ctrlr, uint16_t qid) spdk_nvmf_ctrlr_get_qpair(struct spdk_nvmf_ctrlr *ctrlr, uint16_t qid)
{ {

View File

@ -385,6 +385,7 @@ spdk_nvmf_poll_group_add(struct spdk_nvmf_poll_group *group,
TAILQ_INIT(&qpair->outstanding); TAILQ_INIT(&qpair->outstanding);
qpair->group = group; qpair->group = group;
qpair->state = SPDK_NVMF_QPAIR_ACTIVATING;
TAILQ_FOREACH(tgroup, &group->tgroups, link) { TAILQ_FOREACH(tgroup, &group->tgroups, link) {
if (tgroup->transport == qpair->transport) { if (tgroup->transport == qpair->transport) {
@ -393,6 +394,12 @@ spdk_nvmf_poll_group_add(struct spdk_nvmf_poll_group *group,
} }
} }
if (rc == 0) {
qpair->state = SPDK_NVMF_QPAIR_ACTIVE;
} else {
qpair->state = SPDK_NVMF_QPAIR_INACTIVE;
}
return rc; return rc;
} }

View File

@ -56,6 +56,13 @@ enum spdk_nvmf_subsystem_state {
SPDK_NVMF_SUBSYSTEM_DEACTIVATING, SPDK_NVMF_SUBSYSTEM_DEACTIVATING,
}; };
enum spdk_nvmf_qpair_state {
SPDK_NVMF_QPAIR_INACTIVE = 0,
SPDK_NVMF_QPAIR_ACTIVATING,
SPDK_NVMF_QPAIR_ACTIVE,
SPDK_NVMF_QPAIR_DEACTIVATING,
};
struct spdk_nvmf_tgt { struct spdk_nvmf_tgt {
struct spdk_nvmf_tgt_opts opts; struct spdk_nvmf_tgt_opts opts;
@ -146,6 +153,8 @@ struct spdk_nvmf_ns {
}; };
struct spdk_nvmf_qpair { struct spdk_nvmf_qpair {
enum spdk_nvmf_qpair_state state;
struct spdk_nvmf_transport *transport; struct spdk_nvmf_transport *transport;
struct spdk_nvmf_ctrlr *ctrlr; struct spdk_nvmf_ctrlr *ctrlr;
struct spdk_nvmf_poll_group *group; struct spdk_nvmf_poll_group *group;

View File

@ -119,6 +119,13 @@ spdk_nvmf_request_exec(struct spdk_nvmf_request *req)
nvmf_trace_command(req->cmd, spdk_nvmf_qpair_is_admin_queue(qpair)); nvmf_trace_command(req->cmd, spdk_nvmf_qpair_is_admin_queue(qpair));
if (qpair->state != SPDK_NVMF_QPAIR_ACTIVE) {
req->rsp->nvme_cpl.status.sct = SPDK_NVME_SCT_GENERIC;
req->rsp->nvme_cpl.status.sc = SPDK_NVME_SC_COMMAND_SEQUENCE_ERROR;
spdk_nvmf_request_complete(req);
return;
}
/* Check if the subsystem is paused (if there is a subsystem) */ /* Check if the subsystem is paused (if there is a subsystem) */
if (qpair->ctrlr) { if (qpair->ctrlr) {
struct spdk_nvmf_subsystem_poll_group *sgroup = &qpair->group->sgroups[qpair->ctrlr->subsys->id]; struct spdk_nvmf_subsystem_poll_group *sgroup = &qpair->group->sgroups[qpair->ctrlr->subsys->id];