From 92e9ae12f1d31f5f2a7db0378989af2bc8d9b6cd Mon Sep 17 00:00:00 2001 From: Adam Rutkowski Date: Mon, 8 Apr 2019 19:10:08 -0400 Subject: [PATCH] Wait for metadata requests in stop Signed-off-by: Adam Rutkowski --- src/mngt/ocf_mngt_cache.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index 9fb0877..77b15f0 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -1907,15 +1907,22 @@ struct ocf_mngt_cache_stop_context { int cache_write_error; }; -static void ocf_mngt_cache_stop_wait_io(ocf_pipeline_t pipeline, +static void ocf_mngt_cache_stop_wait_metadata_io_finish(void *priv) +{ + struct ocf_mngt_cache_stop_context *context = priv; + + ocf_pipeline_next(context->pipeline); +} + +static void ocf_mngt_cache_stop_wait_metadata_io(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) { struct ocf_mngt_cache_stop_context *context = priv; ocf_cache_t cache = context->cache; - /* TODO: Make this asynchronous! */ - ocf_cache_wait_for_io_finish(cache); - ocf_pipeline_next(pipeline); + ocf_refcnt_freeze(&cache->refcnt.metadata); + ocf_refcnt_register_zero_cb(&cache->refcnt.metadata, + ocf_mngt_cache_stop_wait_metadata_io_finish, context); } static void ocf_mngt_cache_stop_remove_cores(ocf_pipeline_t pipeline, @@ -1995,6 +2002,9 @@ static void ocf_mngt_cache_stop_finish(ocf_pipeline_t pipeline, list_del(&cache->list); env_mutex_unlock(&ctx->lock); } else { + /* undo metadata counter freeze */ + ocf_refcnt_unfreeze(&cache->refcnt.metadata); + env_bit_clear(ocf_cache_state_stopping, &cache->cache_state); env_bit_set(ocf_cache_state_running, &cache->cache_state); } @@ -2028,7 +2038,7 @@ struct ocf_pipeline_properties ocf_mngt_cache_stop_pipeline_properties = { .priv_size = sizeof(struct ocf_mngt_cache_stop_context), .finish = ocf_mngt_cache_stop_finish, .steps = { - OCF_PL_STEP(ocf_mngt_cache_stop_wait_io), + OCF_PL_STEP(ocf_mngt_cache_stop_wait_metadata_io), OCF_PL_STEP(ocf_mngt_cache_stop_remove_cores), OCF_PL_STEP(ocf_mngt_cache_stop_unplug), OCF_PL_STEP(ocf_mngt_cache_stop_put_io_queues),