fio_plugin: initalize when create_serialize=0
When the fio plugin is used with reate_serialize set to false, fio calls the init callback (spdk_fio_init()) before calling the setup callback (spdk_fio_setup()). When create_serialize is true, spdk_fio_setup() is called earlier. Both spdk_fio_setup() and spdk_fio_init() call functions that require that the SPDK libraries have been initialized. While it is arguably a bug in SPDK that per-thread initialization happens before global initialization, it is not terribly difficult to work around in fio_plugin. The workaround implemented in this patch splits the start of the plugin's init thread into its own function and calls it from both spdk_fio_setup() and spdk_fio_init(). The init thread is started while holding a mutex, and as before there is a guard to be sure that the init thread is created only once. Fixes issue #2843 Signed-off-by: Mike Gerdts <mgerdts@nvidia.com> Change-Id: I20d1863a88b75b416283f9466ee1186d8ef05063 Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/16053 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Ben Walker <benjamin.walker@intel.com>
This commit is contained in:
parent
9b754587c7
commit
9e96e331c3
@ -531,6 +531,26 @@ fio_redirected_to_dev_null(void)
|
||||
return true;
|
||||
}
|
||||
|
||||
static int
|
||||
spdk_fio_init_spdk_env(struct thread_data *td)
|
||||
{
|
||||
static pthread_mutex_t setup_lock = PTHREAD_MUTEX_INITIALIZER;
|
||||
|
||||
pthread_mutex_lock(&setup_lock);
|
||||
if (!g_spdk_env_initialized) {
|
||||
if (spdk_fio_init_env(td)) {
|
||||
pthread_mutex_unlock(&setup_lock);
|
||||
SPDK_ERRLOG("failed to initialize\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_spdk_env_initialized = true;
|
||||
}
|
||||
pthread_mutex_unlock(&setup_lock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Called for each thread to fill in the 'real_file_size' member for
|
||||
* each file associated with this thread. This is called prior to
|
||||
* the init operation (spdk_fio_init()) below. This call will occur
|
||||
@ -564,13 +584,8 @@ spdk_fio_setup(struct thread_data *td)
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!g_spdk_env_initialized) {
|
||||
if (spdk_fio_init_env(td)) {
|
||||
SPDK_ERRLOG("failed to initialize\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
g_spdk_env_initialized = true;
|
||||
if (spdk_fio_init_spdk_env(td) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
ctx.u.sa.td = td;
|
||||
@ -709,6 +724,10 @@ spdk_fio_init(struct thread_data *td)
|
||||
struct spdk_fio_thread *fio_thread;
|
||||
int rc;
|
||||
|
||||
if (spdk_fio_init_spdk_env(td) != 0) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* If thread has already been initialized, do nothing. */
|
||||
if (td->io_ops_data) {
|
||||
return 0;
|
||||
|
Loading…
Reference in New Issue
Block a user