Change ctx lock to rmutex

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2019-07-23 12:50:45 +02:00
parent 6928db4a98
commit 331b99397f
6 changed files with 29 additions and 29 deletions

View File

@ -704,7 +704,7 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param
char cache_name[OCF_CACHE_NAME_SIZE]; char cache_name[OCF_CACHE_NAME_SIZE];
int ret = 0; int ret = 0;
ret = env_mutex_lock_interruptible(&param->ctx->lock); ret = env_rmutex_lock_interruptible(&param->ctx->lock);
if (ret) if (ret)
return ret; return ret;
@ -762,7 +762,7 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param
cache->metadata.is_volatile = cfg->metadata_volatile; cache->metadata.is_volatile = cfg->metadata_volatile;
out: out:
env_mutex_unlock(&param->ctx->lock); env_rmutex_unlock(&param->ctx->lock);
return ret; return ret;
} }
@ -1196,12 +1196,12 @@ static void _ocf_mngt_init_handle_error(ocf_ctx_t ctx,
if (params->flags.metadata_inited) if (params->flags.metadata_inited)
ocf_metadata_deinit(cache); ocf_metadata_deinit(cache);
env_mutex_lock(&ctx->lock); env_rmutex_lock(&ctx->lock);
list_del(&cache->list); list_del(&cache->list);
env_vfree(cache); env_vfree(cache);
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
} }
static void _ocf_mngt_attach_handle_error( static void _ocf_mngt_attach_handle_error(
@ -2028,12 +2028,12 @@ static void ocf_mngt_cache_stop_put_io_queues(ocf_pipeline_t pipeline,
static void ocf_mngt_cache_remove(ocf_ctx_t ctx, ocf_cache_t cache) static void ocf_mngt_cache_remove(ocf_ctx_t ctx, ocf_cache_t cache)
{ {
env_mutex_lock(&ctx->lock); env_rmutex_lock(&ctx->lock);
/* Mark device uninitialized */ /* Mark device uninitialized */
ocf_refcnt_freeze(&cache->refcnt.cache); ocf_refcnt_freeze(&cache->refcnt.cache);
/* Remove cache from the list */ /* Remove cache from the list */
list_del(&cache->list); list_del(&cache->list);
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
} }
static void ocf_mngt_cache_stop_finish(ocf_pipeline_t pipeline, static void ocf_mngt_cache_stop_finish(ocf_pipeline_t pipeline,

View File

@ -156,7 +156,7 @@ int ocf_mngt_cache_get_by_id(ocf_ctx_t ocf_ctx, ocf_cache_id_t id, ocf_cache_t *
} }
/* Lock caches list */ /* Lock caches list */
env_mutex_lock(&ocf_ctx->lock); env_rmutex_lock(&ocf_ctx->lock);
list_for_each_entry(iter, &ocf_ctx->caches, list) { list_for_each_entry(iter, &ocf_ctx->caches, list) {
if (iter->cache_id == id) { if (iter->cache_id == id) {
@ -173,7 +173,7 @@ int ocf_mngt_cache_get_by_id(ocf_ctx_t ocf_ctx, ocf_cache_id_t id, ocf_cache_t *
} }
} }
env_mutex_unlock(&ocf_ctx->lock); env_rmutex_unlock(&ocf_ctx->lock);
if (!instance) if (!instance)
error = -OCF_ERR_CACHE_NOT_EXIST; error = -OCF_ERR_CACHE_NOT_EXIST;
@ -363,7 +363,7 @@ static int _ocf_mngt_cache_get_list_cpy(ocf_ctx_t ocf_ctx, ocf_cache_t **list,
*list = NULL; *list = NULL;
*size = 0; *size = 0;
env_mutex_lock(&ocf_ctx->lock); env_rmutex_lock(&ocf_ctx->lock);
list_for_each_entry(iter, &ocf_ctx->caches, list) { list_for_each_entry(iter, &ocf_ctx->caches, list) {
count++; count++;
@ -392,7 +392,7 @@ static int _ocf_mngt_cache_get_list_cpy(ocf_ctx_t ocf_ctx, ocf_cache_t **list,
} }
END: END:
env_mutex_unlock(&ocf_ctx->lock); env_rmutex_unlock(&ocf_ctx->lock);
return result; return result;
} }

View File

@ -19,9 +19,9 @@ int ocf_mngt_core_pool_get_count(ocf_ctx_t ctx)
{ {
int count; int count;
OCF_CHECK_NULL(ctx); OCF_CHECK_NULL(ctx);
env_mutex_lock(&ctx->lock); env_rmutex_lock(&ctx->lock);
count = ctx->core_pool.core_pool_count; count = ctx->core_pool.core_pool_count;
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
return count; return count;
} }
@ -43,10 +43,10 @@ int ocf_mngt_core_pool_add(ocf_ctx_t ctx, ocf_uuid_t uuid, uint8_t type)
return result; return result;
} }
env_mutex_lock(&ctx->lock); env_rmutex_lock(&ctx->lock);
list_add(&volume->core_pool_item, &ctx->core_pool.core_pool_head); list_add(&volume->core_pool_item, &ctx->core_pool.core_pool_head);
ctx->core_pool.core_pool_count++; ctx->core_pool.core_pool_count++;
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
return result; return result;
} }
@ -59,14 +59,14 @@ int ocf_mngt_core_pool_visit(ocf_ctx_t ctx,
OCF_CHECK_NULL(ctx); OCF_CHECK_NULL(ctx);
OCF_CHECK_NULL(visitor); OCF_CHECK_NULL(visitor);
env_mutex_lock(&ctx->lock); env_rmutex_lock(&ctx->lock);
list_for_each_entry(svolume, &ctx->core_pool.core_pool_head, list_for_each_entry(svolume, &ctx->core_pool.core_pool_head,
core_pool_item) { core_pool_item) {
result = visitor(&svolume->uuid, visitor_ctx); result = visitor(&svolume->uuid, visitor_ctx);
if (result) if (result)
break; break;
} }
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
return result; return result;
} }
@ -94,10 +94,10 @@ void ocf_mngt_core_pool_remove(ocf_ctx_t ctx, ocf_volume_t volume)
{ {
OCF_CHECK_NULL(ctx); OCF_CHECK_NULL(ctx);
OCF_CHECK_NULL(volume); OCF_CHECK_NULL(volume);
env_mutex_lock(&ctx->lock); env_rmutex_lock(&ctx->lock);
ctx->core_pool.core_pool_count--; ctx->core_pool.core_pool_count--;
list_del(&volume->core_pool_item); list_del(&volume->core_pool_item);
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
ocf_volume_destroy(volume); ocf_volume_destroy(volume);
} }

View File

@ -17,13 +17,13 @@ uint32_t ocf_mngt_cache_get_count(ocf_ctx_t ctx)
OCF_CHECK_NULL(ctx); OCF_CHECK_NULL(ctx);
env_mutex_lock(&ctx->lock); env_rmutex_lock(&ctx->lock);
/* currently, there are no macros in list.h to get list size.*/ /* currently, there are no macros in list.h to get list size.*/
list_for_each_entry(cache, &ctx->caches, list) list_for_each_entry(cache, &ctx->caches, list)
count++; count++;
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
return count; return count;
} }

View File

@ -24,10 +24,10 @@ int ocf_ctx_register_volume_type_extended(ocf_ctx_t ctx, uint8_t type_id,
if (!ctx || !properties) if (!ctx || !properties)
return -EINVAL; return -EINVAL;
env_mutex_lock(&ctx->lock); env_rmutex_lock(&ctx->lock);
if (type_id >= OCF_VOLUME_TYPE_MAX || ctx->volume_type[type_id]) { if (type_id >= OCF_VOLUME_TYPE_MAX || ctx->volume_type[type_id]) {
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
result = -EINVAL; result = -EINVAL;
goto err; goto err;
} }
@ -36,7 +36,7 @@ int ocf_ctx_register_volume_type_extended(ocf_ctx_t ctx, uint8_t type_id,
if (!ctx->volume_type[type_id]) if (!ctx->volume_type[type_id])
result = -EINVAL; result = -EINVAL;
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
if (result) if (result)
goto err; goto err;
@ -65,14 +65,14 @@ void ocf_ctx_unregister_volume_type(ocf_ctx_t ctx, uint8_t type_id)
{ {
OCF_CHECK_NULL(ctx); OCF_CHECK_NULL(ctx);
env_mutex_lock(&ctx->lock); env_rmutex_lock(&ctx->lock);
if (type_id < OCF_VOLUME_TYPE_MAX && ctx->volume_type[type_id]) { if (type_id < OCF_VOLUME_TYPE_MAX && ctx->volume_type[type_id]) {
ocf_volume_type_deinit(ctx->volume_type[type_id]); ocf_volume_type_deinit(ctx->volume_type[type_id]);
ctx->volume_type[type_id] = NULL; ctx->volume_type[type_id] = NULL;
} }
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
} }
/* /*
@ -160,7 +160,7 @@ int ocf_ctx_create(ocf_ctx_t *ctx, const struct ocf_ctx_config *cfg)
INIT_LIST_HEAD(&ocf_ctx->caches); INIT_LIST_HEAD(&ocf_ctx->caches);
env_atomic_set(&ocf_ctx->ref_count, 1); env_atomic_set(&ocf_ctx->ref_count, 1);
ret = env_mutex_init(&ocf_ctx->lock); ret = env_rmutex_init(&ocf_ctx->lock);
if (ret) if (ret)
goto err_ctx; goto err_ctx;
@ -216,9 +216,9 @@ void ocf_ctx_put(ocf_ctx_t ctx)
if (env_atomic_dec_return(&ctx->ref_count)) if (env_atomic_dec_return(&ctx->ref_count))
return; return;
env_mutex_lock(&ctx->lock); env_rmutex_lock(&ctx->lock);
ENV_BUG_ON(!list_empty(&ctx->caches)); ENV_BUG_ON(!list_empty(&ctx->caches));
env_mutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
ocf_mngt_core_pool_deinit(ctx); ocf_mngt_core_pool_deinit(ctx);
ocf_core_volume_type_deinit(ctx); ocf_core_volume_type_deinit(ctx);

View File

@ -22,7 +22,7 @@ struct ocf_ctx {
struct ocf_logger logger; struct ocf_logger logger;
struct ocf_volume_type *volume_type[OCF_VOLUME_TYPE_MAX]; struct ocf_volume_type *volume_type[OCF_VOLUME_TYPE_MAX];
env_atomic ref_count; env_atomic ref_count;
env_mutex lock; env_rmutex lock;
struct list_head caches; struct list_head caches;
struct { struct {
struct list_head core_pool_head; struct list_head core_pool_head;