From cdf0caf704d6b9e05bd8e9f0b9d5bc2417bd76a7 Mon Sep 17 00:00:00 2001 From: Slawomir_Jankowski Date: Mon, 30 Sep 2019 15:55:33 +0200 Subject: [PATCH] **ocf_mngt.h**: In core name change pointer type to array which is 32 characters long; **core.py**: Add missing import and modify class' field type to keep consistency; **ocf_mngt_core**: Remove local variable 'name'; remove env_vmalloc for 'name' - isn't no longer needed; remove initialization 'name' - as above; remove env_vfree for context->cfg.name - variable isn't no allocated in memory; check if cfg->name exists; change label in goto from deleted err_name to the closest err_pipeline. Signed-off-by: Slawomir_Jankowski --- inc/ocf_mngt.h | 2 +- src/mngt/ocf_mngt_core.c | 21 ++------------------- tests/functional/pyocf/types/core.py | 6 ++++-- 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/inc/ocf_mngt.h b/inc/ocf_mngt.h index 6f052fe..810b85e 100644 --- a/inc/ocf_mngt.h +++ b/inc/ocf_mngt.h @@ -22,7 +22,7 @@ struct ocf_mngt_core_config { /** * @brief OCF core name */ - const char *name; + char name[OCF_CORE_NAME_SIZE]; /** * @brief OCF core volume UUID diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index 95c7112..60ab3b3 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -476,7 +476,6 @@ static void ocf_mngt_cache_add_core_finish(ocf_pipeline_t pipeline, out: context->cmpl(cache, core, context->priv, error); - env_vfree(context->cfg.name); env_vfree(context->cfg.uuid.data); ocf_pipeline_destroy(context->pipeline); } @@ -509,7 +508,6 @@ void ocf_mngt_cache_add_core(ocf_cache_t cache, { struct ocf_cache_add_core_context *context; ocf_pipeline_t pipeline; - char *name; void *data; int result; @@ -518,7 +516,7 @@ void ocf_mngt_cache_add_core(ocf_cache_t cache, if (!cache->mngt_queue) OCF_CMPL_RET(cache, NULL, priv, -OCF_ERR_INVAL); - if (!cfg->name) + if (!env_strnlen(cfg->name, OCF_CORE_NAME_SIZE)) OCF_CMPL_RET(cache, NULL, priv, -OCF_ERR_INVAL); result = ocf_pipeline_create(&pipeline, cache, cfg->try_add ? @@ -535,23 +533,10 @@ void ocf_mngt_cache_add_core(ocf_cache_t cache, context->cache = cache; context->cfg = *cfg; - name = env_vmalloc(OCF_CORE_NAME_SIZE); - if (!name) { - result = -OCF_ERR_NO_MEM; - goto err_pipeline; - } - - result = env_strncpy(name, OCF_CORE_NAME_SIZE, - cfg->name, OCF_CORE_NAME_SIZE); - if (result) - goto err_name; - - context->cfg.name = name; - data = env_vmalloc(cfg->uuid.size); if (!data) { result = -OCF_ERR_NO_MEM; - goto err_name; + goto err_pipeline; } result = env_memcpy(data, cfg->uuid.size, cfg->uuid.data, @@ -565,8 +550,6 @@ void ocf_mngt_cache_add_core(ocf_cache_t cache, err_uuid: env_vfree(data); -err_name: - env_vfree(context->cfg.name); err_pipeline: ocf_pipeline_destroy(context->pipeline); OCF_CMPL_RET(cache, NULL, priv, result); diff --git a/tests/functional/pyocf/types/core.py b/tests/functional/pyocf/types/core.py index 5c2564e..532a520 100644 --- a/tests/functional/pyocf/types/core.py +++ b/tests/functional/pyocf/types/core.py @@ -13,6 +13,7 @@ from ctypes import ( c_uint16, c_uint32, c_uint64, + c_char, c_char_p, c_bool, cast, @@ -37,8 +38,9 @@ class UserMetadata(Structure): class CoreConfig(Structure): + MAX_CORE_NAME_SIZE = 32 _fields_ = [ - ("_name", c_char_p), + ("_name", c_char * MAX_CORE_NAME_SIZE), ("_uuid", Uuid), ("_volume_type", c_uint8), ("_try_add", c_bool), @@ -70,7 +72,7 @@ class Core: ), _size=len(self.device_name) + 1, ), - _name=cast(create_string_buffer(name.encode("ascii")), c_char_p), + _name=name.encode("ascii"), _volume_type=self.device.type_id, _try_add=try_add, _seq_cutoff_threshold=seq_cutoff_threshold,