Skip to content

Commit

Permalink
A utility to continue pipeline on zero refcnt
Browse files Browse the repository at this point in the history
Signed-off-by: Roel Apfelbaum <[email protected]>
Signed-off-by: Michal Mielewczyk <[email protected]>
  • Loading branch information
roelhuawei authored and mmichal10 committed Jan 28, 2025
1 parent 6da01e8 commit a458281
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 40 deletions.
41 changes: 9 additions & 32 deletions src/mngt/ocf_mngt_cache.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
13 changes: 13 additions & 0 deletions src/mngt/ocf_mngt_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
7 changes: 7 additions & 0 deletions src/mngt/ocf_mngt_common.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
/*
* Copyright(c) 2012-2021 Intel Corporation
* Copyright(c) 2025 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/


#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);
Expand All @@ -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__ */
10 changes: 2 additions & 8 deletions src/mngt/ocf_mngt_flush.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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)
Expand Down

0 comments on commit a458281

Please sign in to comment.