Log errors on cache init

The more (logging) the merrier

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
This commit is contained in:
Michal Mielewczyk 2024-10-04 14:19:15 +02:00
parent f6bdd354d0
commit e8e7a1600c

View File

@ -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 * @brief allocate memory for new cache, add it to cache queue, set initial
* values and running state * 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)); ocf_cache_t cache = env_vzalloc(sizeof(*cache));
int result; 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; return -OCF_ERR_NO_MEM;
}
if (ocf_mngt_cache_lock_init(cache)) { 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; result = -OCF_ERR_NO_MEM;
goto alloc_err; goto alloc_err;
} }
/* Lock cache during setup - this trylock should always succeed */ /* Lock cache during setup - this trylock should always succeed */
result = ocf_mngt_cache_trylock(cache); 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; goto lock_init_err;
}
if (env_mutex_init(&cache->flush_mutex)) { 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; result = -OCF_ERR_NO_MEM;
goto lock_err; goto lock_err;
} }
INIT_LIST_HEAD(&cache->io_queues); INIT_LIST_HEAD(&cache->io_queues);
result = env_spinlock_init(&cache->io_queues_lock); 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; goto mutex_err;
}
result = !ocf_refcnt_inc(&cache->refcnt.cache); 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; goto cache_refcnt_inc_err;
}
/* start with freezed metadata ref counter to indicate detached device*/ /* start with freezed metadata ref counter to indicate detached device*/
ocf_refcnt_freeze(&cache->refcnt.metadata); ocf_refcnt_freeze(&cache->refcnt.metadata);
@ -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); 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) if (ret)
goto out; goto out;
@ -1510,6 +1532,8 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
result = _ocf_mngt_init_prepare_cache(&params, cfg); result = _ocf_mngt_init_prepare_cache(&params, cfg);
if (result) { if (result) {
env_rmutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
ocf_log(ctx, log_err, "Failed to prepare cache %s\n",
cfg->name);
goto _cache_mngt_init_instance_ERROR; goto _cache_mngt_init_instance_ERROR;
} }
@ -1523,6 +1547,8 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
result = ocf_metadata_init(tmp_cache, params.metadata.line_size); result = ocf_metadata_init(tmp_cache, params.metadata.line_size);
if (result) { if (result) {
env_rmutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
ocf_log(ctx, log_err, "Failed to initialize cache %s "
"metadata\n", cfg->name);
result = -OCF_ERR_NO_MEM; result = -OCF_ERR_NO_MEM;
goto _cache_mngt_init_instance_ERROR; goto _cache_mngt_init_instance_ERROR;
} }
@ -1530,6 +1556,8 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
result = ocf_cache_set_name(tmp_cache, cfg->name, OCF_CACHE_NAME_SIZE); result = ocf_cache_set_name(tmp_cache, cfg->name, OCF_CACHE_NAME_SIZE);
if (result) { if (result) {
ocf_log(ctx, log_err, "Failed to set cache %s name\n",
cfg->name);
env_rmutex_unlock(&ctx->lock); env_rmutex_unlock(&ctx->lock);
goto _cache_mngt_init_instance_ERROR; goto _cache_mngt_init_instance_ERROR;
} }