From eba7fce38fcec5a387c5b5515d90f3c1096f54e0 Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Tue, 30 Apr 2019 02:39:11 -0700 Subject: [PATCH] rocksdb: cleanup SpdkInitializeThread/SpdkFinalizeThread Remove SpdkFinalizeThread. It is no longer needed - the thread-local destructor handles the cleanup. Keep SpdkInitializeThread but make it static. We still need this function for the main thread, so that it can be explicitly called after the filesystem has been loaded. Part of this patch moves the rocksdb_commit_id to a version that doesn't make calls to these functions. Signed-off-by: Jim Harris Change-Id: Ib9aefdfede7e5636085079d2226ec1c4d2cae406 Reviewed-on: https://review.gerrithub.io/c/spdk/spdk/+/452687 Tested-by: SPDK CI Jenkins Reviewed-by: Ben Walker Reviewed-by: Shuhei Matsumoto Reviewed-by: Darek Stojaczyk --- lib/rocksdb/env_spdk.cc | 26 +++++++++++++------------- test/blobfs/rocksdb/rocksdb_commit_id | 2 +- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/rocksdb/env_spdk.cc b/lib/rocksdb/env_spdk.cc index d5b02339b..8f00a2c1c 100644 --- a/lib/rocksdb/env_spdk.cc +++ b/lib/rocksdb/env_spdk.cc @@ -59,8 +59,7 @@ std::string g_bdev_name; volatile bool g_spdk_ready = false; volatile bool g_spdk_start_failure = false; -void SpdkInitializeThread(void); -void SpdkFinalizeThread(void); +static void SpdkInitializeThread(void); class SpdkThreadCtx { @@ -74,7 +73,10 @@ public: ~SpdkThreadCtx(void) { - SpdkFinalizeThread(); + if (channel) { + spdk_fs_free_thread_ctx(channel); + channel = NULL; + } } private: @@ -598,25 +600,23 @@ public: } }; -void SpdkInitializeThread(void) +/* The thread local constructor doesn't work for the main thread, since + * the filesystem hasn't been loaded yet. So we break out this + * SpdkInitializeThread function, so that the main thread can explicitly + * call it after the filesystem has been loaded. + */ +static void SpdkInitializeThread(void) { struct spdk_thread *thread; - if (g_fs != NULL && g_sync_args.channel == NULL) { + assert(g_sync_args.channel == NULL); + if (g_fs != NULL) { thread = spdk_thread_create("spdk_rocksdb", NULL); spdk_set_thread(thread); g_sync_args.channel = spdk_fs_alloc_thread_ctx(g_fs); } } -void SpdkFinalizeThread(void) -{ - if (g_sync_args.channel) { - spdk_fs_free_thread_ctx(g_sync_args.channel); - g_sync_args.channel = NULL; - } -} - static void fs_load_cb(__attribute__((unused)) void *ctx, struct spdk_filesystem *fs, int fserrno) diff --git a/test/blobfs/rocksdb/rocksdb_commit_id b/test/blobfs/rocksdb/rocksdb_commit_id index 3d861c9eb..efac5a55d 100644 --- a/test/blobfs/rocksdb/rocksdb_commit_id +++ b/test/blobfs/rocksdb/rocksdb_commit_id @@ -1 +1 @@ -803b318a9e1c0244030c1775c1b84b4f385a8908 +526c73bd94150cc8fbd651f736e1ca95f50d8e13