nvme: Add spdk_nvme_detach_poll() to simplify a common use case

Add a new function spdk_nvme_detach_poll() to simplify a common
use case to continue polling until all detachments complete.
Then use the function for the common use case throughout.

Besides, usage by simple_copy application was not correct, and
fix it in this patch.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: Ic14711cd8478bf221c0fe375301e77b395b37f26
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/8509
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Shuhei Matsumoto 2021-06-25 05:30:55 +09:00 committed by Jim Harris
parent 5d617b4855
commit 4fe4040a14
22 changed files with 58 additions and 39 deletions

View File

@ -60,6 +60,9 @@ that if a controller has a CMB and supports SQs in the CMB, SPDK will not use
the CMB for SQs by default - the user must set use_cmb_sqs to true in
the spdk_nvme_ctrlr_opts structure prior to controller attach.
Add a new function `spdk_nvme_detach_poll` to simplify a common use case to continue
polling until all detachments complete.
### rpc
New RPC `bdev_rbd_register_cluster` and `bdev_rbd_unregister_cluster` was added, it allows to create

View File

@ -912,8 +912,8 @@ unregister_controllers(void)
free(entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
}

View File

@ -1397,8 +1397,8 @@ static void spdk_fio_cleanup(struct thread_data *td)
free(fio_ctrlr);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
if (fio_options->enable_vmd) {

View File

@ -386,8 +386,8 @@ cleanup(void)
free(ctrlr_entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
}

View File

@ -1700,8 +1700,8 @@ int main(int argc, char **argv)
spdk_nvme_detach_async(dev->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
return 0;

View File

@ -2701,8 +2701,8 @@ unregister_controllers(void)
free(entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
if (g_vmd) {

View File

@ -351,8 +351,8 @@ cleanup(void)
spdk_nvme_detach_async(g_config.pmr_dev.ctrlr, &detach_ctx);
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
}

View File

@ -970,8 +970,8 @@ unregister_controllers(void)
free(entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
}

View File

@ -950,6 +950,13 @@ int spdk_nvme_detach_async(struct spdk_nvme_ctrlr *ctrlr,
*/
int spdk_nvme_detach_poll_async(struct spdk_nvme_detach_ctx *detach_ctx);
/**
* Continue calling spdk_nvme_detach_poll_async() internally until it returns 0.
*
* \param detach_ctx Context to track the detachment.
*/
void spdk_nvme_detach_poll(struct spdk_nvme_detach_ctx *detach_ctx);
/**
* Update the transport ID for a given controller.
*

View File

@ -234,6 +234,14 @@ spdk_nvme_detach_poll_async(struct spdk_nvme_detach_ctx *detach_ctx)
return 0;
}
void
spdk_nvme_detach_poll(struct spdk_nvme_detach_ctx *detach_ctx)
{
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
}
}
void
nvme_completion_poll_cb(void *arg, const struct spdk_nvme_cpl *cpl)
{

View File

@ -26,6 +26,7 @@
spdk_nvme_detach;
spdk_nvme_detach_async;
spdk_nvme_detach_poll_async;
spdk_nvme_detach_poll;
spdk_nvme_pcie_set_hotplug_filter;

View File

@ -547,8 +547,8 @@ free_controllers(void)
free(ctrlr);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
}

View File

@ -60,8 +60,8 @@ cleanup(void)
free(ctrlr_entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
}

View File

@ -548,8 +548,8 @@ int main(int argc, char **argv)
spdk_nvme_detach_async(dev->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
done:

View File

@ -649,8 +649,8 @@ int main(int argc, char **argv)
spdk_nvme_detach_async(iter->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
return rc;

View File

@ -273,8 +273,8 @@ exit:
foreach_dev(dev) {
spdk_nvme_detach_async(dev->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
return failed;

View File

@ -662,8 +662,8 @@ cleanup(void)
free(ctrlr_entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
}

View File

@ -451,8 +451,8 @@ int main(int argc, char **argv)
spdk_nvme_detach_async(iter->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
return ret;

View File

@ -561,8 +561,8 @@ unregister_controllers(void)
free(entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
}

View File

@ -540,8 +540,8 @@ int main(int argc, char **argv)
spdk_nvme_detach_async(iter->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
return rc;

View File

@ -385,16 +385,16 @@ cleanup(struct simple_copy_context *context)
while (ns_entry) {
struct ns_entry *next = ns_entry->next;
detach_ctx = NULL;
spdk_nvme_detach_async(ns_entry->ctrlr, &detach_ctx);
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
}
free(ns_entry);
ns_entry = next;
}
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
for (i = 0; i < NUM_LBAS; i++) {
if (context->write_bufs && context->write_bufs[i]) {
spdk_free(context->write_bufs[i]);

View File

@ -113,8 +113,8 @@ cleanup(void)
free(ctrlr_entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
if (detach_ctx) {
spdk_nvme_detach_poll(detach_ctx);
}
}