From 19276570b8415a976ae16b9166cfa3befe122214 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Wed, 14 Apr 2021 16:00:54 +0200 Subject: [PATCH] Prevent adding core with the same UUID twice Signed-off-by: Michal Mielewczyk --- inc/ocf_err.h | 3 +++ src/mngt/ocf_mngt_core.c | 24 ++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/inc/ocf_err.h b/inc/ocf_err.h index 4a763e7..015de7d 100644 --- a/inc/ocf_err.h +++ b/inc/ocf_err.h @@ -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__ */ diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index e68e1cd..328a44e 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -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);