**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 <slawomir.jankowski@intel.com>
This commit is contained in:
Slawomir_Jankowski 2019-09-30 15:55:33 +02:00
parent 46e7dd8748
commit cdf0caf704
3 changed files with 7 additions and 22 deletions

View File

@ -22,7 +22,7 @@ struct ocf_mngt_core_config {
/** /**
* @brief OCF core name * @brief OCF core name
*/ */
const char *name; char name[OCF_CORE_NAME_SIZE];
/** /**
* @brief OCF core volume UUID * @brief OCF core volume UUID

View File

@ -476,7 +476,6 @@ static void ocf_mngt_cache_add_core_finish(ocf_pipeline_t pipeline,
out: out:
context->cmpl(cache, core, context->priv, error); context->cmpl(cache, core, context->priv, error);
env_vfree(context->cfg.name);
env_vfree(context->cfg.uuid.data); env_vfree(context->cfg.uuid.data);
ocf_pipeline_destroy(context->pipeline); 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; struct ocf_cache_add_core_context *context;
ocf_pipeline_t pipeline; ocf_pipeline_t pipeline;
char *name;
void *data; void *data;
int result; int result;
@ -518,7 +516,7 @@ void ocf_mngt_cache_add_core(ocf_cache_t cache,
if (!cache->mngt_queue) if (!cache->mngt_queue)
OCF_CMPL_RET(cache, NULL, priv, -OCF_ERR_INVAL); 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); OCF_CMPL_RET(cache, NULL, priv, -OCF_ERR_INVAL);
result = ocf_pipeline_create(&pipeline, cache, cfg->try_add ? 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->cache = cache;
context->cfg = *cfg; 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); data = env_vmalloc(cfg->uuid.size);
if (!data) { if (!data) {
result = -OCF_ERR_NO_MEM; result = -OCF_ERR_NO_MEM;
goto err_name; goto err_pipeline;
} }
result = env_memcpy(data, cfg->uuid.size, cfg->uuid.data, 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: err_uuid:
env_vfree(data); env_vfree(data);
err_name:
env_vfree(context->cfg.name);
err_pipeline: err_pipeline:
ocf_pipeline_destroy(context->pipeline); ocf_pipeline_destroy(context->pipeline);
OCF_CMPL_RET(cache, NULL, priv, result); OCF_CMPL_RET(cache, NULL, priv, result);

View File

@ -13,6 +13,7 @@ from ctypes import (
c_uint16, c_uint16,
c_uint32, c_uint32,
c_uint64, c_uint64,
c_char,
c_char_p, c_char_p,
c_bool, c_bool,
cast, cast,
@ -37,8 +38,9 @@ class UserMetadata(Structure):
class CoreConfig(Structure): class CoreConfig(Structure):
MAX_CORE_NAME_SIZE = 32
_fields_ = [ _fields_ = [
("_name", c_char_p), ("_name", c_char * MAX_CORE_NAME_SIZE),
("_uuid", Uuid), ("_uuid", Uuid),
("_volume_type", c_uint8), ("_volume_type", c_uint8),
("_try_add", c_bool), ("_try_add", c_bool),
@ -70,7 +72,7 @@ class Core:
), ),
_size=len(self.device_name) + 1, _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, _volume_type=self.device.type_id,
_try_add=try_add, _try_add=try_add,
_seq_cutoff_threshold=seq_cutoff_threshold, _seq_cutoff_threshold=seq_cutoff_threshold,