From 4a2597dc2565311222e1727f00cd1570a4aecbed Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Wed, 26 Mar 2025 08:42:18 +0100 Subject: [PATCH 1/2] stop: Don't deinitialize cleaning policy twice The cleaning metadata has been deinitialized in the previous pipeline step together with other services Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_cache.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 5812f1f..145d333 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -2163,7 +2163,7 @@ static void ocf_mngt_cache_stop_check_dirty(ocf_pipeline_t pipeline, ocf_pipeline_next(context->pipeline); } -static void _ocf_mngt_cache_stop_remove_cores(ocf_cache_t cache, bool attached) +static void _ocf_mngt_cache_stop_remove_cores(ocf_cache_t cache) { ocf_core_t core; ocf_core_id_t core_id; @@ -2172,8 +2172,6 @@ static void _ocf_mngt_cache_stop_remove_cores(ocf_cache_t cache, bool attached) /* All exported objects removed, cleaning up rest. */ for_each_core(cache, core, core_id) { cache_mngt_core_remove_from_cache(core); - if (attached) - cache_mngt_core_remove_from_cleaning_pol(core); cache_mngt_core_deinit(core); if (--no == 0) break; @@ -2186,7 +2184,7 @@ static void ocf_mngt_cache_stop_remove_cores(ocf_pipeline_t pipeline, struct ocf_mngt_cache_unplug_context *context = priv; ocf_cache_t cache = context->cache; - _ocf_mngt_cache_stop_remove_cores(cache, true); + _ocf_mngt_cache_stop_remove_cores(cache); ocf_pipeline_next(pipeline); } @@ -3433,7 +3431,7 @@ void ocf_mngt_cache_standby_activate(ocf_cache_t cache, static void ocf_mngt_cache_stop_detached(ocf_cache_t cache, ocf_mngt_cache_stop_end_t cmpl, void *priv) { - _ocf_mngt_cache_stop_remove_cores(cache, false); + _ocf_mngt_cache_stop_remove_cores(cache); _ocf_mngt_cache_put_io_queues(cache); ocf_mngt_cache_remove(cache->owner, cache); ocf_cache_log(cache, log_info, "Cache %s successfully stopped\n", From dedfa5eed922dd03b3fa0211b22db72fb35a42c1 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Wed, 26 Mar 2025 08:51:41 +0100 Subject: [PATCH 2/2] pytest: Add test for loading cores with cleaning Signed-off-by: Michal Mielewczyk --- .../tests/management/test_start_stop.py | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/tests/functional/tests/management/test_start_stop.py b/tests/functional/tests/management/test_start_stop.py index b7be8d0..e9a1823 100644 --- a/tests/functional/tests/management/test_start_stop.py +++ b/tests/functional/tests/management/test_start_stop.py @@ -496,6 +496,37 @@ def test_start_stop_noqueue(pyocf_ctx): assert not c.results["error"], "Failed to stop cache: {}".format(c.results["error"]) +@pytest.mark.parametrize("cleaning_policy", CleaningPolicy) +def test_load_cache_with_four_cores_with_cleaning(pyocf_ctx, cleaning_policy): + cache_device = RamVolume(Size.from_MiB(100)) + core_device_1 = RamVolume(Size.from_MiB(30)) + core_device_2 = RamVolume(Size.from_MiB(30)) + core_device_3 = RamVolume(Size.from_MiB(30)) + core_device_4 = RamVolume(Size.from_MiB(30)) + + cache = Cache.start_on_device(cache_device, cache_mode=CacheMode.WB) + core_1 = Core.using_device(core_device_1, name="core_1") + core_2 = Core.using_device(core_device_2, name="core_2") + core_3 = Core.using_device(core_device_3, name="core_3") + core_4 = Core.using_device(core_device_4, name="core_4") + + cache.add_core(core_1) + cache.add_core(core_2) + cache.add_core(core_3) + cache.add_core(core_4) + + cache.set_cleaning_policy(cleaning_policy) + + cache.stop() + + cache = Cache.load_from_device(cache_device) + + conf_stats = cache.get_stats()['conf'] + + assert conf_stats['core_count'] == 4 + assert conf_stats['cleaning_policy'] == cleaning_policy + + def run_io_and_cache_data_if_possible(cache, vol, mode, cls, cls_no): queue = vol.parent.get_default_queue()