diff --git a/inc/ocf_debug.h b/inc/ocf_debug.h index 5b8ec52..1c0b144 100644 --- a/inc/ocf_debug.h +++ b/inc/ocf_debug.h @@ -1,5 +1,6 @@ /* * Copyright(c) 2012-2021 Intel Corporation + * Copyright(c) 2024 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ @@ -18,4 +19,6 @@ struct ocf_dbg_seq_cutoff_status { void ocf_dbg_get_seq_cutoff_status(ocf_core_t core, struct ocf_dbg_seq_cutoff_status *status); +bool ocf_dbg_cache_is_settled(ocf_cache_t cache); + #endif /* __OCF_DEBUG_H__ */ diff --git a/src/ocf_cache.c b/src/ocf_cache.c index bafadba..00c6cee 100644 --- a/src/ocf_cache.c +++ b/src/ocf_cache.c @@ -15,6 +15,7 @@ #include "ocf_cache_priv.h" #include "ocf_queue_priv.h" #include "utils/utils_stats.h" +#include "ocf/ocf_debug.h" ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache) { @@ -559,3 +560,9 @@ int ocf_cache_volume_type_init(ocf_ctx_t ctx) return ocf_ctx_register_volume_type_internal(ctx, OCF_VOLUME_TYPE_CACHE, &ocf_cache_volume_properties, NULL); } + +bool ocf_dbg_cache_is_settled(ocf_cache_t cache) +{ + return ocf_refcnt_zeroed(&cache->refcnt.metadata) && + ocf_refcnt_zeroed(&cache->refcnt.d2c); +} diff --git a/src/utils/utils_refcnt.c b/src/utils/utils_refcnt.c index ced88ad..54d0379 100644 --- a/src/utils/utils_refcnt.c +++ b/src/utils/utils_refcnt.c @@ -1,5 +1,6 @@ /* * Copyright(c) 2019-2021 Intel Corporation + * Copyright(c) 2024 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ @@ -68,3 +69,8 @@ bool ocf_refcnt_frozen(struct ocf_refcnt *rc) { return !!env_atomic_read(&rc->freeze); } + +bool ocf_refcnt_zeroed(struct ocf_refcnt *rc) +{ + return (env_atomic_read(&rc->counter) == 0); +} diff --git a/src/utils/utils_refcnt.h b/src/utils/utils_refcnt.h index eca22cc..0871854 100644 --- a/src/utils/utils_refcnt.h +++ b/src/utils/utils_refcnt.h @@ -1,5 +1,6 @@ /* * Copyright(c) 2019-2021 Intel Corporation + * Copyright(c) 2024 Huawei Technologies * SPDX-License-Identifier: BSD-3-Clause */ @@ -40,6 +41,8 @@ void ocf_refcnt_unfreeze(struct ocf_refcnt *rc); bool ocf_refcnt_frozen(struct ocf_refcnt *rc); +bool ocf_refcnt_zeroed(struct ocf_refcnt *rc); + /* Register callback to be called when reference counter drops to 0. * Must be called after counter is frozen. * Cannot be called until previously regsitered callback had fired. */ diff --git a/tests/functional/pyocf/types/cache.py b/tests/functional/pyocf/types/cache.py index ee02344..4c6dd94 100644 --- a/tests/functional/pyocf/types/cache.py +++ b/tests/functional/pyocf/types/cache.py @@ -1010,7 +1010,8 @@ class Cache: # settle all queues accociated with this cache (mngt and I/O) def settle(self): - Queue.settle_many(self.io_queues + [self.mngt_queue]) + while not self.owner.lib.ocf_dbg_cache_is_settled(self.cache_handle): + pass @staticmethod def get_by_name(cache_name, owner=None):