Skip to content

Commit 8bc5a1d

Browse files
roelapmmichal10
authored andcommitted
A utility to continue pipeline on zero refcnt
Signed-off-by: Roel Apfelbaum <roel.apfelbaum@huawei.com> Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
1 parent 1f04873 commit 8bc5a1d

File tree

4 files changed

+31
-40
lines changed

4 files changed

+31
-40
lines changed

src/mngt/ocf_mngt_cache.c

Lines changed: 9 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2145,22 +2145,14 @@ struct ocf_mngt_cache_unplug_context {
21452145
int cache_write_error;
21462146
};
21472147

2148-
static void ocf_mngt_cache_stop_wait_metadata_io_finish(void *priv)
2149-
{
2150-
struct ocf_mngt_cache_unplug_context *context = priv;
2151-
2152-
ocf_pipeline_next(context->pipeline);
2153-
}
2154-
21552148
static void ocf_mngt_cache_stop_wait_metadata_io(ocf_pipeline_t pipeline,
21562149
void *priv, ocf_pipeline_arg_t arg)
21572150
{
21582151
struct ocf_mngt_cache_unplug_context *context = priv;
2159-
ocf_cache_t cache = context->cache;
2152+
struct env_refcnt *refcnt = &context->cache->refcnt.metadata;
21602153

2161-
env_refcnt_freeze(&cache->refcnt.metadata);
2162-
env_refcnt_register_zero_cb(&cache->refcnt.metadata,
2163-
ocf_mngt_cache_stop_wait_metadata_io_finish, context);
2154+
env_refcnt_freeze(refcnt);
2155+
ocf_mngt_continue_pipeline_on_zero_refcnt(refcnt, context->pipeline);
21642156
}
21652157

21662158
static void ocf_mngt_cache_stop_check_dirty(ocf_pipeline_t pipeline,
@@ -2566,22 +2558,14 @@ struct ocf_cache_standby_detach_context {
25662558
void *priv;
25672559
};
25682560

2569-
static void _ocf_mngt_standby_detach_wait_metadata_io_finish(void *priv)
2570-
{
2571-
struct ocf_cache_standby_detach_context *context = priv;
2572-
2573-
ocf_pipeline_next(context->pipeline);
2574-
}
2575-
25762561
static void _ocf_mngt_standby_detach_wait_metadata_io(ocf_pipeline_t pipeline,
25772562
void *priv, ocf_pipeline_arg_t arg)
25782563
{
25792564
struct ocf_cache_standby_detach_context *context = priv;
2580-
ocf_cache_t cache = context->cache;
2565+
struct env_refcnt *refcnt = &context->cache->refcnt.metadata;
25812566

2582-
env_refcnt_freeze(&cache->refcnt.metadata);
2583-
env_refcnt_register_zero_cb(&cache->refcnt.metadata,
2584-
_ocf_mngt_standby_detach_wait_metadata_io_finish, context);
2567+
env_refcnt_freeze(refcnt);
2568+
ocf_mngt_continue_pipeline_on_zero_refcnt(refcnt, context->pipeline);
25852569
}
25862570

25872571
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,
38123796
ocf_mngt_cache_flush(cache, ocf_mngt_cache_detach_flush_cmpl, context);
38133797
}
38143798

3815-
static void ocf_mngt_cache_detach_stop_cache_io_finish(void *priv)
3816-
{
3817-
struct ocf_mngt_cache_unplug_context *context = priv;
3818-
ocf_pipeline_next(context->pipeline);
3819-
}
3820-
38213799
static void ocf_mngt_cache_detach_stop_cache_io(ocf_pipeline_t pipeline,
38223800
void *priv, ocf_pipeline_arg_t arg)
38233801
{
38243802
struct ocf_mngt_cache_unplug_context *context = priv;
3825-
ocf_cache_t cache = context->cache;
3803+
struct env_refcnt *refcnt = &context->cache->refcnt.metadata;
38263804

3827-
env_refcnt_freeze(&cache->refcnt.metadata);
3828-
env_refcnt_register_zero_cb(&cache->refcnt.metadata,
3829-
ocf_mngt_cache_detach_stop_cache_io_finish, context);
3805+
env_refcnt_freeze(refcnt);
3806+
ocf_mngt_continue_pipeline_on_zero_refcnt(refcnt, context->pipeline);
38303807
}
38313808

38323809
static void ocf_mngt_cache_detach_stop_cleaner_io_finish(void *priv)

src/mngt/ocf_mngt_common.c

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,3 +515,16 @@ int ocf_mngt_cache_visit_reverse(ocf_ctx_t ocf_ctx,
515515

516516
return result;
517517
}
518+
519+
static void _ocf_mngt_continue_pipeline_on_zero_refcnt_cb(void *priv)
520+
{
521+
ocf_pipeline_next((ocf_pipeline_t)priv);
522+
}
523+
524+
void ocf_mngt_continue_pipeline_on_zero_refcnt(struct env_refcnt *refcnt,
525+
ocf_pipeline_t pipeline)
526+
{
527+
env_refcnt_register_zero_cb(refcnt,
528+
_ocf_mngt_continue_pipeline_on_zero_refcnt_cb,
529+
pipeline);
530+
}

src/mngt/ocf_mngt_common.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
/*
22
* Copyright(c) 2012-2021 Intel Corporation
3+
* Copyright(c) 2025 Huawei Technologies
34
* SPDX-License-Identifier: BSD-3-Clause
45
*/
56

67

78
#ifndef __OCF_MNGT_COMMON_H__
89
#define __OCF_MNGT_COMMON_H__
910

11+
#include "ocf_env_refcnt.h"
12+
#include "../utils/utils_pipeline.h"
13+
1014
void cache_mngt_core_deinit(ocf_core_t core);
1115

1216
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);
3337
void __set_cleaning_policy(ocf_cache_t cache,
3438
ocf_cleaning_t new_cleaning_policy);
3539

40+
void ocf_mngt_continue_pipeline_on_zero_refcnt(struct env_refcnt *refcnt,
41+
ocf_pipeline_t pipeline);
42+
3643
#endif /* __OCF_MNGT_COMMON_H__ */

src/mngt/ocf_mngt_flush.c

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,6 @@ struct ocf_mngt_cache_flush_context
8282
struct flush_containers_context fcs;
8383
};
8484

85-
static void _ocf_mngt_begin_flush_complete(void *priv)
86-
{
87-
struct ocf_mngt_cache_flush_context *context = priv;
88-
ocf_pipeline_next(context->pipeline);
89-
}
90-
9185
static void _ocf_mngt_begin_flush(ocf_pipeline_t pipeline, void *priv,
9286
ocf_pipeline_arg_t arg)
9387
{
@@ -105,8 +99,8 @@ static void _ocf_mngt_begin_flush(ocf_pipeline_t pipeline, void *priv,
10599
env_refcnt_freeze(&cache->refcnt.dirty);
106100
context->flags.freeze = true;
107101

108-
env_refcnt_register_zero_cb(&cache->refcnt.dirty,
109-
_ocf_mngt_begin_flush_complete, context);
102+
ocf_mngt_continue_pipeline_on_zero_refcnt(&cache->refcnt.dirty,
103+
context->pipeline);
110104
}
111105

112106
bool ocf_mngt_core_is_dirty(ocf_core_t core)

0 commit comments

Comments
 (0)