nvme: expand probe information to a struct

spdk_nvme_probe() will now provide a struct spdk_nvme_probe_info to the
probe and attach callbacks in place of the PCI device pointer.

This struct contains the useful information that could be retrieved from
the PCI device during probe.

The goal of this change is to allow expansion of the probe information
in the future when other transports (specifically, NVMe over Fabrics)
are added that do not necessarily use PCI addressing or device IDs.

Change-Id: I59a2a9e874e248ce5fa1d7f4b57c8056962ff3cd
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2016-10-31 16:55:14 -07:00 committed by Ben Walker
parent bbd7e1c4da
commit fcb00f3780
20 changed files with 208 additions and 167 deletions

View File

@ -334,17 +334,17 @@ spdk_nvmf_parse_addr(char *listen_addr, char **host, char **port)
}
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
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 = spdk_pci_device_get_addr(dev);
if (ctx->any && !ctx->found) {
ctx->found = true;
return true;
}
if (spdk_pci_addr_compare(&pci_addr, &ctx->pci_addr) == 0) {
if (spdk_pci_addr_compare(&probe_info->pci_addr, &ctx->pci_addr) == 0) {
ctx->found = true;
return true;
}
@ -353,20 +353,27 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
struct spdk_nvmf_probe_ctx *ctx = cb_ctx;
struct spdk_pci_addr pci_addr = spdk_pci_device_get_addr(dev);
int rc;
char path[MAX_STRING_LEN];
int numa_node = -1;
SPDK_NOTICELOG("Attaching NVMe device %p at %x:%x:%x.%x to subsystem %p\n",
ctrlr, pci_addr.domain, pci_addr.bus, pci_addr.dev, pci_addr.func, ctx->subsystem);
ctrlr,
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func,
ctx->subsystem);
snprintf(path, sizeof(path), "/sys/bus/pci/devices/%04x:%02x:%02x.%1u/numa_node",
pci_addr.domain, pci_addr.bus, pci_addr.dev, pci_addr.func);
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
numa_node = spdk_get_numa_node_value(path);
if (numa_node >= 0) {
@ -379,7 +386,7 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctr
}
}
rc = nvmf_subsystem_add_ctrlr(ctx->subsystem, ctrlr, &pci_addr);
rc = nvmf_subsystem_add_ctrlr(ctx->subsystem, ctrlr, &probe_info->pci_addr);
if (rc < 0) {
SPDK_ERRLOG("Failed to add controller to subsystem\n");
}

View File

@ -865,29 +865,30 @@ register_workers(void)
}
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
/* Update with user specified arbitration configuration */
opts->arb_mechanism = g_arbitration.arbitration_mechanism;
printf("Attaching to %04x:%02x:%02x.%02x\n",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
return true;
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
/* Update with actual arbitration configuration in use */
g_arbitration.arbitration_mechanism = opts->arb_mechanism;

View File

@ -87,11 +87,9 @@ struct spdk_fio_thread {
};
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
int found_bus = spdk_pci_device_get_bus(dev);
int found_slot = spdk_pci_device_get_dev(dev);
int found_func = spdk_pci_device_get_func(dev);
struct fio_file *f;
unsigned int i;
struct thread_data *td = cb_ctx;
@ -105,7 +103,9 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts
fprintf(stderr, "Invalid filename: %s\n", f->file_name);
continue;
}
if (bus == found_bus && slot == found_slot && func == found_func) {
if (bus == probe_info->pci_addr.bus &&
slot == probe_info->pci_addr.dev &&
func == probe_info->pci_addr.func) {
return true;
}
}
@ -114,12 +114,9 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
int found_bus = spdk_pci_device_get_bus(dev);
int found_slot = spdk_pci_device_get_dev(dev);
int found_func = spdk_pci_device_get_func(dev);
struct thread_data *td = cb_ctx;
struct spdk_fio_thread *fio_thread = td->io_ops->data;
struct spdk_fio_ctrlr *fio_ctrlr;
@ -139,7 +136,10 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctr
for_each_file(fio_thread->td, f, i) {
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 == found_bus && slot == found_slot && func == found_func) {
if (rc == 5 &&
bus == probe_info->pci_addr.bus &&
slot == probe_info->pci_addr.dev &&
func == probe_info->pci_addr.func) {
fio_ns = calloc(1, sizeof(*fio_ns));
if (fio_ns == NULL) {
continue;

View File

@ -238,20 +238,21 @@ hello_world(void)
}
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
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",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
return true;
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
int nsid, num_ns;
struct ctrlr_entry *entry;
@ -264,10 +265,10 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctr
}
printf("Attached to %04x:%02x:%02x.%02x\n",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
snprintf(entry->name, sizeof(entry->name), "%-20.20s (%-20.20s)", cdata->mn, cdata->sn);

View File

@ -383,7 +383,7 @@ print_namespace(struct spdk_nvme_ns *ns)
}
static void
print_controller(struct spdk_nvme_ctrlr *ctrlr, struct spdk_pci_device *pci_dev)
print_controller(struct spdk_nvme_ctrlr *ctrlr, const struct spdk_pci_addr *pci_addr)
{
const struct spdk_nvme_ctrlr_data *cdata;
union spdk_nvme_cap_register cap;
@ -402,8 +402,7 @@ print_controller(struct spdk_nvme_ctrlr *ctrlr, struct spdk_pci_device *pci_dev)
printf("=====================================================\n");
printf("NVMe Controller at PCI bus %d, device %d, function %d\n",
spdk_pci_device_get_bus(pci_dev), spdk_pci_device_get_dev(pci_dev),
spdk_pci_device_get_func(pci_dev));
pci_addr->bus, pci_addr->dev, pci_addr->func);
printf("=====================================================\n");
if (g_hex_dump) {
@ -872,16 +871,17 @@ parse_args(int argc, char **argv)
}
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
return true;
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
print_controller(ctrlr, pci_dev);
print_controller(ctrlr, &probe_info->pci_addr);
spdk_nvme_detach(ctrlr);
}

View File

@ -51,7 +51,7 @@
#define MAX_DEVS 64
struct dev {
struct spdk_pci_device *pci_dev;
struct spdk_pci_addr pci_addr;
struct spdk_nvme_ctrlr *ctrlr;
const struct spdk_nvme_ctrlr_data *cdata;
struct spdk_nvme_ns_data *common_ns_data;
@ -73,14 +73,13 @@ static int
cmp_devs(const void *ap, const void *bp)
{
const struct dev *a = ap, *b = bp;
struct spdk_pci_addr a1 = spdk_pci_device_get_addr(a->pci_dev);
struct spdk_pci_addr a2 = spdk_pci_device_get_addr(b->pci_dev);
return spdk_pci_addr_compare(&a1, &a2);
return spdk_pci_addr_compare(&a->pci_addr, &b->pci_addr);
}
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
return true;
}
@ -100,15 +99,15 @@ identify_common_ns_cb(void *cb_arg, const struct spdk_nvme_cpl *cpl)
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
struct dev *dev;
struct spdk_nvme_cmd cmd;
/* add to dev list */
dev = &devs[num_devs++];
dev->pci_dev = pci_dev;
dev->pci_addr = probe_info->pci_addr;
dev->ctrlr = ctrlr;
/* Retrieve controller data */
@ -244,8 +243,7 @@ display_controller(struct dev *dev, int model)
if (model == CONTROLLER_DISPLAY_SIMPLISTIC) {
printf("%04x:%02x:%02x.%02x ",
spdk_pci_device_get_domain(dev->pci_dev), spdk_pci_device_get_bus(dev->pci_dev),
spdk_pci_device_get_dev(dev->pci_dev), spdk_pci_device_get_func(dev->pci_dev));
dev->pci_addr.domain, dev->pci_addr.bus, dev->pci_addr.dev, dev->pci_addr.func);
printf("%-40.40s %-20.20s ",
cdata->mn, cdata->sn);
printf("%5d ", cdata->cntlid);
@ -255,8 +253,7 @@ display_controller(struct dev *dev, int model)
printf("=====================================================\n");
printf("NVMe Controller: %04x:%02x:%02x.%02x\n",
spdk_pci_device_get_domain(dev->pci_dev), spdk_pci_device_get_bus(dev->pci_dev),
spdk_pci_device_get_dev(dev->pci_dev), spdk_pci_device_get_func(dev->pci_dev));
dev->pci_addr.domain, dev->pci_addr.bus, dev->pci_addr.dev, dev->pci_addr.func);
printf("============================\n");
printf("Controller Capabilities/Features\n");
printf("Controller ID: %d\n", cdata->cntlid);
@ -328,9 +325,7 @@ get_controller(void)
}
foreach_dev(iter) {
struct spdk_pci_addr iter_addr = spdk_pci_device_get_addr(iter->pci_dev);
if (spdk_pci_addr_compare(&pci_addr, &iter_addr) == 0) {
if (spdk_pci_addr_compare(&pci_addr, &iter->pci_addr) == 0) {
return iter;
}
}

View File

@ -962,26 +962,27 @@ unregister_workers(void)
}
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
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",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
return true;
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
register_ctrlr(ctrlr);
}

View File

@ -46,7 +46,7 @@
#define MAX_DEVS 64
struct dev {
struct spdk_pci_device *pci_dev;
struct spdk_pci_addr pci_addr;
struct spdk_nvme_ctrlr *ctrlr;
char name[100];
};
@ -334,7 +334,7 @@ reservation_ns_release(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qp
static void
reserve_controller(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair,
struct spdk_pci_device *pci_dev)
const struct spdk_pci_addr *pci_addr)
{
const struct spdk_nvme_ctrlr_data *cdata;
@ -342,8 +342,7 @@ reserve_controller(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair,
printf("=====================================================\n");
printf("NVMe Controller at PCI bus %d, device %d, function %d\n",
spdk_pci_device_get_bus(pci_dev), spdk_pci_device_get_dev(pci_dev),
spdk_pci_device_get_func(pci_dev));
pci_addr->bus, pci_addr->dev, pci_addr->func);
printf("=====================================================\n");
printf("Reservations: %s\n",
@ -363,20 +362,21 @@ reserve_controller(struct spdk_nvme_ctrlr *ctrlr, struct spdk_nvme_qpair *qpair,
}
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
return true;
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
struct dev *dev;
/* add to dev list */
dev = &devs[num_devs++];
dev->pci_dev = pci_dev;
dev->pci_addr = probe_info->pci_addr;
dev->ctrlr = ctrlr;
}
@ -415,7 +415,7 @@ int main(int argc, char **argv)
fprintf(stderr, "spdk_nvme_ctrlr_alloc_io_qpair() failed\n");
rc = 1;
} else {
reserve_controller(iter->ctrlr, qpair, iter->pci_dev);
reserve_controller(iter->ctrlr, qpair, &iter->pci_addr);
}
}

View File

@ -88,6 +88,25 @@ struct spdk_nvme_ctrlr_opts {
uint32_t keep_alive_timeout_ms;
};
/**
* 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.
*
* If not available, each field will be filled with all 0xFs.
*/
struct spdk_pci_id pci_id;
};
/**
* Callback for spdk_nvme_probe() enumeration.
*
@ -97,7 +116,7 @@ struct spdk_nvme_ctrlr_opts {
* provided during the attach callback.
* \return true to attach to this device.
*/
typedef bool (*spdk_nvme_probe_cb)(void *cb_ctx, struct spdk_pci_device *pci_dev,
typedef bool (*spdk_nvme_probe_cb)(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts);
/**
@ -106,7 +125,7 @@ typedef bool (*spdk_nvme_probe_cb)(void *cb_ctx, struct spdk_pci_device *pci_dev
* \param opts NVMe controller initialization options that were actually used. Options may differ
* from the requested options from the probe call depending on what the controller supports.
*/
typedef void (*spdk_nvme_attach_cb)(void *cb_ctx, struct spdk_pci_device *pci_dev,
typedef void (*spdk_nvme_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);

View File

@ -60,7 +60,7 @@ struct nvme_device {
* target for CONTROLLER IDENTIFY command during initialization
*/
struct spdk_nvme_ctrlr *ctrlr;
struct spdk_pci_device *pci_dev;
struct spdk_pci_addr pci_addr;
/** linked list pointer for device list */
TAILQ_ENTRY(nvme_device) tailq;
@ -339,15 +339,18 @@ static const struct spdk_bdev_fn_table nvmelib_fn_table = {
};
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr_opts *opts)
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
struct nvme_probe_ctx *ctx = cb_ctx;
struct spdk_pci_addr pci_addr = spdk_pci_device_get_addr(pci_dev);
int i;
bool claim_device = false;
SPDK_NOTICELOG("Probing device %x:%x:%x.%x\n",
pci_addr.domain, pci_addr.bus, pci_addr.dev, pci_addr.func);
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
if (ctx->controllers_remaining == 0) {
return false;
@ -357,7 +360,7 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr_o
claim_device = true;
} else {
for (i = 0; i < NVME_MAX_CONTROLLERS; i++) {
if (spdk_pci_addr_compare(&pci_addr, &ctx->whitelist[i]) == 0) {
if (spdk_pci_addr_compare(&probe_info->pci_addr, &ctx->whitelist[i]) == 0) {
claim_device = true;
break;
}
@ -369,7 +372,7 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr_o
}
/* Claim the device in case conflict with other process */
if (spdk_pci_device_claim(&pci_addr) != 0) {
if (spdk_pci_device_claim(&probe_info->pci_addr) != 0) {
return false;
}
@ -377,8 +380,8 @@ probe_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr_o
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
struct nvme_probe_ctx *ctx = cb_ctx;
struct nvme_device *dev;
@ -390,7 +393,7 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr
}
dev->ctrlr = ctrlr;
dev->pci_dev = pci_dev;
dev->pci_addr = probe_info->pci_addr;
dev->id = nvme_controller_index++;
nvme_ctrlr_initialize_blockdevs(dev->ctrlr, nvme_luns_per_ns, dev->id);
@ -408,12 +411,10 @@ blockdev_nvme_exist(struct nvme_probe_ctx *ctx)
{
int i;
struct nvme_device *nvme_dev;
struct spdk_pci_addr dev_addr;
for (i = 0; i < ctx->num_whitelist_controllers; i++) {
TAILQ_FOREACH(nvme_dev, &g_nvme_devices, tailq) {
dev_addr = spdk_pci_device_get_addr(nvme_dev->pci_dev);
if (spdk_pci_addr_compare(&dev_addr, &ctx->whitelist[i]) == 0) {
if (spdk_pci_addr_compare(&nvme_dev->pci_addr, &ctx->whitelist[i]) == 0) {
return true;
}
}

View File

@ -232,8 +232,10 @@ nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
struct spdk_nvme_ctrlr *ctrlr;
struct spdk_nvme_ctrlr_opts opts;
struct spdk_pci_addr dev_addr;
struct spdk_nvme_probe_info probe_info;
dev_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);
/* Verify that this controller is not already attached */
TAILQ_FOREACH(ctrlr, &g_spdk_nvme_driver->attached_ctrlrs, tailq) {
@ -241,14 +243,14 @@ 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(&dev_addr, &ctrlr->pci_addr) == 0) {
if (spdk_pci_addr_compare(&dev_addr, &ctrlr->probe_info.pci_addr) == 0) {
return 0;
}
}
spdk_nvme_ctrlr_opts_set_defaults(&opts);
if (enum_ctx->probe_cb(enum_ctx->cb_ctx, pci_dev, &opts)) {
if (enum_ctx->probe_cb(enum_ctx->cb_ctx, &probe_info, &opts)) {
ctrlr = nvme_attach(pci_dev);
if (ctrlr == NULL) {
SPDK_ERRLOG("nvme_attach() failed\n");
@ -256,6 +258,7 @@ nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
}
ctrlr->opts = opts;
ctrlr->probe_info = probe_info;
TAILQ_INSERT_TAIL(&g_spdk_nvme_driver->init_ctrlrs, ctrlr, tailq);
}
@ -329,7 +332,7 @@ spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb a
* that may take the driver lock, like nvme_detach().
*/
pthread_mutex_unlock(&g_spdk_nvme_driver->lock);
attach_cb(cb_ctx, ctrlr->devhandle, ctrlr, &ctrlr->opts);
attach_cb(cb_ctx, &ctrlr->probe_info, ctrlr, &ctrlr->opts);
pthread_mutex_lock(&g_spdk_nvme_driver->lock);
break;

View File

@ -417,8 +417,7 @@ struct spdk_nvme_ctrlr {
struct spdk_nvme_ctrlr_opts opts;
/** PCI address including domain, bus, device and function */
struct spdk_pci_addr pci_addr;
struct spdk_nvme_probe_info probe_info;
uint64_t quirks;

View File

@ -180,15 +180,10 @@ nvme_pcie_qpair(struct spdk_nvme_qpair *qpair)
static int
nvme_pcie_ctrlr_get_pci_id(struct spdk_nvme_ctrlr *ctrlr, struct spdk_pci_id *pci_id)
{
struct spdk_pci_device *pci_dev;
assert(ctrlr != NULL);
assert(pci_id != NULL);
pci_dev = ctrlr->devhandle;
assert(pci_dev != NULL);
*pci_id = spdk_pci_device_get_id(pci_dev);
*pci_id = ctrlr->probe_info.pci_id;
return 0;
}
@ -471,12 +466,6 @@ static struct spdk_nvme_ctrlr *nvme_pcie_ctrlr_construct(void *devhandle)
* but we want multiples of 4, so drop the + 2 */
pctrlr->doorbell_stride_u32 = 1 << cap.bits.dstrd;
/* Save the PCI address */
pctrlr->ctrlr.pci_addr.domain = spdk_pci_device_get_domain(pci_dev);
pctrlr->ctrlr.pci_addr.bus = spdk_pci_device_get_bus(pci_dev);
pctrlr->ctrlr.pci_addr.dev = spdk_pci_device_get_dev(pci_dev);
pctrlr->ctrlr.pci_addr.func = spdk_pci_device_get_func(pci_dev);
rc = nvme_ctrlr_construct(&pctrlr->ctrlr);
if (rc != 0) {
nvme_ctrlr_destruct(&pctrlr->ctrlr);

View File

@ -44,7 +44,6 @@
#define MAX_DEVS 64
struct dev {
struct spdk_pci_device *pci_dev;
struct spdk_nvme_ctrlr *ctrlr;
struct spdk_nvme_health_information_page *health_page;
uint32_t orig_temp_threshold;
@ -186,20 +185,21 @@ static void aer_cb(void *arg, const struct spdk_nvme_cpl *cpl)
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
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",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
return true;
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
struct dev *dev;
@ -207,11 +207,12 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr
dev = &devs[num_devs++];
dev->ctrlr = ctrlr;
dev->pci_dev = pci_dev;
snprintf(dev->name, sizeof(dev->name), "%04x:%02x:%02x.%02x",
spdk_pci_device_get_domain(pci_dev), spdk_pci_device_get_bus(pci_dev),
spdk_pci_device_get_dev(pci_dev), spdk_pci_device_get_func(pci_dev));
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", dev->name);

View File

@ -606,20 +606,21 @@ write_read_e2e_dp_tests(struct dev *dev, nvme_build_io_req_fn_t build_io_fn, con
}
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
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",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
return true;
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
struct dev *dev;
@ -629,10 +630,10 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr
dev->ctrlr = ctrlr;
snprintf(dev->name, sizeof(dev->name), "%04X:%02X:%02X.%02X",
spdk_pci_device_get_domain(pci_dev),
spdk_pci_device_get_bus(pci_dev),
spdk_pci_device_get_dev(pci_dev),
spdk_pci_device_get_func(pci_dev));
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", dev->name);
}

View File

@ -530,39 +530,40 @@ parse_args(int argc, char **argv)
}
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
static uint32_t ctrlr_found = 0;
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",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
return false;
}
ctrlr_found = 1;
printf("Attaching to %04x:%02x:%02x.%02x\n",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
return true;
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
register_ctrlr(ctrlr);
}

View File

@ -508,14 +508,15 @@ register_workers(void)
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
probe_cb(void *cb_ctx, const struct spdk_nvme_probe_info *probe_info,
struct spdk_nvme_ctrlr_opts *opts)
{
return true;
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
register_ctrlr(ctrlr);
}

View File

@ -382,20 +382,21 @@ writev_readv_tests(struct dev *dev, nvme_build_io_req_fn_t build_io_fn, const ch
}
static bool
probe_cb(void *cb_ctx, struct spdk_pci_device *dev, struct spdk_nvme_ctrlr_opts *opts)
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",
spdk_pci_device_get_domain(dev),
spdk_pci_device_get_bus(dev),
spdk_pci_device_get_dev(dev),
spdk_pci_device_get_func(dev));
probe_info->pci_addr.domain,
probe_info->pci_addr.bus,
probe_info->pci_addr.dev,
probe_info->pci_addr.func);
return true;
}
static void
attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts)
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)
{
struct dev *dev;
@ -405,10 +406,10 @@ attach_cb(void *cb_ctx, struct spdk_pci_device *pci_dev, struct spdk_nvme_ctrlr
dev->ctrlr = ctrlr;
snprintf(dev->name, sizeof(dev->name), "%04X:%02X:%02X.%02X",
spdk_pci_device_get_domain(pci_dev),
spdk_pci_device_get_bus(pci_dev),
spdk_pci_device_get_dev(pci_dev),
spdk_pci_device_get_func(pci_dev));
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", dev->name);
}

View File

@ -50,6 +50,16 @@ spdk_pci_enumerate(enum spdk_pci_device_type type,
return -1;
}
struct spdk_pci_id
spdk_pci_device_get_id(struct spdk_pci_device *pci_dev)
{
struct spdk_pci_id pci_id;
memset(&pci_id, 0xFF, sizeof(pci_id));
return pci_id;
}
void
nvme_ctrlr_destruct(struct spdk_nvme_ctrlr *ctrlr)
{

View File

@ -92,6 +92,16 @@ spdk_pci_device_get_addr(struct spdk_pci_device *pci_dev)
return pci_addr;
}
struct spdk_pci_id
spdk_pci_device_get_id(struct spdk_pci_device *pci_dev)
{
struct spdk_pci_id pci_id;
memset(&pci_id, 0xFF, sizeof(pci_id));
return pci_id;
}
int
spdk_pci_addr_compare(const struct spdk_pci_addr *a1, const struct spdk_pci_addr *a2)
{