From 225ed2833fb77e28d72a9e9ab7c6026de86eb141 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 10 Sep 2019 10:05:31 -0400 Subject: [PATCH 1/2] Added function to retrieve core id from core name. Signed-off-by: Michal Mielewczyk --- modules/cas_cache/cas_cache.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/modules/cas_cache/cas_cache.h b/modules/cas_cache/cas_cache.h index e5fa76e..eed2624 100644 --- a/modules/cas_cache/cas_cache.h +++ b/modules/cas_cache/cas_cache.h @@ -132,6 +132,25 @@ static inline int cache_id_from_name(uint16_t *cache_id, const char *name) return result; } +static inline int core_id_from_name(uint16_t *core_id, const char *name) +{ + const char *id_str; + long res; + int result; + + if (strnlen(name, OCF_CORE_NAME_SIZE) < sizeof("core") - 1) + return -EINVAL; + + id_str = name + sizeof("core") - 1; + + result = kstrtol(id_str, 10, &res); + + if (!result) + *core_id = res; + + return result; +} + static inline int mngt_get_cache_by_id(ocf_ctx_t ctx, uint16_t id, ocf_cache_t *cache) { From 76acefd83179fd96303a0ea1e95bdaa29c4866ec Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Tue, 10 Sep 2019 10:06:38 -0400 Subject: [PATCH 2/2] After loading cache mark used core ids. Since OCF doesn't use core and cache ids anymore adapter has to track occupied ids on its own. After loading cache, ids of all loaded cores should be marked as occupied, otherwise adding new core without explicit specifying core id will fail. Signed-off-by: Michal Mielewczyk --- modules/cas_cache/layer_cache_management.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/modules/cas_cache/layer_cache_management.c b/modules/cas_cache/layer_cache_management.c index 07400d5..0d062bd 100644 --- a/modules/cas_cache/layer_cache_management.c +++ b/modules/cas_cache/layer_cache_management.c @@ -592,10 +592,19 @@ static void _cache_mngt_log_core_device_path(ocf_core_t core) ocf_core_get_name(core), ocf_cache_get_name(cache)); } -static int _cache_mngt_log_core_device_path_visitor(ocf_core_t core, void *cntx) +static int _cache_mngt_core_device_loaded_visitor(ocf_core_t core, void *cntx) { + struct cache_priv *cache_priv; + uint16_t core_id = OCF_CORE_ID_INVALID; + ocf_cache_t cache = ocf_core_get_cache(core); + cache_priv = ocf_cache_get_priv(cache); + _cache_mngt_log_core_device_path(core); + core_id_from_name(&core_id, ocf_core_get_name(core)); + + mark_core_id_used(cache_priv->core_id_bitmap, core_id); + return 0; } @@ -1339,7 +1348,7 @@ static int _cache_mngt_load(struct ocf_mngt_cache_config *cfg, if (result) goto err_core_obj; - ocf_core_visit(tmp_cache, _cache_mngt_log_core_device_path_visitor, + ocf_core_visit(tmp_cache, _cache_mngt_core_device_loaded_visitor, NULL, false); *cache = tmp_cache;