Merge pull request #117 from mmichal10/null-ptr-on-cache-id-reuse
Fix teardown after failed start cache operation.
This commit is contained in:
commit
f0c3e049c6
@ -1142,32 +1142,25 @@ int ocf_mngt_get_ram_needed(ocf_cache_t cache,
|
|||||||
* @brief for error handling do partial cleanup of datastructures upon
|
* @brief for error handling do partial cleanup of datastructures upon
|
||||||
* premature function exit.
|
* premature function exit.
|
||||||
*
|
*
|
||||||
* @param cache cache instance
|
|
||||||
* @param ctx OCF context
|
* @param ctx OCF context
|
||||||
* @param params - startup params containing initialization status flags.
|
* @param params - startup params containing initialization status flags.
|
||||||
* Value of NULL indicates cache is fully initialized but not
|
*
|
||||||
* handling any I/O (cache->valid_ocf_cache_device_t is 0).
|
|
||||||
*/
|
*/
|
||||||
static void _ocf_mngt_init_handle_error(ocf_cache_t cache,
|
static void _ocf_mngt_init_handle_error(ocf_ctx_t ctx,
|
||||||
ocf_ctx_t ctx, struct ocf_cachemng_init_params *params)
|
struct ocf_cachemng_init_params *params)
|
||||||
{
|
{
|
||||||
ocf_queue_t queue, tmp_queue;
|
ocf_cache_t cache = params->cache;
|
||||||
|
|
||||||
if (!params || params->flags.metadata_inited)
|
if (!params->flags.cache_alloc)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (params->flags.metadata_inited)
|
||||||
ocf_metadata_deinit(cache);
|
ocf_metadata_deinit(cache);
|
||||||
|
|
||||||
env_mutex_lock(&ctx->lock);
|
env_mutex_lock(&ctx->lock);
|
||||||
|
|
||||||
if (cache->mngt_queue)
|
|
||||||
ocf_queue_put(cache->mngt_queue);
|
|
||||||
|
|
||||||
list_for_each_entry_safe(queue, tmp_queue, &cache->io_queues, list)
|
|
||||||
ocf_queue_put(queue);
|
|
||||||
|
|
||||||
if (!params || params->flags.cache_alloc) {
|
|
||||||
list_del(&cache->list);
|
list_del(&cache->list);
|
||||||
env_vfree(cache);
|
env_vfree(cache);
|
||||||
}
|
|
||||||
|
|
||||||
env_mutex_unlock(&ctx->lock);
|
env_mutex_unlock(&ctx->lock);
|
||||||
}
|
}
|
||||||
@ -1258,16 +1251,15 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
|
|||||||
if (result) {
|
if (result) {
|
||||||
result = -OCF_ERR_START_CACHE_FAIL;
|
result = -OCF_ERR_START_CACHE_FAIL;
|
||||||
goto _cache_mng_init_instance_ERROR;
|
goto _cache_mng_init_instance_ERROR;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ocf_log(ctx, log_debug, "Metadata initialized\n");
|
||||||
|
params.flags.metadata_inited = true;
|
||||||
|
|
||||||
result = _ocf_mngt_cache_init(*cache, ¶ms);
|
result = _ocf_mngt_cache_init(*cache, ¶ms);
|
||||||
if (result)
|
if (result)
|
||||||
goto _cache_mng_init_instance_ERROR;
|
goto _cache_mng_init_instance_ERROR;
|
||||||
|
|
||||||
ocf_log(ctx, log_debug, "Metadata initialized\n");
|
|
||||||
params.flags.metadata_inited = true;
|
|
||||||
|
|
||||||
if (params.locked) {
|
if (params.locked) {
|
||||||
/* Increment reference counter to match cache_lock /
|
/* Increment reference counter to match cache_lock /
|
||||||
cache_unlock convention. User is expected to call
|
cache_unlock convention. User is expected to call
|
||||||
@ -1285,7 +1277,7 @@ static int _ocf_mngt_cache_start(ocf_ctx_t ctx, ocf_cache_t *cache,
|
|||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
_cache_mng_init_instance_ERROR:
|
_cache_mng_init_instance_ERROR:
|
||||||
_ocf_mngt_init_handle_error(params.cache, ctx, ¶ms);
|
_ocf_mngt_init_handle_error(ctx, ¶ms);
|
||||||
*cache = NULL;
|
*cache = NULL;
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user