From b02481cf740385bb0515ebcc6cd198b3e327e5e5 Mon Sep 17 00:00:00 2001 From: Roel Apfelbaum Date: Tue, 5 Mar 2024 12:36:08 -0500 Subject: [PATCH] A utility to continue pipeline on zero refcnt Signed-off-by: Roel Apfelbaum Signed-off-by: Michal Mielewczyk --- src/mngt/ocf_mngt_cache.c | 41 +++++++++----------------------------- src/mngt/ocf_mngt_common.c | 13 ++++++++++++ src/mngt/ocf_mngt_common.h | 7 +++++++ src/mngt/ocf_mngt_flush.c | 10 ++-------- 4 files changed, 31 insertions(+), 40 deletions(-) diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index ee08ad4..36fe537 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -2145,22 +2145,14 @@ struct ocf_mngt_cache_unplug_context { int cache_write_error; }; -static void ocf_mngt_cache_stop_wait_metadata_io_finish(void *priv) -{ - struct ocf_mngt_cache_unplug_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_unplug_context *context = priv; - ocf_cache_t cache = context->cache; + struct env_refcnt *refcnt = &context->cache->refcnt.metadata; - env_refcnt_freeze(&cache->refcnt.metadata); - env_refcnt_register_zero_cb(&cache->refcnt.metadata, - ocf_mngt_cache_stop_wait_metadata_io_finish, context); + env_refcnt_freeze(refcnt); + ocf_mngt_continue_pipeline_on_zero_refcnt(refcnt, context->pipeline); } static void ocf_mngt_cache_stop_check_dirty(ocf_pipeline_t pipeline, @@ -2566,22 +2558,14 @@ struct ocf_cache_standby_detach_context { void *priv; }; -static void _ocf_mngt_standby_detach_wait_metadata_io_finish(void *priv) -{ - struct ocf_cache_standby_detach_context *context = priv; - - ocf_pipeline_next(context->pipeline); -} - static void _ocf_mngt_standby_detach_wait_metadata_io(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) { struct ocf_cache_standby_detach_context *context = priv; - ocf_cache_t cache = context->cache; + struct env_refcnt *refcnt = &context->cache->refcnt.metadata; - env_refcnt_freeze(&cache->refcnt.metadata); - env_refcnt_register_zero_cb(&cache->refcnt.metadata, - _ocf_mngt_standby_detach_wait_metadata_io_finish, context); + env_refcnt_freeze(refcnt); + ocf_mngt_continue_pipeline_on_zero_refcnt(refcnt, context->pipeline); } static void _ocf_mngt_activate_set_cache_device(ocf_pipeline_t pipeline, @@ -3812,21 +3796,14 @@ static void ocf_mngt_cache_detach_flush(ocf_pipeline_t pipeline, ocf_mngt_cache_flush(cache, ocf_mngt_cache_detach_flush_cmpl, context); } -static void ocf_mngt_cache_detach_stop_cache_io_finish(void *priv) -{ - struct ocf_mngt_cache_unplug_context *context = priv; - ocf_pipeline_next(context->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_unplug_context *context = priv; - ocf_cache_t cache = context->cache; + struct env_refcnt *refcnt = &context->cache->refcnt.metadata; - env_refcnt_freeze(&cache->refcnt.metadata); - env_refcnt_register_zero_cb(&cache->refcnt.metadata, - ocf_mngt_cache_detach_stop_cache_io_finish, context); + env_refcnt_freeze(refcnt); + ocf_mngt_continue_pipeline_on_zero_refcnt(refcnt, context->pipeline); } static void ocf_mngt_cache_detach_stop_cleaner_io_finish(void *priv) diff --git a/src/mngt/ocf_mngt_common.c b/src/mngt/ocf_mngt_common.c index 5a9a3bc..1733e20 100644 --- a/src/mngt/ocf_mngt_common.c +++ b/src/mngt/ocf_mngt_common.c @@ -515,3 +515,16 @@ int ocf_mngt_cache_visit_reverse(ocf_ctx_t ocf_ctx, return result; } + +static void _ocf_mngt_continue_pipeline_on_zero_refcnt_cb(void *priv) +{ + ocf_pipeline_next((ocf_pipeline_t)priv); +} + +void ocf_mngt_continue_pipeline_on_zero_refcnt(struct env_refcnt *refcnt, + ocf_pipeline_t pipeline) +{ + env_refcnt_register_zero_cb(refcnt, + _ocf_mngt_continue_pipeline_on_zero_refcnt_cb, + pipeline); +} diff --git a/src/mngt/ocf_mngt_common.h b/src/mngt/ocf_mngt_common.h index 751a2e0..4e0adc4 100644 --- a/src/mngt/ocf_mngt_common.h +++ b/src/mngt/ocf_mngt_common.h @@ -1,5 +1,6 @@ /* * Copyright(c) 2012-2021 Intel Corporation + * Copyright(c) 2025 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ @@ -7,6 +8,9 @@ #ifndef __OCF_MNGT_COMMON_H__ #define __OCF_MNGT_COMMON_H__ +#include "ocf_env_refcnt.h" +#include "../utils/utils_pipeline.h" + void cache_mngt_core_deinit(ocf_core_t core); void cache_mngt_core_remove_from_meta(ocf_core_t core); @@ -33,4 +37,7 @@ bool ocf_mngt_cache_is_locked(ocf_cache_t cache); void __set_cleaning_policy(ocf_cache_t cache, ocf_cleaning_t new_cleaning_policy); +void ocf_mngt_continue_pipeline_on_zero_refcnt(struct env_refcnt *refcnt, + ocf_pipeline_t pipeline); + #endif /* __OCF_MNGT_COMMON_H__ */ diff --git a/src/mngt/ocf_mngt_flush.c b/src/mngt/ocf_mngt_flush.c index 2e7d060..6ecca4b 100644 --- a/src/mngt/ocf_mngt_flush.c +++ b/src/mngt/ocf_mngt_flush.c @@ -82,12 +82,6 @@ struct ocf_mngt_cache_flush_context struct flush_containers_context fcs; }; -static void _ocf_mngt_begin_flush_complete(void *priv) -{ - struct ocf_mngt_cache_flush_context *context = priv; - ocf_pipeline_next(context->pipeline); -} - static void _ocf_mngt_begin_flush(ocf_pipeline_t pipeline, void *priv, ocf_pipeline_arg_t arg) { @@ -105,8 +99,8 @@ static void _ocf_mngt_begin_flush(ocf_pipeline_t pipeline, void *priv, env_refcnt_freeze(&cache->refcnt.dirty); context->flags.freeze = true; - env_refcnt_register_zero_cb(&cache->refcnt.dirty, - _ocf_mngt_begin_flush_complete, context); + ocf_mngt_continue_pipeline_on_zero_refcnt(&cache->refcnt.dirty, + context->pipeline); } bool ocf_mngt_core_is_dirty(ocf_core_t core)