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 <changpeng.liu@intel.com> Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/976 Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com> Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
parent
1914de0920
commit
0841adda40
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user