Rework volume type management

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2021-09-02 22:00:34 +02:00
parent a2bef43975
commit e31e7283d9
5 changed files with 61 additions and 12 deletions

View File

@ -220,7 +220,8 @@ int ocf_mngt_core_init_front_volume(ocf_core_t core)
}; };
int ret; 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) if (!type)
return -OCF_ERR_INVAL; return -OCF_ERR_INVAL;

View File

@ -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) 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; ocf_volume_t volume;
int result = 0; int result = 0;
OCF_CHECK_NULL(ctx); 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) if (result)
return result; return result;

View File

@ -519,7 +519,7 @@ const struct ocf_volume_extended ocf_core_volume_extended = {
int ocf_core_volume_type_init(ocf_ctx_t ctx) 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_properties,
&ocf_core_volume_extended); &ocf_core_volume_extended);
} }

View File

@ -10,13 +10,14 @@
#include "ocf_request.h" #include "ocf_request.h"
#include "ocf_logger_priv.h" #include "ocf_logger_priv.h"
#include "ocf_core_priv.h" #include "ocf_core_priv.h"
#include "ocf_cache_priv.h"
#include "mngt/ocf_mngt_core_pool_priv.h" #include "mngt/ocf_mngt_core_pool_priv.h"
#include "metadata/metadata_io.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_properties *properties,
const struct ocf_volume_extended *extended) 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, int ocf_ctx_register_volume_type(ocf_ctx_t ctx, uint8_t type_id,
const struct ocf_volume_properties *properties) 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); 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); 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); 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); OCF_CHECK_NULL(ctx);
if (type_id >= OCF_VOLUME_TYPE_MAX) if (type_id >= OCF_VOLUME_TYPE_MAX)
return NULL; 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, int ocf_ctx_volume_create(ocf_ctx_t ctx, ocf_volume_t *volume,
struct ocf_volume_uuid *uuid, uint8_t type_id) struct ocf_volume_uuid *uuid, uint8_t type_id)
{ {
ocf_volume_type_t volume_type;
OCF_CHECK_NULL(ctx); 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 -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) static void check_ops_provided(const struct ocf_ctx_ops *ops)

View File

@ -11,7 +11,13 @@
#include "ocf_logger_priv.h" #include "ocf_logger_priv.h"
#include "ocf_volume_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 * @brief OCF main control structure
@ -50,10 +56,15 @@ struct ocf_ctx {
#define ocf_log_stack_trace(ctx) \ #define ocf_log_stack_trace(ctx) \
ocf_log_stack_trace_raw(&ctx->logger) 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_properties *properties,
const struct ocf_volume_extended *extended); 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 * @name Environment data buffer operations wrappers
* @{ * @{