Drop support for submit_* ops in backend volumes
Signed-off-by: Robert Baldyga <robert.baldyga@huawei.com> Signed-off-by: Michal Mielewczyk <michal.mielewczyk@huawei.com>
This commit is contained in:
parent
39d566c280
commit
7fb6b62825
@ -43,51 +43,6 @@ static void volume_close(ocf_volume_t volume)
|
||||
free(myvolume->mem);
|
||||
}
|
||||
|
||||
/*
|
||||
* In submit_io() function we simulate read or write to backend storage device
|
||||
* by doing memcpy() to or from previously allocated memory buffer.
|
||||
*/
|
||||
static void volume_submit_io(struct ocf_io *io)
|
||||
{
|
||||
struct myvolume_io *myvolume_io = ocf_io_get_priv(io);
|
||||
struct volume_data *data;
|
||||
struct myvolume *myvolume;
|
||||
uint32_t offset = myvolume_io->offset;
|
||||
|
||||
data = ocf_io_get_data(io);
|
||||
myvolume = ocf_volume_get_priv(ocf_io_get_volume(io));
|
||||
|
||||
if (io->dir == OCF_WRITE) {
|
||||
memcpy(myvolume->mem + io->addr,
|
||||
data->ptr + offset, io->bytes);
|
||||
} else {
|
||||
memcpy(data->ptr + offset,
|
||||
myvolume->mem + io->addr, io->bytes);
|
||||
}
|
||||
|
||||
printf("VOL: (name: %s), IO: (dir: %s, addr: %ld, bytes: %d)\n",
|
||||
myvolume->name, io->dir == OCF_READ ? "read" : "write",
|
||||
io->addr, io->bytes);
|
||||
|
||||
io->end(io, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* We don't need to implement submit_flush(). Just complete io with success.
|
||||
*/
|
||||
static void volume_submit_flush(struct ocf_io *io)
|
||||
{
|
||||
io->end(io, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* We don't need to implement submit_discard(). Just complete io with success.
|
||||
*/
|
||||
static void volume_submit_discard(struct ocf_io *io)
|
||||
{
|
||||
io->end(io, 0);
|
||||
}
|
||||
|
||||
void volume_forward_io(ocf_volume_t volume, ocf_forward_token_t token,
|
||||
int dir, uint64_t addr, uint64_t bytes, uint64_t offset)
|
||||
{
|
||||
@ -138,30 +93,6 @@ static uint64_t volume_get_length(ocf_volume_t volume)
|
||||
return VOL_SIZE;
|
||||
}
|
||||
|
||||
/*
|
||||
* In set_data() we just assing data and offset to io.
|
||||
*/
|
||||
static int myvolume_io_set_data(struct ocf_io *io, ctx_data_t *data,
|
||||
uint32_t offset)
|
||||
{
|
||||
struct myvolume_io *myvolume_io = ocf_io_get_priv(io);
|
||||
|
||||
myvolume_io->data = data;
|
||||
myvolume_io->offset = offset;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* In get_data() return data stored in io.
|
||||
*/
|
||||
static ctx_data_t *myvolume_io_get_data(struct ocf_io *io)
|
||||
{
|
||||
struct myvolume_io *myvolume_io = ocf_io_get_priv(io);
|
||||
|
||||
return myvolume_io->data;
|
||||
}
|
||||
|
||||
/*
|
||||
* This structure contains volume properties. It describes volume
|
||||
* type, which can be later instantiated as backend storage for cache
|
||||
@ -169,7 +100,6 @@ static ctx_data_t *myvolume_io_get_data(struct ocf_io *io)
|
||||
*/
|
||||
const struct ocf_volume_properties volume_properties = {
|
||||
.name = "Example volume",
|
||||
.io_priv_size = sizeof(struct myvolume_io),
|
||||
.volume_priv_size = sizeof(struct myvolume),
|
||||
.caps = {
|
||||
.atomic_writes = 0,
|
||||
@ -177,19 +107,12 @@ const struct ocf_volume_properties volume_properties = {
|
||||
.ops = {
|
||||
.open = volume_open,
|
||||
.close = volume_close,
|
||||
.submit_io = volume_submit_io,
|
||||
.submit_flush = volume_submit_flush,
|
||||
.submit_discard = volume_submit_discard,
|
||||
.forward_io = volume_forward_io,
|
||||
.forward_flush = volume_forward_flush,
|
||||
.forward_discard = volume_forward_discard,
|
||||
.get_max_io_size = volume_get_max_io_size,
|
||||
.get_length = volume_get_length,
|
||||
},
|
||||
.io_ops = {
|
||||
.set_data = myvolume_io_set_data,
|
||||
.get_data = myvolume_io_get_data,
|
||||
},
|
||||
};
|
||||
|
||||
/*
|
||||
|
@ -1,5 +1,6 @@
|
||||
/*
|
||||
* Copyright(c) 2019-2021 Intel Corporation
|
||||
* Copyright(c) 2024 Huawei Technologies
|
||||
* SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
@ -11,11 +12,6 @@
|
||||
#include "ctx.h"
|
||||
#include "data.h"
|
||||
|
||||
struct myvolume_io {
|
||||
struct volume_data *data;
|
||||
uint32_t offset;
|
||||
};
|
||||
|
||||
struct myvolume {
|
||||
uint8_t *mem;
|
||||
const char *name;
|
||||
|
@ -27,73 +27,6 @@ struct ocf_composite_volume {
|
||||
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);
|
||||
}
|
||||
|
||||
void ocf_composite_forward_io(ocf_volume_t cvolume,
|
||||
ocf_forward_token_t token, int dir, uint64_t addr,
|
||||
uint64_t bytes, uint64_t offset)
|
||||
@ -392,61 +325,13 @@ static void ocf_composite_volume_on_deinit(ocf_volume_t cvolume)
|
||||
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,
|
||||
.forward_io = ocf_composite_forward_io,
|
||||
.forward_flush = ocf_composite_forward_flush,
|
||||
.forward_discard = ocf_composite_forward_discard,
|
||||
@ -461,133 +346,14 @@ const struct ocf_volume_properties ocf_composite_volume_properties = {
|
||||
|
||||
.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])
|
||||
- cur_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);
|
||||
&ocf_composite_volume_properties, NULL);
|
||||
}
|
||||
|
||||
int ocf_composite_volume_create(ocf_composite_volume_t *volume, ocf_ctx_t ctx)
|
||||
|
@ -39,8 +39,8 @@ int ocf_volume_type_init(struct ocf_volume_type **type,
|
||||
struct ocf_volume_type *new_type;
|
||||
int ret;
|
||||
|
||||
if (!ops->submit_io || !ops->open || !ops->close ||
|
||||
!ops->get_max_io_size || !ops->get_length) {
|
||||
if (!ops->open || !ops->close || !ops->get_max_io_size ||
|
||||
!ops->get_length) {
|
||||
return -OCF_ERR_INVAL;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user