diff --git a/inc/ocf_err.h b/inc/ocf_err.h index a8d0563d..eeb867d8 100644 --- a/inc/ocf_err.h +++ b/inc/ocf_err.h @@ -1,5 +1,6 @@ /* * Copyright(c) 2012-2021 Intel Corporation + * Copyright(c) 2024 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ @@ -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, diff --git a/src/metadata/metadata_superblock.c b/src/metadata/metadata_superblock.c index ed53ea65..49d7381a 100644 --- a/src/metadata/metadata_superblock.c +++ b/src/metadata/metadata_superblock.c @@ -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) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 3ff94a27..b1978e44 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -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); @@ -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); @@ -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); diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index 2b34725d..1c6dc37a 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -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); } @@ -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); @@ -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); } @@ -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); } @@ -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, @@ -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); } @@ -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); } @@ -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); } diff --git a/src/mngt/ocf_mngt_flush.c b/src/mngt/ocf_mngt_flush.c index e9d225e2..c5331b1c 100644 --- a/src/mngt/ocf_mngt_flush.c +++ b/src/mngt/ocf_mngt_flush.c @@ -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); diff --git a/tests/functional/pyocf/types/shared.py b/tests/functional/pyocf/types/shared.py index dc23ddab..a4cd19a3 100644 --- a/tests/functional/pyocf/types/shared.py +++ b/tests/functional/pyocf/types/shared.py @@ -1,5 +1,6 @@ # # Copyright(c) 2019-2022 Intel Corporation +# Copyright(c) 2024 Huawei Technologies # SPDX-License-Identifier: BSD-3-Clause # @@ -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()