From 5e55bf78b4aaaef965678b778b35e6b47500249d Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Mon, 17 Mar 2025 12:10:41 +0100 Subject: [PATCH 1/9] Rename cache_unplug() to deinit_services() The function doesn't unplug anything, it just deinitializes cleaning and promotion. Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_cache.c | 53 ++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 26 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index f1575a1..da41f51 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -2114,7 +2114,7 @@ struct ocf_pipeline_properties _ocf_mngt_cache_load_pipeline_properties = { typedef void (*_ocf_mngt_cache_unplug_end_t)(void *context, int error); -struct _ocf_mngt_cache_unplug_context { +struct _ocf_mngt_cache_deinit_services_context { _ocf_mngt_cache_unplug_end_t cmpl; void *priv; ocf_cache_t cache; @@ -2133,11 +2133,13 @@ struct ocf_mngt_cache_unplug_context { /* Fields that belong to both cache detach and cache stop pipelines */ - /* unplug context - this is private structure of _ocf_mngt_cache_unplug, - * it is member of stop context only to reserve memory in advance for - * _ocf_mngt_cache_unplug, eliminating the possibility of ENOMEM error - * at the point where we are effectively unable to handle it */ - struct _ocf_mngt_cache_unplug_context unplug_context; + /* unplug context - this is private structure of + * _ocf_mngt_cache_deinit_services, it is member of stop context only + * to reserve memory in advance for _ocf_mngt_cache_deinit_services, + * eliminating the possibility of ENOMEM error at the point where we + * are effectively unable to handle it + */ + struct _ocf_mngt_cache_deinit_services_context deinit_services_context; ocf_mngt_cache_stop_end_t cmpl; void *priv; ocf_pipeline_t pipeline; @@ -2202,7 +2204,7 @@ static void ocf_mngt_cache_stop_remove_cores(ocf_pipeline_t pipeline, ocf_pipeline_next(pipeline); } -static void ocf_mngt_cache_stop_unplug_complete(void *priv, int error) +static void ocf_mngt_cache_stop_deinit_services_complete(void *priv, int error) { struct ocf_mngt_cache_unplug_context *context = priv; @@ -2214,18 +2216,19 @@ static void ocf_mngt_cache_stop_unplug_complete(void *priv, int error) ocf_pipeline_next(context->pipeline); } -static void _ocf_mngt_cache_unplug(ocf_cache_t cache, bool stop, - struct _ocf_mngt_cache_unplug_context *context, +static void _ocf_mngt_cache_deinit_services(ocf_cache_t cache, bool stop, + struct _ocf_mngt_cache_deinit_services_context *context, _ocf_mngt_cache_unplug_end_t cmpl, void *priv); -static void ocf_mngt_cache_stop_unplug(ocf_pipeline_t pipeline, +static void ocf_mngt_cache_stop_deinit_services(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) { struct ocf_mngt_cache_unplug_context *context = priv; ocf_cache_t cache = context->cache; - _ocf_mngt_cache_unplug(cache, true, &context->unplug_context, - ocf_mngt_cache_stop_unplug_complete, context); + _ocf_mngt_cache_deinit_services(cache, true, + &context->deinit_services_context, + ocf_mngt_cache_stop_deinit_services_complete, context); } static void _ocf_mngt_detach_zero_superblock_complete(void *priv, int error) @@ -2413,7 +2416,7 @@ struct ocf_pipeline_properties ocf_mngt_cache_stop_pipeline_properties = { OCF_PL_STEP(ocf_mngt_cache_stop_wait_metadata_io), OCF_PL_STEP(ocf_mngt_cache_stop_check_dirty), OCF_PL_STEP(ocf_mngt_cache_stop_remove_cores), - OCF_PL_STEP(ocf_mngt_cache_stop_unplug), + OCF_PL_STEP(ocf_mngt_cache_stop_deinit_services), OCF_PL_STEP(ocf_mngt_cache_close_cache_volume), OCF_PL_STEP(ocf_mngt_cache_deinit_metadata), OCF_PL_STEP(ocf_mngt_cache_deinit_cache_volume), @@ -3216,17 +3219,16 @@ void ocf_mngt_cache_attach(ocf_cache_t cache, _ocf_mngt_cache_attach(cache, cfg, _ocf_mngt_cache_attach_complete, cmpl, priv); } -static void _ocf_mngt_cache_unplug_complete(void *priv, int error) +static void _ocf_mngt_cache_deinit_services_complete(void *priv, int error) { - struct _ocf_mngt_cache_unplug_context *context = priv; + struct _ocf_mngt_cache_deinit_services_context *context = priv; context->cmpl(context->priv, error ? -OCF_ERR_WRITE_CACHE : 0); } /** - * @brief Unplug caching device from cache instance. Variable size metadata - * containers are deinitialiazed as well as other cacheline related - * structures. Cache volume is closed. + * @brief Stop cleaner, deinitialize cleaning policy and promotion policy + * metadata * * @param cache OCF cache instance * @param stop - true if unplugging during stop - in this case we mark @@ -3237,8 +3239,8 @@ static void _ocf_mngt_cache_unplug_complete(void *priv, int error) * @param cmpl Completion callback * @param priv Completion context */ -static void _ocf_mngt_cache_unplug(ocf_cache_t cache, bool stop, - struct _ocf_mngt_cache_unplug_context *context, +static void _ocf_mngt_cache_deinit_services(ocf_cache_t cache, bool stop, + struct _ocf_mngt_cache_deinit_services_context *context, _ocf_mngt_cache_unplug_end_t cmpl, void *priv) { struct ocf_mngt_cache_unplug_context *ctx = priv; @@ -3259,7 +3261,7 @@ static void _ocf_mngt_cache_unplug(ocf_cache_t cache, bool stop, /* Flush metadata */ ocf_metadata_flush_all(cache, - _ocf_mngt_cache_unplug_complete, context); + _ocf_mngt_cache_deinit_services_complete, context); } static int _ocf_mngt_cache_load_core_log(ocf_core_t core, void *cntx) @@ -3885,7 +3887,7 @@ static void ocf_mngt_cache_detach_unplug_complete(void *priv, int error) ocf_pipeline_next(context->pipeline); } -static void ocf_mngt_cache_detach_unplug(ocf_pipeline_t pipeline, +static void ocf_mngt_cache_detach_deinit_services(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) { struct ocf_mngt_cache_unplug_context *context = priv; @@ -3893,9 +3895,8 @@ static void ocf_mngt_cache_detach_unplug(ocf_pipeline_t pipeline, ENV_BUG_ON(cache->conf_meta->dirty_flushed == DIRTY_NOT_FLUSHED); - /* Do the actual detach - deinit cacheline metadata, - * stop cleaner thread and close cache bottom device */ - _ocf_mngt_cache_unplug(cache, false, &context->unplug_context, + _ocf_mngt_cache_deinit_services(cache, false, + &context->deinit_services_context, ocf_mngt_cache_detach_unplug_complete, context); } @@ -3940,7 +3941,7 @@ struct ocf_pipeline_properties ocf_mngt_cache_detach_pipeline_properties = { OCF_PL_STEP(ocf_mngt_cache_detach_stop_cleaner_io), OCF_PL_STEP(ocf_mngt_cache_stop_check_dirty), OCF_PL_STEP(ocf_mngt_cache_detach_update_metadata), - OCF_PL_STEP(ocf_mngt_cache_detach_unplug), + OCF_PL_STEP(ocf_mngt_cache_detach_deinit_services), OCF_PL_STEP(_ocf_mngt_detach_zero_superblock), OCF_PL_STEP(ocf_mngt_cache_close_cache_volume), OCF_PL_STEP(ocf_mngt_cache_deinit_metadata), From 03338d798c929d8df4a11b01191248ba32cebad2 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Mon, 17 Mar 2025 12:29:20 +0100 Subject: [PATCH 2/9] detach pipeline: remove unused completion The completion callback is called only in the cache stop scenario, after flushing the metadata Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_cache.c | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index da41f51..105353e 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -3875,18 +3875,6 @@ static void ocf_mngt_cache_detach_update_metadata(ocf_pipeline_t pipeline, ocf_pipeline_next(context->pipeline); } -static void ocf_mngt_cache_detach_unplug_complete(void *priv, int error) -{ - struct ocf_mngt_cache_unplug_context *context = priv; - - if (error) { - ENV_BUG_ON(error != -OCF_ERR_WRITE_CACHE); - context->cache_write_error = error; - } - - ocf_pipeline_next(context->pipeline); -} - static void ocf_mngt_cache_detach_deinit_services(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) { @@ -3896,8 +3884,7 @@ static void ocf_mngt_cache_detach_deinit_services(ocf_pipeline_t pipeline, ENV_BUG_ON(cache->conf_meta->dirty_flushed == DIRTY_NOT_FLUSHED); _ocf_mngt_cache_deinit_services(cache, false, - &context->deinit_services_context, - ocf_mngt_cache_detach_unplug_complete, context); + &context->deinit_services_context, NULL, context); } static void ocf_mngt_cache_detach_finish(ocf_pipeline_t pipeline, From eca78722991d48fa14bf9cb83f0825ee1ab9fa3d Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Mon, 17 Mar 2025 12:37:23 +0100 Subject: [PATCH 3/9] detach: Rename update_metadata() to remove_cores() Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 105353e..028dcef 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -3855,7 +3855,7 @@ static void ocf_mngt_cache_detach_stop_cleaner_io(ocf_pipeline_t pipeline, pipeline); } -static void ocf_mngt_cache_detach_update_metadata(ocf_pipeline_t pipeline, +static void ocf_mngt_cache_detach_remove_cores(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) { struct ocf_mngt_cache_unplug_context *context = priv; @@ -3927,7 +3927,7 @@ struct ocf_pipeline_properties ocf_mngt_cache_detach_pipeline_properties = { OCF_PL_STEP(ocf_mngt_cache_detach_stop_cache_io), OCF_PL_STEP(ocf_mngt_cache_detach_stop_cleaner_io), OCF_PL_STEP(ocf_mngt_cache_stop_check_dirty), - OCF_PL_STEP(ocf_mngt_cache_detach_update_metadata), + OCF_PL_STEP(ocf_mngt_cache_detach_remove_cores), OCF_PL_STEP(ocf_mngt_cache_detach_deinit_services), OCF_PL_STEP(_ocf_mngt_detach_zero_superblock), OCF_PL_STEP(ocf_mngt_cache_close_cache_volume), From 942825146abd231e37c0da468d2dfbea1c32b1d3 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Mon, 17 Mar 2025 13:32:36 +0100 Subject: [PATCH 4/9] Simplify _ocf_mngt_cache_deinit_services() Move flushing metadata outside cache_detinit_services(), so the function can be shared between stop() and detach() without redundant ifs. Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_cache.c | 69 ++++++--------------------------------- 1 file changed, 10 insertions(+), 59 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 028dcef..5da5fa8 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -2114,12 +2114,6 @@ struct ocf_pipeline_properties _ocf_mngt_cache_load_pipeline_properties = { typedef void (*_ocf_mngt_cache_unplug_end_t)(void *context, int error); -struct _ocf_mngt_cache_deinit_services_context { - _ocf_mngt_cache_unplug_end_t cmpl; - void *priv; - ocf_cache_t cache; -}; - struct ocf_mngt_cache_unplug_context { /* Fields that belong to cache stop pipeline */ ocf_ctx_t ctx; @@ -2132,14 +2126,6 @@ struct ocf_mngt_cache_unplug_context { uint8_t composite_vol_id; /* Fields that belong to both cache detach and cache stop pipelines */ - - /* unplug context - this is private structure of - * _ocf_mngt_cache_deinit_services, it is member of stop context only - * to reserve memory in advance for _ocf_mngt_cache_deinit_services, - * eliminating the possibility of ENOMEM error at the point where we - * are effectively unable to handle it - */ - struct _ocf_mngt_cache_deinit_services_context deinit_services_context; ocf_mngt_cache_stop_end_t cmpl; void *priv; ocf_pipeline_t pipeline; @@ -2208,17 +2194,13 @@ static void ocf_mngt_cache_stop_deinit_services_complete(void *priv, int error) { struct ocf_mngt_cache_unplug_context *context = priv; - if (error) { - ENV_BUG_ON(error != -OCF_ERR_WRITE_CACHE); - context->cache_write_error = error; - } + if (error) + context->cache_write_error = -OCF_ERR_WRITE_CACHE; ocf_pipeline_next(context->pipeline); } -static void _ocf_mngt_cache_deinit_services(ocf_cache_t cache, bool stop, - struct _ocf_mngt_cache_deinit_services_context *context, - _ocf_mngt_cache_unplug_end_t cmpl, void *priv); +static void _ocf_mngt_cache_deinit_services(ocf_cache_t cache); static void ocf_mngt_cache_stop_deinit_services(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) @@ -2226,8 +2208,9 @@ static void ocf_mngt_cache_stop_deinit_services(ocf_pipeline_t pipeline, struct ocf_mngt_cache_unplug_context *context = priv; ocf_cache_t cache = context->cache; - _ocf_mngt_cache_deinit_services(cache, true, - &context->deinit_services_context, + _ocf_mngt_cache_deinit_services(cache); + + ocf_metadata_flush_all(cache, ocf_mngt_cache_stop_deinit_services_complete, context); } @@ -3219,49 +3202,16 @@ void ocf_mngt_cache_attach(ocf_cache_t cache, _ocf_mngt_cache_attach(cache, cfg, _ocf_mngt_cache_attach_complete, cmpl, priv); } -static void _ocf_mngt_cache_deinit_services_complete(void *priv, int error) -{ - struct _ocf_mngt_cache_deinit_services_context *context = priv; - - context->cmpl(context->priv, error ? -OCF_ERR_WRITE_CACHE : 0); -} - /** * @brief Stop cleaner, deinitialize cleaning policy and promotion policy * metadata - * - * @param cache OCF cache instance - * @param stop - true if unplugging during stop - in this case we mark - * clean shutdown in metadata and flush all containers. - * - false if the device is to be detached from cache - loading - * metadata from this device will not be possible. - * @param context - context for this call, must be zeroed - * @param cmpl Completion callback - * @param priv Completion context */ -static void _ocf_mngt_cache_deinit_services(ocf_cache_t cache, bool stop, - struct _ocf_mngt_cache_deinit_services_context *context, - _ocf_mngt_cache_unplug_end_t cmpl, void *priv) +static void _ocf_mngt_cache_deinit_services(ocf_cache_t cache) { - struct ocf_mngt_cache_unplug_context *ctx = priv; - - context->cmpl = cmpl; - context->priv = priv; - context->cache = cache; - ocf_stop_cleaner(cache); __deinit_cleaning_policy(cache); __deinit_promotion_policy(cache); - - if (!stop) { - /* Skip metadata update - will be zeroed later in the detach pipeline */ - OCF_PL_NEXT_RET(ctx->pipeline); - } - - /* Flush metadata */ - ocf_metadata_flush_all(cache, - _ocf_mngt_cache_deinit_services_complete, context); } static int _ocf_mngt_cache_load_core_log(ocf_core_t core, void *cntx) @@ -3883,8 +3833,9 @@ static void ocf_mngt_cache_detach_deinit_services(ocf_pipeline_t pipeline, ENV_BUG_ON(cache->conf_meta->dirty_flushed == DIRTY_NOT_FLUSHED); - _ocf_mngt_cache_deinit_services(cache, false, - &context->deinit_services_context, NULL, context); + _ocf_mngt_cache_deinit_services(cache); + + ocf_pipeline_next(pipeline); } static void ocf_mngt_cache_detach_finish(ocf_pipeline_t pipeline, From 75c4c9b4732da1072426c041bc5edc9014ddc749 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Mon, 17 Mar 2025 14:11:24 +0100 Subject: [PATCH 5/9] Move _ocf_mngt_cache_deinit_services() definition Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_cache.c | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 5da5fa8..ec9eb76 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -2200,7 +2200,13 @@ static void ocf_mngt_cache_stop_deinit_services_complete(void *priv, int error) ocf_pipeline_next(context->pipeline); } -static void _ocf_mngt_cache_deinit_services(ocf_cache_t cache); +static void _ocf_mngt_cache_deinit_services(ocf_cache_t cache) +{ + ocf_stop_cleaner(cache); + + __deinit_cleaning_policy(cache); + __deinit_promotion_policy(cache); +} static void ocf_mngt_cache_stop_deinit_services(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) @@ -3202,18 +3208,6 @@ void ocf_mngt_cache_attach(ocf_cache_t cache, _ocf_mngt_cache_attach(cache, cfg, _ocf_mngt_cache_attach_complete, cmpl, priv); } -/** - * @brief Stop cleaner, deinitialize cleaning policy and promotion policy - * metadata - */ -static void _ocf_mngt_cache_deinit_services(ocf_cache_t cache) -{ - ocf_stop_cleaner(cache); - - __deinit_cleaning_policy(cache); - __deinit_promotion_policy(cache); -} - static int _ocf_mngt_cache_load_core_log(ocf_core_t core, void *cntx) { if (ocf_core_state_active == ocf_core_get_state(core)) From 9c2da08ffebdde7069c3871ca4e670e254faa07b Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Mon, 17 Mar 2025 14:42:29 +0100 Subject: [PATCH 6/9] stop pipeline: flush_metadata as a separate step Flushing metadata has nothing to do with dinitializing services so it should be a separate step in the stop pipeline Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_cache.c | 32 +++++++++++++++++++++----------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index ec9eb76..9223f8e 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -2190,16 +2190,6 @@ static void ocf_mngt_cache_stop_remove_cores(ocf_pipeline_t pipeline, ocf_pipeline_next(pipeline); } -static void ocf_mngt_cache_stop_deinit_services_complete(void *priv, int error) -{ - struct ocf_mngt_cache_unplug_context *context = priv; - - if (error) - context->cache_write_error = -OCF_ERR_WRITE_CACHE; - - ocf_pipeline_next(context->pipeline); -} - static void _ocf_mngt_cache_deinit_services(ocf_cache_t cache) { ocf_stop_cleaner(cache); @@ -2216,8 +2206,27 @@ static void ocf_mngt_cache_stop_deinit_services(ocf_pipeline_t pipeline, _ocf_mngt_cache_deinit_services(cache); + ocf_pipeline_next(context->pipeline); +} + +static void ocf_mngt_cache_stop_flush_metadata_completion(void *priv, int error) +{ + struct ocf_mngt_cache_unplug_context *context = priv; + + if (error) + context->cache_write_error = -OCF_ERR_WRITE_CACHE; + + ocf_pipeline_next(context->pipeline); +} + +static void ocf_mngt_cache_stop_flush_metadata(ocf_pipeline_t pipeline, + void *priv, ocf_pipeline_arg_t arg) +{ + struct ocf_mngt_cache_unplug_context *context = priv; + ocf_cache_t cache = context->cache; + ocf_metadata_flush_all(cache, - ocf_mngt_cache_stop_deinit_services_complete, context); + ocf_mngt_cache_stop_flush_metadata_completion, context); } static void _ocf_mngt_detach_zero_superblock_complete(void *priv, int error) @@ -2406,6 +2415,7 @@ struct ocf_pipeline_properties ocf_mngt_cache_stop_pipeline_properties = { OCF_PL_STEP(ocf_mngt_cache_stop_check_dirty), OCF_PL_STEP(ocf_mngt_cache_stop_remove_cores), OCF_PL_STEP(ocf_mngt_cache_stop_deinit_services), + OCF_PL_STEP(ocf_mngt_cache_stop_flush_metadata), OCF_PL_STEP(ocf_mngt_cache_close_cache_volume), OCF_PL_STEP(ocf_mngt_cache_deinit_metadata), OCF_PL_STEP(ocf_mngt_cache_deinit_cache_volume), From 1e75a9826d1c0c8d82bb73b92922873a679f4c6a Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Mon, 17 Mar 2025 14:48:01 +0100 Subject: [PATCH 7/9] stop&detach: Deinit services before removing cores Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_cache.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 9223f8e..4e17939 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -2413,8 +2413,8 @@ struct ocf_pipeline_properties ocf_mngt_cache_stop_pipeline_properties = { .steps = { OCF_PL_STEP(ocf_mngt_cache_stop_wait_metadata_io), OCF_PL_STEP(ocf_mngt_cache_stop_check_dirty), - OCF_PL_STEP(ocf_mngt_cache_stop_remove_cores), OCF_PL_STEP(ocf_mngt_cache_stop_deinit_services), + OCF_PL_STEP(ocf_mngt_cache_stop_remove_cores), OCF_PL_STEP(ocf_mngt_cache_stop_flush_metadata), OCF_PL_STEP(ocf_mngt_cache_close_cache_volume), OCF_PL_STEP(ocf_mngt_cache_deinit_metadata), @@ -3882,8 +3882,8 @@ struct ocf_pipeline_properties ocf_mngt_cache_detach_pipeline_properties = { OCF_PL_STEP(ocf_mngt_cache_detach_stop_cache_io), OCF_PL_STEP(ocf_mngt_cache_detach_stop_cleaner_io), OCF_PL_STEP(ocf_mngt_cache_stop_check_dirty), - OCF_PL_STEP(ocf_mngt_cache_detach_remove_cores), OCF_PL_STEP(ocf_mngt_cache_detach_deinit_services), + OCF_PL_STEP(ocf_mngt_cache_detach_remove_cores), OCF_PL_STEP(_ocf_mngt_detach_zero_superblock), OCF_PL_STEP(ocf_mngt_cache_close_cache_volume), OCF_PL_STEP(ocf_mngt_cache_deinit_metadata), From 69987bd20c313a2db2467c3fdf4a299605ed2beb Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Mon, 17 Mar 2025 14:50:46 +0100 Subject: [PATCH 8/9] detach: 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 | 1 - 1 file changed, 1 deletion(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 4e17939..fa6cd47 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -3821,7 +3821,6 @@ static void ocf_mngt_cache_detach_remove_cores(ocf_pipeline_t pipeline, /* remove cacheline metadata and cleaning policy meta for all cores */ for_each_core_metadata(cache, core, core_id) { cache_mngt_core_deinit_attached_meta(core); - cache_mngt_core_remove_from_cleaning_pol(core); if (--no == 0) break; } From 98a3aaea89ef71d4b8ba3ed694afc1bfe1be9c89 Mon Sep 17 00:00:00 2001 From: Michal Mielewczyk Date: Fri, 14 Mar 2025 13:36:23 +0100 Subject: [PATCH 9/9] pyocf: Test detaching cache with cleaning policy Signed-off-by: Michal Mielewczyk --- .../tests/management/test_attach_cache.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/functional/tests/management/test_attach_cache.py b/tests/functional/tests/management/test_attach_cache.py index 28daa26..6593fab 100644 --- a/tests/functional/tests/management/test_attach_cache.py +++ b/tests/functional/tests/management/test_attach_cache.py @@ -11,6 +11,7 @@ import pytest from pyocf.types.cache import ( Cache, CacheMode, + CleaningPolicy, ) from pyocf.types.core import Core from pyocf.types.data import Data @@ -67,6 +68,23 @@ def test_detach_cache_twice(pyocf_ctx): cache.stop() +@pytest.mark.parametrize("cleaning_policy", CleaningPolicy) +def test_detach_cache_with_cleaning(pyocf_ctx, cleaning_policy): + cache_device = RamVolume(Size.from_MiB(100)) + core_device = RamVolume(Size.from_MiB(100)) + + cache = Cache.start_on_device(cache_device) + core = Core.using_device(core_device) + + cache.add_core(core) + + cache.set_cleaning_policy(cleaning_policy) + + cache.detach_device() + + cache.stop() + + def test_detach_cache_zero_superblock(pyocf_ctx): """Check if superblock is zeroed after detach and the cache device can be reattached without --force option.