Merge pull request #688 from robertbaldyga/manage-valid-core-bitmap
Manage valid_core_bitmap properly
This commit is contained in:
commit
48fb745686
@ -206,6 +206,41 @@ static void _ocf_metadata_validate_superblock(ocf_pipeline_t pipeline,
|
||||
ocf_pipeline_next(pipeline);
|
||||
}
|
||||
|
||||
static void _ocf_metadata_validate_core_config(ocf_pipeline_t pipeline,
|
||||
void *priv, ocf_pipeline_arg_t arg)
|
||||
{
|
||||
struct ocf_metadata_context *context = priv;
|
||||
ocf_ctx_t ctx = context->cache->owner;
|
||||
struct ocf_metadata_ctrl *ctrl;
|
||||
struct ocf_superblock_config *superblock;
|
||||
struct ocf_core_meta_config *core_config;
|
||||
ocf_core_id_t core_id;
|
||||
bool valid_in_bitmap;
|
||||
|
||||
ctrl = (struct ocf_metadata_ctrl *)context->ctrl;
|
||||
superblock = METADATA_MEM_POOL(ctrl, metadata_segment_sb_config);
|
||||
core_config = METADATA_MEM_POOL(ctrl, metadata_segment_core_config);
|
||||
|
||||
for (core_id = 0; core_id < OCF_CORE_MAX; core_id++) {
|
||||
valid_in_bitmap = env_bit_test(core_id,
|
||||
superblock->valid_core_bitmap);
|
||||
|
||||
if (valid_in_bitmap && !core_config[core_id].valid) {
|
||||
ocf_log(ctx, log_err, "Core is marked as valid in "
|
||||
"bitmap but not in core metadata!\n");
|
||||
OCF_PL_FINISH_RET(pipeline, -OCF_ERR_INVAL);
|
||||
}
|
||||
|
||||
if (core_config[core_id].valid && !valid_in_bitmap) {
|
||||
ocf_log(ctx, log_err, "Core is marked as valid in "
|
||||
"core metadata but not in bitmap!\n");
|
||||
OCF_PL_FINISH_RET(pipeline, -OCF_ERR_INVAL);
|
||||
}
|
||||
}
|
||||
|
||||
ocf_pipeline_next(pipeline);
|
||||
}
|
||||
|
||||
static void ocf_metadata_load_sb_restore(
|
||||
struct ocf_metadata_context *context)
|
||||
{
|
||||
@ -282,6 +317,7 @@ struct ocf_pipeline_properties ocf_metadata_load_sb_pipeline_props = {
|
||||
ocf_metadata_load_sb_load_segment_args),
|
||||
OCF_PL_STEP_FOREACH(ocf_metadata_check_crc,
|
||||
ocf_metadata_load_sb_load_segment_args),
|
||||
OCF_PL_STEP(_ocf_metadata_validate_core_config),
|
||||
OCF_PL_STEP_TERMINATOR(),
|
||||
},
|
||||
};
|
||||
@ -347,6 +383,7 @@ struct ocf_pipeline_properties ocf_metadata_load_sb_recov_pipeline_props = {
|
||||
ocf_metadata_load_sb_recov_load_segment_args),
|
||||
OCF_PL_STEP_FOREACH(ocf_metadata_check_crc,
|
||||
ocf_metadata_load_sb_recov_load_segment_args),
|
||||
OCF_PL_STEP(_ocf_metadata_validate_core_config),
|
||||
OCF_PL_STEP_TERMINATOR(),
|
||||
},
|
||||
};
|
||||
|
@ -312,7 +312,7 @@ static void _ocf_mngt_close_all_uninitialized_cores(
|
||||
int j, i;
|
||||
|
||||
for (j = cache->conf_meta->core_count, i = 0; j > 0; ++i) {
|
||||
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
|
||||
if (!cache->core[i].added)
|
||||
continue;
|
||||
|
||||
volume = &(cache->core[i].volume);
|
||||
@ -326,11 +326,8 @@ static void _ocf_mngt_close_all_uninitialized_cores(
|
||||
|
||||
env_free(cache->core[i].counters);
|
||||
cache->core[i].counters = NULL;
|
||||
|
||||
env_bit_clear(i, cache->conf_meta->valid_core_bitmap);
|
||||
cache->core[i].added = false;
|
||||
}
|
||||
|
||||
cache->conf_meta->core_count = 0;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -351,9 +348,6 @@ static void _ocf_mngt_load_add_cores(ocf_pipeline_t pipeline,
|
||||
|
||||
OCF_ASSERT_PLUGGED(cache);
|
||||
|
||||
/* Count value will be re-calculated on the basis of 'valid' flag */
|
||||
cache->conf_meta->core_count = 0;
|
||||
|
||||
/* Check in metadata which cores were saved in cache metadata */
|
||||
for_each_core_metadata(cache, core, core_id) {
|
||||
struct ocf_metadata_uuid *muuid;
|
||||
@ -401,9 +395,7 @@ static void _ocf_mngt_load_add_cores(ocf_pipeline_t pipeline,
|
||||
}
|
||||
|
||||
}
|
||||
env_bit_set(core_id, cache->conf_meta->valid_core_bitmap);
|
||||
core->added = true;
|
||||
cache->conf_meta->core_count++;
|
||||
core->volume.cache = cache;
|
||||
|
||||
if (ocf_mngt_core_init_front_volume(core))
|
||||
@ -433,8 +425,8 @@ static void _ocf_mngt_load_add_cores(ocf_pipeline_t pipeline,
|
||||
ocf_core_log(core, log_err,
|
||||
"Size of core volume doesn't match with"
|
||||
" the size stored in cache metadata!");
|
||||
error = -OCF_ERR_CORE_SIZE_MISMATCH;
|
||||
goto err;
|
||||
error = -OCF_ERR_CORE_SIZE_MISMATCH;
|
||||
goto err;
|
||||
}
|
||||
|
||||
hd_lines = ocf_bytes_2_lines(cache, length);
|
||||
@ -1963,10 +1955,7 @@ static void _ocf_mngt_cache_stop_remove_cores(ocf_cache_t cache, bool attached)
|
||||
int no = cache->conf_meta->core_count;
|
||||
|
||||
/* All exported objects removed, cleaning up rest. */
|
||||
for_each_core_all(cache, core, core_id) {
|
||||
if (!env_bit_test(core_id, cache->conf_meta->valid_core_bitmap))
|
||||
continue;
|
||||
|
||||
for_each_core(cache, core, core_id) {
|
||||
cache_mngt_core_remove_from_cache(core);
|
||||
if (attached)
|
||||
cache_mngt_core_remove_from_cleaning_pol(core);
|
||||
@ -1974,7 +1963,6 @@ static void _ocf_mngt_cache_stop_remove_cores(ocf_cache_t cache, bool attached)
|
||||
if (--no == 0)
|
||||
break;
|
||||
}
|
||||
ENV_BUG_ON(cache->conf_meta->core_count != 0);
|
||||
}
|
||||
|
||||
static void ocf_mngt_cache_stop_remove_cores(ocf_pipeline_t pipeline,
|
||||
@ -3000,8 +2988,6 @@ static void _ocf_mngt_cache_unplug(ocf_cache_t cache, bool stop,
|
||||
struct _ocf_mngt_cache_unplug_context *context,
|
||||
_ocf_mngt_cache_unplug_end_t cmpl, void *priv)
|
||||
{
|
||||
ENV_BUG_ON(stop && cache->conf_meta->core_count != 0);
|
||||
|
||||
context->cmpl = cmpl;
|
||||
context->priv = priv;
|
||||
context->cache = cache;
|
||||
|
@ -106,6 +106,7 @@ void cache_mngt_core_deinit_attached_meta(ocf_core_t core)
|
||||
void cache_mngt_core_remove_from_meta(ocf_core_t core)
|
||||
{
|
||||
ocf_cache_t cache = ocf_core_get_cache(core);
|
||||
ocf_core_id_t core_id = ocf_core_get_id(core);
|
||||
|
||||
ocf_metadata_start_exclusive_access(&cache->metadata.lock);
|
||||
|
||||
@ -116,6 +117,9 @@ void cache_mngt_core_remove_from_meta(ocf_core_t core)
|
||||
ocf_mngt_core_clear_uuid_metadata(core);
|
||||
core->conf_meta->seq_no = OCF_SEQ_NO_INVALID;
|
||||
|
||||
env_bit_clear(core_id, cache->conf_meta->valid_core_bitmap);
|
||||
cache->conf_meta->core_count--;
|
||||
|
||||
ocf_metadata_end_exclusive_access(&cache->metadata.lock);
|
||||
}
|
||||
|
||||
@ -123,18 +127,14 @@ void cache_mngt_core_remove_from_meta(ocf_core_t core)
|
||||
void cache_mngt_core_remove_from_cache(ocf_core_t core)
|
||||
{
|
||||
ocf_cache_t cache = ocf_core_get_cache(core);
|
||||
ocf_core_id_t core_id = ocf_core_get_id(core);
|
||||
|
||||
ocf_core_seq_cutoff_deinit(core);
|
||||
env_free(core->counters);
|
||||
core->counters = NULL;
|
||||
core->added = false;
|
||||
env_bit_clear(core_id, cache->conf_meta->valid_core_bitmap);
|
||||
|
||||
if (!core->opened && --cache->ocf_core_inactive_count == 0)
|
||||
env_bit_clear(ocf_cache_state_incomplete, &cache->cache_state);
|
||||
|
||||
cache->conf_meta->core_count--;
|
||||
}
|
||||
|
||||
void ocf_mngt_cache_put(ocf_cache_t cache)
|
||||
|
@ -134,6 +134,7 @@ static void _ocf_mngt_cache_add_core_handle_error(
|
||||
if (context->flags.counters_allocated) {
|
||||
env_bit_clear(core_id,
|
||||
cache->conf_meta->valid_core_bitmap);
|
||||
cache->conf_meta->core_count--;
|
||||
core->conf_meta->valid = false;
|
||||
core->added = false;
|
||||
core->opened = false;
|
||||
@ -356,9 +357,6 @@ static void _ocf_mngt_cache_add_core_flush_sb_complete(void *priv, int error)
|
||||
if (error)
|
||||
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_WRITE_CACHE);
|
||||
|
||||
/* Increase value of added cores */
|
||||
context->cache->conf_meta->core_count++;
|
||||
|
||||
ocf_pipeline_next(context->pipeline);
|
||||
}
|
||||
|
||||
@ -463,6 +461,8 @@ static void ocf_mngt_cache_add_core_insert(ocf_pipeline_t pipeline,
|
||||
|
||||
/* In metadata mark data this core was added into cache */
|
||||
env_bit_set(core_id, cache->conf_meta->valid_core_bitmap);
|
||||
context->cache->conf_meta->core_count++;
|
||||
|
||||
core->conf_meta->valid = true;
|
||||
core->added = true;
|
||||
core->opened = true;
|
||||
|
Loading…
Reference in New Issue
Block a user