From a82d420ee099d00541f632c987f2514e7f4a74e1 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Thu, 2 May 2019 17:21:12 +0200 Subject: [PATCH] Add management queue guards where needed Prevent starting management operations that require pipeline when management queue isn't set. Signed-off-by: Robert Baldyga --- src/mngt/ocf_mngt_cache.c | 20 ++++++++++++++++++++ src/mngt/ocf_mngt_core.c | 9 +++++++++ 2 files changed, 29 insertions(+) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index f69aa2a..b535415 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -1736,6 +1736,9 @@ void ocf_mngt_cache_attach(ocf_cache_t cache, OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cfg); + if (!cache->mngt_queue) + OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL); + result = _ocf_mngt_cache_validate_device_cfg(cfg); if (result) OCF_CMPL_RET(cache, priv, result); @@ -1873,6 +1876,9 @@ void ocf_mngt_cache_load(ocf_cache_t cache, OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cfg); + if (!cache->mngt_queue) + OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL); + /* Load is not allowed in volatile metadata mode */ if (cache->metadata.is_volatile) OCF_CMPL_RET(cache, priv, -EINVAL); @@ -2039,6 +2045,14 @@ void ocf_mngt_cache_stop(ocf_cache_t cache, OCF_CHECK_NULL(cache); + /* + * FIXME: What if creating/setting management queue failed? + * In such case we will be unable to use pipeline, and thus + * perform cache stop procedure. + */ + if (!cache->mngt_queue) + OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL); + result = ocf_pipeline_create(&pipeline, cache, &ocf_mngt_cache_stop_pipeline_properties); if (result) @@ -2116,6 +2130,9 @@ void ocf_mngt_cache_save(ocf_cache_t cache, OCF_CHECK_NULL(cache); + if (!cache->mngt_queue) + OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL); + result = ocf_pipeline_create(&pipeline, cache, &ocf_mngt_cache_save_pipeline_properties); if (result) @@ -2386,6 +2403,9 @@ void ocf_mngt_cache_detach(ocf_cache_t cache, OCF_CHECK_NULL(cache); + if (!cache->mngt_queue) + OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL); + if (!env_atomic_read(&cache->attached)) OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL); diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index fa2f827..aef375a 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -522,6 +522,9 @@ void ocf_mngt_cache_add_core(ocf_cache_t cache, OCF_CHECK_NULL(cache); + if (!cache->mngt_queue) + OCF_CMPL_RET(cache, NULL, priv, -OCF_ERR_INVAL); + result = ocf_pipeline_create(&pipeline, cache, &ocf_mngt_cache_add_core_pipeline_properties); if (result) @@ -634,6 +637,9 @@ void ocf_mngt_cache_remove_core(ocf_core_t core, cache = ocf_core_get_cache(core); core_id = ocf_core_get_id(core); + if (!cache->mngt_queue) + OCF_CMPL_RET(cache, -OCF_ERR_INVAL); + /* TODO: Make this asynchronous */ if (_ocf_cleaning_wait_for_finish(cache, 60 * 1000)) OCF_CMPL_RET(priv, -OCF_ERR_CACHE_IN_USE); @@ -697,6 +703,9 @@ void ocf_mngt_cache_detach_core(ocf_core_t core, cache = ocf_core_get_cache(core); core_name = ocf_core_get_name(core); + if (!cache->mngt_queue) + OCF_CMPL_RET(cache, -OCF_ERR_INVAL); + /* TODO: Make this asynchronous */ if (_ocf_cleaning_wait_for_finish(cache, 60 * 1000)) OCF_CMPL_RET(priv, -OCF_ERR_CACHE_IN_USE);