Merge pull request #400 from robertbaldyga/fix-core-volume-lifecycle

Fix core volume lifecycle management
This commit is contained in:
Robert Baldyga 2020-08-21 21:02:30 +02:00 committed by GitHub
commit 0289389f7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 */ /* Initialize core volume */
ocf_volume_init(&core->volume, volume_type, &uuid, false); ocf_volume_init(&core->volume, volume_type, &uuid, false);
core->has_volume = true;
} }
/* Restore all dynamics items */ /* 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); cache_mngt_core_remove_from_cache(core);
if (attached) if (attached)
cache_mngt_core_remove_from_cleaning_pol(core); cache_mngt_core_remove_from_cleaning_pol(core);
cache_mngt_core_close(core); cache_mngt_core_deinit(core);
if (--no == 0) if (--no == 0)
break; break;
} }

View File

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

View File

@ -7,7 +7,7 @@
#ifndef __OCF_MNGT_COMMON_H__ #ifndef __OCF_MNGT_COMMON_H__
#define __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); 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) if (result)
OCF_PL_FINISH_RET(pipeline, result); OCF_PL_FINISH_RET(pipeline, result);
core->has_volume = true;
context->flags.volume_inited = true; context->flags.volume_inited = true;
if (cfg->user_metadata.data && cfg->user_metadata.size > 0) { 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_meta(core);
cache_mngt_core_remove_from_cache(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 */ /* Update super-block with core device removal */
ocf_metadata_flush_superblock(cache, 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; struct ocf_mngt_cache_remove_core_context *context = priv;
ocf_cache_t cache = context->cache; ocf_cache_t cache = context->cache;
ocf_core_t core = context->core; ocf_core_t core = context->core;
int status;
ocf_core_log(core, log_debug, "Detaching core\n"); 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_volume_close(&core->front_volume);
OCF_PL_FINISH_RET(pipeline, status); ocf_volume_deinit(&core->front_volume);
ocf_volume_close(&core->volume);
core->opened = false;
cache->ocf_core_inactive_count++; cache->ocf_core_inactive_count++;
env_bit_set(ocf_cache_state_incomplete, env_bit_set(ocf_cache_state_incomplete,

View File

@ -81,7 +81,9 @@ struct ocf_core {
env_atomic flushed; 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; uint32_t opened : 1;
/* This bit means that core is added into cache */ /* This bit means that core is added into cache */
uint32_t added : 1; uint32_t added : 1;