nvme: untangle internal enum_cb complexity
Change-Id: I73ddb996a652b78534ce49e5d4e43b269940ec4d Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
parent
b4bd76bc63
commit
16ae39419d
@ -228,31 +228,16 @@ nvme_mutex_init_shared(pthread_mutex_t *mtx)
|
|||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
int
|
||||||
nvme_enum_cb(enum spdk_nvme_transport_type type, struct nvme_enum_usr_ctx *enum_ctx,
|
nvme_probe_one(enum spdk_nvme_transport_type type, spdk_nvme_probe_cb probe_cb, void *cb_ctx,
|
||||||
struct spdk_nvme_probe_info *probe_info, void *devhandle)
|
struct spdk_nvme_probe_info *probe_info, void *devhandle)
|
||||||
{
|
{
|
||||||
struct spdk_nvme_ctrlr *ctrlr;
|
struct spdk_nvme_ctrlr *ctrlr;
|
||||||
struct spdk_nvme_ctrlr_opts opts;
|
struct spdk_nvme_ctrlr_opts opts;
|
||||||
|
|
||||||
/* Verify that this controller is not already attached */
|
|
||||||
TAILQ_FOREACH(ctrlr, &g_spdk_nvme_driver->attached_ctrlrs, tailq) {
|
|
||||||
/* NOTE: In the case like multi-process environment where the device handle is
|
|
||||||
* different per each process, we compare by BDF to determine whether it is the
|
|
||||||
* same controller.
|
|
||||||
*/
|
|
||||||
if (type == SPDK_NVME_TRANSPORT_PCIE) {
|
|
||||||
if (spdk_pci_addr_compare(&probe_info->pci_addr, &ctrlr->probe_info.pci_addr) == 0) {
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Todo: need to differentiate the NVMe over fabrics to avoid duplicated connection */
|
|
||||||
}
|
|
||||||
|
|
||||||
spdk_nvme_ctrlr_opts_set_defaults(&opts);
|
spdk_nvme_ctrlr_opts_set_defaults(&opts);
|
||||||
|
|
||||||
if (enum_ctx->probe_cb(enum_ctx->cb_ctx, probe_info, &opts)) {
|
if (probe_cb(cb_ctx, probe_info, &opts)) {
|
||||||
ctrlr = nvme_attach(type, devhandle);
|
ctrlr = nvme_attach(type, devhandle);
|
||||||
if (ctrlr == NULL) {
|
if (ctrlr == NULL) {
|
||||||
SPDK_ERRLOG("nvme_attach() failed\n");
|
SPDK_ERRLOG("nvme_attach() failed\n");
|
||||||
@ -274,7 +259,6 @@ _spdk_nvme_probe(const struct spdk_nvme_discover_info *info, void *cb_ctx,
|
|||||||
spdk_nvme_remove_cb remove_cb)
|
spdk_nvme_remove_cb remove_cb)
|
||||||
{
|
{
|
||||||
int rc, start_rc;
|
int rc, start_rc;
|
||||||
struct nvme_enum_ctx enum_ctx;
|
|
||||||
struct spdk_nvme_ctrlr *ctrlr, *ctrlr_tmp;
|
struct spdk_nvme_ctrlr *ctrlr, *ctrlr_tmp;
|
||||||
enum spdk_nvme_transport_type type;
|
enum spdk_nvme_transport_type type;
|
||||||
|
|
||||||
@ -296,16 +280,13 @@ _spdk_nvme_probe(const struct spdk_nvme_discover_info *info, void *cb_ctx,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
enum_ctx.usr_ctx.probe_cb = probe_cb;
|
|
||||||
enum_ctx.usr_ctx.cb_ctx = cb_ctx;
|
|
||||||
enum_ctx.enum_cb = nvme_enum_cb;
|
|
||||||
if (!info) {
|
if (!info) {
|
||||||
type = SPDK_NVME_TRANSPORT_PCIE;
|
type = SPDK_NVME_TRANSPORT_PCIE;
|
||||||
} else {
|
} else {
|
||||||
type = info->type;
|
type = info->type;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = nvme_transport_ctrlr_scan(type, &enum_ctx, (void *)info);
|
rc = nvme_transport_ctrlr_scan(type, probe_cb, cb_ctx, (void *)info);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Keep going even if one or more nvme_attach() calls failed,
|
* Keep going even if one or more nvme_attach() calls failed,
|
||||||
|
@ -480,6 +480,9 @@ void nvme_completion_poll_cb(void *arg, const struct spdk_nvme_cpl *cpl);
|
|||||||
int nvme_ctrlr_add_process(struct spdk_nvme_ctrlr *ctrlr, void *devhandle);
|
int nvme_ctrlr_add_process(struct spdk_nvme_ctrlr *ctrlr, void *devhandle);
|
||||||
void nvme_ctrlr_free_processes(struct spdk_nvme_ctrlr *ctrlr);
|
void nvme_ctrlr_free_processes(struct spdk_nvme_ctrlr *ctrlr);
|
||||||
|
|
||||||
|
int nvme_probe_one(enum spdk_nvme_transport_type type, spdk_nvme_probe_cb probe_cb, void *cb_ctx,
|
||||||
|
struct spdk_nvme_probe_info *probe_info, void *devhandle);
|
||||||
|
|
||||||
int nvme_ctrlr_construct(struct spdk_nvme_ctrlr *ctrlr);
|
int nvme_ctrlr_construct(struct spdk_nvme_ctrlr *ctrlr);
|
||||||
void nvme_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr);
|
void nvme_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr);
|
||||||
int nvme_ctrlr_process_init(struct spdk_nvme_ctrlr *ctrlr);
|
int nvme_ctrlr_process_init(struct spdk_nvme_ctrlr *ctrlr);
|
||||||
@ -524,25 +527,11 @@ void nvme_qpair_print_command(struct spdk_nvme_qpair *qpair, struct spdk_nvme_cm
|
|||||||
void nvme_qpair_print_completion(struct spdk_nvme_qpair *qpair, struct spdk_nvme_cpl *cpl);
|
void nvme_qpair_print_completion(struct spdk_nvme_qpair *qpair, struct spdk_nvme_cpl *cpl);
|
||||||
struct spdk_nvme_ctrlr *nvme_attach(enum spdk_nvme_transport_type transport, void *devhandle);
|
struct spdk_nvme_ctrlr *nvme_attach(enum spdk_nvme_transport_type transport, void *devhandle);
|
||||||
|
|
||||||
struct nvme_enum_usr_ctx {
|
|
||||||
spdk_nvme_probe_cb probe_cb;
|
|
||||||
void *cb_ctx;
|
|
||||||
};
|
|
||||||
|
|
||||||
typedef int (*nvme_ctrlr_enum_cb)(enum spdk_nvme_transport_type type,
|
|
||||||
struct nvme_enum_usr_ctx *enum_usr_ctx,
|
|
||||||
struct spdk_nvme_probe_info *probe_info, void *devhandle);
|
|
||||||
|
|
||||||
struct nvme_enum_ctx {
|
|
||||||
struct nvme_enum_usr_ctx usr_ctx;
|
|
||||||
nvme_ctrlr_enum_cb enum_cb;
|
|
||||||
};
|
|
||||||
|
|
||||||
/* Transport specific functions */
|
/* Transport specific functions */
|
||||||
#define DECLARE_TRANSPORT(name) \
|
#define DECLARE_TRANSPORT(name) \
|
||||||
struct spdk_nvme_ctrlr *nvme_ ## name ## _ctrlr_construct(enum spdk_nvme_transport_type transport, void *devhandle); \
|
struct spdk_nvme_ctrlr *nvme_ ## name ## _ctrlr_construct(enum spdk_nvme_transport_type transport, void *devhandle); \
|
||||||
int nvme_ ## name ## _ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr); \
|
int nvme_ ## name ## _ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr); \
|
||||||
int nvme_ ## name ## _ctrlr_scan(enum spdk_nvme_transport_type transport, struct nvme_enum_ctx *enum_ctx, void *devhandle); \
|
int nvme_ ## name ## _ctrlr_scan(enum spdk_nvme_transport_type transport, spdk_nvme_probe_cb probe_cb, void *cb_ctx, void *devhandle); \
|
||||||
int nvme_ ## name ## _ctrlr_enable(struct spdk_nvme_ctrlr *ctrlr); \
|
int nvme_ ## name ## _ctrlr_enable(struct spdk_nvme_ctrlr *ctrlr); \
|
||||||
int nvme_ ## name ## _ctrlr_get_pci_id(struct spdk_nvme_ctrlr *ctrlr, struct spdk_pci_id *pci_id); \
|
int nvme_ ## name ## _ctrlr_get_pci_id(struct spdk_nvme_ctrlr *ctrlr, struct spdk_pci_id *pci_id); \
|
||||||
int nvme_ ## name ## _ctrlr_set_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value); \
|
int nvme_ ## name ## _ctrlr_set_reg_4(struct spdk_nvme_ctrlr *ctrlr, uint32_t offset, uint32_t value); \
|
||||||
|
@ -68,6 +68,10 @@
|
|||||||
*/
|
*/
|
||||||
#define NVME_MAX_XFER_SIZE NVME_MAX_PRP_LIST_ENTRIES * PAGE_SIZE
|
#define NVME_MAX_XFER_SIZE NVME_MAX_PRP_LIST_ENTRIES * PAGE_SIZE
|
||||||
|
|
||||||
|
struct nvme_pcie_enum_ctx {
|
||||||
|
spdk_nvme_probe_cb probe_cb;
|
||||||
|
void *cb_ctx;
|
||||||
|
};
|
||||||
|
|
||||||
/* PCIe transport extensions for spdk_nvme_ctrlr */
|
/* PCIe transport extensions for spdk_nvme_ctrlr */
|
||||||
struct nvme_pcie_ctrlr {
|
struct nvme_pcie_ctrlr {
|
||||||
@ -431,20 +435,37 @@ static int
|
|||||||
pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
|
pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
|
||||||
{
|
{
|
||||||
struct spdk_nvme_probe_info probe_info = {};
|
struct spdk_nvme_probe_info probe_info = {};
|
||||||
struct nvme_enum_ctx *enum_ctx = ctx;
|
struct nvme_pcie_enum_ctx *enum_ctx = ctx;
|
||||||
|
struct spdk_nvme_ctrlr *ctrlr;
|
||||||
|
|
||||||
probe_info.pci_addr = spdk_pci_device_get_addr(pci_dev);
|
probe_info.pci_addr = spdk_pci_device_get_addr(pci_dev);
|
||||||
probe_info.pci_id = spdk_pci_device_get_id(pci_dev);
|
probe_info.pci_id = spdk_pci_device_get_id(pci_dev);
|
||||||
|
|
||||||
return enum_ctx->enum_cb(SPDK_NVME_TRANSPORT_PCIE, &enum_ctx->usr_ctx, &probe_info,
|
/* Verify that this controller is not already attached */
|
||||||
(void *)pci_dev);
|
TAILQ_FOREACH(ctrlr, &g_spdk_nvme_driver->attached_ctrlrs, tailq) {
|
||||||
|
/* NOTE: In the case like multi-process environment where the device handle is
|
||||||
|
* different per each process, we compare by BDF to determine whether it is the
|
||||||
|
* same controller.
|
||||||
|
*/
|
||||||
|
if (spdk_pci_addr_compare(&probe_info.pci_addr, &ctrlr->probe_info.pci_addr) == 0) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return nvme_probe_one(SPDK_NVME_TRANSPORT_PCIE, enum_ctx->probe_cb, enum_ctx->cb_ctx,
|
||||||
|
&probe_info, pci_dev);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
nvme_pcie_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
nvme_pcie_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
||||||
struct nvme_enum_ctx *enum_ctx, void *devhandle)
|
spdk_nvme_probe_cb probe_cb, void *cb_ctx, void *devhandle)
|
||||||
{
|
{
|
||||||
return spdk_pci_enumerate(SPDK_PCI_DEVICE_NVME, pcie_nvme_enum_cb, enum_ctx);
|
struct nvme_pcie_enum_ctx enum_ctx;
|
||||||
|
|
||||||
|
enum_ctx.probe_cb = probe_cb;
|
||||||
|
enum_ctx.cb_ctx = cb_ctx;
|
||||||
|
|
||||||
|
return spdk_pci_enumerate(SPDK_PCI_DEVICE_NVME, pcie_nvme_enum_cb, &enum_ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
struct spdk_nvme_ctrlr *nvme_pcie_ctrlr_construct(enum spdk_nvme_transport_type transport,
|
struct spdk_nvme_ctrlr *nvme_pcie_ctrlr_construct(enum spdk_nvme_transport_type transport,
|
||||||
|
@ -1138,7 +1138,7 @@ nvme_fabrics_get_log_discovery_page(struct spdk_nvme_ctrlr *ctrlr,
|
|||||||
/* This function must only be called while holding g_spdk_nvme_driver->lock */
|
/* This function must only be called while holding g_spdk_nvme_driver->lock */
|
||||||
int
|
int
|
||||||
nvme_rdma_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
nvme_rdma_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
||||||
struct nvme_enum_ctx *enum_ctx, void *devhandle)
|
spdk_nvme_probe_cb probe_cb, void *cb_ctx, void *devhandle)
|
||||||
{
|
{
|
||||||
struct spdk_nvme_discover_info *info = (struct spdk_nvme_discover_info *)devhandle;
|
struct spdk_nvme_discover_info *info = (struct spdk_nvme_discover_info *)devhandle;
|
||||||
struct spdk_nvme_probe_info probe_info;
|
struct spdk_nvme_probe_info probe_info;
|
||||||
@ -1170,7 +1170,8 @@ nvme_rdma_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
|||||||
discover_info.trsvcid = probe_info.trsvcid = (const char *)log_page->entries[i].trsvcid;
|
discover_info.trsvcid = probe_info.trsvcid = (const char *)log_page->entries[i].trsvcid;
|
||||||
SPDK_NOTICELOG("nqn=%s, traddr=%s, trsvcid=%s\n", discover_info.nqn,
|
SPDK_NOTICELOG("nqn=%s, traddr=%s, trsvcid=%s\n", discover_info.nqn,
|
||||||
discover_info.traddr, discover_info.trsvcid);
|
discover_info.traddr, discover_info.trsvcid);
|
||||||
enum_ctx->enum_cb(info->type, &enum_ctx->usr_ctx, &probe_info, (void *)&discover_info);
|
/* Todo: need to differentiate the NVMe over fabrics to avoid duplicated connection */
|
||||||
|
nvme_probe_one(info->type, probe_cb, cb_ctx, &probe_info, (void *)&discover_info);
|
||||||
}
|
}
|
||||||
|
|
||||||
nvme_ctrlr_destruct(discovery_ctrlr);
|
nvme_ctrlr_destruct(discovery_ctrlr);
|
||||||
|
@ -74,9 +74,9 @@ struct spdk_nvme_ctrlr *nvme_transport_ctrlr_construct(enum spdk_nvme_transport_
|
|||||||
|
|
||||||
int
|
int
|
||||||
nvme_transport_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
nvme_transport_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
||||||
struct nvme_enum_ctx *enum_ctx, void *devhandle)
|
spdk_nvme_probe_cb probe_cb, void *cb_ctx, void *devhandle)
|
||||||
{
|
{
|
||||||
NVME_TRANSPORT_CALL(transport, ctrlr_scan, (transport, enum_ctx, devhandle));
|
NVME_TRANSPORT_CALL(transport, ctrlr_scan, (transport, probe_cb, cb_ctx, devhandle));
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
|
@ -65,7 +65,7 @@ struct spdk_nvme_ctrlr *nvme_transport_ctrlr_construct(enum spdk_nvme_transport_
|
|||||||
|
|
||||||
int
|
int
|
||||||
nvme_transport_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
nvme_transport_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
||||||
struct nvme_enum_ctx *enum_ctx, void *devhandle)
|
spdk_nvme_probe_cb probe_cb, void *cb_ctx, void *devhandle)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ nvme_ctrlr_get_ref_count(struct spdk_nvme_ctrlr *ctrlr)
|
|||||||
|
|
||||||
int
|
int
|
||||||
nvme_transport_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
nvme_transport_ctrlr_scan(enum spdk_nvme_transport_type transport,
|
||||||
struct nvme_enum_ctx *enum_ctx, void *devhandle)
|
spdk_nvme_probe_cb probe_cb, void *cb_ctx, void *devhandle)
|
||||||
{
|
{
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user