Skip to content

Commit

Permalink
Disable changing cache params for detached cache
Browse files Browse the repository at this point in the history
Majority of management operations should be blocked for detached cache,
although adding and removing cores should be possible.

Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
  • Loading branch information
mmichal10 authored and Rafal Stefanowski committed Jul 10, 2024
1 parent f1bfd94 commit 83ec255
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 0 deletions.
4 changes: 4 additions & 0 deletions inc/ocf_err.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -143,6 +144,9 @@ typedef enum {
/** Invalid operation for cache in standby state. */
OCF_ERR_CACHE_STANDBY,

/** Invalid operation for cache in standby state. */
OCF_ERR_CACHE_DETACHED,

/** Size of core volume doesn't match the size stored in cache metadata */
OCF_ERR_CORE_SIZE_MISMATCH,

Expand Down
2 changes: 2 additions & 0 deletions src/metadata/metadata_superblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ void ocf_metadata_flush_superblock(ocf_cache_t cache,

OCF_DEBUG_TRACE(cache);

ENV_BUG_ON(!ocf_cache_is_device_attached(cache));

result = ocf_pipeline_create(&pipeline, cache,
&ocf_metadata_flush_sb_pipeline_props);
if (result)
Expand Down
13 changes: 13 additions & 0 deletions src/mngt/ocf_mngt_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -3443,6 +3443,13 @@ void ocf_mngt_cache_save(ocf_cache_t cache,

OCF_CHECK_NULL(cache);

if (!ocf_cache_is_device_attached(cache)) {
ocf_cache_log(cache, log_info, "Cache is in detached state. Any changes"
" made to the cache configuration won't persist through cache "
"stop unless a caching volume is attached\n");
OCF_CMPL_RET(cache, priv, -OCF_ERR_CACHE_DETACHED);
}

if (ocf_cache_is_standby(cache))
OCF_CMPL_RET(cache, priv, -OCF_ERR_CACHE_STANDBY);

Expand Down Expand Up @@ -3519,6 +3526,9 @@ int ocf_mngt_cache_set_mode(ocf_cache_t cache, ocf_cache_mode_t mode)
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

if (!ocf_cache_is_device_attached(cache))
result = -OCF_ERR_CACHE_DETACHED;

if (!ocf_cache_mode_is_valid(mode)) {
ocf_cache_log(cache, log_err, "Cache mode %u is invalid\n",
mode);
Expand All @@ -3544,6 +3554,9 @@ int ocf_mngt_cache_promotion_set_policy(ocf_cache_t cache, ocf_promotion_t type)
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

if (!ocf_cache_is_device_attached(cache))
result = -OCF_ERR_CACHE_DETACHED;

ocf_metadata_start_exclusive_access(&cache->metadata.lock);

result = ocf_promotion_set_policy(cache->promotion_policy, type);
Expand Down
31 changes: 31 additions & 0 deletions src/mngt/ocf_mngt_core.c
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,16 @@ static void ocf_mngt_cache_add_core_insert(ocf_pipeline_t pipeline,
core->conf_meta->seq_no = core_sequence_no;

/* Update super-block with core device addition */

if (!ocf_cache_is_device_attached(cache)) {
if (!cache->metadata.is_volatile) {
ocf_cache_log(cache, log_warn, "Cache is in detached state. "
"The changes about the new core won't persist cache stop "
"unless a cache volume is attached\n");
}
OCF_PL_NEXT_RET(pipeline);
}

ocf_metadata_flush_superblock(cache,
_ocf_mngt_cache_add_core_flush_sb_complete, context);
}
Expand Down Expand Up @@ -694,6 +704,9 @@ static void _ocf_mngt_cache_remove_core(ocf_pipeline_t pipeline, void *priv,
cache_mngt_core_remove_from_cache(core);
cache_mngt_core_deinit(core);

if (!ocf_cache_is_device_attached(cache))
OCF_PL_NEXT_RET(pipeline);

ocf_metadata_flush_superblock(cache,
ocf_mngt_cache_remove_core_flush_superblock_complete,
context);
Expand Down Expand Up @@ -999,6 +1012,9 @@ int ocf_mngt_core_set_seq_cutoff_threshold(ocf_core_t core, uint32_t thresh)
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

if (!ocf_cache_is_device_attached(cache))
return -OCF_ERR_CACHE_DETACHED;

return _cache_mngt_set_core_seq_cutoff_threshold(core, &thresh);
}

Expand All @@ -1010,6 +1026,9 @@ int ocf_mngt_core_set_seq_cutoff_threshold_all(ocf_cache_t cache,
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

if (!ocf_cache_is_device_attached(cache))
return -OCF_ERR_CACHE_DETACHED;

return ocf_core_visit(cache, _cache_mngt_set_core_seq_cutoff_threshold,
&thresh, true);
}
Expand Down Expand Up @@ -1084,6 +1103,9 @@ int ocf_mngt_core_set_seq_cutoff_policy(ocf_core_t core,
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

if (!ocf_cache_is_device_attached(cache))
return -OCF_ERR_CACHE_DETACHED;

return _cache_mngt_set_core_seq_cutoff_policy(core, &policy);
}
int ocf_mngt_core_set_seq_cutoff_policy_all(ocf_cache_t cache,
Expand All @@ -1094,6 +1116,9 @@ int ocf_mngt_core_set_seq_cutoff_policy_all(ocf_cache_t cache,
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

if (!ocf_cache_is_device_attached(cache))
return -OCF_ERR_CACHE_DETACHED;

return ocf_core_visit(cache, _cache_mngt_set_core_seq_cutoff_policy,
&policy, true);
}
Expand Down Expand Up @@ -1156,6 +1181,9 @@ int ocf_mngt_core_set_seq_cutoff_promotion_count(ocf_core_t core,
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

if (!ocf_cache_is_device_attached(cache))
return -OCF_ERR_CACHE_DETACHED;

return _cache_mngt_set_core_seq_cutoff_promo_count(core, &count);
}

Expand All @@ -1167,6 +1195,9 @@ int ocf_mngt_core_set_seq_cutoff_promotion_count_all(ocf_cache_t cache,
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

if (!ocf_cache_is_device_attached(cache))
return -OCF_ERR_CACHE_DETACHED;

return ocf_core_visit(cache, _cache_mngt_set_core_seq_cutoff_promo_count,
&count, true);
}
Expand Down
3 changes: 3 additions & 0 deletions src/mngt/ocf_mngt_flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -1102,6 +1102,9 @@ int ocf_mngt_cache_cleaning_set_param(ocf_cache_t cache, ocf_cleaning_t type,
if (ocf_cache_is_standby(cache))
return -OCF_ERR_CACHE_STANDBY;

if (!ocf_cache_is_device_attached(cache))
return -OCF_ERR_CACHE_DETACHED;

ocf_metadata_start_exclusive_access(&cache->metadata.lock);

ret = ocf_cleaning_set_param(cache, type, param_id, param_value);
Expand Down
2 changes: 2 additions & 0 deletions tests/functional/pyocf/types/shared.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#
# Copyright(c) 2019-2022 Intel Corporation
# Copyright(c) 2024 Huawei Technologies
# SPDX-License-Identifier: BSD-3-Clause
#

Expand Down Expand Up @@ -55,6 +56,7 @@ class OcfErrorCode(IntEnum):
OCF_ERR_CORE_UUID_EXISTS = auto()
OCF_ERR_CACHE_LINE_SIZE_MISMATCH = auto()
OCF_ERR_CACHE_STANDBY = auto()
OCF_ERR_CACHE_DETACHED = auto()
OCF_ERR_CORE_SIZE_MISMATCH = auto()
OCF_ERR_STANDBY_ATTACHED = auto()
OCF_ERR_CORE_NOT_REMOVED = auto()
Expand Down

0 comments on commit 83ec255

Please sign in to comment.