nvme: Unify spdk_nvme_discover and spdk_nvme_probe

They were very close to the same already, so finish the job.

Change-Id: Ifba9e3b2d11a3e70cbfbe46f57a67552db2757ed
Signed-off-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2016-12-09 15:33:47 -07:00 committed by Daniel Verkamp
parent c00bce397d
commit df46c41a4c
17 changed files with 31 additions and 61 deletions

View File

@ -557,7 +557,7 @@ spdk_nvmf_parse_subsystem(struct spdk_conf_section *sp)
ctx.any = false; ctx.any = false;
} }
if (spdk_nvme_probe(&ctx, probe_cb, attach_cb, NULL)) { if (spdk_nvme_probe(NULL, &ctx, probe_cb, attach_cb, NULL)) {
SPDK_ERRLOG("One or more controllers failed in spdk_nvme_probe()\n"); SPDK_ERRLOG("One or more controllers failed in spdk_nvme_probe()\n");
} }
@ -748,7 +748,7 @@ spdk_nvmf_parse_subsystem_for_rpc(const char *name,
ctx.any = false; ctx.any = false;
} }
if (spdk_nvme_probe(&ctx, probe_cb, attach_cb, NULL)) { if (spdk_nvme_probe(NULL, &ctx, probe_cb, attach_cb, NULL)) {
SPDK_ERRLOG("One or more controllers failed in spdk_nvme_probe()\n"); SPDK_ERRLOG("One or more controllers failed in spdk_nvme_probe()\n");
} }

View File

@ -882,7 +882,7 @@ register_controllers(void)
{ {
printf("Initializing NVMe Controllers\n"); printf("Initializing NVMe Controllers\n");
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
return 1; return 1;
} }

View File

@ -205,7 +205,7 @@ static int spdk_fio_setup(struct thread_data *td)
} }
/* Enumerate all of the controllers */ /* Enumerate all of the controllers */
if (spdk_nvme_probe(td, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, td, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
return 1; return 1;
} }

View File

@ -340,7 +340,7 @@ int main(int argc, char **argv)
* called for each controller after the SPDK NVMe driver has completed * called for each controller after the SPDK NVMe driver has completed
* initializing the controller we chose to attach. * initializing the controller we chose to attach.
*/ */
rc = spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL); rc = spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL);
if (rc != 0) { if (rc != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
cleanup(); cleanup();

View File

@ -337,7 +337,7 @@ io_loop(void)
/* /*
* Check for hotplug events. * Check for hotplug events.
*/ */
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, remove_cb) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, remove_cb) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
break; break;
} }
@ -421,7 +421,7 @@ register_controllers(void)
{ {
fprintf(stderr, "Initializing NVMe Controllers\n"); fprintf(stderr, "Initializing NVMe Controllers\n");
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, remove_cb) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, remove_cb) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
return 1; return 1;
} }

View File

@ -990,12 +990,12 @@ int main(int argc, char **argv)
rc = 0; rc = 0;
if (trid.trtype == SPDK_NVME_TRANSPORT_RDMA) { if (trid.trtype == SPDK_NVME_TRANSPORT_RDMA) {
if (spdk_nvme_discover(&trid, NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(&trid, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
} }
} }
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
rc = 1; rc = 1;
} }

View File

@ -853,7 +853,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
return 1; return 1;
} }

View File

@ -1045,7 +1045,7 @@ register_controllers(void)
printf("Initializing NVMe Controllers\n"); printf("Initializing NVMe Controllers\n");
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
} }
@ -1091,8 +1091,8 @@ register_controllers(void)
p = (char *)p1 + 1; p = (char *)p1 + 1;
snprintf(trid.trsvcid, sizeof(trid.trsvcid), "%s", p); snprintf(trid.trsvcid, sizeof(trid.trsvcid), "%s", p);
if (spdk_nvme_discover(&trid, NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(&trid, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_discover() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
} }
} }

View File

@ -400,7 +400,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
return 1; return 1;
} }

View File

@ -215,28 +215,12 @@ typedef void (*spdk_nvme_attach_cb)(void *cb_ctx, const struct spdk_nvme_transpo
typedef void (*spdk_nvme_remove_cb)(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr); typedef void (*spdk_nvme_remove_cb)(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr);
/** /**
* \brief Perform a device discovery using the discovery service specified by trid. * \brief Enumerate the bus indicated by the transport ID and attach the userspace NVMe driver
* * to each device found if desired.
* \param trid The address of the discovery service on which to perform the discovery.
* \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of the callbacks.
* \param probe_cb will be called once per NVMe device found in the system.
* \param attach_cb will be called for devices for which probe_cb returned true once that NVMe
* controller has been attached to the userspace driver.
* \param remove_cb will be called for devices that were attached in a previous spdk_nvme_probe()
* call but are no longer attached to the system. Optional; specify NULL if removal notices are not
* desired.
*
*/
int spdk_nvme_discover(const struct spdk_nvme_transport_id *trid,
void *cb_ctx,
spdk_nvme_probe_cb probe_cb,
spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb);
/**
* \brief Enumerate the NVMe devices attached to the system and attach the userspace NVMe driver
* to them if desired.
* *
* \param trid The transport ID indicating which bus to enumerate. If the trtype is PCIe or trid is NULL,
* this will scan the local PCIe bus. If the trtype is RDMA, the traddr and trsvcid must point at the
* location of an NVMe-oF discovery service.
* \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of the callbacks. * \param cb_ctx Opaque value which will be passed back in cb_ctx parameter of the callbacks.
* \param probe_cb will be called once per NVMe device found in the system. * \param probe_cb will be called once per NVMe device found in the system.
* \param attach_cb will be called for devices for which probe_cb returned true once that NVMe * \param attach_cb will be called for devices for which probe_cb returned true once that NVMe
@ -257,7 +241,8 @@ int spdk_nvme_discover(const struct spdk_nvme_transport_id *trid,
* To stop using the the controller and release its associated resources, * To stop using the the controller and release its associated resources,
* call \ref spdk_nvme_detach with the spdk_nvme_ctrlr instance returned by this function. * call \ref spdk_nvme_detach with the spdk_nvme_ctrlr instance returned by this function.
*/ */
int spdk_nvme_probe(void *cb_ctx, int spdk_nvme_probe(const struct spdk_nvme_transport_id *trid,
void *cb_ctx,
spdk_nvme_probe_cb probe_cb, spdk_nvme_probe_cb probe_cb,
spdk_nvme_attach_cb attach_cb, spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb); spdk_nvme_remove_cb remove_cb);

View File

@ -551,7 +551,7 @@ spdk_bdev_nvme_create(struct nvme_probe_ctx *ctx)
prev_index_max = blockdev_index_max; prev_index_max = blockdev_index_max;
if (spdk_nvme_probe(ctx, probe_cb, attach_cb, NULL)) { if (spdk_nvme_probe(NULL, ctx, probe_cb, attach_cb, NULL)) {
return -1; return -1;
} }

View File

@ -434,10 +434,10 @@ nvme_hotplug_monitor(void *cb_ctx, spdk_nvme_probe_cb probe_cb,
return 0; return 0;
} }
static int int
_spdk_nvme_probe(const struct spdk_nvme_transport_id *trid, void *cb_ctx, spdk_nvme_probe(const struct spdk_nvme_transport_id *trid, void *cb_ctx,
spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb) spdk_nvme_remove_cb remove_cb)
{ {
int rc; int rc;
struct spdk_nvme_ctrlr *ctrlr; struct spdk_nvme_ctrlr *ctrlr;
@ -501,19 +501,4 @@ _spdk_nvme_probe(const struct spdk_nvme_transport_id *trid, void *cb_ctx,
return rc; return rc;
} }
int spdk_nvme_discover(const struct spdk_nvme_transport_id *trid,
void *cb_ctx,
spdk_nvme_probe_cb probe_cb,
spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb)
{
return _spdk_nvme_probe(trid, cb_ctx, probe_cb, attach_cb, remove_cb);
}
int
spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb)
{
return _spdk_nvme_probe(NULL, cb_ctx, probe_cb, attach_cb, remove_cb);
}
SPDK_LOG_REGISTER_TRACE_FLAG("nvme", SPDK_TRACE_NVME) SPDK_LOG_REGISTER_TRACE_FLAG("nvme", SPDK_TRACE_NVME)

View File

@ -237,7 +237,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
return 1; return 1;
} }

View File

@ -653,7 +653,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "nvme_probe() failed\n"); fprintf(stderr, "nvme_probe() failed\n");
exit(1); exit(1);
} }

View File

@ -562,7 +562,7 @@ register_controllers(void)
{ {
printf("Initializing NVMe Controllers\n"); printf("Initializing NVMe Controllers\n");
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
return 1; return 1;
} }

View File

@ -526,7 +526,7 @@ register_controllers(void)
{ {
printf("Initializing NVMe Controllers\n"); printf("Initializing NVMe Controllers\n");
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "spdk_nvme_probe() failed\n"); fprintf(stderr, "spdk_nvme_probe() failed\n");
return 1; return 1;
} }

View File

@ -427,7 +427,7 @@ int main(int argc, char **argv)
exit(1); exit(1);
} }
if (spdk_nvme_probe(NULL, probe_cb, attach_cb, NULL) != 0) { if (spdk_nvme_probe(NULL, NULL, probe_cb, attach_cb, NULL) != 0) {
fprintf(stderr, "nvme_probe() failed\n"); fprintf(stderr, "nvme_probe() failed\n");
exit(1); exit(1);
} }