Verify standby/active cache state in OCF entry points

Signed-off-by: Adam Rutkowski <adam.j.rutkowski@intel.com>
This commit is contained in:
Adam Rutkowski
2022-03-23 15:03:50 +01:00
parent e741160f8d
commit 4a839cd332
11 changed files with 174 additions and 1 deletions

View File

@@ -2963,6 +2963,9 @@ void ocf_mngt_cache_attach(ocf_cache_t cache,
OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(cfg);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(cache, priv, -OCF_ERR_CACHE_STANDBY);
if (!cache->mngt_queue)
OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL);
@@ -3070,6 +3073,9 @@ void ocf_mngt_cache_load(ocf_cache_t cache,
OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(cfg);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(cache, priv, -OCF_ERR_CACHE_STANDBY);
if (!cache->mngt_queue)
OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL);
@@ -3322,6 +3328,9 @@ void ocf_mngt_cache_save(ocf_cache_t cache,
OCF_CHECK_NULL(cache);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(cache, priv, -OCF_ERR_CACHE_STANDBY);
if (!cache->mngt_queue)
OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL);
@@ -3706,6 +3715,9 @@ void ocf_mngt_cache_detach(ocf_cache_t cache,
OCF_CHECK_NULL(cache);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(cache, priv, -OCF_ERR_CACHE_STANDBY);
if (!cache->mngt_queue)
OCF_CMPL_RET(cache, priv, -OCF_ERR_INVAL);

View File

@@ -559,6 +559,9 @@ void ocf_mngt_cache_add_core(ocf_cache_t cache,
OCF_CHECK_NULL(cache);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(cache, NULL, priv, -OCF_ERR_CACHE_STANDBY);
if (!cache->mngt_queue)
OCF_CMPL_RET(cache, NULL, priv, -OCF_ERR_INVAL);
@@ -735,6 +738,9 @@ void ocf_mngt_cache_remove_core(ocf_core_t core,
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(cache, -OCF_ERR_CACHE_STANDBY);
if (!cache->mngt_queue)
OCF_CMPL_RET(cache, -OCF_ERR_INVAL);
@@ -852,6 +858,9 @@ void ocf_mngt_cache_detach_core(ocf_core_t core,
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(cache, -OCF_ERR_CACHE_STANDBY);
if (!cache->mngt_queue)
OCF_CMPL_RET(cache, -OCF_ERR_INVAL);
@@ -877,11 +886,17 @@ int ocf_mngt_core_set_uuid(ocf_core_t core, const struct ocf_volume_uuid *uuid)
struct ocf_volume_uuid *current_uuid;
int result;
int diff;
ocf_cache_t cache;
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(uuid);
OCF_CHECK_NULL(uuid->data);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
current_uuid = &ocf_core_get_volume(core)->uuid;
result = env_memcmp(current_uuid->data, current_uuid->size,
@@ -905,9 +920,16 @@ int ocf_mngt_core_set_uuid(ocf_core_t core, const struct ocf_volume_uuid *uuid)
int ocf_mngt_core_set_user_metadata(ocf_core_t core, void *data, size_t size)
{
ocf_cache_t cache;
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(data);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
if (size > OCF_CORE_USER_DATA_SIZE)
return -EINVAL;
@@ -917,9 +939,16 @@ int ocf_mngt_core_set_user_metadata(ocf_core_t core, void *data, size_t size)
int ocf_mngt_core_get_user_metadata(ocf_core_t core, void *data, size_t size)
{
ocf_cache_t cache;
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(data);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
if (size > sizeof(core->conf_meta->user_data))
return -EINVAL;
@@ -957,8 +986,14 @@ static int _cache_mngt_set_core_seq_cutoff_threshold(ocf_core_t core, void *cntx
int ocf_mngt_core_set_seq_cutoff_threshold(ocf_core_t core, uint32_t thresh)
{
ocf_cache_t cache;
OCF_CHECK_NULL(core);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
return _cache_mngt_set_core_seq_cutoff_threshold(core, &thresh);
}
@@ -976,9 +1011,15 @@ int ocf_mngt_core_set_seq_cutoff_threshold_all(ocf_cache_t cache,
int ocf_mngt_core_get_seq_cutoff_threshold(ocf_core_t core, uint32_t *thresh)
{
ocf_cache_t cache;
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(thresh);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
*thresh = ocf_core_get_seq_cutoff_threshold(core);
return 0;
@@ -1030,14 +1071,21 @@ static int _cache_mngt_set_core_seq_cutoff_policy(ocf_core_t core, void *cntx)
int ocf_mngt_core_set_seq_cutoff_policy(ocf_core_t core,
ocf_seq_cutoff_policy policy)
{
ocf_cache_t cache;
OCF_CHECK_NULL(core);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
return _cache_mngt_set_core_seq_cutoff_policy(core, &policy);
}
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;
@@ -1048,9 +1096,15 @@ int ocf_mngt_core_set_seq_cutoff_policy_all(ocf_cache_t cache,
int ocf_mngt_core_get_seq_cutoff_policy(ocf_core_t core,
ocf_seq_cutoff_policy *policy)
{
ocf_cache_t cache;
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(policy);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
*policy = ocf_core_get_seq_cutoff_policy(core);
return 0;
@@ -1089,8 +1143,14 @@ static int _cache_mngt_set_core_seq_cutoff_promo_count(ocf_core_t core,
int ocf_mngt_core_set_seq_cutoff_promotion_count(ocf_core_t core,
uint32_t count)
{
ocf_cache_t cache;
OCF_CHECK_NULL(core);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
return _cache_mngt_set_core_seq_cutoff_promo_count(core, &count);
}
@@ -1109,9 +1169,15 @@ int ocf_mngt_core_set_seq_cutoff_promotion_count_all(ocf_cache_t cache,
int ocf_mngt_core_get_seq_cutoff_promotion_count(ocf_core_t core,
uint32_t *count)
{
ocf_cache_t cache;
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(count);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
*count = ocf_core_get_seq_cutoff_promotion_count(core);
return 0;
@@ -1143,8 +1209,14 @@ static int _cache_mngt_set_core_seq_cutoff_promote_on_threshold(
int ocf_mngt_core_set_seq_cutoff_promote_on_threshold(ocf_core_t core,
bool promote)
{
ocf_cache_t cache;
OCF_CHECK_NULL(core);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
return _cache_mngt_set_core_seq_cutoff_promote_on_threshold(core, &promote);
}
@@ -1164,9 +1236,15 @@ int ocf_mngt_core_set_seq_cutoff_promote_on_threshold_all(ocf_cache_t cache,
int ocf_mngt_core_get_seq_cutoff_promote_on_threshold(ocf_core_t core,
bool *promote)
{
ocf_cache_t cache;
OCF_CHECK_NULL(core);
OCF_CHECK_NULL(promote);
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;
*promote = ocf_core_get_seq_cutoff_promote_on_threshold(core);
return 0;

View File

@@ -110,6 +110,12 @@ static void _ocf_mngt_begin_flush(ocf_pipeline_t pipeline, void *priv,
bool ocf_mngt_core_is_dirty(ocf_core_t core)
{
ocf_cache_t cache;
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
return false;
return !!env_atomic_read(&core->runtime_meta->dirty_clines);
}
@@ -120,6 +126,9 @@ bool ocf_mngt_cache_is_dirty(ocf_cache_t cache)
OCF_CHECK_NULL(cache);
if (ocf_cache_is_standby(cache))
return false;
for_each_core(cache, core, core_id) {
if (ocf_mngt_core_is_dirty(core))
return true;
@@ -655,6 +664,9 @@ void ocf_mngt_cache_flush(ocf_cache_t cache,
OCF_CHECK_NULL(cache);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(cache, priv, -OCF_ERR_CACHE_STANDBY);
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);
@@ -749,6 +761,9 @@ void ocf_mngt_core_flush(ocf_core_t core,
cache = ocf_core_get_cache(core);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(core, priv, -OCF_ERR_CACHE_STANDBY);
if (!ocf_cache_is_device_attached(cache)) {
ocf_cache_log(cache, log_err, "Cannot flush core - "
"cache device is detached\n");
@@ -820,6 +835,9 @@ void ocf_mngt_cache_purge(ocf_cache_t cache,
OCF_CHECK_NULL(cache);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(cache, priv, -OCF_ERR_CACHE_STANDBY);
if (!cache->mngt_queue) {
ocf_cache_log(cache, log_err,
"Cannot purge cache - no flush queue set\n");
@@ -871,6 +889,9 @@ void ocf_mngt_core_purge(ocf_core_t core,
cache = ocf_core_get_cache(core);
core_id = ocf_core_get_id(core);
if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(core, priv, -OCF_ERR_CACHE_STANDBY);
if (!cache->mngt_queue) {
ocf_core_log(core, log_err,
"Cannot purge core - no flush queue set\n");
@@ -902,6 +923,9 @@ void ocf_mngt_cache_flush_interrupt(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
if (ocf_cache_is_standby(cache))
return;
ocf_cache_log(cache, log_alert, "Flushing interrupt\n");
cache->flushing_interrupted = 1;
}