Fix core volume lifecycle management

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2020-08-21 16:27:06 +02:00
parent 1d7762d095
commit 0dfdcb05e9
6 changed files with 22 additions and 17 deletions

View File

@ -1346,6 +1346,7 @@ static void ocf_medatata_hash_load_superblock_post(ocf_pipeline_t pipeline,
/* Initialize core volume */
ocf_volume_init(&core->volume, volume_type, &uuid, false);
core->has_volume = true;
}
/* Restore all dynamics items */

View File

@ -1609,7 +1609,7 @@ static void _ocf_mngt_cache_stop_remove_cores(ocf_cache_t cache, bool attached)
cache_mngt_core_remove_from_cache(core);
if (attached)
cache_mngt_core_remove_from_cleaning_pol(core);
cache_mngt_core_close(core);
cache_mngt_core_deinit(core);
if (--no == 0)
break;
}

View File

@ -17,19 +17,18 @@
#include "../engine/engine_common.h"
/* Close if opened */
int cache_mngt_core_close(ocf_core_t core)
void cache_mngt_core_deinit(ocf_core_t core)
{
if (!core->opened)
return -OCF_ERR_CORE_IN_INACTIVE_STATE;
if (core->opened) {
ocf_volume_close(&core->front_volume);
ocf_volume_deinit(&core->front_volume);
ocf_volume_close(&core->volume);
}
ocf_volume_close(&core->front_volume);
ocf_volume_deinit(&core->front_volume);
if (core->has_volume)
ocf_volume_deinit(&core->volume);
ocf_volume_close(&core->volume);
ocf_volume_deinit(&core->volume);
core->opened = false;
return 0;
}
/* Remove core from cleaning policy */

View File

@ -7,7 +7,7 @@
#ifndef __OCF_MNGT_COMMON_H__
#define __OCF_MNGT_COMMON_H__
int cache_mngt_core_close(ocf_core_t core);
void cache_mngt_core_deinit(ocf_core_t core);
void cache_mngt_core_remove_from_meta(ocf_core_t core);

View File

@ -378,6 +378,7 @@ static void ocf_mngt_cache_add_core_insert(ocf_pipeline_t pipeline,
if (result)
OCF_PL_FINISH_RET(pipeline, result);
core->has_volume = true;
context->flags.volume_inited = true;
if (cfg->user_metadata.data && cfg->user_metadata.size > 0) {
@ -621,7 +622,7 @@ static void _ocf_mngt_cache_remove_core(ocf_pipeline_t pipeline, void *priv,
}
cache_mngt_core_remove_from_meta(core);
cache_mngt_core_remove_from_cache(core);
cache_mngt_core_close(core);
cache_mngt_core_deinit(core);
/* Update super-block with core device removal */
ocf_metadata_flush_superblock(cache,
@ -707,14 +708,16 @@ static void _ocf_mngt_cache_detach_core(ocf_pipeline_t pipeline,
struct ocf_mngt_cache_remove_core_context *context = priv;
ocf_cache_t cache = context->cache;
ocf_core_t core = context->core;
int status;
ocf_core_log(core, log_debug, "Detaching core\n");
status = cache_mngt_core_close(core);
if (!core->opened)
OCF_PL_FINISH_RET(pipeline, -OCF_ERR_CORE_IN_INACTIVE_STATE);
if (status)
OCF_PL_FINISH_RET(pipeline, status);
ocf_volume_close(&core->front_volume);
ocf_volume_deinit(&core->front_volume);
ocf_volume_close(&core->volume);
core->opened = false;
cache->ocf_core_inactive_count++;
env_bit_set(ocf_cache_state_incomplete,

View File

@ -81,7 +81,9 @@ struct ocf_core {
env_atomic flushed;
/* This bit means that object is open */
/* This bit means that core volume is initialized */
uint32_t has_volume : 1;
/* This bit means that core volume is open */
uint32_t opened : 1;
/* This bit means that core is added into cache */
uint32_t added : 1;