Fix core load cleanup loop
conf_meta->core_count is not modified during load/recovery in the latest
version. Thus in case of error in cores initialization, in order to
iterate over the initialized cores we must depend on core->added only,
regardles of conf_meta->core_count value. for_each_core() macro does
exactly this.
@@ -300,33 +300,29 @@ static void init_attached_data_structures_recovery(ocf_cache_t cache,
}
/****************************************************************
- * Function for removing all uninitialized core objects *
+ * Function for removing all initialized core objects *
* from the cache instance. *
* Used in case of cache initialization errors. *
****************************************************************/
-static void _ocf_mngt_close_all_uninitialized_cores(
+static void _ocf_mngt_deinit_added_cores(
struct ocf_cache_attach_context *context)
{
ocf_cache_t cache = context->cache;
+ ocf_core_t core;
+ ocf_core_id_t core_id;
ocf_volume_t volume;
- int j, i;
-
- for (j = cache->conf_meta->core_count, i = 0; j > 0; ++i) {
- if (!cache->core[i].added)
- continue;
- volume = &(cache->core[i].volume);
+ for_each_core(cache, core, core_id) {
+ volume = &core->volume;
if (context->cfg.open_cores)
ocf_volume_close(volume);
- --j;
-
- if (cache->core[i].seq_cutoff)
- ocf_core_seq_cutoff_deinit(&cache->core[i]);
+ if (core->seq_cutoff)
+ ocf_core_seq_cutoff_deinit(core);
- env_free(cache->core[i].counters);
- cache->core[i].counters = NULL;
- cache->core[i].added = false;
+ env_free(core->counters);
+ core->counters = NULL;
+ core->added = false;
}
}
@@ -441,7 +437,7 @@ static void _ocf_mngt_load_add_cores(ocf_pipeline_t pipeline,
OCF_PL_NEXT_RET(context->pipeline);
err:
- _ocf_mngt_close_all_uninitialized_cores(context);
+ _ocf_mngt_deinit_added_cores(context);
OCF_PL_FINISH_RET(pipeline, error);
}
@@ -1781,7 +1777,7 @@ static void _ocf_mngt_attach_handle_error(
__deinit_promotion_policy(cache);
if (context->flags.cores_opened)
- _ocf_mngt_close_all_uninitialized_cores(context);
+ _ocf_mngt_deinit_added_cores(context);
if (context->flags.attached_metadata_inited)
ocf_metadata_deinit_variable_size(cache);
@@ -2455,7 +2451,7 @@ static void _ocf_mngt_activate_handle_error(
__deinit_promotion_policy(cache);
if (context->flags.cores_opened)
- _ocf_mngt_close_all_uninitialized_cores(context);
+ _ocf_mngt_deinit_added_cores(context);
if (context->flags.volume_opened)
ocf_volume_close(&cache->device->volume);
