From cda536a14af938fd1ded6767c2e71cba84f1889e Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 27 May 2019 12:49:45 +0200 Subject: [PATCH 1/6] Remove mpool from OCF utils Signed-off-by: Robert Baldyga --- inc/ocf.h | 1 - inc/ocf_utilities.h | 74 ------------------ src/utils/utils_allocator.c | 150 ------------------------------------ 3 files changed, 225 deletions(-) delete mode 100644 inc/ocf_utilities.h diff --git a/inc/ocf.h b/inc/ocf.h index 766027a..cfa4ad9 100644 --- a/inc/ocf.h +++ b/inc/ocf.h @@ -16,7 +16,6 @@ #include "ocf_def.h" #include "ocf_types.h" -#include "ocf_utilities.h" #include "ocf_io.h" #include "ocf_volume.h" #include "ocf_cache.h" diff --git a/inc/ocf_utilities.h b/inc/ocf_utilities.h deleted file mode 100644 index a4feb71..0000000 --- a/inc/ocf_utilities.h +++ /dev/null @@ -1,74 +0,0 @@ -/* - * Copyright(c) 2012-2018 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ - - -#ifndef __OCF_UTILITIES_H__ -#define __OCF_UTILITIES_H__ - -/** - * @file - * @brief OCF memory pool reference - */ - -struct ocf_mpool; - -/** - * @brief Create OCF memory pool - * - * @param cache OCF cache instance - * @param size Size of particular item - * @param hdr_size Header size before array of items - * @param flags Allocation flags - * @param mpool_max Maximal allocator size (power of two) - * @param fmt_name Format name of allocator - * @param ... Format parameters - * - * @return OCF memory pool reference - */ -struct ocf_mpool *ocf_mpool_create(struct ocf_cache *cache, - uint32_t hdr_size, uint32_t size, int flags, int mpool_max, - const char *name_perfix); - -/** - * @brief Destroy existing memory pool - * - * @param mpool memory pool - */ -void ocf_mpool_destroy(struct ocf_mpool *mpool); - -/** - * @brief Allocate new items of memory pool - * - * @note Allocation based on ATOMIC memory pool and this function can be called - * when IRQ disable - * - * @param mpool OCF memory pool reference - * @param count Count of elements to be allocated - * - * @return Pointer to the new items - */ -void *ocf_mpool_new(struct ocf_mpool *mpool, uint32_t count); - -/** - * @brief Allocate new items of memory pool with specified allocation flag - * - * @param mpool OCF memory pool reference - * @param count Count of elements to be allocated - * @param flags Kernel allocation falgs - * - * @return Pointer to the new items - */ -void *ocf_mpool_new_f(struct ocf_mpool *mpool, uint32_t count, int flags); - -/** - * @brief Free existing items of memory pool - * - * @param mpool OCF memory pool reference - * @param items Items to be freed - * @param count - Count of elements to be free - */ -void ocf_mpool_del(struct ocf_mpool *mpool, void *items, uint32_t count); - -#endif /* __OCF_UTILITIES_H__ */ diff --git a/src/utils/utils_allocator.c b/src/utils/utils_allocator.c index 3cd7f57..34580a7 100644 --- a/src/utils/utils_allocator.c +++ b/src/utils/utils_allocator.c @@ -4,8 +4,6 @@ */ #include "ocf/ocf.h" #include "utils_allocator.h" -#include "../ocf_priv.h" -#include "../ocf_cache_priv.h" #include "ocf_env.h" #define OCF_ALLOCATOR_K_MAX (128 * KiB) @@ -117,151 +115,3 @@ void ocf_realloc_init(void **mem, size_t *limit) *mem = NULL; *((size_t *)limit) = 0; } - -enum { - ocf_mpool_1, - ocf_mpool_2, - ocf_mpool_4, - ocf_mpool_8, - ocf_mpool_16, - ocf_mpool_32, - ocf_mpool_64, - ocf_mpool_128, - - ocf_mpool_max -}; - -struct ocf_mpool { - struct ocf_cache *cache; - /*!< Cache instance */ - - uint32_t item_size; - /*!< Size of specific item of memory pool */ - - uint32_t hdr_size; - /*!< Header size before items */ - - env_allocator *allocator[ocf_mpool_max]; - /*!< OS handle to memory pool */ - - int flags; - /*!< Allocation flags */ -}; - -#define ALLOCATOR_NAME_MAX 128 - -struct ocf_mpool *ocf_mpool_create(struct ocf_cache *cache, - uint32_t hdr_size, uint32_t size, int flags, int mpool_max, - const char *name_perfix) -{ - uint32_t i; - char name[ALLOCATOR_NAME_MAX] = { '\0' }; - int result; - struct ocf_mpool *mpool; - - OCF_CHECK_NULL(name_perfix); - - mpool = env_zalloc(sizeof(*mpool), ENV_MEM_NORMAL); - if (!mpool) - goto ocf_multi_allocator_create_ERROR; - - mpool->item_size = size; - mpool->hdr_size = hdr_size; - mpool->cache = cache; - mpool->flags = flags; - - for (i = 0; i < OCF_MIN(ocf_mpool_max, mpool_max + 1); i++) { - result = snprintf(name, sizeof(name), "%s_%u", name_perfix, - (1 << i)); - if (result < 0 || result >= sizeof(name)) - goto ocf_multi_allocator_create_ERROR; - - mpool->allocator[i] = env_allocator_create( - hdr_size + (size * (1 << i)), name); - - if (!mpool->allocator[i]) - goto ocf_multi_allocator_create_ERROR; - } - - return mpool; - -ocf_multi_allocator_create_ERROR: - - ocf_mpool_destroy(mpool); - - return NULL; -} - -void ocf_mpool_destroy(struct ocf_mpool *mallocator) -{ - if (mallocator) { - uint32_t i; - - for (i = 0; i < ocf_mpool_max; i++) - if (mallocator->allocator[i]) - env_allocator_destroy(mallocator->allocator[i]); - - env_free(mallocator); - } -} - -static env_allocator *ocf_mpool_get_allocator( - struct ocf_mpool *mallocator, uint32_t count) -{ - unsigned int idx; - - if (unlikely(count == 0)) - return ocf_mpool_1; - - idx = 31 - __builtin_clz(count); - - if (__builtin_ffs(count) <= idx) - idx++; - - if (idx >= ocf_mpool_max) - return NULL; - - return mallocator->allocator[idx]; -} - -void *ocf_mpool_new_f(struct ocf_mpool *mpool, uint32_t count, int flags) -{ - void *items = NULL; - env_allocator *allocator; - - OCF_CHECK_NULL(mpool); - - allocator = ocf_mpool_get_allocator(mpool, count); - - if (allocator) - items = env_allocator_new(allocator); - else - items = env_zalloc(mpool->hdr_size + (mpool->item_size * count), flags); - -#ifdef ZERO_OR_NULL_PTR - if (ZERO_OR_NULL_PTR(items)) - return NULL; -#endif - - return items; -} - -void *ocf_mpool_new(struct ocf_mpool *mpool, uint32_t count) -{ - return ocf_mpool_new_f(mpool, count, mpool->flags); -} - -void ocf_mpool_del(struct ocf_mpool *mpool, - void *items, uint32_t count) -{ - env_allocator *allocator; - - OCF_CHECK_NULL(mpool); - - allocator = ocf_mpool_get_allocator(mpool, count); - - if (allocator) - env_allocator_del(allocator, items); - else - env_free(items); -} From ab2fc6d3c36ecfdf8028b6060b6649a9fc6155a5 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 27 May 2019 13:09:17 +0200 Subject: [PATCH 2/6] Rename utils_allocator to utils_realloc Signed-off-by: Robert Baldyga --- src/cleaning/alru.c | 2 +- src/concurrency/ocf_cache_concurrency.c | 2 +- src/metadata/metadata_io.c | 2 +- src/metadata/metadata_updater.c | 2 +- src/utils/{utils_allocator.c => utils_realloc.c} | 10 +++++----- src/utils/{utils_allocator.h => utils_realloc.h} | 10 +++++----- .../alru.c/cleaning_policy_alru_initialize_part_test.c | 2 +- 7 files changed, 15 insertions(+), 15 deletions(-) rename src/utils/{utils_allocator.c => utils_realloc.c} (91%) rename src/utils/{utils_allocator.h => utils_realloc.h} (93%) diff --git a/src/cleaning/alru.c b/src/cleaning/alru.c index 10ec27b..1c45928 100644 --- a/src/cleaning/alru.c +++ b/src/cleaning/alru.c @@ -10,7 +10,7 @@ #include "../metadata/metadata.h" #include "../utils/utils_cleaner.h" #include "../utils/utils_part.h" -#include "../utils/utils_allocator.h" +#include "../utils/utils_realloc.h" #include "../concurrency/ocf_cache_concurrency.h" #include "../ocf_def_priv.h" #include "cleaning_priv.h" diff --git a/src/concurrency/ocf_cache_concurrency.c b/src/concurrency/ocf_cache_concurrency.c index b902b97..9cfc88b 100644 --- a/src/concurrency/ocf_cache_concurrency.c +++ b/src/concurrency/ocf_cache_concurrency.c @@ -7,7 +7,7 @@ #include "../ocf_priv.h" #include "../ocf_request.h" #include "../utils/utils_cache_line.h" -#include "../utils/utils_allocator.h" +#include "../utils/utils_realloc.h" #define OCF_CACHE_CONCURRENCY_DEBUG 0 diff --git a/src/metadata/metadata_io.c b/src/metadata/metadata_io.c index 4a89c55..56348df 100644 --- a/src/metadata/metadata_io.c +++ b/src/metadata/metadata_io.c @@ -9,7 +9,7 @@ #include "../engine/engine_common.h" #include "../engine/engine_bf.h" #include "../utils/utils_cache_line.h" -#include "../utils/utils_allocator.h" +#include "../utils/utils_realloc.h" #include "../utils/utils_io.h" #include "../ocf_def_priv.h" diff --git a/src/metadata/metadata_updater.c b/src/metadata/metadata_updater.c index bd93a7f..4c24475 100644 --- a/src/metadata/metadata_updater.c +++ b/src/metadata/metadata_updater.c @@ -11,7 +11,7 @@ #include "../ocf_cache_priv.h" #include "../ocf_ctx_priv.h" #include "../utils/utils_io.h" -#include "../utils/utils_allocator.h" +#include "../utils/utils_realloc.h" int ocf_metadata_updater_init(ocf_cache_t cache) { diff --git a/src/utils/utils_allocator.c b/src/utils/utils_realloc.c similarity index 91% rename from src/utils/utils_allocator.c rename to src/utils/utils_realloc.c index 34580a7..7c805fb 100644 --- a/src/utils/utils_allocator.c +++ b/src/utils/utils_realloc.c @@ -3,10 +3,10 @@ * SPDX-License-Identifier: BSD-3-Clause-Clear */ #include "ocf/ocf.h" -#include "utils_allocator.h" +#include "utils_realloc.h" #include "ocf_env.h" -#define OCF_ALLOCATOR_K_MAX (128 * KiB) +#define OCF_REALLOC_K_MAX (128 * KiB) static int _ocf_realloc_with_cp(void **mem, size_t size, size_t count, size_t *limit, bool cp) @@ -24,7 +24,7 @@ static int _ocf_realloc_with_cp(void **mem, size_t size, size_t count, void *new_mem; - if (alloc_size > OCF_ALLOCATOR_K_MAX) + if (alloc_size > OCF_REALLOC_K_MAX) new_mem = env_vzalloc(alloc_size); else new_mem = env_zalloc(alloc_size, ENV_MEM_NOIO); @@ -44,7 +44,7 @@ static int _ocf_realloc_with_cp(void **mem, size_t size, size_t count, } - if (*limit > OCF_ALLOCATOR_K_MAX) + if (*limit > OCF_REALLOC_K_MAX) env_vfree(*mem); else env_free(*mem); @@ -74,7 +74,7 @@ static int _ocf_realloc_with_cp(void **mem, size_t size, size_t count, if ((*mem) && (*limit)) { /* Need to free memory */ - if (*limit > OCF_ALLOCATOR_K_MAX) + if (*limit > OCF_REALLOC_K_MAX) env_vfree(*mem); else env_free(*mem); diff --git a/src/utils/utils_allocator.h b/src/utils/utils_realloc.h similarity index 93% rename from src/utils/utils_allocator.h rename to src/utils/utils_realloc.h index 9542e9b..ee2fd6f 100644 --- a/src/utils/utils_allocator.h +++ b/src/utils/utils_realloc.h @@ -3,12 +3,12 @@ * SPDX-License-Identifier: BSD-3-Clause-Clear */ -#ifndef UTILS_ALLOCATOR_H_ -#define UTILS_ALLOCATOR_H_ +#ifndef UTILS_REALLOC_H_ +#define UTILS_REALLOC_H_ /** - * @file utils_allocator.h - * @brief OCF memory reallocator + * @file utils_realloc.h + * @brief OCF realloc */ void ocf_realloc_init(void **mem, size_t *limit); @@ -66,4 +66,4 @@ int ocf_realloc_cp(void **mem, size_t size, size_t count, size_t *limit); #define OCF_REALLOC_CP(mem, size, count, limit) \ ocf_realloc_cp((void **)mem, size, count, limit) -#endif /* UTILS_ALLOCATOR_H_ */ +#endif /* UTILS_REALLOC_H_ */ diff --git a/tests/unit/tests/cleaning/alru.c/cleaning_policy_alru_initialize_part_test.c b/tests/unit/tests/cleaning/alru.c/cleaning_policy_alru_initialize_part_test.c index ba8f16f..045f63a 100644 --- a/tests/unit/tests/cleaning/alru.c/cleaning_policy_alru_initialize_part_test.c +++ b/tests/unit/tests/cleaning/alru.c/cleaning_policy_alru_initialize_part_test.c @@ -31,7 +31,7 @@ #include "../metadata/metadata.h" #include "../utils/utils_cleaner.h" #include "../utils/utils_part.h" -#include "../utils/utils_allocator.h" +#include "../utils/utils_realloc.h" #include "../concurrency/ocf_cache_concurrency.h" #include "../ocf_def_priv.h" From 57bc19103ddc343372ab822a3932c362160f7875 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 27 May 2019 14:19:10 +0200 Subject: [PATCH 3/6] Remove unused core_io_allocator Signed-off-by: Robert Baldyga --- src/ocf_ctx_priv.h | 1 - src/ocf_utils.c | 25 +------------------------ 2 files changed, 1 insertion(+), 25 deletions(-) diff --git a/src/ocf_ctx_priv.h b/src/ocf_ctx_priv.h index c16fc36..3de4a51 100644 --- a/src/ocf_ctx_priv.h +++ b/src/ocf_ctx_priv.h @@ -30,7 +30,6 @@ struct ocf_ctx { struct { struct ocf_req_allocator *req; - env_allocator *core_io_allocator; } resources; }; diff --git a/src/ocf_utils.c b/src/ocf_utils.c index fb18890..fb6a651 100644 --- a/src/ocf_utils.c +++ b/src/ocf_utils.c @@ -11,33 +11,10 @@ int ocf_utils_init(struct ocf_ctx *ocf_ctx) { - int result; - - result = ocf_req_allocator_init(ocf_ctx); - if (result) - goto ocf_utils_init_ERROR; - - ocf_ctx->resources.core_io_allocator = - env_allocator_create(sizeof(struct ocf_core_io), - "ocf_io"); - if (!ocf_ctx->resources.core_io_allocator) - goto ocf_utils_init_ERROR; - - return 0; - -ocf_utils_init_ERROR: - - ocf_utils_deinit(ocf_ctx); - - return -1; + return ocf_req_allocator_init(ocf_ctx); } void ocf_utils_deinit(struct ocf_ctx *ocf_ctx) { ocf_req_allocator_deinit(ocf_ctx); - - if (ocf_ctx->resources.core_io_allocator) { - env_allocator_destroy(ocf_ctx->resources.core_io_allocator); - ocf_ctx->resources.core_io_allocator = NULL; - } } From 7de56940a43ff5469bb44242376138205fa2f2e4 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 27 May 2019 15:40:13 +0200 Subject: [PATCH 4/6] Move ocf_request from utils ocf_request has always been first class citizen in OCF, so lets place it along with another essential objects. Signed-off-by: Robert Baldyga --- src/cleaning/acp.c | 2 +- src/engine/cache_engine.c | 2 +- src/engine/engine_bf.c | 2 +- src/engine/engine_common.c | 2 +- src/engine/engine_d2c.c | 2 +- src/engine/engine_discard.c | 2 +- src/engine/engine_fast.c | 2 +- src/engine/engine_inv.c | 2 +- src/engine/engine_ops.c | 2 +- src/engine/engine_pt.c | 2 +- src/engine/engine_rd.c | 2 +- src/engine/engine_wa.c | 2 +- src/engine/engine_wb.c | 2 +- src/engine/engine_wi.c | 2 +- src/engine/engine_wt.c | 2 +- src/engine/engine_zero.c | 2 +- src/eviction/lru.c | 2 +- src/metadata/metadata_raw_dynamic.c | 2 +- src/mngt/ocf_mngt_cache.c | 1 - src/mngt/ocf_mngt_common.c | 2 +- src/mngt/ocf_mngt_flush.c | 2 +- src/ocf_cache.c | 2 +- src/ocf_core.c | 2 +- src/ocf_ctx.c | 8 +- src/{utils/utils_req.c => ocf_request.c} | 19 +-- src/ocf_request.h | 131 +++++++++++++++- src/ocf_utils.c | 20 --- src/ocf_utils.h | 13 -- src/utils/utils_cleaner.c | 2 +- src/utils/utils_pipeline.c | 2 +- src/utils/utils_req.h | 145 ------------------ .../_cache_mng_set_cache_mode_test.c | 1 - ...gt_cache_set_fallback_pt_error_threshold.c | 1 - 33 files changed, 166 insertions(+), 221 deletions(-) rename src/{utils/utils_req.c => ocf_request.c} (95%) delete mode 100644 src/ocf_utils.c delete mode 100644 src/ocf_utils.h delete mode 100644 src/utils/utils_req.h diff --git a/src/cleaning/acp.c b/src/cleaning/acp.c index c5c585f..06c429c 100644 --- a/src/cleaning/acp.c +++ b/src/cleaning/acp.c @@ -9,7 +9,7 @@ #include "../metadata/metadata.h" #include "../utils/utils_cleaner.h" #include "../utils/utils_cache_line.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../cleaning/acp.h" #include "../engine/engine_common.h" #include "../concurrency/ocf_cache_concurrency.h" diff --git a/src/engine/cache_engine.c b/src/engine/cache_engine.c index 19769e2..910f47a 100644 --- a/src/engine/cache_engine.c +++ b/src/engine/cache_engine.c @@ -21,7 +21,7 @@ #include "engine_ops.h" #include "../utils/utils_part.h" #include "../utils/utils_refcnt.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../metadata/metadata.h" #include "../eviction/eviction.h" diff --git a/src/engine/engine_bf.c b/src/engine/engine_bf.c index 832f410..f045b72 100644 --- a/src/engine/engine_bf.c +++ b/src/engine/engine_bf.c @@ -10,7 +10,7 @@ #include "engine_inv.h" #include "engine_common.h" #include "cache_engine.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_io.h" #include "../concurrency/ocf_concurrency.h" diff --git a/src/engine/engine_common.c b/src/engine/engine_common.c index 751e0bb..2976f37 100644 --- a/src/engine/engine_common.c +++ b/src/engine/engine_common.c @@ -11,7 +11,7 @@ #define OCF_ENGINE_DEBUG_IO_NAME "common" #include "engine_debug.h" #include "../utils/utils_cache_line.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_cleaner.h" #include "../metadata/metadata.h" #include "../eviction/eviction.h" diff --git a/src/engine/engine_d2c.c b/src/engine/engine_d2c.c index 2b7796c..8728daf 100644 --- a/src/engine/engine_d2c.c +++ b/src/engine/engine_d2c.c @@ -7,7 +7,7 @@ #include "engine_d2c.h" #include "engine_common.h" #include "cache_engine.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_io.h" #include "../metadata/metadata.h" diff --git a/src/engine/engine_discard.c b/src/engine/engine_discard.c index 3d12fa0..f7973d4 100644 --- a/src/engine/engine_discard.c +++ b/src/engine/engine_discard.c @@ -8,7 +8,7 @@ #include "engine_common.h" #include "engine_discard.h" #include "../metadata/metadata.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_io.h" #include "../utils/utils_cache_line.h" #include "../concurrency/ocf_concurrency.h" diff --git a/src/engine/engine_fast.c b/src/engine/engine_fast.c index 888e878..5d51e11 100644 --- a/src/engine/engine_fast.c +++ b/src/engine/engine_fast.c @@ -9,7 +9,7 @@ #include "engine_common.h" #include "engine_pt.h" #include "engine_wb.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_part.h" #include "../utils/utils_io.h" #include "../concurrency/ocf_concurrency.h" diff --git a/src/engine/engine_inv.c b/src/engine/engine_inv.c index 8ebcb2e..fd30204 100644 --- a/src/engine/engine_inv.c +++ b/src/engine/engine_inv.c @@ -8,7 +8,7 @@ #include "engine_inv.h" #include "engine_common.h" #include "cache_engine.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_cache_line.h" #include "../metadata/metadata.h" #include "../concurrency/ocf_concurrency.h" diff --git a/src/engine/engine_ops.c b/src/engine/engine_ops.c index f2463a3..4ce0ef6 100644 --- a/src/engine/engine_ops.c +++ b/src/engine/engine_ops.c @@ -7,7 +7,7 @@ #include "engine_common.h" #include "cache_engine.h" #include "engine_ops.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_io.h" #define OCF_ENGINE_DEBUG_IO_NAME "ops" diff --git a/src/engine/engine_pt.c b/src/engine/engine_pt.c index f7a4a3a..25304ed 100644 --- a/src/engine/engine_pt.c +++ b/src/engine/engine_pt.c @@ -7,7 +7,7 @@ #include "engine_pt.h" #include "engine_common.h" #include "cache_engine.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_io.h" #include "../utils/utils_part.h" #include "../metadata/metadata.h" diff --git a/src/engine/engine_rd.c b/src/engine/engine_rd.c index 86a230f..022ae5c 100644 --- a/src/engine/engine_rd.c +++ b/src/engine/engine_rd.c @@ -13,7 +13,7 @@ #include "cache_engine.h" #include "../concurrency/ocf_concurrency.h" #include "../utils/utils_io.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_cache_line.h" #include "../utils/utils_part.h" #include "../metadata/metadata.h" diff --git a/src/engine/engine_wa.c b/src/engine/engine_wa.c index 6741b28..2d8a5e8 100644 --- a/src/engine/engine_wa.c +++ b/src/engine/engine_wa.c @@ -7,7 +7,7 @@ #include "engine_wa.h" #include "engine_common.h" #include "cache_engine.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_io.h" #include "../metadata/metadata.h" diff --git a/src/engine/engine_wb.c b/src/engine/engine_wb.c index a716d2e..7f9d133 100644 --- a/src/engine/engine_wb.c +++ b/src/engine/engine_wb.c @@ -9,7 +9,7 @@ #include "engine_common.h" #include "engine_wb.h" #include "../metadata/metadata.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_io.h" #include "../utils/utils_cache_line.h" #include "../utils/utils_part.h" diff --git a/src/engine/engine_wi.c b/src/engine/engine_wi.c index 845dd5c..2838d65 100644 --- a/src/engine/engine_wi.c +++ b/src/engine/engine_wi.c @@ -8,7 +8,7 @@ #include "engine_wi.h" #include "engine_common.h" #include "../concurrency/ocf_concurrency.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_cache_line.h" #include "../utils/utils_io.h" #include "../metadata/metadata.h" diff --git a/src/engine/engine_wt.c b/src/engine/engine_wt.c index febf1a1..f8962ba 100644 --- a/src/engine/engine_wt.c +++ b/src/engine/engine_wt.c @@ -8,7 +8,7 @@ #include "engine_wt.h" #include "engine_inv.h" #include "engine_common.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_io.h" #include "../utils/utils_cache_line.h" #include "../utils/utils_part.h" diff --git a/src/engine/engine_zero.c b/src/engine/engine_zero.c index e9b29b7..57dc489 100644 --- a/src/engine/engine_zero.c +++ b/src/engine/engine_zero.c @@ -8,7 +8,7 @@ #include "engine_zero.h" #include "engine_common.h" #include "../concurrency/ocf_concurrency.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_cache_line.h" #include "../utils/utils_io.h" #include "../metadata/metadata.h" diff --git a/src/eviction/lru.c b/src/eviction/lru.c index 9a4fbdc..8371d3f 100644 --- a/src/eviction/lru.c +++ b/src/eviction/lru.c @@ -11,7 +11,7 @@ #include "../concurrency/ocf_concurrency.h" #include "../mngt/ocf_mngt_common.h" #include "../engine/engine_zero.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #define OCF_EVICTION_MAX_SCAN 1024 diff --git a/src/metadata/metadata_raw_dynamic.c b/src/metadata/metadata_raw_dynamic.c index 06cae29..f2e698b 100644 --- a/src/metadata/metadata_raw_dynamic.c +++ b/src/metadata/metadata_raw_dynamic.c @@ -11,7 +11,7 @@ #include "../engine/cache_engine.h" #include "../engine/engine_common.h" #include "../utils/utils_io.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../ocf_def_priv.h" #include "../ocf_priv.h" diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index cf60718..d3ad54e 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -18,7 +18,6 @@ #include "../utils/utils_cache_line.h" #include "../utils/utils_pipeline.h" #include "../utils/utils_refcnt.h" -#include "../ocf_utils.h" #include "../concurrency/ocf_concurrency.h" #include "../eviction/ops.h" #include "../ocf_ctx_priv.h" diff --git a/src/mngt/ocf_mngt_common.c b/src/mngt/ocf_mngt_common.c index 37daa8f..fc0ef91 100644 --- a/src/mngt/ocf_mngt_common.c +++ b/src/mngt/ocf_mngt_common.c @@ -9,7 +9,7 @@ #include "../ocf_ctx_priv.h" #include "../metadata/metadata.h" #include "../engine/cache_engine.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../utils/utils_device.h" #include "../eviction/ops.h" #include "../ocf_logger_priv.h" diff --git a/src/mngt/ocf_mngt_flush.c b/src/mngt/ocf_mngt_flush.c index 9872c83..ff2173c 100644 --- a/src/mngt/ocf_mngt_flush.c +++ b/src/mngt/ocf_mngt_flush.c @@ -15,7 +15,7 @@ #include "../utils/utils_part.h" #include "../utils/utils_pipeline.h" #include "../utils/utils_refcnt.h" -#include "../utils/utils_req.h" +#include "../ocf_request.h" #include "../ocf_def_priv.h" struct ocf_mngt_cache_flush_context; diff --git a/src/ocf_cache.c b/src/ocf_cache.c index 0970f75..8849a46 100644 --- a/src/ocf_cache.c +++ b/src/ocf_cache.c @@ -7,7 +7,7 @@ #include "metadata/metadata.h" #include "engine/cache_engine.h" #include "utils/utils_cache_line.h" -#include "utils/utils_req.h" +#include "ocf_request.h" #include "utils/utils_part.h" #include "ocf_priv.h" #include "ocf_cache_priv.h" diff --git a/src/ocf_core.c b/src/ocf_core.c index 383cacd..2fb1288 100644 --- a/src/ocf_core.c +++ b/src/ocf_core.c @@ -9,7 +9,7 @@ #include "ocf_io_priv.h" #include "metadata/metadata.h" #include "engine/cache_engine.h" -#include "utils/utils_req.h" +#include "ocf_request.h" #include "utils/utils_part.h" #include "utils/utils_device.h" #include "ocf_request.h" diff --git a/src/ocf_ctx.c b/src/ocf_ctx.c index 00a0cbf..5bfc4a2 100644 --- a/src/ocf_ctx.c +++ b/src/ocf_ctx.c @@ -7,7 +7,7 @@ #include "ocf_ctx_priv.h" #include "ocf_priv.h" #include "ocf_volume_priv.h" -#include "ocf_utils.h" +#include "ocf_request.h" #include "ocf_logger_priv.h" #include "ocf_core_priv.h" #include "mngt/ocf_mngt_core_pool_priv.h" @@ -141,7 +141,7 @@ int ocf_ctx_create(ocf_ctx_t *ctx, const struct ocf_ctx_config *cfg) if (ret) goto err_ctx; - ret = ocf_utils_init(ocf_ctx); + ret = ocf_req_allocator_init(ocf_ctx); if (ret) goto err_logger; @@ -156,7 +156,7 @@ int ocf_ctx_create(ocf_ctx_t *ctx, const struct ocf_ctx_config *cfg) return 0; err_utils: - ocf_utils_deinit(ocf_ctx); + ocf_req_allocator_deinit(ocf_ctx); err_logger: ocf_logger_close(&ocf_ctx->logger); err_ctx: @@ -190,7 +190,7 @@ void ocf_ctx_put(ocf_ctx_t ctx) ocf_mngt_core_pool_deinit(ctx); ocf_core_volume_type_deinit(ctx); - ocf_utils_deinit(ctx); + ocf_req_allocator_deinit(ctx); ocf_logger_close(&ctx->logger); env_free(ctx); } diff --git a/src/utils/utils_req.c b/src/ocf_request.c similarity index 95% rename from src/utils/utils_req.c rename to src/ocf_request.c index 85c69c2..6d13009 100644 --- a/src/utils/utils_req.c +++ b/src/ocf_request.c @@ -4,11 +4,10 @@ */ #include "ocf/ocf.h" -#include "utils_req.h" -#include "utils_cache_line.h" -#include "../ocf_request.h" -#include "../ocf_cache_priv.h" -#include "../ocf_queue_priv.h" +#include "ocf_request.h" +#include "ocf_cache_priv.h" +#include "ocf_queue_priv.h" +#include "utils/utils_cache_line.h" #define OCF_UTILS_RQ_DEBUG 0 @@ -76,20 +75,20 @@ int ocf_req_allocator_init(struct ocf_ctx *ocf_ctx) req = ocf_ctx->resources.req; if (!req) - goto ocf_utils_req_init_ERROR; + goto err; for (i = 0; i < ARRAY_SIZE(req->allocator); i++) { req->size[i] = ocf_req_sizeof(1 << i); if (snprintf(name, sizeof(name), ALLOCATOR_NAME_FMT, (1 << i)) < 0) { - goto ocf_utils_req_init_ERROR; + goto err; } req->allocator[i] = env_allocator_create(req->size[i], name); if (!req->allocator[i]) - goto ocf_utils_req_init_ERROR; + goto err; OCF_DEBUG_PARAM(cache, "New request allocator, lines = %u, " "size = %lu", 1 << i, req->size[i]); @@ -97,10 +96,8 @@ int ocf_req_allocator_init(struct ocf_ctx *ocf_ctx) return 0; -ocf_utils_req_init_ERROR: - +err: ocf_req_allocator_deinit(ocf_ctx); - return -1; } diff --git a/src/ocf_request.h b/src/ocf_request.h index ececaf4..b26de96 100644 --- a/src/ocf_request.h +++ b/src/ocf_request.h @@ -8,6 +8,8 @@ #include "ocf_env.h" +struct ocf_req_allocator; + struct ocf_req_info { /* Number of hits, invalid, misses. */ unsigned int hit_no; @@ -201,4 +203,131 @@ struct ocf_request { typedef void (*ocf_req_end_t)(struct ocf_request *req, int error); -#endif +/** + * @brief Initialize OCF request allocation utility + * + * @param cache - OCF cache instance + * @return Operation status 0 - successful, non-zero failure + */ +int ocf_req_allocator_init(struct ocf_ctx *ocf_ctx); + +/** + * @brief De-initialize OCF request allocation utility + * + * @param cache - OCF cache instance + */ +void ocf_req_allocator_deinit(struct ocf_ctx *ocf_ctx); + +/** + * @brief Allocate new OCF request + * + * @param queue - I/O queue handle + * @param core - OCF core instance + * @param addr - LBA of request + * @param bytes - number of bytes of request + * @param rw - Read or Write + * + * @return new OCF request + */ +struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core, + uint64_t addr, uint32_t bytes, int rw); + +/** + * @brief Allocate OCF request map + * + * @param req OCF request + * + * @retval 0 Allocation succeed + * @retval non-zero Allocation failed + */ +int ocf_req_alloc_map(struct ocf_request *req); + +/** + * @brief Allocate new OCF request with NOIO map allocation for huge request + * + * @param queue - I/O queue handle + * @param core - OCF core instance + * @param addr - LBA of request + * @param bytes - number of bytes of request + * @param rw - Read or Write + * + * @return new OCF request + */ + +struct ocf_request *ocf_req_new_extended(ocf_queue_t queue, ocf_core_t core, + uint64_t addr, uint32_t bytes, int rw); + +/** + * @brief Allocate new OCF request for DISCARD operation + * + * @param queue - I/O queue handle + * @param core - OCF core instance + * @param addr - LBA of request + * @param bytes - number of bytes of request + * @param rw - Read or Write + * + * @return new OCF request + */ +struct ocf_request *ocf_req_new_discard(ocf_queue_t queue, ocf_core_t core, + uint64_t addr, uint32_t bytes, int rw); + +/** + * @brief Increment OCF request reference count + * + * @param req - OCF request + */ +void ocf_req_get(struct ocf_request *req); + +/** + * @brief Decrement OCF request reference. If reference is 0 then request will + * be deallocated + * + * @param req - OCF request + */ +void ocf_req_put(struct ocf_request *req); + +/** + * @brief Clear OCF request info + * + * @param req - OCF request + */ +void ocf_req_clear_info(struct ocf_request *req); + +/** + * @brief Clear OCF request map + * + * @param req - OCF request + */ +void ocf_req_clear_map(struct ocf_request *req); + +/** + * @brief Clear OCF request + * + * @param req - OCF request + */ +static inline void ocf_req_clear(struct ocf_request *req) +{ + ocf_req_clear_info(req); + ocf_req_clear_map(req); + + env_atomic_set(&req->lock_remaining, 0); + env_atomic_set(&req->req_remaining, 0); +} + +/** + * @brief Return OCF request reference count + * + * @param req - OCF request + * @return OCF request reference count + */ +static inline int ocf_req_ref_count(struct ocf_request *req) +{ + return env_atomic_read(&req->ref_count); +} + +static inline bool ocf_req_is_4k(uint64_t addr, uint32_t bytes) +{ + return !((addr % PAGE_SIZE) || (bytes % PAGE_SIZE)); +} + +#endif /* __OCF_REQUEST_H__ */ diff --git a/src/ocf_utils.c b/src/ocf_utils.c deleted file mode 100644 index fb6a651..0000000 --- a/src/ocf_utils.c +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Copyright(c) 2012-2018 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ - -#include "ocf/ocf.h" -#include "ocf_cache_priv.h" -#include "utils/utils_req.h" -#include "ocf_utils.h" -#include "ocf_ctx_priv.h" - -int ocf_utils_init(struct ocf_ctx *ocf_ctx) -{ - return ocf_req_allocator_init(ocf_ctx); -} - -void ocf_utils_deinit(struct ocf_ctx *ocf_ctx) -{ - ocf_req_allocator_deinit(ocf_ctx); -} diff --git a/src/ocf_utils.h b/src/ocf_utils.h deleted file mode 100644 index 96ef656..0000000 --- a/src/ocf_utils.h +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright(c) 2012-2018 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ - -#ifndef OCF_UTILS_H_ -#define OCF_UTILS_H_ - -int ocf_utils_init(struct ocf_ctx *ocf_ctx); - -void ocf_utils_deinit(struct ocf_ctx *ocf_ctx); - -#endif /* OCF_UTILS_H_ */ diff --git a/src/utils/utils_cleaner.c b/src/utils/utils_cleaner.c index bdfd40f..0fe500f 100644 --- a/src/utils/utils_cleaner.c +++ b/src/utils/utils_cleaner.c @@ -7,9 +7,9 @@ #include "../engine/cache_engine.h" #include "../engine/engine_common.h" #include "../concurrency/ocf_concurrency.h" +#include "../ocf_request.h" #include "utils_cleaner.h" #include "utils_part.h" -#include "utils_req.h" #include "utils_io.h" #include "utils_cache_line.h" diff --git a/src/utils/utils_pipeline.c b/src/utils/utils_pipeline.c index 79496e0..1676898 100644 --- a/src/utils/utils_pipeline.c +++ b/src/utils/utils_pipeline.c @@ -1,8 +1,8 @@ #include "ocf/ocf.h" #include "../engine/cache_engine.h" #include "../engine/engine_common.h" +#include "../ocf_request.h" #include "utils_pipeline.h" -#include "utils_req.h" struct ocf_pipeline { struct ocf_pipeline_properties *properties; diff --git a/src/utils/utils_req.h b/src/utils/utils_req.h deleted file mode 100644 index c53b878..0000000 --- a/src/utils/utils_req.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - * Copyright(c) 2012-2018 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ - -#ifndef UTILS_RQ_H_ -#define UTILS_RQ_H_ - -#include "../ocf_request.h" - -/** - * @file utils_req.h - * @brief OCF request allocation utilities - */ - -struct ocf_req_allocator; - -/** - * @brief Initialize OCF request allocation utility - * - * @param cache - OCF cache instance - * @return Operation status 0 - successful, non-zero failure - */ -int ocf_req_allocator_init(struct ocf_ctx *ocf_ctx); - -/** - * @brief De-initialize OCF request allocation utility - * - * @param cache - OCF cache instance - */ -void ocf_req_allocator_deinit(struct ocf_ctx *ocf_ctx); - -/** - * @brief Allocate new OCF request - * - * @param queue - I/O queue handle - * @param core - OCF core instance - * @param addr - LBA of request - * @param bytes - number of bytes of request - * @param rw - Read or Write - * - * @return new OCF request - */ -struct ocf_request *ocf_req_new(ocf_queue_t queue, ocf_core_t core, - uint64_t addr, uint32_t bytes, int rw); - -/** - * @brief Allocate OCF request map - * - * @param req OCF request - * - * @retval 0 Allocation succeed - * @retval non-zero Allocation failed - */ -int ocf_req_alloc_map(struct ocf_request *req); - -/** - * @brief Allocate new OCF request with NOIO map allocation for huge request - * - * @param queue - I/O queue handle - * @param core - OCF core instance - * @param addr - LBA of request - * @param bytes - number of bytes of request - * @param rw - Read or Write - * - * @return new OCF request - */ - -struct ocf_request *ocf_req_new_extended(ocf_queue_t queue, ocf_core_t core, - uint64_t addr, uint32_t bytes, int rw); - -/** - * @brief Allocate new OCF request for DISCARD operation - * - * @param queue - I/O queue handle - * @param core - OCF core instance - * @param addr - LBA of request - * @param bytes - number of bytes of request - * @param rw - Read or Write - * - * @return new OCF request - */ -struct ocf_request *ocf_req_new_discard(ocf_queue_t queue, ocf_core_t core, - uint64_t addr, uint32_t bytes, int rw); - -/** - * @brief Increment OCF request reference count - * - * @param req - OCF request - */ -void ocf_req_get(struct ocf_request *req); - -/** - * @brief Decrement OCF request reference. If reference is 0 then request will - * be deallocated - * - * @param req - OCF request - */ -void ocf_req_put(struct ocf_request *req); - -/** - * @brief Clear OCF request info - * - * @param req - OCF request - */ -void ocf_req_clear_info(struct ocf_request *req); - -/** - * @brief Clear OCF request map - * - * @param req - OCF request - */ -void ocf_req_clear_map(struct ocf_request *req); - -/** - * @brief Clear OCF request - * - * @param req - OCF request - */ -static inline void ocf_req_clear(struct ocf_request *req) -{ - ocf_req_clear_info(req); - ocf_req_clear_map(req); - - env_atomic_set(&req->lock_remaining, 0); - env_atomic_set(&req->req_remaining, 0); -} - -/** - * @brief Return OCF request reference count - * - * @param req - OCF request - * @return OCF request reference count - */ -static inline int ocf_req_ref_count(struct ocf_request *req) -{ - return env_atomic_read(&req->ref_count); -} - -static inline bool ocf_req_is_4k(uint64_t addr, uint32_t bytes) -{ - return !((addr % PAGE_SIZE) || (bytes % PAGE_SIZE)); -} - -#endif /* UTILS_RQ_H_ */ diff --git a/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c b/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c index 69e283c..61b1920 100644 --- a/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c +++ b/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c @@ -35,7 +35,6 @@ #include "../utils/utils_io.h" #include "../utils/utils_cache_line.h" #include "../utils/utils_pipeline.h" -#include "../ocf_utils.h" #include "../concurrency/ocf_concurrency.h" #include "../eviction/ops.h" #include "../ocf_ctx_priv.h" diff --git a/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c b/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c index d9e11b7..996ceee 100644 --- a/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c +++ b/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c @@ -30,7 +30,6 @@ #include "../utils/utils_io.h" #include "../utils/utils_cache_line.h" #include "../utils/utils_pipeline.h" -#include "../ocf_utils.h" #include "../concurrency/ocf_concurrency.h" #include "../eviction/ops.h" #include "../ocf_ctx_priv.h" From bdcd4df0efe46ec29a2d8394c3924bce15e010df Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 27 May 2019 16:44:23 +0200 Subject: [PATCH 5/6] Remove utils_device.h Move core mngt related code to ocf_mngt_core.c Signed-off-by: Robert Baldyga --- src/mngt/ocf_mngt_cache.c | 1 - src/mngt/ocf_mngt_common.c | 4 +- src/mngt/ocf_mngt_core.c | 60 +++++++++++++++-- src/mngt/ocf_mngt_core_priv.h | 2 + src/ocf_core.c | 1 - src/utils/utils_device.h | 64 ------------------- .../_cache_mng_set_cache_mode_test.c | 1 - ...gt_cache_set_fallback_pt_error_threshold.c | 1 - 8 files changed, 60 insertions(+), 74 deletions(-) delete mode 100644 src/utils/utils_device.h diff --git a/src/mngt/ocf_mngt_cache.c b/src/mngt/ocf_mngt_cache.c index d3ad54e..5ba09c2 100644 --- a/src/mngt/ocf_mngt_cache.c +++ b/src/mngt/ocf_mngt_cache.c @@ -13,7 +13,6 @@ #include "../engine/cache_engine.h" #include "../utils/utils_part.h" #include "../utils/utils_cache_line.h" -#include "../utils/utils_device.h" #include "../utils/utils_io.h" #include "../utils/utils_cache_line.h" #include "../utils/utils_pipeline.h" diff --git a/src/mngt/ocf_mngt_common.c b/src/mngt/ocf_mngt_common.c index fc0ef91..e145b43 100644 --- a/src/mngt/ocf_mngt_common.c +++ b/src/mngt/ocf_mngt_common.c @@ -5,12 +5,12 @@ #include "ocf/ocf.h" #include "ocf_mngt_common.h" +#include "ocf_mngt_core_priv.h" #include "../ocf_priv.h" #include "../ocf_ctx_priv.h" #include "../metadata/metadata.h" #include "../engine/cache_engine.h" #include "../ocf_request.h" -#include "../utils/utils_device.h" #include "../eviction/ops.h" #include "../ocf_logger_priv.h" #include "../ocf_queue_priv.h" @@ -96,7 +96,7 @@ void cache_mng_core_remove_from_meta(struct ocf_cache *cache, int core_id) cache->core_conf_meta[core_id].added = false; /* Clear UUID of core */ - ocf_metadata_clear_core_uuid(&cache->core[core_id]); + ocf_mngt_core_clear_uuid_metadata(&cache->core[core_id]); cache->core_conf_meta[core_id].seq_no = OCF_SEQ_NO_INVALID; OCF_METADATA_UNLOCK_WR(); diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index 2e23483..6425935 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -9,7 +9,6 @@ #include "../ocf_priv.h" #include "../metadata/metadata.h" #include "../engine/cache_engine.h" -#include "../utils/utils_device.h" #include "../utils/utils_pipeline.h" #include "../ocf_stats_priv.h" #include "../ocf_def_priv.h" @@ -22,6 +21,59 @@ static ocf_seq_no_t _ocf_mngt_get_core_seq_no(ocf_cache_t cache) return ++cache->conf_meta->curr_core_seq_no; } +static int _ocf_uuid_set(const struct ocf_volume_uuid *uuid, + struct ocf_metadata_uuid *muuid) +{ + int result; + + if (!uuid->data || !muuid->data) + return -EINVAL; + + if (uuid->size > sizeof(muuid->data)) + return -ENOBUFS; + + result = env_memcpy(muuid->data, sizeof(muuid->data), + uuid->data, uuid->size); + if (result) + return result; + + result = env_memset(muuid->data + uuid->size, + sizeof(muuid->data) - uuid->size, 0); + if (result) + return result; + + muuid->size = uuid->size; + + return 0; +} + +static int ocf_mngt_core_set_uuid_metadata(ocf_core_t core, + const struct ocf_volume_uuid *uuid, + struct ocf_volume_uuid *new_uuid) +{ + ocf_cache_t cache = ocf_core_get_cache(core); + struct ocf_metadata_uuid *muuid = ocf_metadata_get_core_uuid(cache, + ocf_core_get_id(core)); + + if (_ocf_uuid_set(uuid, muuid)) + return -ENOBUFS; + + if (new_uuid) { + new_uuid->data = muuid->data; + new_uuid->size = muuid->size; + } + + return 0; +} + +void ocf_mngt_core_clear_uuid_metadata(ocf_core_t core) +{ + struct ocf_volume_uuid uuid = { .size = 0, }; + + ocf_mngt_core_set_uuid_metadata(core, &uuid, NULL); +} + + static int _ocf_mngt_cache_try_add_core(ocf_cache_t cache, ocf_core_t *core, struct ocf_mngt_core_config *cfg) { @@ -118,7 +170,7 @@ static void _ocf_mngt_cache_add_core_handle_error( ocf_volume_deinit(volume); if (context->flags.uuid_set) - ocf_metadata_clear_core_uuid(core); + ocf_mngt_core_clear_uuid_metadata(core); } static void _ocf_mngt_cache_add_core_flush_sb_complete(void *priv, int error) @@ -154,7 +206,7 @@ static void _ocf_mngt_cache_add_core(ocf_cache_t cache, volume->cache = cache; /* Set uuid */ - result = ocf_metadata_set_core_uuid(core, &cfg->uuid, &new_uuid); + result = ocf_mngt_core_set_uuid_metadata(core, &cfg->uuid, &new_uuid); if (result) OCF_PL_FINISH_RET(context->pipeline, result); @@ -830,7 +882,7 @@ int ocf_mngt_core_set_uuid(ocf_core_t core, const struct ocf_volume_uuid *uuid) return 0; } - result = ocf_metadata_set_core_uuid(core, uuid, NULL); + result = ocf_mngt_core_set_uuid_metadata(core, uuid, NULL); if (result) return result; diff --git a/src/mngt/ocf_mngt_core_priv.h b/src/mngt/ocf_mngt_core_priv.h index 7b79ec8..4d0c4e1 100644 --- a/src/mngt/ocf_mngt_core_priv.h +++ b/src/mngt/ocf_mngt_core_priv.h @@ -10,4 +10,6 @@ int ocf_mngt_core_init_front_volume(ocf_core_t core); +void ocf_mngt_core_clear_uuid_metadata(ocf_core_t core); + #endif /* __OCF_MNGT_CORE_PRIV_H__ */ diff --git a/src/ocf_core.c b/src/ocf_core.c index 2fb1288..3776738 100644 --- a/src/ocf_core.c +++ b/src/ocf_core.c @@ -11,7 +11,6 @@ #include "engine/cache_engine.h" #include "ocf_request.h" #include "utils/utils_part.h" -#include "utils/utils_device.h" #include "ocf_request.h" #include "ocf_trace_priv.h" diff --git a/src/utils/utils_device.h b/src/utils/utils_device.h deleted file mode 100644 index d3643e6..0000000 --- a/src/utils/utils_device.h +++ /dev/null @@ -1,64 +0,0 @@ -/* - * Copyright(c) 2012-2018 Intel Corporation - * SPDX-License-Identifier: BSD-3-Clause-Clear - */ - -#ifndef UTILS_DEVICE_H_ -#define UTILS_DEVICE_H_ - -static inline int _ocf_uuid_set(const struct ocf_volume_uuid *uuid, - struct ocf_metadata_uuid *muuid) -{ - int result; - - if (!uuid || !muuid) { - return -EINVAL; - } - - if (!uuid->data || !muuid->data) { - return -EINVAL; - } - - if (uuid->size > sizeof(muuid->data)) { - return -ENOBUFS; - } - - result = env_memcpy(muuid->data, sizeof(muuid->data), uuid->data, uuid->size); - if (result) - return result; - result = env_memset(muuid->data + uuid->size, - sizeof(muuid->data) - uuid->size, 0); - if (result) - return result; - muuid->size = uuid->size; - - return 0; -} - -static inline int ocf_metadata_set_core_uuid(ocf_core_t core, - const struct ocf_volume_uuid *uuid, - struct ocf_volume_uuid *new_uuid) -{ - ocf_cache_t cache = ocf_core_get_cache(core); - struct ocf_metadata_uuid *muuid = ocf_metadata_get_core_uuid(cache, - ocf_core_get_id(core)); - - if (_ocf_uuid_set(uuid, muuid)) - return -ENOBUFS; - - if (new_uuid) { - new_uuid->data = muuid->data; - new_uuid->size = muuid->size; - } - - return 0; -} - -static inline void ocf_metadata_clear_core_uuid(ocf_core_t core) -{ - struct ocf_volume_uuid uuid = { .size = 0, }; - - ocf_metadata_set_core_uuid(core, &uuid, NULL); -} - -#endif /* UTILS_MEM_H_ */ diff --git a/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c b/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c index 61b1920..ec883a8 100644 --- a/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c +++ b/tests/unit/tests/mngt/ocf_mngt_cache.c/_cache_mng_set_cache_mode_test.c @@ -31,7 +31,6 @@ #include "../engine/cache_engine.h" #include "../utils/utils_part.h" #include "../utils/utils_cache_line.h" -#include "../utils/utils_device.h" #include "../utils/utils_io.h" #include "../utils/utils_cache_line.h" #include "../utils/utils_pipeline.h" diff --git a/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c b/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c index 996ceee..f924954 100644 --- a/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c +++ b/tests/unit/tests/mngt/ocf_mngt_cache.c/ocf_mngt_cache_set_fallback_pt_error_threshold.c @@ -26,7 +26,6 @@ #include "../engine/cache_engine.h" #include "../utils/utils_part.h" #include "../utils/utils_cache_line.h" -#include "../utils/utils_device.h" #include "../utils/utils_io.h" #include "../utils/utils_cache_line.h" #include "../utils/utils_pipeline.h" From f9447fda7554bf29390d1e4da976b5a77b523b4c Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Mon, 27 May 2019 15:53:27 +0200 Subject: [PATCH 6/6] Remove all the trailing whitespaces Signed-off-by: Robert Baldyga --- src/metadata/metadata_hash.c | 2 +- src/ocf_io.c | 2 +- src/ocf_volume.c | 4 ++-- src/utils/utils_cache_line.c | 6 +++--- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/src/metadata/metadata_hash.c b/src/metadata/metadata_hash.c index 1ee01a8..17b69ff 100644 --- a/src/metadata/metadata_hash.c +++ b/src/metadata/metadata_hash.c @@ -1457,7 +1457,7 @@ static void ocf_medatata_hash_flush_segment(ocf_pipeline_t pipeline, ocf_cache_t cache = context->cache; ctrl = (struct ocf_metadata_hash_ctrl *)cache->metadata.iface_priv; - + ocf_metadata_raw_flush_all(cache, &ctrl->raw_desc[segment], ocf_metadata_hash_generic_complete, context); } diff --git a/src/ocf_io.c b/src/ocf_io.c index 12a0db2..081eede 100644 --- a/src/ocf_io.c +++ b/src/ocf_io.c @@ -69,7 +69,7 @@ struct ocf_io *ocf_io_new(ocf_volume_t volume) io->volume = volume; io->ops = &volume->type->properties->io_ops; - env_atomic_set(&io_meta->ref_count, 1); + env_atomic_set(&io_meta->ref_count, 1); return io; } diff --git a/src/ocf_volume.c b/src/ocf_volume.c index 5459f46..b007e0a 100644 --- a/src/ocf_volume.c +++ b/src/ocf_volume.c @@ -247,7 +247,7 @@ void ocf_volume_submit_flush(struct ocf_io *io) io->end(io, -EIO); if (!io->volume->type->properties->ops.submit_flush) { - ocf_io_end(io, 0); + ocf_io_end(io, 0); return; } @@ -260,7 +260,7 @@ void ocf_volume_submit_discard(struct ocf_io *io) io->end(io, -EIO); if (!io->volume->type->properties->ops.submit_discard) { - ocf_io_end(io, 0); + ocf_io_end(io, 0); return; } diff --git a/src/utils/utils_cache_line.c b/src/utils/utils_cache_line.c index e239ee0..ff6350b 100644 --- a/src/utils/utils_cache_line.c +++ b/src/utils/utils_cache_line.c @@ -133,7 +133,7 @@ void set_cache_line_clean(struct ocf_cache *cache, uint8_t start_bit, evict_policy_ops[evp_type].clean_cline(cache, part_id, line); ocf_purge_cleaning_policy(cache, line); - ocf_metadata_flush_mark(cache, req, map_idx, CLEAN, start_bit, + ocf_metadata_flush_mark(cache, req, map_idx, CLEAN, start_bit, end_bit); } } @@ -169,8 +169,8 @@ void set_cache_line_dirty(struct ocf_cache *cache, uint8_t start_bit, if (likely(evict_policy_ops[evp_type].dirty_cline)) evict_policy_ops[evp_type].dirty_cline(cache, part_id, line); - - ocf_metadata_flush_mark(cache, req, map_idx, DIRTY, start_bit, + + ocf_metadata_flush_mark(cache, req, map_idx, DIRTY, start_bit, end_bit); }