diff --git a/examples/nvme/arbitration/arbitration.c b/examples/nvme/arbitration/arbitration.c index d0d7513d4..d1391b6b7 100644 --- a/examples/nvme/arbitration/arbitration.c +++ b/examples/nvme/arbitration/arbitration.c @@ -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; } diff --git a/examples/nvme/fio_plugin/fio_plugin.c b/examples/nvme/fio_plugin/fio_plugin.c index 36463b38e..a845d4fb0 100644 --- a/examples/nvme/fio_plugin/fio_plugin.c +++ b/examples/nvme/fio_plugin/fio_plugin.c @@ -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; } diff --git a/examples/nvme/hello_world/hello_world.c b/examples/nvme/hello_world/hello_world.c index d6a512116..19ba9843a 100644 --- a/examples/nvme/hello_world/hello_world.c +++ b/examples/nvme/hello_world/hello_world.c @@ -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(); diff --git a/examples/nvme/identify/identify.c b/examples/nvme/identify/identify.c index 753e9d356..80f8c6120 100644 --- a/examples/nvme/identify/identify.c +++ b/examples/nvme/identify/identify.c @@ -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; } diff --git a/examples/nvme/nvme_manage/nvme_manage.c b/examples/nvme/nvme_manage/nvme_manage.c index a8df9bb81..03ecee46c 100644 --- a/examples/nvme/nvme_manage/nvme_manage.c +++ b/examples/nvme/nvme_manage/nvme_manage.c @@ -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; } diff --git a/examples/nvme/perf/perf.c b/examples/nvme/perf/perf.c index cd6b2f845..f1530966d 100644 --- a/examples/nvme/perf/perf.c +++ b/examples/nvme/perf/perf.c @@ -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; } diff --git a/examples/nvme/reserve/reservation.c b/examples/nvme/reserve/reservation.c index 60fe675af..75918e891 100644 --- a/examples/nvme/reserve/reservation.c +++ b/examples/nvme/reserve/reservation.c @@ -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; } diff --git a/include/spdk/nvme.h b/include/spdk/nvme.h index bb8d08ff0..57b2fb0ad 100644 --- a/include/spdk/nvme.h +++ b/include/spdk/nvme.h @@ -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. diff --git a/lib/nvme/nvme.c b/lib/nvme/nvme.c index 3260f128b..d4bb5ab6f 100644 --- a/lib/nvme/nvme.c +++ b/lib/nvme/nvme.c @@ -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; diff --git a/lib/nvmf/controller.c b/lib/nvmf/controller.c index ea3749d37..97ed795af 100644 --- a/lib/nvmf/controller.c +++ b/lib/nvmf/controller.c @@ -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"); } diff --git a/test/lib/nvme/aer/aer.c b/test/lib/nvme/aer/aer.c index da0bf3d2d..f1e619018 100644 --- a/test/lib/nvme/aer/aer.c +++ b/test/lib/nvme/aer/aer.c @@ -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; } diff --git a/test/lib/nvme/e2edp/nvme_dp.c b/test/lib/nvme/e2edp/nvme_dp.c index e5f5fcc87..95062e2a6 100644 --- a/test/lib/nvme/e2edp/nvme_dp.c +++ b/test/lib/nvme/e2edp/nvme_dp.c @@ -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); } diff --git a/test/lib/nvme/reset/reset.c b/test/lib/nvme/reset/reset.c index 39d672853..f288c45f2 100644 --- a/test/lib/nvme/reset/reset.c +++ b/test/lib/nvme/reset/reset.c @@ -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; } diff --git a/test/lib/nvme/sgl/nvme_sgl.c b/test/lib/nvme/sgl/nvme_sgl.c index bde8669ac..3cc7a46ac 100644 --- a/test/lib/nvme/sgl/nvme_sgl.c +++ b/test/lib/nvme/sgl/nvme_sgl.c @@ -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); } diff --git a/test/lib/nvmf/nvmf_c/nvmf_ut.c b/test/lib/nvmf/nvmf_c/nvmf_ut.c index 8b5b43443..40311d347 100644 --- a/test/lib/nvmf/nvmf_c/nvmf_ut.c +++ b/test/lib/nvmf/nvmf_c/nvmf_ut.c @@ -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; }