nvme: add remove callback to spdk_nvme_probe()

This will allow removal notifications to be propagated to the library
user (e.g. for hotplug).

The callback is currently unused, but this at least prepares the API for
the future hotplug support.

Based on a patch by Dave Jiang <dave.jiang@intel.com>

Change-Id: I20b1c2dbf5e084e0b45a7e51205aba4514ee9a95
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Daniel Verkamp 2016-06-21 16:49:26 -07:00
parent e2d3cc6502
commit 19fec6bb9c
15 changed files with 31 additions and 15 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -100,6 +100,14 @@ typedef void (*spdk_nvme_attach_cb)(void *cb_ctx, struct spdk_pci_device *pci_de
struct spdk_nvme_ctrlr *ctrlr,
const struct spdk_nvme_ctrlr_opts *opts);
/**
* Callback for spdk_nvme_probe() to report that a device attached to the userspace NVMe driver
* has been removed from the system.
*
* \param ctrlr NVMe controller instance that was removed.
*/
typedef void (*spdk_nvme_remove_cb)(void *cb_ctx, struct spdk_nvme_ctrlr *ctrlr);
/**
* \brief Enumerate the NVMe devices attached to the system and attach the userspace NVMe driver
* to them if desired.
@ -108,6 +116,9 @@ typedef void (*spdk_nvme_attach_cb)(void *cb_ctx, struct spdk_pci_device *pci_de
* \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.
*
* If called more than once, only devices that are not already attached to the SPDK NVMe driver
* will be reported.
@ -115,7 +126,10 @@ typedef void (*spdk_nvme_attach_cb)(void *cb_ctx, struct spdk_pci_device *pci_de
* 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.
*/
int spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_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);
/**
* \brief Detaches specified device returned by \ref spdk_nvme_probe()'s attach_cb from the NVMe driver.

View File

@ -197,7 +197,8 @@ nvme_enum_cb(void *ctx, struct spdk_pci_device *pci_dev)
}
int
spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb)
spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb,
spdk_nvme_remove_cb remove_cb)
{
int rc, start_rc;
struct nvme_enum_ctx enum_ctx;

View File

@ -279,7 +279,7 @@ spdk_nvmf_init_nvme(void)
}
/* Probe the physical NVMe devices */
if (spdk_nvme_probe(&ctx, probe_cb, attach_cb)) {
if (spdk_nvme_probe(&ctx, probe_cb, attach_cb, NULL)) {
SPDK_ERRLOG("One or more controllers failed in spdk_nvme_probe()\n");
}

View File

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

View File

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

View File

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

View File

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

View File

@ -123,7 +123,8 @@ spdk_nvmf_request_complete(struct spdk_nvmf_request *req)
}
int
spdk_nvme_probe(void *cb_ctx, spdk_nvme_probe_cb probe_cb, spdk_nvme_attach_cb attach_cb)
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 -1;
}