Merge pull request #490 from mmichal10/check-core-uuid

Prevent adding core with the same UUID twice
This commit is contained in:
Michał Mielewczyk 2021-04-14 20:05:22 +02:00 committed by GitHub
commit 5b3a9606d3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 27 additions and 0 deletions

View File

@ -125,6 +125,9 @@ typedef enum {
/** Device does not meet requirements */
OCF_ERR_INVAL_CACHE_DEV,
/** Core with the uuid already exists */
OCF_ERR_CORE_UUID_EXISTS,
} ocf_error_t;
#endif /* __OCF_ERR_H__ */

View File

@ -27,6 +27,25 @@ static int ocf_mngt_core_set_name(ocf_core_t core, const char *name)
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,
struct ocf_metadata_uuid *muuid)
{
@ -317,6 +336,11 @@ static void ocf_mngt_cache_add_core_prepare(ocf_pipeline_t pipeline,
if (!result)
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);
if (result)
OCF_PL_FINISH_RET(context->pipeline, result);