From 0841adda406755adae3f8bd6cbdcf424523aadd3 Mon Sep 17 00:00:00 2001 From: Changpeng Liu Date: Fri, 21 Feb 2020 01:46:51 -0500 Subject: [PATCH] blobfs: move global cache initialization and free into a function Also rename __initialize_cache()/__free_cache() to the new name to reflect the logic. Change-Id: I69bec4a10b2f21a7c40475fc2a99919bc526c556 Signed-off-by: Changpeng Liu Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/976 Tested-by: SPDK CI Jenkins Reviewed-by: Shuhei Matsumoto Reviewed-by: Jim Harris --- lib/blobfs/blobfs.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/blobfs/blobfs.c b/lib/blobfs/blobfs.c index 6d114b09e..629cc42e5 100644 --- a/lib/blobfs/blobfs.c +++ b/lib/blobfs/blobfs.c @@ -315,17 +315,27 @@ __stop_cache_pool_mgmt(void *ctx) } static void -__initialize_cache(void) +initialize_global_cache(void) { - g_cache_pool_thread = spdk_thread_create("cache_pool_mgmt", NULL); - assert(g_cache_pool_thread != NULL); - spdk_thread_send_msg(g_cache_pool_thread, __start_cache_pool_mgmt, NULL); + pthread_mutex_lock(&g_cache_init_lock); + if (g_fs_count == 0) { + g_cache_pool_thread = spdk_thread_create("cache_pool_mgmt", NULL); + assert(g_cache_pool_thread != NULL); + spdk_thread_send_msg(g_cache_pool_thread, __start_cache_pool_mgmt, NULL); + } + g_fs_count++; + pthread_mutex_unlock(&g_cache_init_lock); } static void -__free_cache(void) +free_global_cache(void) { - spdk_thread_send_msg(g_cache_pool_thread, __stop_cache_pool_mgmt, NULL); + pthread_mutex_lock(&g_cache_init_lock); + g_fs_count--; + if (g_fs_count == 0) { + spdk_thread_send_msg(g_cache_pool_thread, __stop_cache_pool_mgmt, NULL); + } + pthread_mutex_unlock(&g_cache_init_lock); } static uint64_t @@ -521,12 +531,7 @@ common_fs_bs_init(struct spdk_filesystem *fs, struct spdk_blob_store *bs) fs->sync_target.sync_fs_channel->bs_channel = spdk_bs_alloc_io_channel(fs->bs); fs->sync_target.sync_fs_channel->send_request = __send_request_direct; - pthread_mutex_lock(&g_cache_init_lock); - if (g_fs_count == 0) { - __initialize_cache(); - } - g_fs_count++; - pthread_mutex_unlock(&g_cache_init_lock); + initialize_global_cache(); } static void @@ -898,12 +903,7 @@ unload_cb(void *ctx, int bserrno) free(file); } - pthread_mutex_lock(&g_cache_init_lock); - g_fs_count--; - if (g_fs_count == 0) { - __free_cache(); - } - pthread_mutex_unlock(&g_cache_init_lock); + free_global_cache(); args->fn.fs_op(args->arg, bserrno); free(req);