Prevent adding core with the same UUID twice
Signed-off-by: Michal Mielewczyk <michal.mielewczyk@intel.com>
This commit is contained in:
parent
aa5de7342c
commit
19276570b8
@ -125,6 +125,9 @@ typedef enum {
|
|||||||
|
|
||||||
/** Device does not meet requirements */
|
/** Device does not meet requirements */
|
||||||
OCF_ERR_INVAL_CACHE_DEV,
|
OCF_ERR_INVAL_CACHE_DEV,
|
||||||
|
|
||||||
|
/** Core with the uuid already exists */
|
||||||
|
OCF_ERR_CORE_UUID_EXISTS,
|
||||||
} ocf_error_t;
|
} ocf_error_t;
|
||||||
|
|
||||||
#endif /* __OCF_ERR_H__ */
|
#endif /* __OCF_ERR_H__ */
|
||||||
|
@ -27,6 +27,25 @@ static int ocf_mngt_core_set_name(ocf_core_t core, const char *name)
|
|||||||
name, OCF_CORE_NAME_SIZE);
|
name, OCF_CORE_NAME_SIZE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int ocf_core_get_by_uuid(ocf_cache_t cache, void *uuid, size_t uuid_size,
|
||||||
|
ocf_core_t *core)
|
||||||
|
{
|
||||||
|
struct ocf_volume *volume;
|
||||||
|
ocf_core_t i_core;
|
||||||
|
ocf_core_id_t i_core_id;
|
||||||
|
|
||||||
|
for_each_core_metadata(cache, i_core, i_core_id) {
|
||||||
|
volume = ocf_core_get_volume(i_core);
|
||||||
|
if (!env_strncmp(volume->uuid.data, volume->uuid.size, uuid,
|
||||||
|
uuid_size)) {
|
||||||
|
*core = i_core;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return -OCF_ERR_CORE_NOT_EXIST;
|
||||||
|
}
|
||||||
|
|
||||||
static int _ocf_uuid_set(const struct ocf_volume_uuid *uuid,
|
static int _ocf_uuid_set(const struct ocf_volume_uuid *uuid,
|
||||||
struct ocf_metadata_uuid *muuid)
|
struct ocf_metadata_uuid *muuid)
|
||||||
{
|
{
|
||||||
@ -317,6 +336,11 @@ static void ocf_mngt_cache_add_core_prepare(ocf_pipeline_t pipeline,
|
|||||||
if (!result)
|
if (!result)
|
||||||
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CORE_EXIST);
|
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CORE_EXIST);
|
||||||
|
|
||||||
|
result = ocf_core_get_by_uuid(cache, cfg->uuid.data,
|
||||||
|
cfg->uuid.size, &core);
|
||||||
|
if (!result)
|
||||||
|
OCF_PL_FINISH_RET(context->pipeline, -OCF_ERR_CORE_UUID_EXISTS);
|
||||||
|
|
||||||
result = ocf_mngt_find_free_core(cache, &core);
|
result = ocf_mngt_find_free_core(cache, &core);
|
||||||
if (result)
|
if (result)
|
||||||
OCF_PL_FINISH_RET(context->pipeline, result);
|
OCF_PL_FINISH_RET(context->pipeline, result);
|
||||||
|
Loading…
Reference in New Issue
Block a user