test/nvme: Use spdk_nvme_detach_async() and spdk_nvme_detach_poll_async()

Use spdk_nvme_detach_async() and spdk_nvme_detach_poll_async() with
a local variable detach_ctx to detach multiple controllers.

Signed-off-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Change-Id: I77cdc07ddfcd97569e31eeb245cd4e5a26289dbd
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/4441
Reviewed-by: Aleksey Marchuk <alexeymar@mellanox.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
This commit is contained in:
Shuhei Matsumoto 2020-10-16 09:02:22 +09:00 committed by Jim Harris
parent 7a85c283d9
commit 938d2ae254
8 changed files with 47 additions and 8 deletions

View File

@ -523,6 +523,7 @@ int main(int argc, char **argv)
struct dev *dev;
struct spdk_env_opts opts;
int rc;
struct spdk_nvme_detach_ctx *detach_ctx = NULL;
rc = parse_args(argc, argv);
if (rc != 0) {
@ -593,7 +594,11 @@ int main(int argc, char **argv)
}
foreach_dev(dev) {
spdk_nvme_detach(dev->ctrlr);
spdk_nvme_detach_async(dev->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
}
done:

View File

@ -607,6 +607,7 @@ int main(int argc, char **argv)
struct dev *iter;
int rc;
struct spdk_env_opts opts;
struct spdk_nvme_detach_ctx *detach_ctx = NULL;
spdk_env_opts_init(&opts);
opts.name = "nvme_dp";
@ -643,7 +644,11 @@ int main(int argc, char **argv)
printf("Cleaning up...\n");
foreach_dev(iter) {
spdk_nvme_detach(iter->ctrlr);
spdk_nvme_detach_async(iter->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
}
return rc;

View File

@ -215,6 +215,7 @@ int main(int argc, char **argv)
struct dev *dev;
struct spdk_env_opts opts;
int rc;
struct spdk_nvme_detach_ctx *detach_ctx = NULL;
spdk_env_opts_init(&opts);
opts.name = "err_injection";
@ -270,7 +271,10 @@ int main(int argc, char **argv)
exit:
printf("Cleaning up...\n");
foreach_dev(dev) {
spdk_nvme_detach(dev->ctrlr);
spdk_nvme_detach_async(dev->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
}
return failed;

View File

@ -645,6 +645,7 @@ cleanup(void)
{
struct ns_entry *ns_entry = g_ns;
struct ctrlr_entry *ctrlr_entry, *tmp_ctrlr_entry;
struct spdk_nvme_detach_ctx *detach_ctx = NULL;
while (ns_entry) {
struct ns_entry *next = ns_entry->next;
@ -657,9 +658,13 @@ cleanup(void)
TAILQ_FOREACH_SAFE(ctrlr_entry, &g_ctrlr, link, tmp_ctrlr_entry) {
TAILQ_REMOVE(&g_ctrlr, ctrlr_entry, link);
spdk_nvme_detach(ctrlr_entry->ctrlr);
spdk_nvme_detach_async(ctrlr_entry->ctrlr, &detach_ctx);
free(ctrlr_entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
}
}
int main(int argc, char **argv)

View File

@ -414,6 +414,7 @@ int main(int argc, char **argv)
struct dev *iter;
struct spdk_env_opts opts;
int ret = 0;
struct spdk_nvme_detach_ctx *detach_ctx = NULL;
spdk_env_opts_init(&opts);
opts.name = "reserve";
@ -448,7 +449,11 @@ int main(int argc, char **argv)
printf("Reservation test %s\n", ret ? "failed" : "passed");
foreach_dev(iter) {
spdk_nvme_detach(iter->ctrlr);
spdk_nvme_detach_async(iter->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
}
return ret;

View File

@ -553,12 +553,17 @@ static void
unregister_controllers(void)
{
struct ctrlr_entry *entry, *tmp;
struct spdk_nvme_detach_ctx *detach_ctx = NULL;
TAILQ_FOREACH_SAFE(entry, &g_controllers, link, tmp) {
TAILQ_REMOVE(&g_controllers, entry, link);
spdk_nvme_detach(entry->ctrlr);
spdk_nvme_detach_async(entry->ctrlr, &detach_ctx);
free(entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
}
}
static int

View File

@ -495,6 +495,7 @@ int main(int argc, char **argv)
struct dev *iter;
int rc;
struct spdk_env_opts opts;
struct spdk_nvme_detach_ctx *detach_ctx = NULL;
spdk_env_opts_init(&opts);
opts.name = "nvme_sgl";
@ -536,7 +537,11 @@ int main(int argc, char **argv)
printf("Cleaning up...\n");
foreach_dev(iter) {
spdk_nvme_detach(iter->ctrlr);
spdk_nvme_detach_async(iter->ctrlr, &detach_ctx);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
}
return rc;

View File

@ -100,6 +100,7 @@ cleanup(void)
{
struct ns_entry *ns_entry, *tmp_ns_entry;
struct ctrlr_entry *ctrlr_entry, *tmp_ctrlr_entry;
struct spdk_nvme_detach_ctx *detach_ctx = NULL;
TAILQ_FOREACH_SAFE(ns_entry, &g_namespaces, link, tmp_ns_entry) {
TAILQ_REMOVE(&g_namespaces, ns_entry, link);
@ -108,9 +109,13 @@ cleanup(void)
TAILQ_FOREACH_SAFE(ctrlr_entry, &g_controllers, link, tmp_ctrlr_entry) {
TAILQ_REMOVE(&g_controllers, ctrlr_entry, link);
spdk_nvme_detach(ctrlr_entry->ctrlr);
spdk_nvme_detach_async(ctrlr_entry->ctrlr, &detach_ctx);
free(ctrlr_entry);
}
while (detach_ctx && spdk_nvme_detach_poll_async(detach_ctx) == -EAGAIN) {
;
}
}
static void