Merge pull request #702 from robertbaldyga/v22.6-composite-volume
Introduce composite volume
This commit is contained in:
@@ -135,10 +135,6 @@ struct ocf_cache_attach_context {
|
||||
* load or recovery
|
||||
*/
|
||||
|
||||
bool uuid_copied : 1;
|
||||
/*!< copied uuid data to context.
|
||||
*/
|
||||
|
||||
bool metadata_frozen : 1;
|
||||
/*!< metadata reference counter frozen
|
||||
*/
|
||||
@@ -790,7 +786,6 @@ static void _ocf_mngt_attach_cache_device(ocf_pipeline_t pipeline,
|
||||
struct ocf_cache_attach_context *context = priv;
|
||||
struct ocf_mngt_cache_device_config *device_cfg = &context->cfg.device;
|
||||
ocf_cache_t cache = context->cache;
|
||||
ocf_volume_type_t type;
|
||||
int ret;
|
||||
|
||||
cache->device = env_vzalloc(sizeof(*cache->device));
|
||||
@@ -799,20 +794,9 @@ static void _ocf_mngt_attach_cache_device(ocf_pipeline_t pipeline,
|
||||
|
||||
context->flags.device_alloc = true;
|
||||
|
||||
/* Prepare UUID of cache volume */
|
||||
type = ocf_ctx_get_volume_type(cache->owner, device_cfg->volume_type);
|
||||
if (!type) {
|
||||
OCF_PL_FINISH_RET(pipeline,
|
||||
-OCF_ERR_INVAL_VOLUME_TYPE);
|
||||
}
|
||||
|
||||
ret = ocf_volume_init(&cache->device->volume, type,
|
||||
&device_cfg->uuid, true);
|
||||
if (ret)
|
||||
OCF_PL_FINISH_RET(pipeline, ret);
|
||||
|
||||
cache->device->volume.cache = cache;
|
||||
ocf_volume_move(&cache->device->volume, device_cfg->volume);
|
||||
context->flags.volume_inited = true;
|
||||
cache->device->volume.cache = cache;
|
||||
|
||||
/*
|
||||
* Open cache device, It has to be done first because metadata service
|
||||
@@ -1279,8 +1263,6 @@ uint64_t _ocf_mngt_calculate_ram_needed(ocf_cache_line_size_t line_size,
|
||||
int ocf_mngt_get_ram_needed(ocf_cache_t cache,
|
||||
struct ocf_mngt_cache_device_config *cfg, uint64_t *ram_needed)
|
||||
{
|
||||
ocf_volume_t volume;
|
||||
ocf_volume_type_t type;
|
||||
ocf_cache_line_size_t line_size;
|
||||
uint64_t volume_size;
|
||||
int result;
|
||||
@@ -1289,26 +1271,15 @@ int ocf_mngt_get_ram_needed(ocf_cache_t cache,
|
||||
OCF_CHECK_NULL(cfg);
|
||||
OCF_CHECK_NULL(ram_needed);
|
||||
|
||||
type = ocf_ctx_get_volume_type(cache->owner, cfg->volume_type);
|
||||
if (!type)
|
||||
return -OCF_ERR_INVAL_VOLUME_TYPE;
|
||||
|
||||
result = ocf_volume_create(&volume, type, &cfg->uuid);
|
||||
result = ocf_volume_open(cfg->volume, cfg->volume_params);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
result = ocf_volume_open(volume, cfg->volume_params);
|
||||
if (result) {
|
||||
ocf_volume_destroy(volume);
|
||||
return result;
|
||||
}
|
||||
|
||||
line_size = ocf_line_size(cache);
|
||||
volume_size = ocf_volume_get_length(volume);
|
||||
volume_size = ocf_volume_get_length(cfg->volume);
|
||||
*ram_needed = _ocf_mngt_calculate_ram_needed(line_size, volume_size);
|
||||
|
||||
ocf_volume_close(volume);
|
||||
ocf_volume_destroy(volume);
|
||||
ocf_volume_close(cfg->volume);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1479,34 +1450,6 @@ static void _ocf_mngt_init_attached_nonpersistent(ocf_pipeline_t pipeline,
|
||||
ocf_pipeline_next(pipeline);
|
||||
}
|
||||
|
||||
static void _ocf_mngt_copy_uuid_data(ocf_pipeline_t pipeline,
|
||||
void *priv, ocf_pipeline_arg_t arg)
|
||||
{
|
||||
struct ocf_cache_attach_context *context = priv;
|
||||
struct ocf_mngt_cache_device_config *device_cfg = &context->cfg.device;
|
||||
void *data;
|
||||
int result;
|
||||
|
||||
if (device_cfg->uuid.size == 0)
|
||||
OCF_PL_NEXT_RET(pipeline);
|
||||
|
||||
data = env_vmalloc(device_cfg->uuid.size);
|
||||
if (!data)
|
||||
OCF_PL_FINISH_RET(pipeline, -OCF_ERR_NO_MEM);
|
||||
|
||||
result = env_memcpy(data, device_cfg->uuid.size, device_cfg->uuid.data,
|
||||
device_cfg->uuid.size);
|
||||
if (result) {
|
||||
env_vfree(data);
|
||||
OCF_PL_FINISH_RET(pipeline, -OCF_ERR_INVAL);
|
||||
}
|
||||
|
||||
device_cfg->uuid.data = data;
|
||||
context->flags.uuid_copied = true;
|
||||
|
||||
ocf_pipeline_next(pipeline);
|
||||
}
|
||||
|
||||
static void _ocf_mngt_attach_check_ram(ocf_pipeline_t pipeline,
|
||||
void *priv, ocf_pipeline_arg_t arg)
|
||||
{
|
||||
@@ -1799,6 +1742,8 @@ static void _ocf_mngt_attach_handle_error(
|
||||
|
||||
if (context->flags.volume_inited)
|
||||
ocf_volume_deinit(&cache->device->volume);
|
||||
else
|
||||
ocf_volume_deinit(context->cfg.device.volume);
|
||||
|
||||
if (context->flags.front_volume_opened)
|
||||
ocf_volume_close(&cache->device->front_volume);
|
||||
@@ -1824,16 +1769,12 @@ static void _ocf_mngt_cache_attach_finish(ocf_pipeline_t pipeline,
|
||||
void *priv, int error)
|
||||
{
|
||||
struct ocf_cache_attach_context *context = priv;
|
||||
struct ocf_mngt_cache_device_config *device_cfg = &context->cfg.device;
|
||||
|
||||
if (error)
|
||||
_ocf_mngt_attach_handle_error(context);
|
||||
|
||||
context->cmpl(context->cache, context->priv1, context->priv2, error);
|
||||
|
||||
if (context->flags.uuid_copied)
|
||||
env_vfree(device_cfg->uuid.data);
|
||||
|
||||
ocf_pipeline_destroy(context->pipeline);
|
||||
}
|
||||
|
||||
@@ -1841,7 +1782,6 @@ struct ocf_pipeline_properties _ocf_mngt_cache_attach_pipeline_properties = {
|
||||
.priv_size = sizeof(struct ocf_cache_attach_context),
|
||||
.finish = _ocf_mngt_cache_attach_finish,
|
||||
.steps = {
|
||||
OCF_PL_STEP(_ocf_mngt_copy_uuid_data),
|
||||
OCF_PL_STEP(_ocf_mngt_init_attached_nonpersistent),
|
||||
OCF_PL_STEP(_ocf_mngt_attach_cache_device),
|
||||
OCF_PL_STEP(_ocf_mngt_init_properties),
|
||||
@@ -1868,7 +1808,6 @@ struct ocf_pipeline_properties _ocf_mngt_cache_load_pipeline_properties = {
|
||||
.priv_size = sizeof(struct ocf_cache_attach_context),
|
||||
.finish = _ocf_mngt_cache_attach_finish,
|
||||
.steps = {
|
||||
OCF_PL_STEP(_ocf_mngt_copy_uuid_data),
|
||||
OCF_PL_STEP(_ocf_mngt_init_attached_nonpersistent),
|
||||
OCF_PL_STEP(_ocf_mngt_attach_cache_device),
|
||||
OCF_PL_STEP(_ocf_mngt_init_properties),
|
||||
@@ -2265,7 +2204,6 @@ struct ocf_pipeline_properties _ocf_mngt_cache_standby_attach_pipeline_propertie
|
||||
.priv_size = sizeof(struct ocf_cache_attach_context),
|
||||
.finish = _ocf_mngt_cache_attach_finish,
|
||||
.steps = {
|
||||
OCF_PL_STEP(_ocf_mngt_copy_uuid_data),
|
||||
OCF_PL_STEP(_ocf_mngt_init_attached_nonpersistent),
|
||||
OCF_PL_STEP(_ocf_mngt_attach_cache_device),
|
||||
OCF_PL_STEP(_ocf_mngt_attach_read_properties),
|
||||
@@ -2292,7 +2230,6 @@ struct ocf_pipeline_properties _ocf_mngt_cache_standby_load_pipeline_properties
|
||||
.priv_size = sizeof(struct ocf_cache_attach_context),
|
||||
.finish = _ocf_mngt_cache_attach_finish,
|
||||
.steps = {
|
||||
OCF_PL_STEP(_ocf_mngt_copy_uuid_data),
|
||||
OCF_PL_STEP(_ocf_mngt_init_attached_nonpersistent),
|
||||
OCF_PL_STEP(_ocf_mngt_attach_cache_device),
|
||||
OCF_PL_STEP(_ocf_mngt_init_cache_front_volume),
|
||||
@@ -2342,20 +2279,9 @@ static void _ocf_mngt_activate_set_cache_device(ocf_pipeline_t pipeline,
|
||||
struct ocf_cache_attach_context *context = priv;
|
||||
struct ocf_mngt_cache_device_config *device_cfg = &context->cfg.device;
|
||||
ocf_cache_t cache = context->cache;
|
||||
ocf_volume_type_t type;
|
||||
int ret;
|
||||
|
||||
type = ocf_ctx_get_volume_type(cache->owner, device_cfg->volume_type);
|
||||
if (!type) {
|
||||
OCF_PL_FINISH_RET(pipeline,
|
||||
-OCF_ERR_INVAL_VOLUME_TYPE);
|
||||
}
|
||||
|
||||
ret = ocf_volume_init(&cache->device->volume, type,
|
||||
&device_cfg->uuid, true);
|
||||
if (ret)
|
||||
OCF_PL_FINISH_RET(pipeline, ret);
|
||||
|
||||
ocf_volume_move(&cache->device->volume, device_cfg->volume);
|
||||
cache->device->volume.cache = cache;
|
||||
context->flags.volume_inited = true;
|
||||
|
||||
@@ -2473,6 +2399,8 @@ static void _ocf_mngt_activate_handle_error(
|
||||
|
||||
if (context->flags.volume_inited)
|
||||
ocf_volume_deinit(&cache->device->volume);
|
||||
else
|
||||
ocf_volume_deinit(context->cfg.device.volume);
|
||||
|
||||
if (context->flags.volume_stored)
|
||||
ocf_volume_move(&cache->device->volume, &context->cache_volume);
|
||||
@@ -2485,7 +2413,6 @@ static void _ocf_mngt_cache_activate_finish(ocf_pipeline_t pipeline,
|
||||
void *priv, int error)
|
||||
{
|
||||
struct ocf_cache_attach_context *context = priv;
|
||||
struct ocf_mngt_cache_device_config *device_cfg = &context->cfg.device;
|
||||
ocf_cache_t cache = context->cache;
|
||||
ocf_pipeline_t stop_pipeline;
|
||||
|
||||
@@ -2510,12 +2437,9 @@ static void _ocf_mngt_cache_activate_finish(ocf_pipeline_t pipeline,
|
||||
ocf_volume_deinit(&context->cache_volume);
|
||||
}
|
||||
|
||||
|
||||
out:
|
||||
context->cmpl(context->cache, context->priv1, context->priv2, error);
|
||||
|
||||
if (context->flags.uuid_copied)
|
||||
env_vfree(device_cfg->uuid.data);
|
||||
ocf_pipeline_destroy(context->pipeline);
|
||||
}
|
||||
|
||||
@@ -2523,7 +2447,6 @@ struct ocf_pipeline_properties _ocf_mngt_cache_activate_pipeline_properties = {
|
||||
.priv_size = sizeof(struct ocf_cache_attach_context),
|
||||
.finish = _ocf_mngt_cache_activate_finish,
|
||||
.steps = {
|
||||
OCF_PL_STEP(_ocf_mngt_copy_uuid_data),
|
||||
OCF_PL_STEP(_ocf_mngt_activate_set_cache_device),
|
||||
OCF_PL_STEP(_ocf_mngt_activate_init_properties),
|
||||
OCF_PL_STEP(_ocf_mngt_activate_compare_superblock),
|
||||
@@ -2870,10 +2793,7 @@ static int _ocf_mngt_cache_validate_cfg(struct ocf_mngt_cache_config *cfg)
|
||||
static int _ocf_mngt_cache_validate_device_cfg(
|
||||
struct ocf_mngt_cache_device_config *device_cfg)
|
||||
{
|
||||
if (!device_cfg->uuid.data)
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
if (device_cfg->uuid.size > OCF_VOLUME_UUID_MAX_SIZE)
|
||||
if (!device_cfg->volume)
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
return 0;
|
||||
|
||||
387
src/ocf_composite_volume.c
Normal file
387
src/ocf_composite_volume.c
Normal file
@@ -0,0 +1,387 @@
|
||||
/*
|
||||
* Copyright(c) 2022 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#include "ocf/ocf.h"
|
||||
#include "ocf_priv.h"
|
||||
#include "ocf_core_priv.h"
|
||||
#include "ocf_io_priv.h"
|
||||
#include "metadata/metadata.h"
|
||||
#include "engine/cache_engine.h"
|
||||
#include "utils/utils_user_part.h"
|
||||
#include "ocf_request.h"
|
||||
#include "ocf_composite_volume_priv.h"
|
||||
|
||||
#define OCF_COMPOSITE_VOLUME_MEMBERS_MAX 16
|
||||
|
||||
struct ocf_composite_volume {
|
||||
uint8_t members_cnt;
|
||||
struct {
|
||||
struct ocf_volume volume;
|
||||
void *volume_params;
|
||||
} member[OCF_COMPOSITE_VOLUME_MEMBERS_MAX];
|
||||
uint64_t end_addr[OCF_COMPOSITE_VOLUME_MEMBERS_MAX];
|
||||
uint64_t length;
|
||||
unsigned max_io_size;
|
||||
};
|
||||
|
||||
struct ocf_composite_volume_io {
|
||||
struct ocf_io *member_io[OCF_COMPOSITE_VOLUME_MEMBERS_MAX];
|
||||
ctx_data_t *data;
|
||||
uint8_t begin_member;
|
||||
uint8_t end_member;
|
||||
env_atomic remaining;
|
||||
env_atomic error;
|
||||
};
|
||||
|
||||
static void ocf_composite_volume_master_cmpl(struct ocf_io *master_io,
|
||||
int error)
|
||||
{
|
||||
struct ocf_composite_volume_io *cio = ocf_io_get_priv(master_io);
|
||||
|
||||
env_atomic_cmpxchg(&cio->error, 0, error);
|
||||
|
||||
if (env_atomic_dec_return(&cio->remaining))
|
||||
return;
|
||||
|
||||
ocf_io_end(master_io, env_atomic_read(&cio->error));
|
||||
}
|
||||
|
||||
static void ocf_composite_volume_io_cmpl(struct ocf_io *io, int error)
|
||||
{
|
||||
struct ocf_io *master_io = io->priv1;
|
||||
|
||||
ocf_composite_volume_master_cmpl(master_io, error);
|
||||
}
|
||||
|
||||
static void ocf_composite_volume_handle_io(struct ocf_io *master_io,
|
||||
void (*hndl)(struct ocf_io *io))
|
||||
{
|
||||
struct ocf_composite_volume_io *cio = ocf_io_get_priv(master_io);
|
||||
int i;
|
||||
|
||||
env_atomic_set(&cio->remaining,
|
||||
cio->end_member - cio->begin_member + 1);
|
||||
env_atomic_set(&cio->error, 0);
|
||||
|
||||
for (i = cio->begin_member; i < cio->end_member; i++) {
|
||||
ocf_io_set_cmpl(cio->member_io[i], master_io, NULL,
|
||||
ocf_composite_volume_io_cmpl);
|
||||
|
||||
cio->member_io[i]->io_class = master_io->io_class;
|
||||
cio->member_io[i]->flags = master_io->flags;
|
||||
|
||||
hndl(cio->member_io[i]);
|
||||
}
|
||||
|
||||
ocf_composite_volume_master_cmpl(master_io, 0);
|
||||
}
|
||||
|
||||
static void ocf_composite_volume_submit_io(struct ocf_io *master_io)
|
||||
{
|
||||
ocf_composite_volume_handle_io(master_io, ocf_volume_submit_io);
|
||||
}
|
||||
|
||||
static void ocf_composite_volume_submit_flush(struct ocf_io *master_io)
|
||||
{
|
||||
ocf_composite_volume_handle_io(master_io, ocf_volume_submit_flush);
|
||||
}
|
||||
|
||||
static void ocf_composite_volume_submit_discard(struct ocf_io *master_io)
|
||||
{
|
||||
ocf_composite_volume_handle_io(master_io, ocf_volume_submit_discard);
|
||||
}
|
||||
|
||||
/* *** VOLUME OPS *** */
|
||||
|
||||
static int ocf_composite_volume_open(ocf_volume_t cvolume, void *volume_params)
|
||||
{
|
||||
struct ocf_composite_volume *composite = ocf_volume_get_priv(cvolume);
|
||||
int result, i;
|
||||
|
||||
composite->length = 0;
|
||||
composite->max_io_size = UINT_MAX;
|
||||
for (i = 0; i < composite->members_cnt; i++) {
|
||||
ocf_volume_t volume = &composite->member[i].volume;
|
||||
result = ocf_volume_open(volume,
|
||||
composite->member[i].volume_params);
|
||||
if (result)
|
||||
goto err;
|
||||
|
||||
composite->length += ocf_volume_get_length(volume);
|
||||
composite->end_addr[i] = composite->length;
|
||||
composite->max_io_size = OCF_MIN(composite->max_io_size,
|
||||
ocf_volume_get_max_io_size(volume));
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
while (i--)
|
||||
ocf_volume_close(&composite->member[i].volume);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static void ocf_composite_volume_close(ocf_volume_t cvolume)
|
||||
{
|
||||
struct ocf_composite_volume *composite = ocf_volume_get_priv(cvolume);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < composite->members_cnt; i++)
|
||||
ocf_volume_close(&composite->member[i].volume);
|
||||
}
|
||||
|
||||
static unsigned int ocf_composite_volume_get_max_io_size(ocf_volume_t cvolume)
|
||||
{
|
||||
struct ocf_composite_volume *composite = ocf_volume_get_priv(cvolume);
|
||||
|
||||
return composite->max_io_size;
|
||||
}
|
||||
|
||||
static uint64_t ocf_composite_volume_get_byte_length(ocf_volume_t cvolume)
|
||||
{
|
||||
struct ocf_composite_volume *composite = ocf_volume_get_priv(cvolume);
|
||||
|
||||
return composite->length;
|
||||
}
|
||||
|
||||
static void ocf_composite_volume_on_deinit(ocf_volume_t cvolume)
|
||||
{
|
||||
struct ocf_composite_volume *composite = ocf_volume_get_priv(cvolume);
|
||||
int i;
|
||||
|
||||
for (i = 0; i < composite->members_cnt; i++)
|
||||
ocf_volume_deinit(&composite->member[i].volume);
|
||||
}
|
||||
|
||||
/* *** IO OPS *** */
|
||||
|
||||
static int ocf_composite_io_set_data(struct ocf_io *io,
|
||||
ctx_data_t *data, uint32_t offset)
|
||||
{
|
||||
ocf_volume_t cvolume = ocf_io_get_volume(io);
|
||||
struct ocf_composite_volume *composite = ocf_volume_get_priv(cvolume);
|
||||
struct ocf_composite_volume_io *cio = ocf_io_get_priv(io);
|
||||
uint64_t member_volume_start, member_data_offset;
|
||||
int i, ret = 0;
|
||||
|
||||
cio->data = data;
|
||||
|
||||
for (i = cio->begin_member; i < cio->end_member; i++) {
|
||||
/* Each member IO will have the same data set, but with
|
||||
* different offset. First member will use bare offset set from
|
||||
* caller, each subsequent member IO has to skip over parts
|
||||
* "belonging" to previous members. */
|
||||
|
||||
if (i == cio->begin_member) {
|
||||
member_data_offset = offset;
|
||||
} else {
|
||||
member_volume_start = composite->end_addr[i - 1];
|
||||
member_data_offset = member_volume_start - io->addr;
|
||||
member_data_offset += offset;
|
||||
}
|
||||
|
||||
ret = ocf_io_set_data(cio->member_io[i], data,
|
||||
member_data_offset);
|
||||
if (ret)
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static ctx_data_t *ocf_composite_io_get_data(struct ocf_io *io)
|
||||
{
|
||||
struct ocf_composite_volume_io *cio = ocf_io_get_priv(io);
|
||||
|
||||
return cio->data;
|
||||
}
|
||||
|
||||
const struct ocf_volume_properties ocf_composite_volume_properties = {
|
||||
.name = "OCF Composite",
|
||||
.io_priv_size = sizeof(struct ocf_composite_volume_io),
|
||||
.volume_priv_size = sizeof(struct ocf_composite_volume),
|
||||
.caps = {
|
||||
.atomic_writes = 0,
|
||||
},
|
||||
.ops = {
|
||||
.submit_io = ocf_composite_volume_submit_io,
|
||||
.submit_flush = ocf_composite_volume_submit_flush,
|
||||
.submit_discard = ocf_composite_volume_submit_discard,
|
||||
.submit_metadata = NULL,
|
||||
|
||||
.open = ocf_composite_volume_open,
|
||||
.close = ocf_composite_volume_close,
|
||||
.get_max_io_size = ocf_composite_volume_get_max_io_size,
|
||||
.get_length = ocf_composite_volume_get_byte_length,
|
||||
|
||||
.on_deinit = ocf_composite_volume_on_deinit,
|
||||
},
|
||||
.io_ops = {
|
||||
.set_data = ocf_composite_io_set_data,
|
||||
.get_data = ocf_composite_io_get_data,
|
||||
},
|
||||
.deinit = NULL,
|
||||
};
|
||||
|
||||
static int ocf_composite_io_allocator_init(ocf_io_allocator_t allocator,
|
||||
uint32_t priv_size, const char *name)
|
||||
{
|
||||
return ocf_io_allocator_default_init(allocator, priv_size, name);
|
||||
}
|
||||
|
||||
static void ocf_composite_io_allocator_deinit(ocf_io_allocator_t allocator)
|
||||
{
|
||||
ocf_io_allocator_default_deinit(allocator);
|
||||
}
|
||||
|
||||
static void *ocf_composite_io_allocator_new(ocf_io_allocator_t allocator,
|
||||
ocf_volume_t cvolume, ocf_queue_t queue,
|
||||
uint64_t addr, uint32_t bytes, uint32_t dir)
|
||||
{
|
||||
struct ocf_composite_volume *composite = ocf_volume_get_priv(cvolume);
|
||||
struct ocf_composite_volume_io *cio;
|
||||
struct ocf_io_internal *ioi;
|
||||
uint64_t member_addr, member_bytes, cur_addr, cur_bytes;
|
||||
int i;
|
||||
|
||||
ioi = ocf_io_allocator_default_new(allocator, cvolume, queue,
|
||||
addr, bytes, dir);
|
||||
if (!ioi)
|
||||
return NULL;
|
||||
|
||||
cio = ocf_io_get_priv(&ioi->io);
|
||||
|
||||
if (bytes == 0) {
|
||||
/* Flush io - allocate io for each volume */
|
||||
for (i = 0; i < composite->members_cnt; i++) {
|
||||
cio->member_io[i] = ocf_io_new(&composite->member[i].volume,
|
||||
queue, 0, 0, dir, 0, 0);
|
||||
if (!cio->member_io[i])
|
||||
goto err;
|
||||
}
|
||||
cio->begin_member = 0;
|
||||
cio->end_member = composite->members_cnt;
|
||||
|
||||
return ioi;
|
||||
}
|
||||
|
||||
for (i = 0; i < composite->members_cnt; i++) {
|
||||
if (addr < composite->end_addr[i]) {
|
||||
cio->begin_member = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cur_addr = addr;
|
||||
cur_bytes = bytes;
|
||||
|
||||
for (; i < composite->members_cnt; i++) {
|
||||
member_addr = cur_addr - (i > 0 ? composite->end_addr[i-1] : 0);
|
||||
member_bytes =
|
||||
OCF_MIN(cur_addr + cur_bytes, composite->end_addr[i])
|
||||
- member_addr;
|
||||
|
||||
cio->member_io[i] = ocf_io_new(&composite->member[i].volume, queue,
|
||||
member_addr, member_bytes, dir, 0, 0);
|
||||
if (!cio->member_io[i])
|
||||
goto err;
|
||||
|
||||
cur_addr += member_bytes;
|
||||
cur_bytes -= member_bytes;
|
||||
|
||||
if (!cur_bytes) {
|
||||
cio->end_member = i + 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
ENV_BUG_ON(cur_bytes != 0);
|
||||
|
||||
return ioi;
|
||||
|
||||
err:
|
||||
for (i = 0; i < composite->members_cnt; i++) {
|
||||
if (cio->member_io[i])
|
||||
ocf_io_put(cio->member_io[i]);
|
||||
}
|
||||
|
||||
ocf_io_allocator_default_del(allocator, ioi);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static void ocf_composite_io_allocator_del(ocf_io_allocator_t allocator, void *obj)
|
||||
{
|
||||
struct ocf_io_internal *ioi = obj;
|
||||
struct ocf_composite_volume_io *cio = ocf_io_get_priv(&ioi->io);
|
||||
int i;
|
||||
|
||||
for (i = cio->begin_member; i < cio->end_member; i++) {
|
||||
if (cio->member_io[i])
|
||||
ocf_io_put(cio->member_io[i]);
|
||||
}
|
||||
|
||||
ocf_io_allocator_default_del(allocator, ioi);
|
||||
}
|
||||
|
||||
const struct ocf_io_allocator_type ocf_composite_io_allocator_type = {
|
||||
.ops = {
|
||||
.allocator_init = ocf_composite_io_allocator_init,
|
||||
.allocator_deinit = ocf_composite_io_allocator_deinit,
|
||||
.allocator_new = ocf_composite_io_allocator_new,
|
||||
.allocator_del = ocf_composite_io_allocator_del,
|
||||
},
|
||||
};
|
||||
|
||||
const struct ocf_volume_extended ocf_composite_volume_extended = {
|
||||
.allocator_type = &ocf_composite_io_allocator_type,
|
||||
};
|
||||
|
||||
int ocf_composite_volume_type_init(ocf_ctx_t ctx)
|
||||
{
|
||||
return ocf_ctx_register_volume_type_internal(ctx,
|
||||
OCF_VOLUME_TYPE_COMPOSITE,
|
||||
&ocf_composite_volume_properties,
|
||||
&ocf_composite_volume_extended);
|
||||
}
|
||||
|
||||
int ocf_composite_volume_create(ocf_composite_volume_t *volume, ocf_ctx_t ctx)
|
||||
{
|
||||
ocf_volume_type_t type;
|
||||
|
||||
type = ocf_ctx_get_volume_type_internal(ctx, OCF_VOLUME_TYPE_COMPOSITE);
|
||||
if (!type)
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
return ocf_volume_create(volume, type, NULL);
|
||||
}
|
||||
|
||||
void ocf_composite_volume_destroy(ocf_composite_volume_t cvolume)
|
||||
{
|
||||
ocf_volume_destroy(cvolume);
|
||||
}
|
||||
|
||||
int ocf_composite_volume_add(ocf_composite_volume_t cvolume,
|
||||
ocf_volume_type_t type, struct ocf_volume_uuid *uuid,
|
||||
void *volume_params)
|
||||
{
|
||||
struct ocf_composite_volume *composite = ocf_volume_get_priv(cvolume);
|
||||
ocf_volume_t volume;
|
||||
int result;
|
||||
|
||||
if (composite->members_cnt >= OCF_COMPOSITE_VOLUME_MEMBERS_MAX)
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
volume = &composite->member[composite->members_cnt].volume;
|
||||
result = ocf_volume_init(volume, type, uuid, true);
|
||||
if (result)
|
||||
return result;
|
||||
|
||||
composite->member[composite->members_cnt].volume_params = volume_params;
|
||||
composite->members_cnt++;
|
||||
|
||||
return 0;
|
||||
}
|
||||
13
src/ocf_composite_volume_priv.h
Normal file
13
src/ocf_composite_volume_priv.h
Normal file
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* Copyright(c) 2022 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause-Clear
|
||||
*/
|
||||
|
||||
#ifndef __OCF_COMPOSITE_VOLUME_PRIV_H__
|
||||
#define __OCF_COMPOSITE_VOLUME_PRIV_H__
|
||||
|
||||
#include "ocf/ocf.h"
|
||||
|
||||
int ocf_composite_volume_type_init(ocf_ctx_t ctx);
|
||||
|
||||
#endif /* __OCF_COMPOSITE_VOLUME_H__ */
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2021 Intel Corporation
|
||||
* Copyright(c) 2012-2022 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include "ocf_logger_priv.h"
|
||||
#include "ocf_core_priv.h"
|
||||
#include "ocf_cache_priv.h"
|
||||
#include "ocf_composite_volume_priv.h"
|
||||
#include "mngt/ocf_mngt_core_pool_priv.h"
|
||||
#include "metadata/metadata_io.h"
|
||||
|
||||
@@ -220,12 +221,18 @@ int ocf_ctx_create(ocf_ctx_t *ctx, const struct ocf_ctx_config *cfg)
|
||||
if (ret)
|
||||
goto err_utils;
|
||||
|
||||
ret = ocf_composite_volume_type_init(ocf_ctx);
|
||||
if (ret)
|
||||
goto err_core_volume;
|
||||
|
||||
ocf_mngt_core_pool_init(ocf_ctx);
|
||||
|
||||
*ctx = ocf_ctx;
|
||||
|
||||
return 0;
|
||||
|
||||
err_core_volume:
|
||||
ocf_ctx_unregister_volume_type(ocf_ctx, OCF_VOLUME_TYPE_CORE);
|
||||
err_utils:
|
||||
ocf_metadata_io_ctx_deinit(ocf_ctx);
|
||||
err_mio:
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2021 Intel Corporation
|
||||
* Copyright(c) 2012-2022 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
@@ -12,13 +12,14 @@
|
||||
#include "ocf_volume_priv.h"
|
||||
|
||||
#define OCF_VOLUME_TYPE_CNT_USER 8
|
||||
#define OCF_VOLUME_TYPE_CNT_PRIV 2
|
||||
#define OCF_VOLUME_TYPE_CNT_PRIV 3
|
||||
#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)
|
||||
#define OCF_VOLUME_TYPE_CACHE (OCF_VOLUME_TYPE_MAX_USER + 1)
|
||||
#define OCF_VOLUME_TYPE_COMPOSITE (OCF_VOLUME_TYPE_MAX_USER + 2)
|
||||
|
||||
/**
|
||||
* @brief OCF main control structure
|
||||
|
||||
10
src/ocf_io.c
10
src/ocf_io.c
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2021 Intel Corporation
|
||||
* Copyright(c) 2012-2022 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
#define OCF_IO_TOTAL(priv_size) \
|
||||
(sizeof(struct ocf_io_internal) + priv_size)
|
||||
|
||||
static int ocf_io_allocator_default_init(ocf_io_allocator_t allocator,
|
||||
int ocf_io_allocator_default_init(ocf_io_allocator_t allocator,
|
||||
uint32_t priv_size, const char *name)
|
||||
{
|
||||
allocator->priv = env_allocator_create(OCF_IO_TOTAL(priv_size), name,
|
||||
@@ -42,20 +42,20 @@ static int ocf_io_allocator_default_init(ocf_io_allocator_t allocator,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void ocf_io_allocator_default_deinit(ocf_io_allocator_t allocator)
|
||||
void ocf_io_allocator_default_deinit(ocf_io_allocator_t allocator)
|
||||
{
|
||||
env_allocator_destroy(allocator->priv);
|
||||
allocator->priv = NULL;
|
||||
}
|
||||
|
||||
static void *ocf_io_allocator_default_new(ocf_io_allocator_t allocator,
|
||||
void *ocf_io_allocator_default_new(ocf_io_allocator_t allocator,
|
||||
ocf_volume_t volume, ocf_queue_t queue,
|
||||
uint64_t addr, uint32_t bytes, uint32_t dir)
|
||||
{
|
||||
return env_allocator_new(allocator->priv);
|
||||
}
|
||||
|
||||
static void ocf_io_allocator_default_del(ocf_io_allocator_t allocator, void *obj)
|
||||
void ocf_io_allocator_default_del(ocf_io_allocator_t allocator, void *obj)
|
||||
{
|
||||
env_allocator_del(allocator->priv, obj);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2021 Intel Corporation
|
||||
* Copyright(c) 2012-2022 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
@@ -27,6 +27,17 @@ static inline struct ocf_io_internal *ocf_io_get_internal(struct ocf_io* io)
|
||||
return container_of(io, struct ocf_io_internal, io);
|
||||
}
|
||||
|
||||
int ocf_io_allocator_default_init(ocf_io_allocator_t allocator,
|
||||
uint32_t priv_size, const char *name);
|
||||
|
||||
void ocf_io_allocator_default_deinit(ocf_io_allocator_t allocator);
|
||||
|
||||
void *ocf_io_allocator_default_new(ocf_io_allocator_t allocator,
|
||||
ocf_volume_t volume, ocf_queue_t queue,
|
||||
uint64_t addr, uint32_t bytes, uint32_t dir);
|
||||
|
||||
void ocf_io_allocator_default_del(ocf_io_allocator_t allocator, void *obj);
|
||||
|
||||
int ocf_io_allocator_init(ocf_io_allocator_t allocator, ocf_io_allocator_type_t type,
|
||||
uint32_t priv_size, const char *name);
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright(c) 2012-2021 Intel Corporation
|
||||
* Copyright(c) 2012-2022 Intel Corporation
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
@@ -94,57 +94,73 @@ int ocf_volume_init(ocf_volume_t volume, ocf_volume_type_t type,
|
||||
return -OCF_ERR_INVAL;
|
||||
|
||||
priv_size = type->properties->volume_priv_size;
|
||||
|
||||
volume->opened = false;
|
||||
volume->type = type;
|
||||
|
||||
volume->priv = env_zalloc(priv_size, ENV_MEM_NORMAL);
|
||||
if (!volume->priv)
|
||||
return -OCF_ERR_NO_MEM;
|
||||
|
||||
volume->opened = false;
|
||||
volume->type = type;
|
||||
|
||||
volume->uuid.size = 0;
|
||||
volume->uuid.data = NULL;
|
||||
volume->uuid_copy = false;
|
||||
|
||||
ocf_refcnt_init(&volume->refcnt);
|
||||
ocf_refcnt_freeze(&volume->refcnt);
|
||||
|
||||
if (!uuid) {
|
||||
volume->uuid.size = 0;
|
||||
volume->uuid.data = NULL;
|
||||
volume->uuid_copy = false;
|
||||
if (!uuid)
|
||||
return 0;
|
||||
}
|
||||
|
||||
volume->uuid_copy = uuid_copy;
|
||||
|
||||
if (uuid_copy) {
|
||||
data = env_vmalloc(uuid->size);
|
||||
if (!data)
|
||||
goto err;
|
||||
|
||||
ret = env_memcpy(data, uuid->size, uuid->data, uuid->size);
|
||||
if (ret) {
|
||||
env_vfree(data);
|
||||
if (!data) {
|
||||
ret = -OCF_ERR_NO_MEM;
|
||||
goto err;
|
||||
}
|
||||
|
||||
volume->uuid.data = data;
|
||||
|
||||
ret = env_memcpy(data, uuid->size, uuid->data, uuid->size);
|
||||
if (ret) {
|
||||
ret = -OCF_ERR_INVAL;
|
||||
goto err;
|
||||
}
|
||||
} else {
|
||||
volume->uuid.data = uuid->data;
|
||||
}
|
||||
|
||||
volume->uuid.size = uuid->size;
|
||||
|
||||
if (volume->type->properties->ops.on_init) {
|
||||
ret = volume->type->properties->ops.on_init(volume);
|
||||
if (ret)
|
||||
goto err;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
err:
|
||||
ocf_refcnt_unfreeze(&volume->refcnt);
|
||||
env_free(volume->priv);
|
||||
return -OCF_ERR_NO_MEM;
|
||||
volume->priv = NULL;
|
||||
if (volume->uuid_copy && volume->uuid.data)
|
||||
env_vfree(volume->uuid.data);
|
||||
volume->uuid.data = NULL;
|
||||
volume->uuid.size = 0;
|
||||
return ret;
|
||||
}
|
||||
|
||||
void ocf_volume_deinit(ocf_volume_t volume)
|
||||
{
|
||||
OCF_CHECK_NULL(volume);
|
||||
|
||||
if (volume->type && volume->type->properties->ops.on_deinit)
|
||||
volume->type->properties->ops.on_deinit(volume);
|
||||
|
||||
env_free(volume->priv);
|
||||
volume->priv = NULL;
|
||||
|
||||
if (volume->uuid_copy && volume->uuid.data) {
|
||||
env_vfree(volume->uuid.data);
|
||||
|
||||
Reference in New Issue
Block a user