Rename "data object" to "volume"

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga
2019-02-08 12:19:04 +01:00
parent 21012df2f8
commit 97300b1137
65 changed files with 1420 additions and 1386 deletions

View File

@@ -7,7 +7,7 @@
#include <ocf/ocf.h>
#include "ocf_env.h"
#include "data.h"
#include "dobj.h"
#include "volume.h"
#include "ctx.h"
#define PAGE_SIZE 4096
@@ -17,7 +17,7 @@
*/
ctx_data_t *ctx_data_alloc(uint32_t pages)
{
struct dobj_data *data;
struct volume_data *data;
data = malloc(sizeof(*data));
data->ptr = malloc(pages * PAGE_SIZE);
@@ -31,7 +31,7 @@ ctx_data_t *ctx_data_alloc(uint32_t pages)
*/
void ctx_data_free(ctx_data_t *ctx_data)
{
struct dobj_data *data = ctx_data;
struct volume_data *data = ctx_data;
if (!data)
return;
@@ -61,7 +61,7 @@ static void ctx_data_munlock(ctx_data_t *ctx_data)
*/
static uint32_t ctx_data_read(void *dst, ctx_data_t *src, uint32_t size)
{
struct dobj_data *data = src;
struct volume_data *data = src;
memcpy(dst, data->ptr + data->offset, size);
@@ -73,7 +73,7 @@ static uint32_t ctx_data_read(void *dst, ctx_data_t *src, uint32_t size)
*/
static uint32_t ctx_data_write(ctx_data_t *dst, const void *src, uint32_t size)
{
struct dobj_data *data = dst;
struct volume_data *data = dst;
memcpy(data->ptr + data->offset, src, size);
@@ -85,7 +85,7 @@ static uint32_t ctx_data_write(ctx_data_t *dst, const void *src, uint32_t size)
*/
static uint32_t ctx_data_zero(ctx_data_t *dst, uint32_t size)
{
struct dobj_data *data = dst;
struct volume_data *data = dst;
memset(data->ptr + data->offset, 0, size);
@@ -98,7 +98,7 @@ static uint32_t ctx_data_zero(ctx_data_t *dst, uint32_t size)
static uint32_t ctx_data_seek(ctx_data_t *dst, ctx_data_seek_t seek,
uint32_t offset)
{
struct dobj_data *data = dst;
struct volume_data *data = dst;
switch (seek) {
case ctx_data_seek_begin:
@@ -118,8 +118,8 @@ static uint32_t ctx_data_seek(ctx_data_t *dst, ctx_data_seek_t seek,
static uint64_t ctx_data_copy(ctx_data_t *dst, ctx_data_t *src,
uint64_t to, uint64_t from, uint64_t bytes)
{
struct dobj_data *data_dst = dst;
struct dobj_data *data_src = src;
struct volume_data *data_dst = dst;
struct volume_data *data_src = src;
memcpy(data_dst->ptr + to, data_src->ptr + from, bytes);
@@ -308,7 +308,7 @@ static const struct ocf_ctx_config ctx_cfg = {
/*
* Function initializing context. Prepares context, sets logger and
* registers data object type.
* registers volume type.
*/
int ctx_init(ocf_ctx_t *ctx)
{
@@ -318,7 +318,7 @@ int ctx_init(ocf_ctx_t *ctx)
if (ret)
return ret;
ret = dobj_init(*ctx);
ret = volume_init(*ctx);
if (ret) {
ocf_ctx_exit(*ctx);
return ret;
@@ -328,11 +328,11 @@ int ctx_init(ocf_ctx_t *ctx)
}
/*
* Function cleaning up context. Unregisters data object type and
* Function cleaning up context. Unregisters volume type and
* deinitializes context.
*/
void ctx_cleanup(ocf_ctx_t ctx)
{
dobj_cleanup(ctx);
volume_cleanup(ctx);
ocf_ctx_exit(ctx);
}

View File

@@ -8,7 +8,7 @@
#include <ocf/ocf.h>
#define OBJ_TYPE 1
#define VOL_TYPE 1
ctx_data_t *ctx_data_alloc(uint32_t pages);
void ctx_data_free(ctx_data_t *ctx_data);

View File

@@ -6,7 +6,7 @@
#ifndef __DATA_H__
#define __DATA_H__
struct dobj_data {
struct volume_data {
void *ptr;
int offset;
};

View File

@@ -1,168 +0,0 @@
/*
* Copyright(c) 2019 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include <ocf/ocf.h>
#include "dobj.h"
#include "data.h"
#include "ctx.h"
#define DOBJ_SIZE 200*1024*1024
/*
* In open() function we store uuid data as object name (for debug messages)
* and allocate 200 MiB of memory to simulate backend storage device.
*/
static int dobj_open(ocf_data_obj_t obj)
{
const struct ocf_data_obj_uuid *uuid = ocf_dobj_get_uuid(obj);
struct dobj *dobj = ocf_dobj_get_priv(obj);
dobj->name = ocf_uuid_to_str(uuid);
dobj->mem = malloc(DOBJ_SIZE);
printf("DOBJ OPEN: (name: %s)\n", dobj->name);
return 0;
}
/*
* In close() function we just free memory allocated in open().
*/
static void dobj_close(ocf_data_obj_t obj)
{
struct dobj *dobj = ocf_dobj_get_priv(obj);
printf("DOBJ CLOSE: (name: %s)\n", dobj->name);
free(dobj->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 dobj_submit_io(struct ocf_io *io)
{
struct dobj_data *data;
struct dobj *dobj;
data = ocf_io_get_data(io);
dobj = ocf_dobj_get_priv(io->obj);
if (io->dir == OCF_WRITE) {
memcpy(dobj->mem + io->addr,
data->ptr + data->offset, io->bytes);
} else {
memcpy(data->ptr + data->offset,
dobj->mem + io->addr, io->bytes);
}
printf("DOBJ: (name: %s), IO: (dir: %s, addr: %ld, bytes: %d)\n",
dobj->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 dobj_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 dobj_submit_discard(struct ocf_io *io)
{
io->end(io, 0);
}
/*
* Let's set maximum io size to 128 KiB.
*/
static unsigned int dobj_get_max_io_size(ocf_data_obj_t obj)
{
return 128 * 1024;
}
/*
* Return data object size.
*/
static uint64_t dobj_get_length(ocf_data_obj_t obj)
{
return DOBJ_SIZE;
}
/*
* In set_data() we just assing data and offset to io.
*/
static int dobj_io_set_data(struct ocf_io *io, ctx_data_t *data,
uint32_t offset)
{
struct dobj_io *dobj_io = ocf_io_get_priv(io);
dobj_io->data = data;
dobj_io->offset = offset;
return 0;
}
/*
* In get_data() return data stored in io.
*/
static ctx_data_t *dobj_io_get_data(struct ocf_io *io)
{
struct dobj_io *dobj_io = ocf_io_get_priv(io);
return dobj_io->data;
}
/*
* This structure contains data object properties. It describes data object
* type, which can be later instantiated as backend storage object for cache
* or core.
*/
const struct ocf_data_obj_properties dobj_properties = {
.name = "Example dobj",
.io_priv_size = sizeof(struct dobj_io),
.dobj_priv_size = sizeof(struct dobj),
.caps = {
.atomic_writes = 0,
},
.ops = {
.open = dobj_open,
.close = dobj_close,
.submit_io = dobj_submit_io,
.submit_flush = dobj_submit_flush,
.submit_discard = dobj_submit_discard,
.get_max_io_size = dobj_get_max_io_size,
.get_length = dobj_get_length,
},
.io_ops = {
.set_data = dobj_io_set_data,
.get_data = dobj_io_get_data,
},
};
/*
* This function registers data object type in OCF context.
* It should be called just after context initialization.
*/
int dobj_init(ocf_ctx_t ocf_ctx)
{
return ocf_ctx_register_data_obj_type(ocf_ctx, OBJ_TYPE,
&dobj_properties);
}
/*
* This function unregisters data object type in OCF context.
* It should be called just before context cleanup.
*/
void dobj_cleanup(ocf_ctx_t ocf_ctx)
{
ocf_ctx_unregister_data_obj_type(ocf_ctx, OBJ_TYPE);
}

View File

@@ -36,8 +36,8 @@ int initialize_cache(ocf_ctx_t ctx, ocf_cache_t *cache)
cache_cfg.io_queues = 1;
cache_cfg.name = "cache1";
/* Cache deivce (data object) configuration */
device_cfg.data_obj_type = OBJ_TYPE;
/* Cache deivce (volume) configuration */
device_cfg.volume_type = VOL_TYPE;
device_cfg.cache_line_size = ocf_cache_line_size_4;
ret = ocf_uuid_set_str(&device_cfg.uuid, "cache");
if (ret)
@@ -48,7 +48,7 @@ int initialize_cache(ocf_ctx_t ctx, ocf_cache_t *cache)
if (ret)
return ret;
/* Attach data object to cache */
/* Attach volume to cache */
ret = ocf_mngt_cache_attach(*cache, &device_cfg);
if (ret) {
ocf_mngt_cache_stop(*cache);
@@ -67,7 +67,7 @@ int initialize_core(ocf_cache_t cache, ocf_core_t *core)
int ret;
/* Core configuration */
core_cfg.data_obj_type = OBJ_TYPE;
core_cfg.volume_type = VOL_TYPE;
core_cfg.name = "core1";
ret = ocf_uuid_set_str(&core_cfg.uuid, "core");
if (ret)
@@ -82,7 +82,7 @@ int initialize_core(ocf_cache_t cache, ocf_core_t *core)
*/
void complete_write(struct ocf_io *io, int error)
{
struct dobj_data *data = ocf_io_get_data(io);
struct volume_data *data = ocf_io_get_data(io);
printf("WRITE COMPLETE: (error: %d)\n", error);
@@ -96,7 +96,7 @@ void complete_write(struct ocf_io *io, int error)
*/
void complete_read(struct ocf_io *io, int error)
{
struct dobj_data *data = ocf_io_get_data(io);
struct volume_data *data = ocf_io_get_data(io);
printf("WRITE COMPLETE (error: %d)\n", error);
printf("DATA: \"%s\"\n", (char *)data->ptr);
@@ -109,7 +109,7 @@ void complete_read(struct ocf_io *io, int error)
/*
* Wrapper function for io submition.
*/
int submit_io(ocf_core_t core, struct dobj_data *data,
int submit_io(ocf_core_t core, struct volume_data *data,
uint64_t addr, uint64_t len, int dir, ocf_end_io_t cmpl)
{
struct ocf_io *io;
@@ -154,7 +154,7 @@ int submit_io(ocf_core_t core, struct dobj_data *data,
*/
void perform_workload(ocf_core_t core)
{
struct dobj_data *data1, *data2;
struct volume_data *data1, *data2;
/* Allocate data buffer and fill it with example data */
data1 = ctx_data_alloc(1);

168
example/simple/src/volume.c Normal file
View File

@@ -0,0 +1,168 @@
/*
* Copyright(c) 2019 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include <ocf/ocf.h>
#include "volume.h"
#include "data.h"
#include "ctx.h"
#define VOL_SIZE 200*1024*1024
/*
* In open() function we store uuid data as volume name (for debug messages)
* and allocate 200 MiB of memory to simulate backend storage device.
*/
static int volume_open(ocf_volume_t volume)
{
const struct ocf_volume_uuid *uuid = ocf_volume_get_uuid(volume);
struct myvolume *myvolume = ocf_volume_get_priv(volume);
myvolume->name = ocf_uuid_to_str(uuid);
myvolume->mem = malloc(VOL_SIZE);
printf("VOL OPEN: (name: %s)\n", myvolume->name);
return 0;
}
/*
* In close() function we just free memory allocated in open().
*/
static void volume_close(ocf_volume_t volume)
{
struct myvolume *myvolume = ocf_volume_get_priv(volume);
printf("VOL CLOSE: (name: %s)\n", myvolume->name);
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 volume_data *data;
struct myvolume *myvolume;
data = ocf_io_get_data(io);
myvolume = ocf_volume_get_priv(io->volume);
if (io->dir == OCF_WRITE) {
memcpy(myvolume->mem + io->addr,
data->ptr + data->offset, io->bytes);
} else {
memcpy(data->ptr + data->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);
}
/*
* Let's set maximum io size to 128 KiB.
*/
static unsigned int volume_get_max_io_size(ocf_volume_t volume)
{
return 128 * 1024;
}
/*
* Return volume size.
*/
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,
.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,
},
};
/*
* This function registers volume type in OCF context.
* It should be called just after context initialization.
*/
int volume_init(ocf_ctx_t ocf_ctx)
{
return ocf_ctx_register_volume_type(ocf_ctx, VOL_TYPE,
&volume_properties);
}
/*
* This function unregisters volume type in OCF context.
* It should be called just before context cleanup.
*/
void volume_cleanup(ocf_ctx_t ocf_ctx)
{
ocf_ctx_unregister_volume_type(ocf_ctx, VOL_TYPE);
}

View File

@@ -3,25 +3,25 @@
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __DOBJ_H__
#define __DOBJ_H__
#ifndef __VOLUME_H__
#define __VOLUME_H__
#include <ocf/ocf.h>
#include "ocf_env.h"
#include "ctx.h"
#include "data.h"
struct dobj_io {
struct dobj_data *data;
struct myvolume_io {
struct volume_data *data;
uint32_t offset;
};
struct dobj {
struct myvolume {
uint8_t *mem;
const char *name;
};
int dobj_init(ocf_ctx_t ocf_ctx);
void dobj_cleanup(ocf_ctx_t ocf_ctx);
int volume_init(ocf_ctx_t ocf_ctx);
void volume_cleanup(ocf_ctx_t ocf_ctx);
#endif