Give ocf_ctx get/put semantics
Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
@@ -1216,6 +1216,8 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
|
||||
if (result)
|
||||
goto _cache_mng_init_instance_ERROR;
|
||||
|
||||
ocf_ctx_get(ctx);
|
||||
|
||||
if (params.locked) {
|
||||
/* Increment reference counter to match cache_lock /
|
||||
cache_unlock convention. User is expected to call
|
||||
|
||||
@@ -119,11 +119,15 @@ void cache_mng_core_remove_from_cache(struct ocf_cache *cache, int core_id)
|
||||
|
||||
void ocf_mngt_cache_put(ocf_cache_t cache)
|
||||
{
|
||||
ocf_ctx_t ctx;
|
||||
|
||||
OCF_CHECK_NULL(cache);
|
||||
|
||||
if (ocf_refcnt_dec(&cache->refcnt.cache) == 0) {
|
||||
ctx = cache->owner;
|
||||
ocf_metadata_deinit(cache);
|
||||
env_vfree(cache);
|
||||
ocf_ctx_put(ctx);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ int ocf_ctx_volume_create(ocf_ctx_t ctx, ocf_volume_t *volume,
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int ocf_ctx_init(ocf_ctx_t *ctx, const struct ocf_ctx_config *cfg)
|
||||
int ocf_ctx_create(ocf_ctx_t *ctx, const struct ocf_ctx_config *cfg)
|
||||
{
|
||||
ocf_ctx_t ocf_ctx;
|
||||
int ret;
|
||||
@@ -127,6 +127,7 @@ int ocf_ctx_init(ocf_ctx_t *ctx, const struct ocf_ctx_config *cfg)
|
||||
return -ENOMEM;
|
||||
|
||||
INIT_LIST_HEAD(&ocf_ctx->caches);
|
||||
env_atomic_set(&ocf_ctx->ref_count, 1);
|
||||
ret = env_mutex_init(&ocf_ctx->lock);
|
||||
if (ret)
|
||||
goto err_ctx;
|
||||
@@ -166,25 +167,30 @@ err_ctx:
|
||||
/*
|
||||
*
|
||||
*/
|
||||
int ocf_ctx_exit(ocf_ctx_t ctx)
|
||||
void ocf_ctx_get(ocf_ctx_t ctx)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
OCF_CHECK_NULL(ctx);
|
||||
|
||||
/* Check if caches are setup */
|
||||
env_atomic_inc(&ctx->ref_count);
|
||||
}
|
||||
|
||||
/*
|
||||
*
|
||||
*/
|
||||
void ocf_ctx_put(ocf_ctx_t ctx)
|
||||
{
|
||||
OCF_CHECK_NULL(ctx);
|
||||
|
||||
if (env_atomic_dec_return(&ctx->ref_count))
|
||||
return;
|
||||
|
||||
env_mutex_lock(&ctx->lock);
|
||||
if (!list_empty(&ctx->caches))
|
||||
result = -EEXIST;
|
||||
ENV_BUG_ON(!list_empty(&ctx->caches));
|
||||
env_mutex_unlock(&ctx->lock);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
ocf_mngt_core_pool_deinit(ctx);
|
||||
ocf_core_volume_type_deinit(ctx);
|
||||
ocf_utils_deinit(ctx);
|
||||
ocf_logger_close(&ctx->logger);
|
||||
env_free(ctx);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -20,6 +20,7 @@ struct ocf_ctx {
|
||||
const struct ocf_ctx_config *cfg;
|
||||
struct ocf_logger logger;
|
||||
struct ocf_volume_type *volume_type[OCF_VOLUME_TYPE_MAX];
|
||||
env_atomic ref_count;
|
||||
env_mutex lock;
|
||||
struct list_head caches;
|
||||
struct {
|
||||
|
||||
Reference in New Issue
Block a user