Commit f14189b9 authored by Ben Walker's avatar Ben Walker Committed by Jim Harris
Browse files

nvmf: Add states to spdk_nvmf_qpair

parent 4a8b3adb
Loading
Loading
Loading
Loading
+17 −3
Original line number Diff line number Diff line
@@ -426,6 +426,9 @@ _spdk_nvmf_qpair_destroy(void *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);
}

@@ -452,17 +455,21 @@ _spdk_nvmf_ctrlr_remove_qpair(void *ctx)
	}
}

void
spdk_nvmf_ctrlr_disconnect(struct spdk_nvmf_qpair *qpair)
static void
_spdk_nvmf_qpair_deactivate(void *ctx)
{
	struct spdk_nvmf_qpair *qpair = ctx;
	struct spdk_nvmf_ctrlr *ctrlr;

	assert(qpair->state == SPDK_NVMF_QPAIR_ACTIVE);
	qpair->state = SPDK_NVMF_QPAIR_DEACTIVATING;

	ctrlr = qpair->ctrlr;

	if (ctrlr == NULL) {
		/* This qpair was never added to a controller. Skip a step
		 * and destroy it immediately. */
		spdk_thread_send_msg(qpair->group->thread, _spdk_nvmf_qpair_destroy, qpair);
		_spdk_nvmf_qpair_destroy(qpair);
		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);
}

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 *
spdk_nvmf_ctrlr_get_qpair(struct spdk_nvmf_ctrlr *ctrlr, uint16_t qid)
{
+7 −0
Original line number Diff line number Diff line
@@ -385,6 +385,7 @@ spdk_nvmf_poll_group_add(struct spdk_nvmf_poll_group *group,

	TAILQ_INIT(&qpair->outstanding);
	qpair->group = group;
	qpair->state = SPDK_NVMF_QPAIR_ACTIVATING;

	TAILQ_FOREACH(tgroup, &group->tgroups, link) {
		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;
}

+9 −0
Original line number Diff line number Diff line
@@ -56,6 +56,13 @@ enum spdk_nvmf_subsystem_state {
	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_opts		opts;

@@ -146,6 +153,8 @@ struct spdk_nvmf_ns {
};

struct spdk_nvmf_qpair {
	enum spdk_nvmf_qpair_state		state;

	struct spdk_nvmf_transport		*transport;
	struct spdk_nvmf_ctrlr			*ctrlr;
	struct spdk_nvmf_poll_group		*group;
+7 −0
Original line number Diff line number Diff line
@@ -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));

	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) */
	if (qpair->ctrlr) {
		struct spdk_nvmf_subsystem_poll_group *sgroup = &qpair->group->sgroups[qpair->ctrlr->subsys->id];