Introduce io_queues_lock

The queues can be created and destroyed dynamically at any point in
the cache lifetime, and this can happen from different execution contexts,
thus there is a need to protect the queue_list with a lock.

Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com>
Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
This commit is contained in:
Robert Baldyga
2024-01-30 18:49:36 +01:00
committed by Michal Mielewczyk
parent 8db93260ae
commit b00ab08473
3 changed files with 32 additions and 11 deletions

View File

@@ -850,6 +850,11 @@ static int _ocf_mngt_init_new_cache(struct ocf_cache_mngt_init_params *params)
goto lock_err;
}
INIT_LIST_HEAD(&cache->io_queues);
result = env_spinlock_init(&cache->io_queues_lock);
if (result)
goto mutex_err;
ENV_BUG_ON(!ocf_refcnt_inc(&cache->refcnt.cache));
/* start with freezed metadata ref counter to indicate detached device*/
@@ -865,6 +870,8 @@ static int _ocf_mngt_init_new_cache(struct ocf_cache_mngt_init_params *params)
return 0;
mutex_err:
env_mutex_destroy(&cache->flush_mutex);
lock_err:
ocf_mngt_cache_unlock(cache);
ocf_mngt_cache_lock_deinit(cache);
@@ -1438,6 +1445,8 @@ static void _ocf_mngt_init_handle_error(ocf_ctx_t ctx,
if (!params->flags.cache_alloc)
return;
env_spinlock_destroy(&cache->io_queues_lock);
env_mutex_destroy(&cache->flush_mutex);
ocf_mngt_cache_lock_deinit(cache);
@@ -1466,8 +1475,6 @@ static void _ocf_mngt_cache_init(ocf_cache_t cache,
cache->conf_meta->promotion_policy_type = params->metadata.promotion_policy;
__set_cleaning_policy(cache, ocf_cleaning_default);
INIT_LIST_HEAD(&cache->io_queues);
/* Init Partitions */
ocf_user_part_init(cache);
__init_free(cache);
@@ -2197,6 +2204,9 @@ static void ocf_mngt_cache_remove(ocf_ctx_t ctx, ocf_cache_t cache)
/* Deinitialize locks */
ocf_mngt_cache_lock_deinit(cache);
env_spinlock_destroy(&cache->io_queues_lock);
env_mutex_destroy(&cache->flush_mutex);
/* Remove cache from the list */