From 71262d5097cf8b9c72e3f71148ab02509301b004 Mon Sep 17 00:00:00 2001 From: Krzysztof Majzerowicz-Jaszcz Date: Wed, 15 Sep 2021 17:27:33 +0200 Subject: [PATCH] Cache standby mode API changes Error for an invalid cache operation while in passive mode added Signed-off-by: Krzysztof Majzerowicz-Jaszcz Error name correction Signed-off-by: Krzysztof Majzerowicz-Jaszcz API changes for passive cache mode Moved the passive cache error return source to the api for flush and set_param Signed-off-by: Krzysztof Majzerowicz-Jaszcz Further API changes for passive cache mode Signed-off-by: Krzysztof Majzerowicz-Jaszcz Passive api - review changes Signed-off-by: Krzysztof Majzerowicz-Jaszcz --- inc/ocf_cache.h | 6 +-- inc/ocf_err.h | 3 ++ inc/ocf_mngt.h | 7 ++- inc/ocf_stats.h | 5 ++- src/mngt/ocf_mngt_cache.c | 44 ++++++++++++++----- src/mngt/ocf_mngt_core.c | 15 +++++-- src/mngt/ocf_mngt_flush.c | 17 +++++++ src/mngt/ocf_mngt_io_class.c | 3 ++ src/ocf_core.c | 3 ++ src/ocf_stats.c | 7 ++- ...gt_cache_set_fallback_pt_error_threshold.c | 5 +++ .../ocf_mngt_io_class.c/ocf_mngt_io_class.c | 5 +++ 12 files changed, 99 insertions(+), 21 deletions(-) diff --git a/inc/ocf_cache.h b/inc/ocf_cache.h index 5be621f..f712351 100644 --- a/inc/ocf_cache.h +++ b/inc/ocf_cache.h @@ -155,12 +155,12 @@ bool ocf_cache_is_device_attached(ocf_cache_t cache); bool ocf_cache_is_running(ocf_cache_t cache); /** - * @brief Check if cache object is passive + * @brief Check if cache object is standby * * @param[in] cache Cache object * - * @retval 1 Caching device is in passive state - * @retval 0 Caching device is not in passive state + * @retval 1 Caching device is in standby state + * @retval 0 Caching device is not in standby state */ bool ocf_cache_is_standby(ocf_cache_t cache); diff --git a/inc/ocf_err.h b/inc/ocf_err.h index b5a889b..7fd0b7b 100644 --- a/inc/ocf_err.h +++ b/inc/ocf_err.h @@ -134,6 +134,9 @@ typedef enum { /** Cache initialized with wrong cache line size */ OCF_ERR_CACHE_LINE_SIZE_MISMATCH, + + /** Invalid operation for cache in standby state. */ + OCF_ERR_CACHE_STANDBY, } ocf_error_t; #endif /* __OCF_ERR_H__ */ diff --git a/inc/ocf_mngt.h b/inc/ocf_mngt.h index a6db0a9..176c0dd 100644 --- a/inc/ocf_mngt.h +++ b/inc/ocf_mngt.h @@ -873,10 +873,12 @@ int ocf_mngt_cache_promotion_set_policy(ocf_cache_t cache, ocf_promotion_t type) * @brief Get promotion policy in given cache * * @param[in] cache Cache handle + * @param[out] type Policy type * - * @retval Currently set promotion policy type + * @retval 0 success + * @retval Non-zero Error occurred and policy type could not be retrieved */ -ocf_promotion_t ocf_mngt_cache_promotion_get_policy(ocf_cache_t cache); +int ocf_mngt_cache_promotion_get_policy(ocf_cache_t cache, ocf_promotion_t *type); /** * @brief Set promotion policy parameter for given cache @@ -1149,6 +1151,7 @@ int ocf_mngt_cache_get_fallback_pt_error_threshold(ocf_cache_t cache, * @param[in] cache Cache handle * * @retval 0 Threshold have been reset successfully + * @retval Non-zero Error occured */ int ocf_mngt_cache_reset_fallback_pt_error_counter(ocf_cache_t cache); diff --git a/inc/ocf_stats.h b/inc/ocf_stats.h index 603d1ec..16448be 100644 --- a/inc/ocf_stats.h +++ b/inc/ocf_stats.h @@ -233,7 +233,10 @@ void ocf_core_stats_initialize(ocf_core_t core); * Initialize or reset counters used for statistics. * * @param[in] cache Cache handle + * + * @retval 0 Success + * @retval Non-zero Error */ -void ocf_core_stats_initialize_all(ocf_cache_t cache); +int ocf_core_stats_initialize_all(ocf_cache_t cache); #endif /* __OCF_STATS_H__ */ diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 33b7588..4285237 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -1323,10 +1323,10 @@ static void _ocf_mngt_cache_set_valid(ocf_cache_t cache) env_bit_set(ocf_cache_state_running, &cache->cache_state); } -static void _ocf_mngt_cache_set_passive(ocf_cache_t cache) +static void _ocf_mngt_cache_set_standby(ocf_cache_t cache) { /* - * Clear initialization state and set the passive bit. + * Clear initialization state and set the standby bit. */ env_bit_clear(ocf_cache_state_initializing, &cache->cache_state); env_bit_set(ocf_cache_state_standby, &cache->cache_state); @@ -2386,7 +2386,7 @@ static void _ocf_mngt_cache_load(ocf_cache_t cache, } struct ocf_pipeline_properties -ocf_mngt_cache_stop_passive_pipeline_properties = { +ocf_mngt_cache_stop_standby_pipeline_properties = { .priv_size = sizeof(struct ocf_mngt_cache_stop_context), .finish = ocf_mngt_cache_stop_finish, .steps = { @@ -2411,7 +2411,7 @@ static void _ocf_mngt_cache_standby(ocf_cache_t cache, OCF_CMPL_RET(cache, priv1, priv2, -OCF_ERR_NO_MEM); result = ocf_pipeline_create(&cache->stop_pipeline, cache, - &ocf_mngt_cache_stop_passive_pipeline_properties); + &ocf_mngt_cache_stop_standby_pipeline_properties); if (result) { ocf_pipeline_destroy(pipeline); OCF_CMPL_RET(cache, priv1, priv2, -OCF_ERR_NO_MEM); @@ -2804,8 +2804,8 @@ static void _ocf_mngt_cache_standby_complete(ocf_cache_t cache, void *priv1, if (error) OCF_CMPL_RET(cache, priv2, error); - _ocf_mngt_cache_set_passive(cache); - ocf_cache_log(cache, log_info, "Successfully binded\n"); + _ocf_mngt_cache_set_standby(cache); + ocf_cache_log(cache, log_info, "Successfully bound\n"); OCF_CMPL_RET(cache, priv2, 0); } @@ -3053,6 +3053,9 @@ int ocf_mngt_cache_set_mode(ocf_cache_t cache, ocf_cache_mode_t mode) OCF_CHECK_NULL(cache); + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + if (!ocf_cache_mode_is_valid(mode)) { ocf_cache_log(cache, log_err, "Cache mode %u is invalid\n", mode); @@ -3075,6 +3078,9 @@ int ocf_mngt_cache_promotion_set_policy(ocf_cache_t cache, ocf_promotion_t type) { int result; + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + ocf_metadata_start_exclusive_access(&cache->metadata.lock); result = ocf_promotion_set_policy(cache->promotion_policy, type); @@ -3084,17 +3090,20 @@ int ocf_mngt_cache_promotion_set_policy(ocf_cache_t cache, ocf_promotion_t type) return result; } -ocf_promotion_t ocf_mngt_cache_promotion_get_policy(ocf_cache_t cache) +int ocf_mngt_cache_promotion_get_policy(ocf_cache_t cache, ocf_promotion_t *type) { - ocf_promotion_t result; + OCF_CHECK_NULL(type); + + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; ocf_metadata_start_shared_access(&cache->metadata.lock, 0); - result = cache->conf_meta->promotion_policy_type; + *type = cache->conf_meta->promotion_policy_type; ocf_metadata_end_shared_access(&cache->metadata.lock, 0); - return result; + return 0; } int ocf_mngt_cache_promotion_get_param(ocf_cache_t cache, ocf_promotion_t type, @@ -3102,6 +3111,9 @@ int ocf_mngt_cache_promotion_get_param(ocf_cache_t cache, ocf_promotion_t type, { int result; + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + ocf_metadata_start_shared_access(&cache->metadata.lock, 0); result = ocf_promotion_get_param(cache, type, param_id, param_value); @@ -3116,6 +3128,9 @@ int ocf_mngt_cache_promotion_set_param(ocf_cache_t cache, ocf_promotion_t type, { int result; + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + ocf_metadata_start_exclusive_access(&cache->metadata.lock); result = ocf_promotion_set_param(cache, type, param_id, param_value); @@ -3129,6 +3144,9 @@ int ocf_mngt_cache_reset_fallback_pt_error_counter(ocf_cache_t cache) { OCF_CHECK_NULL(cache); + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + if (ocf_fallback_pt_is_on(cache)) { ocf_cache_log(cache, log_info, "Fallback Pass Through inactive\n"); @@ -3146,6 +3164,9 @@ int ocf_mngt_cache_set_fallback_pt_error_threshold(ocf_cache_t cache, OCF_CHECK_NULL(cache); + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + if (new_threshold > OCF_CACHE_FALLBACK_PT_MAX_ERROR_THRESHOLD) return -OCF_ERR_INVAL; @@ -3174,6 +3195,9 @@ int ocf_mngt_cache_get_fallback_pt_error_threshold(ocf_cache_t cache, OCF_CHECK_NULL(cache); OCF_CHECK_NULL(threshold); + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + *threshold = cache->fallback_pt_error_threshold; return 0; diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index f409de9..b31c670 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -954,6 +954,9 @@ int ocf_mngt_core_set_seq_cutoff_threshold_all(ocf_cache_t cache, { OCF_CHECK_NULL(cache); + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + return ocf_core_visit(cache, _cache_mngt_set_core_seq_cutoff_threshold, &thresh, true); } @@ -1022,9 +1025,11 @@ int ocf_mngt_core_set_seq_cutoff_policy_all(ocf_cache_t cache, ocf_seq_cutoff_policy policy) { OCF_CHECK_NULL(cache); + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; return ocf_core_visit(cache, _cache_mngt_set_core_seq_cutoff_policy, - &policy, true); + &policy, true); } int ocf_mngt_core_get_seq_cutoff_policy(ocf_core_t core, @@ -1081,9 +1086,11 @@ int ocf_mngt_core_set_seq_cutoff_promotion_count_all(ocf_cache_t cache, { OCF_CHECK_NULL(cache); - return ocf_core_visit(cache, - _cache_mngt_set_core_seq_cutoff_promo_count, - &count, true); + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + + return ocf_core_visit(cache, _cache_mngt_set_core_seq_cutoff_promo_count, + &count, true); } int ocf_mngt_core_get_seq_cutoff_promotion_count(ocf_core_t core, diff --git a/src/mngt/ocf_mngt_flush.c b/src/mngt/ocf_mngt_flush.c index afa1ab7..007a8bd 100644 --- a/src/mngt/ocf_mngt_flush.c +++ b/src/mngt/ocf_mngt_flush.c @@ -655,6 +655,11 @@ void ocf_mngt_cache_flush(ocf_cache_t cache, OCF_CHECK_NULL(cache); + if (ocf_cache_is_standby(cache)) { + ocf_cache_log(cache, log_err, "Cannot flush cache - cache is standby\n"); + OCF_CMPL_RET(cache, priv, -OCF_ERR_CACHE_STANDBY); + } + if (!ocf_cache_is_device_attached(cache)) { ocf_cache_log(cache, log_err, "Cannot flush cache - " "cache device is detached\n"); @@ -1006,6 +1011,9 @@ void ocf_mngt_cache_cleaning_set_policy(ocf_cache_t cache, if (new_policy < 0 || new_policy >= ocf_cleaning_max) OCF_CMPL_RET(priv, -OCF_ERR_INVAL); + if (ocf_cache_is_standby(cache)) + OCF_CMPL_RET(priv, -OCF_ERR_CACHE_STANDBY); + old_policy = cache->conf_meta->cleaning_policy_type; if (new_policy == old_policy) { @@ -1036,6 +1044,9 @@ int ocf_mngt_cache_cleaning_get_policy(ocf_cache_t cache, ocf_cleaning_t *type) OCF_CHECK_NULL(cache); OCF_CHECK_NULL(type); + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + *type = cache->conf_meta->cleaning_policy_type; return 0; @@ -1051,6 +1062,9 @@ int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type, if (type < 0 || type >= ocf_cleaning_max) return -OCF_ERR_INVAL; + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + ocf_metadata_start_exclusive_access(&cache->metadata.lock); ret = ocf_cleaning_set_param(cache, type, param_id, param_value); @@ -1069,5 +1083,8 @@ int ocf_mngt_cache_cleaning_get_param(ocf_cache_t cache, ocf_cleaning_t type, if (type < 0 || type >= ocf_cleaning_max) return -OCF_ERR_INVAL; + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + return ocf_cleaning_get_param(cache, type, param_id, param_value); } diff --git a/src/mngt/ocf_mngt_io_class.c b/src/mngt/ocf_mngt_io_class.c index ada3ef3..9cd57b8 100644 --- a/src/mngt/ocf_mngt_io_class.c +++ b/src/mngt/ocf_mngt_io_class.c @@ -285,6 +285,9 @@ int ocf_mngt_cache_io_classes_configure(ocf_cache_t cache, OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cfg); + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + for (i = 0; i < OCF_USER_IO_CLASS_MAX; i++) { result = _ocf_mngt_io_class_validate_cfg(cache, &cfg->config[i]); if (result) diff --git a/src/ocf_core.c b/src/ocf_core.c index 660c383..0653f42 100644 --- a/src/ocf_core.c +++ b/src/ocf_core.c @@ -53,6 +53,9 @@ int ocf_core_get_by_name(ocf_cache_t cache, const char *name, size_t name_len, ocf_core_t i_core; ocf_core_id_t i_core_id; + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + for_each_core(cache, i_core, i_core_id) { if (!env_strncmp(ocf_core_get_name(i_core), OCF_CORE_NAME_SIZE, name, name_len)) { diff --git a/src/ocf_stats.c b/src/ocf_stats.c index 0fa2139..f464101 100644 --- a/src/ocf_stats.c +++ b/src/ocf_stats.c @@ -203,16 +203,21 @@ void ocf_core_stats_initialize(ocf_core_t core) #endif } -void ocf_core_stats_initialize_all(ocf_cache_t cache) +int ocf_core_stats_initialize_all(ocf_cache_t cache) { ocf_core_id_t id; + if (ocf_cache_is_standby(cache)) + return -OCF_ERR_CACHE_STANDBY; + for (id = 0; id < OCF_CORE_MAX; id++) { if (!env_bit_test(id, cache->conf_meta->valid_core_bitmap)) continue; ocf_core_stats_initialize(&cache->core[id]); } + + return 0; } static void copy_req_stats(struct ocf_stats_req *dest, diff --git a/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c b/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c index 84898b7..7f3f9b5 100644 --- a/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c +++ b/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c @@ -52,6 +52,11 @@ int __wrap_ocf_mngt_cache_set_fallback_pt(ocf_cache_t cache) function_called(); } +bool __wrap_ocf_cache_is_standby(struct ocf_cache_t *cache) +{ + return false; +} + static void ocf_mngt_cache_set_fallback_pt_error_threshold_test01(void **state) { struct ocf_cache *cache; diff --git a/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c b/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c index 8777284..abcf3f9 100644 --- a/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c +++ b/tests/unit/tests/mngt/ocf_mngt_io_class.c/ocf_mngt_io_class.c @@ -88,6 +88,11 @@ int __wrap_ocf_metadata_flush_superblock(struct ocf_cache *cache) { } +bool __wrap_ocf_cache_is_standby(struct ocf_cache *cache) +{ + return false; +} + /* Helper function for test prepration */ static inline void setup_valid_config(struct ocf_mngt_io_class_config *cfg, bool remove)