From af4b9b13d0d57a0c103132759f34f87099d9c005 Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Thu, 11 Apr 2019 13:16:34 -0400 Subject: [PATCH] Freeze / unfreeze cleaning reference counters in detach/attach Signed-off-by: Adam Rutkowski --- src/mngt/ocf_mngt_cache.c | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 77b15f0..ec30c08 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -209,6 +209,8 @@ static void __init_partitions(ocf_cache_t cache) /* Add other partition to the cache and make it as dummy */ for (i_part = 0; i_part < OCF_IO_CLASS_MAX; i_part++) { + ocf_refcnt_freeze(&cache->refcnt.cleaning[i_part]); + if (i_part == PARTITION_DEFAULT) continue; @@ -1514,6 +1516,7 @@ static void _ocf_mngt_attach_post_init(ocf_pipeline_t pipeline, context->flags.cleaner_started = true; } + ocf_cleaner_refcnt_unfreeze(cache); ocf_refcnt_unfreeze(&cache->refcnt.metadata); ocf_pipeline_next(context->pipeline); @@ -2285,6 +2288,7 @@ struct ocf_mngt_cache_detach_context { ocf_pipeline_t pipeline; ocf_cache_t cache; int cache_write_error; + struct ocf_cleaner_wait_context cleaner_wait; }; static void ocf_mngt_cache_detach_flush_cmpl(ocf_cache_t cache, @@ -2305,13 +2309,13 @@ static void ocf_mngt_cache_detach_flush(ocf_pipeline_t pipeline, context); } -static void ocf_mngt_cache_detach_wait_pending_finish(void *priv) +static void ocf_mngt_cache_detach_stop_cache_io_finish(void *priv) { struct ocf_mngt_cache_detach_context *context = priv; ocf_pipeline_next(context->pipeline); } -static void ocf_mngt_cache_detach_wait_pending(ocf_pipeline_t pipeline, +static void ocf_mngt_cache_detach_stop_cache_io(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) { struct ocf_mngt_cache_detach_context *context = priv; @@ -2319,7 +2323,25 @@ static void ocf_mngt_cache_detach_wait_pending(ocf_pipeline_t pipeline, ocf_refcnt_freeze(&cache->refcnt.metadata); ocf_refcnt_register_zero_cb(&cache->refcnt.metadata, - ocf_mngt_cache_detach_wait_pending_finish, context); + ocf_mngt_cache_detach_stop_cache_io_finish, context); +} + +static void ocf_mngt_cache_detach_stop_cleaner_io_finish(void *priv) +{ + ocf_pipeline_t pipeline = priv; + ocf_pipeline_next(pipeline); +} + +static void ocf_mngt_cache_detach_stop_cleaner_io(ocf_pipeline_t pipeline, + void *priv, ocf_pipeline_arg_t arg) +{ + struct ocf_mngt_cache_detach_context *context = priv; + ocf_cache_t cache = context->cache; + + ocf_cleaner_refcnt_freeze(cache); + ocf_cleaner_refcnt_register_zero_cb(cache, &context->cleaner_wait, + ocf_mngt_cache_detach_stop_cleaner_io_finish, + pipeline); } static void ocf_mngt_cache_detach_update_metadata(ocf_pipeline_t pipeline, @@ -2399,7 +2421,8 @@ struct ocf_pipeline_properties ocf_mngt_cache_detach_pipeline_properties = { .finish = ocf_mngt_cache_detach_finish, .steps = { OCF_PL_STEP(ocf_mngt_cache_detach_flush), - OCF_PL_STEP(ocf_mngt_cache_detach_wait_pending), + 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_detach_update_metadata), OCF_PL_STEP(ocf_mngt_cache_detach_unplug), OCF_PL_STEP_TERMINATOR(),