diff --git a/inc/ocf_mngt.h b/inc/ocf_mngt.h index 65e9d4c..7318bd6 100644 --- a/inc/ocf_mngt.h +++ b/inc/ocf_mngt.h @@ -235,7 +235,7 @@ struct ocf_mngt_cache_config { /** * @brief Cache name */ - const char *name; + char name[OCF_CACHE_NAME_SIZE]; /** * @brief Cache mode diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index c08e907..1f4cd51 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -1582,7 +1582,7 @@ err_pipeline: static int _ocf_mngt_cache_validate_cfg(struct ocf_mngt_cache_config *cfg) { - if (!cfg->name) + if (!strnlen(cfg->name, OCF_CACHE_NAME_SIZE)) return -OCF_ERR_INVAL; if (!ocf_cache_mode_is_valid(cfg->cache_mode)) diff --git a/tests/functional/pyocf/types/cache.py b/tests/functional/pyocf/types/cache.py index 31c6711..d3aa744 100644 --- a/tests/functional/pyocf/types/cache.py +++ b/tests/functional/pyocf/types/cache.py @@ -8,6 +8,7 @@ from ctypes import ( c_uint32, c_uint16, c_int, + c_char, c_char_p, c_void_p, c_bool, @@ -41,8 +42,9 @@ class Backfill(Structure): class CacheConfig(Structure): + MAX_CACHE_NAME_SIZE = 32 _fields_ = [ - ("_name", c_char_p), + ("_name", c_char * MAX_CACHE_NAME_SIZE), ("_cache_mode", c_uint32), ("_eviction_policy", c_uint32), ("_promotion_policy", c_uint32), @@ -152,7 +154,7 @@ class Cache: self.cache_line_size = cache_line_size self.cfg = CacheConfig( - _name=cast(create_string_buffer(name.encode("ascii")), c_char_p), + _name=name.encode("ascii"), _cache_mode=cache_mode, _eviction_policy=eviction_policy, _promotion_policy=promotion_policy, @@ -307,7 +309,7 @@ class Cache: raise OcfError("Loading cache device failed", c.results["error"]) @classmethod - def load_from_device(cls, device, name=""): + def load_from_device(cls, device, name="cache"): c = cls(name=name, owner=device.owner) c.start_cache()