Cache standby mode API changes

Error for an invalid cache operation while in passive mode added

Signed-off-by: Krzysztof Majzerowicz-Jaszcz <krzysztof.majzerowicz-jaszcz@intel.com>

Error name correction

Signed-off-by: Krzysztof Majzerowicz-Jaszcz <krzysztof.majzerowicz-jaszcz@intel.com>

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 <krzysztof.majzerowicz-jaszcz@intel.com>

Further API changes for passive cache mode

Signed-off-by: Krzysztof Majzerowicz-Jaszcz <krzysztof.majzerowicz-jaszcz@intel.com>

 Passive api - review changes

Signed-off-by: Krzysztof Majzerowicz-Jaszcz <krzysztof.majzerowicz-jaszcz@intel.com>
This commit is contained in:
Krzysztof Majzerowicz-Jaszcz 2021-09-15 17:27:33 +02:00
parent 7b120162a5
commit 71262d5097
12 changed files with 99 additions and 21 deletions

View File

@ -155,12 +155,12 @@ bool ocf_cache_is_device_attached(ocf_cache_t cache);
bool ocf_cache_is_running(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 * @param[in] cache Cache object
* *
* @retval 1 Caching device is in passive state * @retval 1 Caching device is in standby state
* @retval 0 Caching device is not in passive state * @retval 0 Caching device is not in standby state
*/ */
bool ocf_cache_is_standby(ocf_cache_t cache); bool ocf_cache_is_standby(ocf_cache_t cache);

View File

@ -134,6 +134,9 @@ typedef enum {
/** Cache initialized with wrong cache line size */ /** Cache initialized with wrong cache line size */
OCF_ERR_CACHE_LINE_SIZE_MISMATCH, OCF_ERR_CACHE_LINE_SIZE_MISMATCH,
/** Invalid operation for cache in standby state. */
OCF_ERR_CACHE_STANDBY,
} ocf_error_t; } ocf_error_t;
#endif /* __OCF_ERR_H__ */ #endif /* __OCF_ERR_H__ */

View File

@ -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 * @brief Get promotion policy in given cache
* *
* @param[in] cache Cache handle * @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 * @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 * @param[in] cache Cache handle
* *
* @retval 0 Threshold have been reset successfully * @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); int ocf_mngt_cache_reset_fallback_pt_error_counter(ocf_cache_t cache);

View File

@ -233,7 +233,10 @@ void ocf_core_stats_initialize(ocf_core_t core);
* Initialize or reset counters used for statistics. * Initialize or reset counters used for statistics.
* *
* @param[in] cache Cache handle * @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__ */ #endif /* __OCF_STATS_H__ */

View File

@ -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); 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_clear(ocf_cache_state_initializing, &cache->cache_state);
env_bit_set(ocf_cache_state_standby, &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 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), .priv_size = sizeof(struct ocf_mngt_cache_stop_context),
.finish = ocf_mngt_cache_stop_finish, .finish = ocf_mngt_cache_stop_finish,
.steps = { .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); OCF_CMPL_RET(cache, priv1, priv2, -OCF_ERR_NO_MEM);
result = ocf_pipeline_create(&cache->stop_pipeline, cache, result = ocf_pipeline_create(&cache->stop_pipeline, cache,
&ocf_mngt_cache_stop_passive_pipeline_properties); &ocf_mngt_cache_stop_standby_pipeline_properties);
if (result) { if (result) {
ocf_pipeline_destroy(pipeline); ocf_pipeline_destroy(pipeline);
OCF_CMPL_RET(cache, priv1, priv2, -OCF_ERR_NO_MEM); 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) if (error)
OCF_CMPL_RET(cache, priv2, error); OCF_CMPL_RET(cache, priv2, error);
_ocf_mngt_cache_set_passive(cache); _ocf_mngt_cache_set_standby(cache);
ocf_cache_log(cache, log_info, "Successfully binded\n"); ocf_cache_log(cache, log_info, "Successfully bound\n");
OCF_CMPL_RET(cache, priv2, 0); 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); OCF_CHECK_NULL(cache);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
if (!ocf_cache_mode_is_valid(mode)) { if (!ocf_cache_mode_is_valid(mode)) {
ocf_cache_log(cache, log_err, "Cache mode %u is invalid\n", ocf_cache_log(cache, log_err, "Cache mode %u is invalid\n",
mode); mode);
@ -3075,6 +3078,9 @@ int ocf_mngt_cache_promotion_set_policy(ocf_cache_t cache, ocf_promotion_t type)
{ {
int result; int result;
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
ocf_metadata_start_exclusive_access(&cache->metadata.lock); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
result = ocf_promotion_set_policy(cache->promotion_policy, type); 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; 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); 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); 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, 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; int result;
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
ocf_metadata_start_shared_access(&cache->metadata.lock, 0); ocf_metadata_start_shared_access(&cache->metadata.lock, 0);
result = ocf_promotion_get_param(cache, type, param_id, param_value); 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; int result;
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
ocf_metadata_start_exclusive_access(&cache->metadata.lock); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
result = ocf_promotion_set_param(cache, type, param_id, param_value); 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); OCF_CHECK_NULL(cache);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
if (ocf_fallback_pt_is_on(cache)) { if (ocf_fallback_pt_is_on(cache)) {
ocf_cache_log(cache, log_info, ocf_cache_log(cache, log_info,
"Fallback Pass Through inactive\n"); "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); 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) if (new_threshold > OCF_CACHE_FALLBACK_PT_MAX_ERROR_THRESHOLD)
return -OCF_ERR_INVAL; 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(cache);
OCF_CHECK_NULL(threshold); OCF_CHECK_NULL(threshold);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
*threshold = cache->fallback_pt_error_threshold; *threshold = cache->fallback_pt_error_threshold;
return 0; return 0;

View File

@ -954,6 +954,9 @@ int ocf_mngt_core_set_seq_cutoff_threshold_all(ocf_cache_t cache,
{ {
OCF_CHECK_NULL(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, return ocf_core_visit(cache, _cache_mngt_set_core_seq_cutoff_threshold,
&thresh, true); &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_seq_cutoff_policy policy)
{ {
OCF_CHECK_NULL(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_policy, 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, 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); OCF_CHECK_NULL(cache);
return ocf_core_visit(cache, if (ocf_cache_is_standby(cache))
_cache_mngt_set_core_seq_cutoff_promo_count, return -OCF_ERR_CACHE_STANDBY;
&count, true);
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, int ocf_mngt_core_get_seq_cutoff_promotion_count(ocf_core_t core,

View File

@ -655,6 +655,11 @@ void ocf_mngt_cache_flush(ocf_cache_t cache,
OCF_CHECK_NULL(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)) { if (!ocf_cache_is_device_attached(cache)) {
ocf_cache_log(cache, log_err, "Cannot flush cache - " ocf_cache_log(cache, log_err, "Cannot flush cache - "
"cache device is detached\n"); "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) if (new_policy < 0 || new_policy >= ocf_cleaning_max)
OCF_CMPL_RET(priv, -OCF_ERR_INVAL); 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; old_policy = cache->conf_meta->cleaning_policy_type;
if (new_policy == old_policy) { 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(cache);
OCF_CHECK_NULL(type); OCF_CHECK_NULL(type);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
*type = cache->conf_meta->cleaning_policy_type; *type = cache->conf_meta->cleaning_policy_type;
return 0; 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) if (type < 0 || type >= ocf_cleaning_max)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
ocf_metadata_start_exclusive_access(&cache->metadata.lock); ocf_metadata_start_exclusive_access(&cache->metadata.lock);
ret = ocf_cleaning_set_param(cache, type, param_id, param_value); 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) if (type < 0 || type >= ocf_cleaning_max)
return -OCF_ERR_INVAL; 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); return ocf_cleaning_get_param(cache, type, param_id, param_value);
} }

View File

@ -285,6 +285,9 @@ int ocf_mngt_cache_io_classes_configure(ocf_cache_t cache,
OCF_CHECK_NULL(cache); OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(cfg); 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++) { for (i = 0; i < OCF_USER_IO_CLASS_MAX; i++) {
result = _ocf_mngt_io_class_validate_cfg(cache, &cfg->config[i]); result = _ocf_mngt_io_class_validate_cfg(cache, &cfg->config[i]);
if (result) if (result)

View File

@ -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_t i_core;
ocf_core_id_t i_core_id; 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) { for_each_core(cache, i_core, i_core_id) {
if (!env_strncmp(ocf_core_get_name(i_core), OCF_CORE_NAME_SIZE, if (!env_strncmp(ocf_core_get_name(i_core), OCF_CORE_NAME_SIZE,
name, name_len)) { name, name_len)) {

View File

@ -203,16 +203,21 @@ void ocf_core_stats_initialize(ocf_core_t core)
#endif #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; ocf_core_id_t id;
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
for (id = 0; id < OCF_CORE_MAX; id++) { for (id = 0; id < OCF_CORE_MAX; id++) {
if (!env_bit_test(id, cache->conf_meta->valid_core_bitmap)) if (!env_bit_test(id, cache->conf_meta->valid_core_bitmap))
continue; continue;
ocf_core_stats_initialize(&cache->core[id]); ocf_core_stats_initialize(&cache->core[id]);
} }
return 0;
} }
static void copy_req_stats(struct ocf_stats_req *dest, static void copy_req_stats(struct ocf_stats_req *dest,

View File

@ -52,6 +52,11 @@ int __wrap_ocf_mngt_cache_set_fallback_pt(ocf_cache_t cache)
function_called(); 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) static void ocf_mngt_cache_set_fallback_pt_error_threshold_test01(void **state)
{ {
struct ocf_cache *cache; struct ocf_cache *cache;

View File

@ -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 */ /* Helper function for test prepration */
static inline void setup_valid_config(struct ocf_mngt_io_class_config *cfg, static inline void setup_valid_config(struct ocf_mngt_io_class_config *cfg,
bool remove) bool remove)