nvmf: Remove the data structure spdk_nvmf_controller.
Change-Id: Ie6e8d0f60abc16216b8c95f12c658ba7cbb3aba0 Signed-off-by: Cunyin Chang <cunyin.chang@intel.com>
This commit is contained in:
parent
1c5093358e
commit
9e501ce2fe
@ -492,9 +492,9 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
|
||||
return -1;
|
||||
}
|
||||
|
||||
subsystem->ctrlr.dev.virtual.ns_count = 0;
|
||||
snprintf(subsystem->ctrlr.dev.virtual.sn, MAX_SN_LEN, "%s", sn);
|
||||
subsystem->ctrlr.ops = &spdk_nvmf_virtual_ctrlr_ops;
|
||||
subsystem->dev.virtual.ns_count = 0;
|
||||
snprintf(subsystem->dev.virtual.sn, MAX_SN_LEN, "%s", sn);
|
||||
subsystem->ops = &spdk_nvmf_virtual_ctrlr_ops;
|
||||
|
||||
for (i = 0; i < MAX_VIRTUAL_NAMESPACE; i++) {
|
||||
val = spdk_conf_section_get_nval(sp, "Namespace", i);
|
||||
|
@ -44,15 +44,15 @@ nvmf_direct_ctrlr_get_data(struct nvmf_session *session)
|
||||
{
|
||||
const struct spdk_nvme_ctrlr_data *cdata;
|
||||
|
||||
cdata = spdk_nvme_ctrlr_get_data(session->subsys->ctrlr.dev.direct.ctrlr);
|
||||
cdata = spdk_nvme_ctrlr_get_data(session->subsys->dev.direct.ctrlr);
|
||||
memcpy(&session->vcdata, cdata, sizeof(struct spdk_nvme_ctrlr_data));
|
||||
}
|
||||
|
||||
static void
|
||||
nvmf_direct_ctrlr_poll_for_completions(struct nvmf_session *session)
|
||||
{
|
||||
spdk_nvme_ctrlr_process_admin_completions(session->subsys->ctrlr.dev.direct.ctrlr);
|
||||
spdk_nvme_qpair_process_completions(session->subsys->ctrlr.dev.direct.io_qpair, 0);
|
||||
spdk_nvme_ctrlr_process_admin_completions(session->subsys->dev.direct.ctrlr);
|
||||
spdk_nvme_qpair_process_completions(session->subsys->dev.direct.io_qpair, 0);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -134,10 +134,10 @@ nvmf_direct_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req)
|
||||
memcpy(req->data, &session->vcdata, sizeof(struct spdk_nvme_ctrlr_data));
|
||||
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
||||
} else if ((cmd->cdw10 & 0xFF) == SPDK_NVME_IDENTIFY_ACTIVE_NS_LIST) {
|
||||
vs = spdk_nvme_ctrlr_get_regs_vs(subsystem->ctrlr.dev.direct.ctrlr);
|
||||
vs = spdk_nvme_ctrlr_get_regs_vs(subsystem->dev.direct.ctrlr);
|
||||
if (vs.raw < SPDK_NVME_VERSION(1, 1, 0)) {
|
||||
/* fill in identify ns list with virtual controller information */
|
||||
rc = nvmf_direct_ctrlr_admin_identify_nslist(subsystem->ctrlr.dev.direct.ctrlr, req);
|
||||
rc = nvmf_direct_ctrlr_admin_identify_nslist(subsystem->dev.direct.ctrlr, req);
|
||||
if (rc < 0) {
|
||||
SPDK_ERRLOG("Invalid Namespace or Format\n");
|
||||
response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
|
||||
@ -210,7 +210,7 @@ nvmf_direct_ctrlr_process_admin_cmd(struct spdk_nvmf_request *req)
|
||||
default:
|
||||
passthrough:
|
||||
SPDK_TRACELOG(SPDK_TRACE_NVMF, "admin_cmd passthrough: opc 0x%02x\n", cmd->opc);
|
||||
rc = spdk_nvme_ctrlr_cmd_admin_raw(subsystem->ctrlr.dev.direct.ctrlr,
|
||||
rc = spdk_nvme_ctrlr_cmd_admin_raw(subsystem->dev.direct.ctrlr,
|
||||
cmd,
|
||||
req->data, req->length,
|
||||
nvmf_direct_ctrlr_complete_cmd,
|
||||
@ -231,8 +231,8 @@ nvmf_direct_ctrlr_process_io_cmd(struct spdk_nvmf_request *req)
|
||||
struct spdk_nvmf_subsystem *subsystem = req->conn->sess->subsys;
|
||||
int rc;
|
||||
|
||||
rc = spdk_nvme_ctrlr_cmd_io_raw(subsystem->ctrlr.dev.direct.ctrlr,
|
||||
subsystem->ctrlr.dev.direct.io_qpair,
|
||||
rc = spdk_nvme_ctrlr_cmd_io_raw(subsystem->dev.direct.ctrlr,
|
||||
subsystem->dev.direct.io_qpair,
|
||||
&req->cmd->nvme_cmd,
|
||||
req->data, req->length,
|
||||
nvmf_direct_ctrlr_complete_cmd,
|
||||
@ -250,8 +250,8 @@ nvmf_direct_ctrlr_process_io_cmd(struct spdk_nvmf_request *req)
|
||||
static void
|
||||
nvmf_direct_ctrlr_detach(struct spdk_nvmf_subsystem *subsystem)
|
||||
{
|
||||
if (subsystem->ctrlr.dev.direct.ctrlr) {
|
||||
spdk_nvme_detach(subsystem->ctrlr.dev.direct.ctrlr);
|
||||
if (subsystem->dev.direct.ctrlr) {
|
||||
spdk_nvme_detach(subsystem->dev.direct.ctrlr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -343,10 +343,10 @@ spdk_nvmf_request_exec(struct spdk_nvmf_request *req)
|
||||
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_DISCOVERY) {
|
||||
status = nvmf_process_discovery_cmd(req);
|
||||
} else {
|
||||
status = session->subsys->ctrlr.ops->process_admin_cmd(req);
|
||||
status = session->subsys->ops->process_admin_cmd(req);
|
||||
}
|
||||
} else {
|
||||
status = session->subsys->ctrlr.ops->process_io_cmd(req);
|
||||
status = session->subsys->ops->process_io_cmd(req);
|
||||
}
|
||||
|
||||
switch (status) {
|
||||
|
@ -88,7 +88,7 @@ nvmf_init_nvme_session_properties(struct nvmf_session *session)
|
||||
assert((g_nvmf_tgt.max_io_size % 4096) == 0);
|
||||
|
||||
/* Init the controller details */
|
||||
session->subsys->ctrlr.ops->ctrlr_get_data(session);
|
||||
session->subsys->ops->ctrlr_get_data(session);
|
||||
|
||||
session->vcdata.aerl = 0;
|
||||
session->vcdata.cntlid = 0;
|
||||
|
@ -85,7 +85,7 @@ spdk_nvmf_subsystem_poll(struct spdk_nvmf_subsystem *subsystem)
|
||||
|
||||
/* For NVMe subsystems, check the backing physical device for completions. */
|
||||
if (subsystem->subtype == SPDK_NVMF_SUBTYPE_NVME) {
|
||||
session->subsys->ctrlr.ops->poll_for_completions(session);
|
||||
session->subsys->ops->poll_for_completions(session);
|
||||
}
|
||||
|
||||
/* For each connection in the session, check for completions */
|
||||
@ -188,8 +188,8 @@ nvmf_delete_subsystem_poller_unreg(struct spdk_event *event)
|
||||
if (subsystem->session) {
|
||||
spdk_nvmf_session_destruct(subsystem->session);
|
||||
}
|
||||
if (subsystem->ctrlr.ops) {
|
||||
subsystem->ctrlr.ops->detach(subsystem);
|
||||
if (subsystem->ops) {
|
||||
subsystem->ops->detach(subsystem);
|
||||
}
|
||||
|
||||
TAILQ_REMOVE(&g_subsystems, subsystem, entries);
|
||||
@ -284,14 +284,14 @@ int
|
||||
nvmf_subsystem_add_ctrlr(struct spdk_nvmf_subsystem *subsystem,
|
||||
struct spdk_nvme_ctrlr *ctrlr)
|
||||
{
|
||||
subsystem->ctrlr.dev.direct.ctrlr = ctrlr;
|
||||
subsystem->dev.direct.ctrlr = ctrlr;
|
||||
/* Assume that all I/O will be handled on one thread for now */
|
||||
subsystem->ctrlr.dev.direct.io_qpair = spdk_nvme_ctrlr_alloc_io_qpair(ctrlr, 0);
|
||||
if (subsystem->ctrlr.dev.direct.io_qpair == NULL) {
|
||||
subsystem->dev.direct.io_qpair = spdk_nvme_ctrlr_alloc_io_qpair(ctrlr, 0);
|
||||
if (subsystem->dev.direct.io_qpair == NULL) {
|
||||
SPDK_ERRLOG("spdk_nvme_ctrlr_alloc_io_qpair() failed\n");
|
||||
return -1;
|
||||
}
|
||||
subsystem->ctrlr.ops = &spdk_nvmf_direct_ctrlr_ops;
|
||||
subsystem->ops = &spdk_nvmf_direct_ctrlr_ops;
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -349,14 +349,14 @@ spdk_nvmf_subsystem_add_ns(struct spdk_nvmf_subsystem *subsystem, struct spdk_bd
|
||||
int i = 0;
|
||||
|
||||
assert(subsystem->mode == NVMF_SUBSYSTEM_MODE_VIRTUAL);
|
||||
while (i < MAX_VIRTUAL_NAMESPACE && subsystem->ctrlr.dev.virtual.ns_list[i]) {
|
||||
while (i < MAX_VIRTUAL_NAMESPACE && subsystem->dev.virtual.ns_list[i]) {
|
||||
i++;
|
||||
}
|
||||
if (i == MAX_VIRTUAL_NAMESPACE) {
|
||||
SPDK_ERRLOG("spdk_nvmf_subsystem_add_ns() failed\n");
|
||||
return -1;
|
||||
}
|
||||
subsystem->ctrlr.dev.virtual.ns_list[i] = bdev;
|
||||
subsystem->ctrlr.dev.virtual.ns_count++;
|
||||
subsystem->dev.virtual.ns_list[i] = bdev;
|
||||
subsystem->dev.virtual.ns_count++;
|
||||
return 0;
|
||||
}
|
||||
|
@ -92,26 +92,6 @@ struct spdk_nvmf_ctrlr_ops {
|
||||
void (*detach)(struct spdk_nvmf_subsystem *subsystem);
|
||||
};
|
||||
|
||||
struct spdk_nvmf_controller {
|
||||
union {
|
||||
struct {
|
||||
struct nvmf_session *session;
|
||||
struct spdk_nvme_ctrlr *ctrlr;
|
||||
struct spdk_nvme_qpair *io_qpair;
|
||||
} direct;
|
||||
|
||||
struct {
|
||||
struct nvmf_session *session;
|
||||
char sn[MAX_SN_LEN + 1];
|
||||
struct spdk_bdev *ns_list[MAX_VIRTUAL_NAMESPACE];
|
||||
uint16_t ns_count;
|
||||
} virtual;
|
||||
} dev;
|
||||
|
||||
const struct spdk_nvmf_ctrlr_ops *ops;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* The NVMf subsystem, as indicated in the specification, is a collection
|
||||
* of virtual controller sessions. Any individual controller session has
|
||||
@ -124,7 +104,21 @@ struct spdk_nvmf_subsystem {
|
||||
enum spdk_nvmf_subsystem_mode mode;
|
||||
enum spdk_nvmf_subtype subtype;
|
||||
struct nvmf_session *session;
|
||||
struct spdk_nvmf_controller ctrlr;
|
||||
|
||||
union {
|
||||
struct {
|
||||
struct spdk_nvme_ctrlr *ctrlr;
|
||||
struct spdk_nvme_qpair *io_qpair;
|
||||
} direct;
|
||||
|
||||
struct {
|
||||
char sn[MAX_SN_LEN + 1];
|
||||
struct spdk_bdev *ns_list[MAX_VIRTUAL_NAMESPACE];
|
||||
uint16_t ns_count;
|
||||
} virtual;
|
||||
} dev;
|
||||
|
||||
const struct spdk_nvmf_ctrlr_ops *ops;
|
||||
|
||||
struct spdk_poller *poller;
|
||||
|
||||
|
@ -62,8 +62,8 @@ static void nvmf_virtual_set_dsm(struct spdk_nvmf_subsystem *subsys)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < subsys->ctrlr.dev.virtual.ns_count; i++) {
|
||||
struct spdk_bdev *bdev = subsys->ctrlr.dev.virtual.ns_list[i];
|
||||
for (i = 0; i < subsys->dev.virtual.ns_count; i++) {
|
||||
struct spdk_bdev *bdev = subsys->dev.virtual.ns_list[i];
|
||||
|
||||
if (!spdk_bdev_io_type_supported(bdev, SPDK_BDEV_IO_TYPE_UNMAP)) {
|
||||
SPDK_TRACELOG(SPDK_TRACE_NVMF,
|
||||
@ -88,7 +88,7 @@ nvmf_virtual_ctrlr_get_data(struct nvmf_session *session)
|
||||
spdk_strcpy_pad(session->vcdata.mn, MODEL_NUMBER, sizeof(session->vcdata.mn), ' ');
|
||||
session->vcdata.vid = 0x8086;
|
||||
session->vcdata.ssvid = 0x8086;
|
||||
spdk_strcpy_pad(session->vcdata.sn, subsys->ctrlr.dev.virtual.sn, sizeof(session->vcdata.sn), ' ');
|
||||
spdk_strcpy_pad(session->vcdata.sn, subsys->dev.virtual.sn, sizeof(session->vcdata.sn), ' ');
|
||||
session->vcdata.rab = 6;
|
||||
session->vcdata.ver.bits.mjr = 1;
|
||||
session->vcdata.ver.bits.mnr = 2;
|
||||
@ -104,7 +104,7 @@ nvmf_virtual_ctrlr_get_data(struct nvmf_session *session)
|
||||
session->vcdata.cqes.min = 0x04;
|
||||
session->vcdata.cqes.max = 0x04;
|
||||
session->vcdata.maxcmd = 1024;
|
||||
session->vcdata.nn = subsys->ctrlr.dev.virtual.ns_count;
|
||||
session->vcdata.nn = subsys->dev.virtual.ns_count;
|
||||
session->vcdata.vwc.present = 1;
|
||||
session->vcdata.sgls.supported = 1;
|
||||
strncpy(session->vcdata.subnqn, session->subsys->subnqn, sizeof(session->vcdata.subnqn));
|
||||
@ -166,20 +166,20 @@ nvmf_virtual_ctrlr_get_log_page(struct spdk_nvmf_request *req)
|
||||
}
|
||||
|
||||
static int
|
||||
identify_ns(struct spdk_nvmf_controller *ctrlr,
|
||||
identify_ns(struct spdk_nvmf_subsystem *subsystem,
|
||||
struct spdk_nvme_cmd *cmd,
|
||||
struct spdk_nvme_cpl *rsp,
|
||||
struct spdk_nvme_ns_data *nsdata)
|
||||
{
|
||||
struct spdk_bdev *bdev;
|
||||
|
||||
if (cmd->nsid > ctrlr->dev.virtual.ns_count || cmd->nsid == 0) {
|
||||
if (cmd->nsid > subsystem->dev.virtual.ns_count || cmd->nsid == 0) {
|
||||
SPDK_ERRLOG("Identify Namespace for invalid NSID %u\n", cmd->nsid);
|
||||
rsp->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
|
||||
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
||||
}
|
||||
|
||||
bdev = ctrlr->dev.virtual.ns_list[cmd->nsid - 1];
|
||||
bdev = subsystem->dev.virtual.ns_list[cmd->nsid - 1];
|
||||
|
||||
nsdata->nsze = bdev->blockcnt;
|
||||
nsdata->ncap = bdev->blockcnt;
|
||||
@ -199,7 +199,7 @@ identify_ctrlr(struct nvmf_session *session, struct spdk_nvme_ctrlr_data *cdata)
|
||||
}
|
||||
|
||||
static int
|
||||
identify_active_ns_list(struct spdk_nvmf_controller *ctrlr,
|
||||
identify_active_ns_list(struct spdk_nvmf_subsystem *subsystem,
|
||||
struct spdk_nvme_cmd *cmd,
|
||||
struct spdk_nvme_cpl *rsp,
|
||||
struct spdk_nvme_ns_list *ns_list)
|
||||
@ -212,7 +212,7 @@ identify_active_ns_list(struct spdk_nvmf_controller *ctrlr,
|
||||
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
||||
}
|
||||
|
||||
num_ns = ctrlr->dev.virtual.ns_count;
|
||||
num_ns = subsystem->dev.virtual.ns_count;
|
||||
|
||||
for (i = 1; i <= num_ns; i++) {
|
||||
if (i <= cmd->nsid) {
|
||||
@ -247,11 +247,11 @@ nvmf_virtual_ctrlr_identify(struct spdk_nvmf_request *req)
|
||||
cns = cmd->cdw10 & 0xFF;
|
||||
switch (cns) {
|
||||
case SPDK_NVME_IDENTIFY_NS:
|
||||
return identify_ns(&subsystem->ctrlr, cmd, rsp, req->data);
|
||||
return identify_ns(subsystem, cmd, rsp, req->data);
|
||||
case SPDK_NVME_IDENTIFY_CTRLR:
|
||||
return identify_ctrlr(session, req->data);
|
||||
case SPDK_NVME_IDENTIFY_ACTIVE_NS_LIST:
|
||||
return identify_active_ns_list(&subsystem->ctrlr, cmd, rsp, req->data);
|
||||
return identify_active_ns_list(subsystem, cmd, rsp, req->data);
|
||||
default:
|
||||
SPDK_ERRLOG("Identify command with unsupported CNS 0x%02x\n", cns);
|
||||
rsp->status.sc = SPDK_NVME_SC_INVALID_FIELD;
|
||||
@ -504,13 +504,13 @@ nvmf_virtual_ctrlr_process_io_cmd(struct spdk_nvmf_request *req)
|
||||
response->status.sc = SPDK_NVME_SC_SUCCESS;
|
||||
nsid = cmd->nsid;
|
||||
|
||||
if (nsid > subsystem->ctrlr.dev.virtual.ns_count || nsid == 0) {
|
||||
if (nsid > subsystem->dev.virtual.ns_count || nsid == 0) {
|
||||
SPDK_ERRLOG("Unsuccessful query for nsid %u\n", cmd->nsid);
|
||||
response->status.sc = SPDK_NVME_SC_INVALID_NAMESPACE_OR_FORMAT;
|
||||
return SPDK_NVMF_REQUEST_EXEC_STATUS_COMPLETE;
|
||||
}
|
||||
|
||||
bdev = subsystem->ctrlr.dev.virtual.ns_list[nsid - 1];
|
||||
bdev = subsystem->dev.virtual.ns_list[nsid - 1];
|
||||
switch (cmd->opc) {
|
||||
case SPDK_NVME_OPC_READ:
|
||||
case SPDK_NVME_OPC_WRITE:
|
||||
|
Loading…
Reference in New Issue
Block a user