Skip to content

Commit

Permalink
Merge pull request #831 from mmichal10/io_forward_pt2
Browse files Browse the repository at this point in the history
Io forward pt2
  • Loading branch information
robertbaldyga committed Sep 20, 2024
2 parents c7580a7 + 3fbb757 commit 6907abe
Show file tree
Hide file tree
Showing 53 changed files with 1,425 additions and 1,876 deletions.
6 changes: 3 additions & 3 deletions example/simple/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ int initialize_core(ocf_cache_t cache, ocf_core_t *core)
/*
* Callback function called when write completes.
*/
void complete_write(struct ocf_io *io, int error)
void complete_write(ocf_io_t io, void *priv1, void *priv2, int error)
{
struct volume_data *data = ocf_io_get_data(io);

Expand All @@ -253,7 +253,7 @@ void complete_write(struct ocf_io *io, int error)
/*
* Callback function called when read completes.
*/
void complete_read(struct ocf_io *io, int error)
void complete_read(ocf_io_t io, void *priv1, void *priv2, int error)
{
struct volume_data *data = ocf_io_get_data(io);

Expand All @@ -274,7 +274,7 @@ int submit_io(ocf_core_t core, struct volume_data *data,
ocf_cache_t cache = ocf_core_get_cache(core);
ocf_volume_t core_vol = ocf_core_get_front_volume(core);
struct cache_priv *cache_priv = ocf_cache_get_priv(cache);
struct ocf_io *io;
ocf_io_t io;

/* Allocate new io */
io = ocf_volume_new_io(core_vol, cache_priv->io_queue, addr, len, dir, 0, 0);
Expand Down
80 changes: 1 addition & 79 deletions example/simple/src/volume.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,57 +43,11 @@ 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)
{
struct ocf_io *io = ocf_forward_get_io(token);
struct myvolume *myvolume = ocf_volume_get_priv(volume);
struct volume_data *data = ocf_io_get_data(io);
struct volume_data *data = ocf_forward_get_data(token);

if (dir == OCF_WRITE) {
memcpy(myvolume->mem + addr,
Expand Down Expand Up @@ -139,58 +93,26 @@ 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
* or core.
*/
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,
},
.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,
},
};

/*
Expand Down
6 changes: 1 addition & 5 deletions example/simple/src/volume.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2019-2021 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand All @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions inc/ocf_core.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*
* Copyright(c) 2012-2022 Intel Corporation
* Copyright(c) 2024 Huawei Technologies
* SPDX-License-Identifier: BSD-3-Clause
*/

Expand Down Expand Up @@ -151,7 +152,7 @@ ocf_core_state_t ocf_core_get_state(ocf_core_t core);
*
* @param[in] io IO to be submitted
*/
static inline void ocf_core_submit_io(struct ocf_io *io)
static inline void ocf_core_submit_io(ocf_io_t io)
{
ocf_volume_submit_io(io);
}
Expand All @@ -161,7 +162,7 @@ static inline void ocf_core_submit_io(struct ocf_io *io)
*
* @param[in] io IO to be submitted
*/
static inline void ocf_core_submit_flush(struct ocf_io *io)
static inline void ocf_core_submit_flush(ocf_io_t io)
{
ocf_volume_submit_flush(io);
}
Expand All @@ -171,7 +172,7 @@ static inline void ocf_core_submit_flush(struct ocf_io *io)
*
* @param[in] io IO to be submitted
*/
static inline void ocf_core_submit_discard(struct ocf_io *io)
static inline void ocf_core_submit_discard(ocf_io_t io)
{
ocf_volume_submit_discard(io);
}
Expand Down
Loading

0 comments on commit 6907abe

Please sign in to comment.