From 11104c1c85607ef3bd1ef2f4508ef378a175fc88 Mon Sep 17 00:00:00 2001 From: Tomasz Zawadzki Date: Fri, 27 Oct 2017 11:57:11 +0200 Subject: [PATCH] fio_plugin: add back bdev and copy engine finish During SPDK asynchronous finish cleaning up of bdev and copy engine was removed. Now it is added back taking into account asynchronous nature of those two calls. Only when spdk environment was initialized, on fio_exit SPDK environment is cleaned up. Similar to init path, this is done in temporary SPDK thread. When in here, fixed fio_thread->iocq memleak. Signed-off-by: Tomasz Zawadzki Change-Id: I4558af4539dd2617d17aeda9b568b697ea54ff44 Reviewed-on: https://review.gerrithub.io/383731 Reviewed-by: Jim Harris Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp --- examples/bdev/fio_plugin/fio_plugin.c | 55 +++++++++++++++++++++++++-- 1 file changed, 52 insertions(+), 3 deletions(-) diff --git a/examples/bdev/fio_plugin/fio_plugin.c b/examples/bdev/fio_plugin/fio_plugin.c index 14bcec53a3..1b9a6289db 100644 --- a/examples/bdev/fio_plugin/fio_plugin.c +++ b/examples/bdev/fio_plugin/fio_plugin.c @@ -94,6 +94,7 @@ struct spdk_fio_thread { }; static __thread struct spdk_fio_thread *g_thread; +static bool g_spdk_env_initialized = false; static int spdk_fio_init(struct thread_data *td); static void spdk_fio_cleanup(struct thread_data *td); @@ -296,7 +297,6 @@ spdk_fio_init_env(struct thread_data *td) static int spdk_fio_setup(struct thread_data *td) { - static bool env_initialized = false; unsigned int i; struct fio_file *f; @@ -305,13 +305,13 @@ spdk_fio_setup(struct thread_data *td) return -1; } - if (!env_initialized) { + if (!g_spdk_env_initialized) { if (spdk_fio_init_env(td)) { SPDK_ERRLOG("failed to initialize\n"); return -1; } - env_initialized = true; + g_spdk_env_initialized = true; } for_each_file(td, f, i) { @@ -402,6 +402,7 @@ spdk_fio_cleanup(struct thread_data *td) spdk_free_thread(); spdk_ring_free(fio_thread->ring); + free(fio_thread->iocq); free(fio_thread); td->io_ops_data = NULL; @@ -646,7 +647,55 @@ static void fio_init spdk_fio_register(void) register_ioengine(&ioengine); } +static void +spdk_fio_module_finish_done(void *cb_arg) +{ + *(bool *)cb_arg = true; +} + +static void +spdk_fio_finish_env(void) +{ + struct thread_data *td; + int rc; + bool done = false; + + td = calloc(1, sizeof(*td)); + if (!td) { + SPDK_ERRLOG("Unable to allocate thread_data\n"); + return; + } + /* Create an SPDK thread temporarily */ + rc = spdk_fio_init_thread(td); + if (rc < 0) { + SPDK_ERRLOG("Failed to create finish thread\n"); + free(td); + return; + } + + spdk_bdev_finish(spdk_fio_module_finish_done, &done); + + while (!done) { + spdk_fio_getevents(td, 0, 128, NULL); + } + done = false; + + spdk_copy_engine_finish(spdk_fio_module_finish_done, &done); + + while (!done) { + spdk_fio_getevents(td, 0, 128, NULL); + } + + /* Destroy the temporary SPDK thread */ + spdk_fio_cleanup(td); + free(td); +} + static void fio_exit spdk_fio_unregister(void) { + if (g_spdk_env_initialized) { + spdk_fio_finish_env(); + g_spdk_env_initialized = false; + } unregister_ioengine(&ioengine); }