diff options
author | Yaniv Kaul <ykaul@redhat.com> | 2018-12-27 18:56:16 +0200 |
---|---|---|
committer | Amar Tumballi <amarts@redhat.com> | 2019-01-29 09:27:22 +0000 |
commit | c7d1aee76d5713d1f337ab1c831c0ed74e4676e1 (patch) | |
tree | dac0618f33a560ae1bfbd5c92c5762d42d26797b /rpc | |
parent | f747d55a7fd364e2b9a74fe40360ab3cb7b11537 (diff) |
Multiple files: reduce work while under lock.
Mostly, unlock before logging.
In some cases, moved different code that was not needed
to be under lock (for example, taking time, or malloc'ing)
to be executed before taking the lock.
Note: logging might be slightly less accurate in order, since it may
not be done now under the lock, so order of logs is racy. I think
it's a reasonable compromise.
Compile-tested only!
updates: bz#1193929
Signed-off-by: Yaniv Kaul <ykaul@redhat.com>
Change-Id: I2438710016afc9f4f62a176ef1a0d3ed793b4f89
Diffstat (limited to 'rpc')
-rw-r--r-- | rpc/rpc-lib/src/rpc-drc.c | 30 |
1 files changed, 13 insertions, 17 deletions
diff --git a/rpc/rpc-lib/src/rpc-drc.c b/rpc/rpc-lib/src/rpc-drc.c index e2a448fa640..bd8695c5ccf 100644 --- a/rpc/rpc-lib/src/rpc-drc.c +++ b/rpc/rpc-lib/src/rpc-drc.c @@ -699,47 +699,42 @@ rpcsvc_drc_init(rpcsvc_t *svc, dict_t *options) LOCK_INIT(&drc->lock); svc->drc = drc; - LOCK(&drc->lock); - /* Specify type of DRC to be used */ ret = dict_get_uint32(options, "nfs.drc-type", &drc_type); if (ret) { gf_log(GF_RPCSVC, GF_LOG_DEBUG, - "drc type not set." - " Continuing with default"); + "drc type not set. Continuing with default"); drc_type = DRC_DEFAULT_TYPE; } - drc->type = drc_type; - /* Set the global cache size (no. of ops to cache) */ ret = dict_get_uint32(options, "nfs.drc-size", &drc_size); if (ret) { gf_log(GF_RPCSVC, GF_LOG_DEBUG, - "drc size not set." - " Continuing with default size"); + "drc size not set. Continuing with default size"); drc_size = DRC_DEFAULT_CACHE_SIZE; } + LOCK(&drc->lock); + + drc->type = drc_type; drc->global_cache_size = drc_size; /* Mempool for cached ops */ drc->mempool = mem_pool_new(drc_cached_op_t, drc->global_cache_size); if (!drc->mempool) { + UNLOCK(&drc->lock); gf_log(GF_RPCSVC, GF_LOG_ERROR, - "Failed to get mempool for" - " DRC, drc-size: %d", - drc->global_cache_size); + "Failed to get mempool for DRC, drc-size: %d", drc_size); ret = -1; - goto out; + goto post_unlock; } /* What percent of cache to be evicted whenever it fills up */ ret = dict_get_uint32(options, "nfs.drc-lru-factor", &drc_factor); if (ret) { gf_log(GF_RPCSVC, GF_LOG_DEBUG, - "drc lru factor not set." - " Continuing with policy default"); + "drc lru factor not set. Continuing with policy default"); drc_factor = DRC_DEFAULT_LRU_FACTOR; } @@ -750,15 +745,16 @@ rpcsvc_drc_init(rpcsvc_t *svc, dict_t *options) ret = rpcsvc_register_notify(svc, rpcsvc_drc_notify, THIS); if (ret) { + UNLOCK(&drc->lock); gf_log(GF_RPCSVC, GF_LOG_ERROR, "registration of drc_notify function failed"); - goto out; + goto post_unlock; } - gf_log(GF_RPCSVC, GF_LOG_DEBUG, "drc init successful"); drc->status = DRC_INITIATED; -out: UNLOCK(&drc->lock); + gf_log(GF_RPCSVC, GF_LOG_DEBUG, "drc init successful"); +post_unlock: if (ret == -1) { if (drc->mempool) { mem_pool_destroy(drc->mempool); |