From e31e7283d938d7a1973eb34a24b3d5fe32782ef7 Mon Sep 17 00:00:00 2001 From: Robert Baldyga Date: Thu, 2 Sep 2021 22:00:34 +0200 Subject: [PATCH] Rework volume type management Signed-off-by: Robert Baldyga --- src/mngt/ocf_mngt_core.c | 3 ++- src/mngt/ocf_mngt_core_pool.c | 7 +++++- src/ocf_core.c | 2 +- src/ocf_ctx.c | 46 +++++++++++++++++++++++++++++------ src/ocf_ctx_priv.h | 15 ++++++++++-- 5 files changed, 61 insertions(+), 12 deletions(-) diff --git a/src/mngt/ocf_mngt_core.c b/src/mngt/ocf_mngt_core.c index 1732bc4..a818e25 100644 --- a/src/mngt/ocf_mngt_core.c +++ b/src/mngt/ocf_mngt_core.c @@ -220,7 +220,8 @@ int ocf_mngt_core_init_front_volume(ocf_core_t core) }; int ret; - type = ocf_ctx_get_volume_type(cache->owner, 0); + type = ocf_ctx_get_volume_type_internal(cache->owner, + OCF_VOLUME_TYPE_CORE); if (!type) return -OCF_ERR_INVAL; diff --git a/src/mngt/ocf_mngt_core_pool.c b/src/mngt/ocf_mngt_core_pool.c index 7a8ce9b..57b451c 100644 --- a/src/mngt/ocf_mngt_core_pool.c +++ b/src/mngt/ocf_mngt_core_pool.c @@ -27,13 +27,18 @@ int ocf_mngt_core_pool_get_count(ocf_ctx_t ctx) int ocf_mngt_core_pool_add(ocf_ctx_t ctx, ocf_uuid_t uuid, uint8_t type) { + ocf_volume_type_t volume_type; ocf_volume_t volume; int result = 0; OCF_CHECK_NULL(ctx); - result = ocf_ctx_volume_create(ctx, &volume, uuid, type); + volume_type = ocf_ctx_get_volume_type(ctx, type); + if (!volume_type) + return -OCF_ERR_INVAL; + + result = ocf_volume_create(&volume, volume_type, uuid); if (result) return result; diff --git a/src/ocf_core.c b/src/ocf_core.c index 13804cd..660c383 100644 --- a/src/ocf_core.c +++ b/src/ocf_core.c @@ -519,7 +519,7 @@ const struct ocf_volume_extended ocf_core_volume_extended = { int ocf_core_volume_type_init(ocf_ctx_t ctx) { - return ocf_ctx_register_volume_type_extended(ctx, 0, + return ocf_ctx_register_volume_type_internal(ctx, OCF_VOLUME_TYPE_CORE, &ocf_core_volume_properties, &ocf_core_volume_extended); } diff --git a/src/ocf_ctx.c b/src/ocf_ctx.c index 6bbb97d..083364b 100644 --- a/src/ocf_ctx.c +++ b/src/ocf_ctx.c @@ -10,13 +10,14 @@ #include "ocf_request.h" #include "ocf_logger_priv.h" #include "ocf_core_priv.h" +#include "ocf_cache_priv.h" #include "mngt/ocf_mngt_core_pool_priv.h" #include "metadata/metadata_io.h" /* * */ -int ocf_ctx_register_volume_type_extended(ocf_ctx_t ctx, uint8_t type_id, +int ocf_ctx_register_volume_type_internal(ocf_ctx_t ctx, uint8_t type_id, const struct ocf_volume_properties *properties, const struct ocf_volume_extended *extended) { @@ -55,14 +56,17 @@ err: int ocf_ctx_register_volume_type(ocf_ctx_t ctx, uint8_t type_id, const struct ocf_volume_properties *properties) { - return ocf_ctx_register_volume_type_extended(ctx, type_id, + if (type_id >= OCF_VOLUME_TYPE_MAX_USER) + return -EINVAL; + + return ocf_ctx_register_volume_type_internal(ctx, type_id, properties, NULL); } /* * */ -void ocf_ctx_unregister_volume_type(ocf_ctx_t ctx, uint8_t type_id) +void ocf_ctx_unregister_volume_type_internal(ocf_ctx_t ctx, uint8_t type_id) { OCF_CHECK_NULL(ctx); @@ -76,17 +80,42 @@ void ocf_ctx_unregister_volume_type(ocf_ctx_t ctx, uint8_t type_id) env_rmutex_unlock(&ctx->lock); } +void ocf_ctx_unregister_volume_type(ocf_ctx_t ctx, uint8_t type_id) +{ + OCF_CHECK_NULL(ctx); + + if (type_id < OCF_VOLUME_TYPE_MAX_USER) + ocf_ctx_unregister_volume_type_internal(ctx, type_id); +} + /* * */ -ocf_volume_type_t ocf_ctx_get_volume_type(ocf_ctx_t ctx, uint8_t type_id) +ocf_volume_type_t ocf_ctx_get_volume_type_internal(ocf_ctx_t ctx, + uint8_t type_id) { + ocf_volume_type_t volume_type; + OCF_CHECK_NULL(ctx); if (type_id >= OCF_VOLUME_TYPE_MAX) return NULL; - return ctx->volume_type[type_id]; + env_rmutex_lock(&ctx->lock); + volume_type = ctx->volume_type[type_id]; + env_rmutex_unlock(&ctx->lock); + + return volume_type; +} + +ocf_volume_type_t ocf_ctx_get_volume_type(ocf_ctx_t ctx, uint8_t type_id) +{ + OCF_CHECK_NULL(ctx); + + if (type_id >= OCF_VOLUME_TYPE_MAX_USER) + return NULL; + + return ocf_ctx_get_volume_type_internal(ctx, type_id); } /* @@ -114,12 +143,15 @@ int ocf_ctx_get_volume_type_id(ocf_ctx_t ctx, ocf_volume_type_t type) int ocf_ctx_volume_create(ocf_ctx_t ctx, ocf_volume_t *volume, struct ocf_volume_uuid *uuid, uint8_t type_id) { + ocf_volume_type_t volume_type; + OCF_CHECK_NULL(ctx); - if (type_id >= OCF_VOLUME_TYPE_MAX) + volume_type = ocf_ctx_get_volume_type(ctx, type_id); + if (!volume_type) return -EINVAL; - return ocf_volume_create(volume, ctx->volume_type[type_id], uuid); + return ocf_volume_create(volume, volume_type, uuid); } static void check_ops_provided(const struct ocf_ctx_ops *ops) diff --git a/src/ocf_ctx_priv.h b/src/ocf_ctx_priv.h index 9f8c3ad..ab7385f 100644 --- a/src/ocf_ctx_priv.h +++ b/src/ocf_ctx_priv.h @@ -11,7 +11,13 @@ #include "ocf_logger_priv.h" #include "ocf_volume_priv.h" -#define OCF_VOLUME_TYPE_MAX 8 +#define OCF_VOLUME_TYPE_CNT_USER 8 +#define OCF_VOLUME_TYPE_CNT_PRIV 2 +#define OCF_VOLUME_TYPE_MAX_USER OCF_VOLUME_TYPE_CNT_USER +#define OCF_VOLUME_TYPE_MAX \ + (OCF_VOLUME_TYPE_CNT_USER + OCF_VOLUME_TYPE_CNT_PRIV) + +#define OCF_VOLUME_TYPE_CORE (OCF_VOLUME_TYPE_MAX_USER + 0) /** * @brief OCF main control structure @@ -50,10 +56,15 @@ struct ocf_ctx { #define ocf_log_stack_trace(ctx) \ ocf_log_stack_trace_raw(&ctx->logger) -int ocf_ctx_register_volume_type_extended(ocf_ctx_t ctx, uint8_t type_id, +int ocf_ctx_register_volume_type_internal(ocf_ctx_t ctx, uint8_t type_id, const struct ocf_volume_properties *properties, const struct ocf_volume_extended *extended); +void ocf_ctx_unregister_volume_type_internal(ocf_ctx_t ctx, uint8_t type_id); + +ocf_volume_type_t ocf_ctx_get_volume_type_internal(ocf_ctx_t ctx, + uint8_t type_id); + /** * @name Environment data buffer operations wrappers * @{