From 3da43e64e4a86a3940a6e8e9035d7113803a4495 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Fri, 9 Dec 2016 14:23:55 -0700 Subject: [PATCH] nvme: Remove pci_addr from probe_info This can be obtained by parsing the traddr. Change-Id: Idaf35066cbf900c87e771a44934de99fb5420001 Signed-off-by: Ben Walker --- app/nvmf_tgt/conf.c | 26 +++++++------ examples/nvme/arbitration/arbitration.c | 12 +----- examples/nvme/fio_plugin/fio_plugin.c | 20 +++++++--- examples/nvme/hello_world/hello_world.c | 12 +----- examples/nvme/hotplug/hotplug.c | 12 +----- examples/nvme/identify/identify.c | 11 ++++-- examples/nvme/nvme_manage/nvme_manage.c | 2 +- examples/nvme/perf/perf.c | 14 +++---- examples/nvme/reserve/reserve.c | 2 +- include/spdk/nvme.h | 7 ---- lib/bdev/nvme/blockdev_nvme.c | 18 +++++---- lib/nvme/nvme.c | 15 +++++--- lib/nvme/nvme_pcie.c | 7 +++- lib/nvme/nvme_uevent.c | 8 ++-- lib/nvme/nvme_uevent.h | 3 +- test/lib/nvme/aer/aer.c | 13 ++----- test/lib/nvme/e2edp/nvme_dp.c | 13 ++----- test/lib/nvme/overhead/overhead.c | 19 ++-------- test/lib/nvme/sgl/sgl.c | 13 ++----- test/lib/nvme/unit/test_env.c | 50 +++++++++++++++++++++++++ 20 files changed, 143 insertions(+), 134 deletions(-) diff --git a/app/nvmf_tgt/conf.c b/app/nvmf_tgt/conf.c index 2cab9d6fa..ac4c919a7 100644 --- a/app/nvmf_tgt/conf.c +++ b/app/nvmf_tgt/conf.c @@ -338,13 +338,18 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr_opts *opts) { struct spdk_nvmf_probe_ctx *ctx = cb_ctx; + struct spdk_pci_addr pci_addr; + + if (spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr)) { + return false; + } if (ctx->any && !ctx->found) { ctx->found = true; return true; } - if (spdk_pci_addr_compare(&probe_info->pci_addr, &ctx->pci_addr) == 0) { + if (spdk_pci_addr_compare(&pci_addr, &ctx->pci_addr) == 0) { ctx->found = true; return true; } @@ -360,20 +365,17 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, int rc; char path[MAX_STRING_LEN]; int numa_node = -1; + struct spdk_pci_addr pci_addr; - SPDK_NOTICELOG("Attaching NVMe device %p at %x:%x:%x.%x to subsystem %s\n", + spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr); + + SPDK_NOTICELOG("Attaching NVMe device %p at %s to subsystem %s\n", ctrlr, - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func, + probe_info->trid.traddr, spdk_nvmf_subsystem_get_nqn(ctx->app_subsystem->subsystem)); - snprintf(path, sizeof(path), "/sys/bus/pci/devices/%04x:%02x:%02x.%1u/numa_node", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + snprintf(path, sizeof(path), "/sys/bus/pci/devices/%s/numa_node", + probe_info->trid.traddr); numa_node = spdk_get_numa_node_value(path); if (numa_node >= 0) { @@ -390,7 +392,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, } } - rc = nvmf_subsystem_add_ctrlr(ctx->app_subsystem->subsystem, ctrlr, &probe_info->pci_addr); + rc = nvmf_subsystem_add_ctrlr(ctx->app_subsystem->subsystem, ctrlr, &pci_addr); if (rc < 0) { SPDK_ERRLOG("Failed to add controller to subsystem\n"); } diff --git a/examples/nvme/arbitration/arbitration.c b/examples/nvme/arbitration/arbitration.c index 6bbb62e3d..2c9a5df02 100644 --- a/examples/nvme/arbitration/arbitration.c +++ b/examples/nvme/arbitration/arbitration.c @@ -859,11 +859,7 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, /* Update with user specified arbitration configuration */ opts->arb_mechanism = g_arbitration.arbitration_mechanism; - printf("Attaching to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attaching to %s\n", probe_info->trid.traddr); return true; } @@ -872,11 +868,7 @@ static void attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts) { - printf("Attached to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attached to %s\n", probe_info->trid.traddr); /* Update with actual arbitration configuration in use */ g_arbitration.arbitration_mechanism = opts->arb_mechanism; diff --git a/examples/nvme/fio_plugin/fio_plugin.c b/examples/nvme/fio_plugin/fio_plugin.c index bd566cc2c..5e1967dff 100644 --- a/examples/nvme/fio_plugin/fio_plugin.c +++ b/examples/nvme/fio_plugin/fio_plugin.c @@ -94,6 +94,11 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, unsigned int i; struct thread_data *td = cb_ctx; int rc; + struct spdk_pci_addr pci_addr; + + if (spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr)) { + return false; + } /* Check if we want to claim this device */ for_each_file(td, f, i) { @@ -103,9 +108,9 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, fprintf(stderr, "Invalid filename: %s\n", f->file_name); continue; } - if (bus == probe_info->pci_addr.bus && - slot == probe_info->pci_addr.dev && - func == probe_info->pci_addr.func) { + if (bus == pci_addr.bus && + slot == pci_addr.dev && + func == pci_addr.func) { return true; } } @@ -123,6 +128,9 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_fio_ns *fio_ns; struct fio_file *f; unsigned int i; + struct spdk_pci_addr pci_addr; + + spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr); /* Create an fio_ctrlr and add it to the list */ fio_ctrlr = calloc(1, sizeof(*fio_ctrlr)); @@ -137,9 +145,9 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, int domain, bus, slot, func, nsid, rc; rc = sscanf(f->file_name, "%x.%x.%x.%x/%x", &domain, &bus, &slot, &func, &nsid); if (rc == 5 && - bus == probe_info->pci_addr.bus && - slot == probe_info->pci_addr.dev && - func == probe_info->pci_addr.func) { + bus == pci_addr.bus && + slot == pci_addr.dev && + func == pci_addr.func) { fio_ns = calloc(1, sizeof(*fio_ns)); if (fio_ns == NULL) { continue; diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index 61ee13c71..589f413b2 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -241,11 +241,7 @@ static bool probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr_opts *opts) { - printf("Attaching to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attaching to %s\n", probe_info->trid.traddr); return true; } @@ -264,11 +260,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, exit(1); } - printf("Attached to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attached to %s\n", probe_info->trid.traddr); snprintf(entry->name, sizeof(entry->name), "%-20.20s (%-20.20s)", cdata->mn, cdata->sn); diff --git a/examples/nvme/hotplug/hotplug.c b/examples/nvme/hotplug/hotplug.c index 419c9148a..f652311a9 100644 --- a/examples/nvme/hotplug/hotplug.c +++ b/examples/nvme/hotplug/hotplug.c @@ -265,11 +265,7 @@ static bool probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr_opts *opts) { - printf("Attaching to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attaching to %s\n", probe_info->trid.traddr); return true; } @@ -278,11 +274,7 @@ static void attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts) { - printf("Attached to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attached to %s\n", probe_info->trid.traddr); register_dev(ctrlr); } diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index 8d61f1447..3baf54e00 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -396,6 +396,7 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_probe_inf uint8_t str[512]; uint32_t i; struct spdk_nvme_error_information_entry *error_entry; + struct spdk_pci_addr pci_addr; cap = spdk_nvme_ctrlr_get_regs_cap(ctrlr); vs = spdk_nvme_ctrlr_get_regs_vs(ctrlr); @@ -406,13 +407,17 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_probe_inf cdata = spdk_nvme_ctrlr_get_data(ctrlr); printf("=====================================================\n"); - if (probe_info->trid.subnqn[0]) { + if (probe_info->trid.trtype != SPDK_NVME_TRANSPORT_PCIE) { printf("NVMe over Fabrics controller at %s:%s: %s\n", probe_info->trid.traddr, probe_info->trid.trsvcid, probe_info->trid.subnqn); } else { + if (spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr) != 0) { + return; + } + printf("NVMe Controller at %04x:%02x:%02x.%x [%04x:%04x]\n", - probe_info->pci_addr.domain, probe_info->pci_addr.bus, - probe_info->pci_addr.dev, probe_info->pci_addr.func, + pci_addr.domain, pci_addr.bus, + pci_addr.dev, pci_addr.func, probe_info->pci_id.vendor_id, probe_info->pci_id.device_id); } printf("=====================================================\n"); diff --git a/examples/nvme/nvme_manage/nvme_manage.c b/examples/nvme/nvme_manage/nvme_manage.c index 143e3be62..cb734fbba 100644 --- a/examples/nvme/nvme_manage/nvme_manage.c +++ b/examples/nvme/nvme_manage/nvme_manage.c @@ -107,7 +107,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, /* add to dev list */ dev = &devs[num_devs++]; - dev->pci_addr = probe_info->pci_addr; + spdk_pci_addr_parse(&dev->pci_addr, probe_info->trid.traddr); dev->ctrlr = ctrlr; /* Retrieve controller data */ diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index 590a4a944..3ebd4afa7 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -976,14 +976,13 @@ static bool probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr_opts *opts) { - if (probe_info->trid.subnqn[0]) { + if (probe_info->trid.trtype != SPDK_NVME_TRANSPORT_PCIE) { printf("Attaching to NVMe over Fabrics controller at %s:%s: %s\n", probe_info->trid.traddr, probe_info->trid.trsvcid, probe_info->trid.subnqn); } else { - printf("Attaching to NVMe Controller at %04x:%02x:%02x.%x [%04x:%04x]\n", - probe_info->pci_addr.domain, probe_info->pci_addr.bus, - probe_info->pci_addr.dev, probe_info->pci_addr.func, + printf("Attaching to NVMe Controller at %s [%04x:%04x]\n", + probe_info->trid.traddr, probe_info->pci_id.vendor_id, probe_info->pci_id.device_id); } @@ -994,14 +993,13 @@ static void attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts) { - if (probe_info->trid.subnqn[0]) { + if (probe_info->trid.trtype != SPDK_NVME_TRANSPORT_PCIE) { printf("Attached to NVMe over Fabrics controller at %s:%s: %s\n", probe_info->trid.traddr, probe_info->trid.trsvcid, probe_info->trid.subnqn); } else { - printf("Attached to NVMe Controller at %04x:%02x:%02x.%x [%04x:%04x]\n", - probe_info->pci_addr.domain, probe_info->pci_addr.bus, - probe_info->pci_addr.dev, probe_info->pci_addr.func, + printf("Attached to NVMe Controller at %s [%04x:%04x]\n", + probe_info->trid.traddr, probe_info->pci_id.vendor_id, probe_info->pci_id.device_id); } diff --git a/examples/nvme/reserve/reserve.c b/examples/nvme/reserve/reserve.c index bba4b13ae..aced4864c 100644 --- a/examples/nvme/reserve/reserve.c +++ b/examples/nvme/reserve/reserve.c @@ -376,7 +376,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, /* add to dev list */ dev = &devs[num_devs++]; - dev->pci_addr = probe_info->pci_addr; + spdk_pci_addr_parse(&dev->pci_addr, probe_info->trid.traddr); dev->ctrlr = ctrlr; } diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index 547f34d0b..b4df6cdf1 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -166,13 +166,6 @@ struct spdk_nvme_transport_id { * NVMe controller information provided during spdk_nvme_probe(). */ struct spdk_nvme_probe_info { - /** - * PCI address. - * - * If not available, each field will be filled with all 0xFs. - */ - struct spdk_pci_addr pci_addr; - /** * PCI device ID. * diff --git a/lib/bdev/nvme/blockdev_nvme.c b/lib/bdev/nvme/blockdev_nvme.c index 19717dad1..eaef3f6ce 100644 --- a/lib/bdev/nvme/blockdev_nvme.c +++ b/lib/bdev/nvme/blockdev_nvme.c @@ -413,12 +413,14 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct nvme_probe_ctx *ctx = cb_ctx; int i; bool claim_device = false; + struct spdk_pci_addr pci_addr; - SPDK_NOTICELOG("Probing device %x:%x:%x.%x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + if (spdk_pci_addr_parse(&pci_addr, probe_info->trid.traddr)) { + return false; + } + + SPDK_NOTICELOG("Probing device %s\n", + probe_info->trid.traddr); if (ctx->controllers_remaining == 0) { return false; @@ -428,7 +430,7 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, claim_device = true; } else { for (i = 0; i < NVME_MAX_CONTROLLERS; i++) { - if (spdk_pci_addr_compare(&probe_info->pci_addr, &ctx->whitelist[i]) == 0) { + if (spdk_pci_addr_compare(&pci_addr, &ctx->whitelist[i]) == 0) { claim_device = true; break; } @@ -440,7 +442,7 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, } /* Claim the device in case conflict with other process */ - if (spdk_pci_device_claim(&probe_info->pci_addr) != 0) { + if (spdk_pci_device_claim(&pci_addr) != 0) { return false; } @@ -475,7 +477,7 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, } dev->ctrlr = ctrlr; - dev->pci_addr = probe_info->pci_addr; + spdk_pci_addr_parse(&dev->pci_addr, probe_info->trid.traddr); dev->id = nvme_controller_index++; nvme_ctrlr_initialize_blockdevs(dev, nvme_luns_per_ns, dev->id); diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index 410b125b1..a8942e891 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -476,20 +476,23 @@ nvme_hotplug_monitor(void *cb_ctx, spdk_nvme_probe_cb probe_cb, { struct spdk_nvme_ctrlr *ctrlr; struct spdk_uevent event; + struct spdk_pci_addr pci_addr; while (spdk_get_uevent(hotplug_fd, &event) > 0) { if (event.subsystem == SPDK_NVME_UEVENT_SUBSYSTEM_UIO) { if (event.action == SPDK_NVME_UEVENT_ADD) { - SPDK_TRACELOG(SPDK_TRACE_NVME, "add nvme address: %04x:%02x:%02x.%u\n", - event.pci_addr.domain, event.pci_addr.bus, event.pci_addr.dev, event.pci_addr.func); + SPDK_TRACELOG(SPDK_TRACE_NVME, "add nvme address: %s\n", + event.traddr); if (spdk_process_is_primary()) { - nvme_transport_ctrlr_attach(SPDK_NVME_TRANSPORT_PCIE, probe_cb, cb_ctx, &event.pci_addr); + if (spdk_pci_addr_parse(&pci_addr, event.traddr)) { + nvme_transport_ctrlr_attach(SPDK_NVME_TRANSPORT_PCIE, probe_cb, cb_ctx, &pci_addr); + } } } else if (event.action == SPDK_NVME_UEVENT_REMOVE) { bool in_list = false; TAILQ_FOREACH(ctrlr, &g_spdk_nvme_driver->attached_ctrlrs, tailq) { - if (spdk_pci_addr_compare(&event.pci_addr, &ctrlr->probe_info.pci_addr) == 0) { + if (strcmp(event.traddr, ctrlr->probe_info.trid.traddr) == 0) { in_list = true; break; } @@ -497,8 +500,8 @@ nvme_hotplug_monitor(void *cb_ctx, spdk_nvme_probe_cb probe_cb, if (in_list == false) { return 0; } - SPDK_TRACELOG(SPDK_TRACE_NVME, "remove nvme address: %04x:%02x:%02x.%u\n", - event.pci_addr.domain, event.pci_addr.bus, event.pci_addr.dev, event.pci_addr.func); + SPDK_TRACELOG(SPDK_TRACE_NVME, "remove nvme address: %s\n", + event.traddr); nvme_ctrlr_fail(ctrlr, true); diff --git a/lib/nvme/nvme_pcie.c b/lib/nvme/nvme_pcie.c index e5427e303..1530124dd 100644 --- a/lib/nvme/nvme_pcie.c +++ b/lib/nvme/nvme_pcie.c @@ -528,9 +528,12 @@ pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev) struct nvme_pcie_enum_ctx *enum_ctx = ctx; struct spdk_nvme_ctrlr *ctrlr; int rc = 0; + struct spdk_pci_addr pci_addr; + + pci_addr = spdk_pci_device_get_addr(pci_dev); probe_info.trid.trtype = SPDK_NVME_TRANSPORT_PCIE; - probe_info.pci_addr = spdk_pci_device_get_addr(pci_dev); + spdk_pci_addr_fmt(probe_info.trid.traddr, sizeof(probe_info.trid.traddr), &pci_addr); probe_info.pci_id = spdk_pci_device_get_id(pci_dev); /* Verify that this controller is not already attached */ @@ -539,7 +542,7 @@ pcie_nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev) * 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) { + if (strcmp(probe_info.trid.traddr, ctrlr->probe_info.trid.traddr) == 0) { if (!spdk_process_is_primary()) { rc = nvme_ctrlr_add_process(ctrlr, pci_dev); } diff --git a/lib/nvme/nvme_uevent.c b/lib/nvme/nvme_uevent.c index 07ce578c8..c675c544c 100644 --- a/lib/nvme/nvme_uevent.c +++ b/lib/nvme/nvme_uevent.c @@ -38,6 +38,8 @@ #ifdef __linux__ #include +#include +#include #include #include #include @@ -48,6 +50,7 @@ #include #define SPDK_UEVENT_MSG_LEN 4096 +#define TRADDR_FMT "%.4" PRIx16 ":%.2" PRIx8 ":%.2" PRIx8 ".%" PRIx8 int spdk_uevent_connect(void) @@ -138,10 +141,7 @@ parse_event(const char *buf, struct spdk_uevent *event) if (ret != 4) { SPDK_ERRLOG("Invalid format for NVMe BDF: %s\n", pci_address); } - event->pci_addr.domain = domain; - event->pci_addr.bus = bus; - event->pci_addr.dev = dev; - event->pci_addr.func = func; + snprintf(event->traddr, sizeof(event->traddr), TRADDR_FMT, domain, bus, dev, func); return 1; } return -1; diff --git a/lib/nvme/nvme_uevent.h b/lib/nvme/nvme_uevent.h index e4630e932..bda4f3e12 100644 --- a/lib/nvme/nvme_uevent.h +++ b/lib/nvme/nvme_uevent.h @@ -36,6 +36,7 @@ */ #include "spdk/env.h" +#include "spdk/nvmf_spec.h" #ifndef SPDK_UEVENT_H_ #define SPDK_UEVENT_H_ @@ -50,7 +51,7 @@ enum spdk_nvme_uevent_action { struct spdk_uevent { enum spdk_nvme_uevent_action action; int subsystem; - struct spdk_pci_addr pci_addr; + char traddr[SPDK_NVMF_TRADDR_MAX_LEN + 1]; }; int spdk_uevent_connect(void); diff --git a/test/lib/nvme/aer/aer.c b/test/lib/nvme/aer/aer.c index cad0edd73..d9da6abcc 100644 --- a/test/lib/nvme/aer/aer.c +++ b/test/lib/nvme/aer/aer.c @@ -188,11 +188,7 @@ static bool probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr_opts *opts) { - printf("Attaching to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attaching to %s\n", probe_info->trid.traddr); return true; } @@ -208,11 +204,8 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, dev->ctrlr = ctrlr; - snprintf(dev->name, sizeof(dev->name), "%04x:%02x:%02x.%02x", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + snprintf(dev->name, sizeof(dev->name), "%s", + probe_info->trid.traddr); printf("Attached to %s\n", dev->name); diff --git a/test/lib/nvme/e2edp/nvme_dp.c b/test/lib/nvme/e2edp/nvme_dp.c index 1c3ff1ad6..ccdefb478 100644 --- a/test/lib/nvme/e2edp/nvme_dp.c +++ b/test/lib/nvme/e2edp/nvme_dp.c @@ -609,11 +609,7 @@ static bool probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr_opts *opts) { - printf("Attaching to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attaching to %s\n", probe_info->trid.traddr); return true; } @@ -629,11 +625,8 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, dev->ctrlr = ctrlr; - snprintf(dev->name, sizeof(dev->name), "%04X:%02X:%02X.%02X", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + snprintf(dev->name, sizeof(dev->name), "%s", + probe_info->trid.traddr); printf("Attached to %s\n", dev->name); } diff --git a/test/lib/nvme/overhead/overhead.c b/test/lib/nvme/overhead/overhead.c index 64c113b21..7c9a2a577 100644 --- a/test/lib/nvme/overhead/overhead.c +++ b/test/lib/nvme/overhead/overhead.c @@ -537,20 +537,13 @@ probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, if (ctrlr_found == 1) { fprintf(stderr, "only attching to one controller, so skipping\n"); - fprintf(stderr, " controller at PCI address %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + fprintf(stderr, " controller at PCI address %s\n", + probe_info->trid.traddr); return false; } ctrlr_found = 1; - printf("Attaching to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attaching to %s\n", probe_info->trid.traddr); return true; } @@ -559,11 +552,7 @@ static void attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr *ctrlr, const struct spdk_nvme_ctrlr_opts *opts) { - printf("Attached to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attached to %s\n", probe_info->trid.traddr); register_ctrlr(ctrlr); } diff --git a/test/lib/nvme/sgl/sgl.c b/test/lib/nvme/sgl/sgl.c index 5d8083f2f..3447a6d8b 100644 --- a/test/lib/nvme/sgl/sgl.c +++ b/test/lib/nvme/sgl/sgl.c @@ -383,11 +383,7 @@ static bool probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, struct spdk_nvme_ctrlr_opts *opts) { - printf("Attaching to %04x:%02x:%02x.%02x\n", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + printf("Attaching to %s\n", probe_info->trid.traddr); return true; } @@ -403,11 +399,8 @@ attach_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info, dev->ctrlr = ctrlr; - snprintf(dev->name, sizeof(dev->name), "%04X:%02X:%02X.%02X", - probe_info->pci_addr.domain, - probe_info->pci_addr.bus, - probe_info->pci_addr.dev, - probe_info->pci_addr.func); + snprintf(dev->name, sizeof(dev->name), "%s", + probe_info->trid.traddr); printf("Attached to %s\n", dev->name); } diff --git a/test/lib/nvme/unit/test_env.c b/test/lib/nvme/unit/test_env.c index a28f471db..fc03ec9e5 100644 --- a/test/lib/nvme/unit/test_env.c +++ b/test/lib/nvme/unit/test_env.c @@ -145,3 +145,53 @@ uint64_t spdk_get_ticks_hz(void) { return 1000000; } + +int +spdk_pci_addr_parse(struct spdk_pci_addr *addr, const char *bdf) +{ + unsigned domain, bus, dev, func; + + if (addr == NULL || bdf == NULL) { + return -EINVAL; + } + + if (sscanf(bdf, "%x:%x:%x.%x", &domain, &bus, &dev, &func) == 4) { + /* Matched a full address - all variables are initialized */ + } else if (sscanf(bdf, "%x:%x:%x", &domain, &bus, &dev) == 3) { + func = 0; + } else if (sscanf(bdf, "%x:%x.%x", &bus, &dev, &func) == 3) { + domain = 0; + } else if (sscanf(bdf, "%x:%x", &bus, &dev) == 2) { + domain = 0; + func = 0; + } else { + return -EINVAL; + } + + if (domain > 0xFFFF || bus > 0xFF || dev > 0x1F || func > 7) { + return -EINVAL; + } + + addr->domain = domain; + addr->bus = bus; + addr->dev = dev; + addr->func = func; + + return 0; +} + +int +spdk_pci_addr_fmt(char *bdf, size_t sz, const struct spdk_pci_addr *addr) +{ + int rc; + + rc = snprintf(bdf, sz, "%04x:%02x:%02x.%x", + addr->domain, addr->bus, + addr->dev, addr->func); + + if (rc > 0 && (size_t)rc < sz) { + return 0; + } + + return -1; +}