Skip to content

Commit

Permalink
Log errors on cache init
Browse files Browse the repository at this point in the history
The more (logging) the merrier

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
  • Loading branch information
mmichal10 committed Oct 4, 2024
1 parent a4e922e commit acdb6df
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/mngt/ocf_mngt_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -826,37 +826,59 @@ static void _ocf_mngt_load_metadata(ocf_pipeline_t pipeline,
* @brief allocate memory for new cache, add it to cache queue, set initial
* values and running state
*/
static int _ocf_mngt_init_new_cache(struct ocf_cache_mngt_init_params *params)
static int _ocf_mngt_init_new_cache(struct ocf_cache_mngt_init_params *params,
char *new_cache_name)
{
ocf_cache_t cache = env_vzalloc(sizeof(*cache));
int result;

if (!cache)
if (!cache) {
ocf_log(params->ctx, log_err, "Failed to allocate cache %s\n",
new_cache_name);
return -OCF_ERR_NO_MEM;
}

if (ocf_mngt_cache_lock_init(cache)) {
ocf_log(params->ctx, log_err,
"Failed to allocate cache %s lock\n",
new_cache_name);
result = -OCF_ERR_NO_MEM;
goto alloc_err;
}

/* Lock cache during setup - this trylock should always succeed */
result = ocf_mngt_cache_trylock(cache);
if (result)
if (result) {
ocf_log(params->ctx, log_crit,
"Failed to lock the newly created cache %s\n",
new_cache_name);
goto lock_init_err;
}

if (env_mutex_init(&cache->flush_mutex)) {
ocf_log(params->ctx, log_err,
"Failed to allocate cache %s flush lock\n",
new_cache_name);
result = -OCF_ERR_NO_MEM;
goto lock_err;
}

INIT_LIST_HEAD(&cache->io_queues);
result = env_spinlock_init(&cache->io_queues_lock);
if (result)
if (result) {
ocf_log(params->ctx, log_err,
"Failed to allocate cache %s queue lock\n",
new_cache_name);
goto mutex_err;
}

result = !ocf_refcnt_inc(&cache->refcnt.cache);
if (result)
if (result) {
ocf_log(params->ctx, log_crit,
"Failed to increment %s refcnt\n",
new_cache_name);
goto cache_refcnt_inc_err;
}

/* start with freezed metadata ref counter to indicate detached device*/
ocf_refcnt_freeze(&cache->refcnt.metadata);
Expand Down Expand Up @@ -957,7 +979,7 @@ static int _ocf_mngt_init_prepare_cache(struct ocf_cache_mngt_init_params *param

ocf_log(param->ctx, log_info, "Inserting cache %s\n", cfg->name);

ret = _ocf_mngt_init_new_cache(param);
ret = _ocf_mngt_init_new_cache(param, cfg->name);
if (ret)
goto out;

Expand Down

0 comments on commit acdb6df

Please sign in to comment.