Merge pull request #58 from robertbaldyga/rename-data-obj-to-volume

Rename "data object" to "volume"
This commit is contained in:
Michal Rakowski 2019-02-08 14:33:18 +01:00 committed by GitHub
commit 709c9a872b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
65 changed files with 1420 additions and 1386 deletions

View File

@ -19,7 +19,7 @@ For this usage model OCF comes with following adaptation layers:
cache volume representing primary storage device. Application can
read/write from/to the cache volume block device as to regular primary
storage device.
- <b>Block device data object (bottom adapter)</b> - is responsible for issuing
- <b>Block device volume (bottom adapter)</b> - is responsible for issuing
IO operations to underlying block device.
A system administrator can manage cache instances via Intel CAS CLI management
@ -31,7 +31,7 @@ Another example of OCF usage is user space block level cache for QEMU
(see picture below). In this example following adaptation layers may exist:
- <b>CAS virtIO-blk driver for QEMU (top adapter)</b> - it exposes
primary storage device (another virtIO driver) to guest OS via OCF library
- <b>virtIO-blk data object (bottom adapter)</b> - enables OCF to access
- <b>virtIO-blk volume (bottom adapter)</b> - enables OCF to access
data on primary storage device or cache device via original virtIO driver
Please note that actual adapters depend on the environment where OCF is
@ -55,7 +55,7 @@ For more details please see below examples:
OCF enables possibility use it simultaneously from two independent libraries linked
into the same executable by means of concept of contexts. Each context has its own
set of operations which allow to handle specific data types used by data objects
set of operations which allow to handle specific data types used by volumes
within this context.
```c
@ -69,21 +69,21 @@ const struct ocf_ctx_ops ctx_ops = {
/* Fill your interface functions */
};
/* Your unique data object type IDs */
enum my_data_obj_type {
my_data_obj_type_1,
my_data_obj_type_2
/* Your unique volume type IDs */
enum my_volume_type {
my_volume_type_1,
my_volume_type_2
};
/* Your data objects interface declaration */
const struct ocf_data_obj_ops my_data_obj_ops1 = {
.name = "My data object 1",
/* Fill your data object interface functions */
/* Your volumes interface declaration */
const struct ocf_volume_ops my_volume_ops1 = {
.name = "My volume 1",
/* Fill your volume interface functions */
};
const struct ocf_data_obj_ops my_data_obj_ops2 = {
.name = "My data object 2"
/* Fill your data object interface functions */
const struct ocf_volume_ops my_volume_ops2 = {
.name = "My volume 2"
/* Fill your volume interface functions */
};
int my_cache_init(void)
@ -97,18 +97,18 @@ int my_cache_init(void)
}
/* Initialization successful */
/* Now we can register data objects */
result |= ocf_ctx_register_data_obj_ops(ctx, &my_data_obj_ops1,
my_data_obj_type_1);
/* Now we can register volumes */
result |= ocf_ctx_register_volume_ops(ctx, &my_volume_ops1,
my_volume_type_1);
if (result) {
/* Cannot register data object interface */
/* Cannot register volume interface */
goto err;
}
result |= ocf_ctx_register_data_obj_ops(ctx, &my_data_obj_ops2,
my_data_obj_type_2);
result |= ocf_ctx_register_volume_ops(ctx, &my_volume_ops2,
my_volume_type_2);
if (result) {
/* Cannot register data object interface */
/* Cannot register volume interface */
goto err;
}
@ -141,8 +141,8 @@ cfg.init_mode = ocf_init_mode_init;
cfg.uuid.data = "/path/to/your/cache/or/unique/id";
/* Specify cache data object type */
cfg.data_obj_type = my_data_obj_type_1;
/* Specify cache volume type */
cfg.volume_type = my_volume_type_1;
/* Other cache configuration */
...
@ -162,8 +162,8 @@ struct ocf_mngt_core_config cfg; /* Your core configuration */
/* Prepare core configuration */
/* Select core data object type */
cfg.data_obj_type = my_data_obj_type_2;
/* Select core volume type */
cfg.volume_type = my_volume_type_2;
/* Set UUID or path of your core */
cfg.uuid.data = "/path/to/your/core/or/unique/id";

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

View File

@ -18,7 +18,7 @@
#include "ocf_types.h"
#include "ocf_utilities.h"
#include "ocf_io.h"
#include "ocf_data_obj.h"
#include "ocf_volume.h"
#include "ocf_cache.h"
#include "ocf_core.h"
#include "ocf_queue.h"

View File

@ -13,7 +13,7 @@
*/
#include "ocf_types.h"
#include "ocf_data_obj.h"
#include "ocf_volume.h"
#include "ocf_ctx.h"
#include "ocf_def.h"
@ -24,8 +24,8 @@ struct ocf_cache_info {
bool attached;
/*!< True if caching cache is attached to cache */
uint8_t data_obj_type;
/*!< Cache data object type */
uint8_t volume_type;
/*!< Cache volume type */
uint32_t size;
/*!< Actual cache size (in cache lines) */
@ -92,13 +92,13 @@ struct ocf_cache_info {
};
/**
* @brief Obtain data object from cache
* @brief Obtain volume from cache
*
* @param[in] cache Cache object
*
* @retval Data object, NULL if dettached.
* @retval Volume, NULL if dettached.
*/
ocf_data_obj_t ocf_cache_get_data_object(ocf_cache_t cache);
ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache);
/**
* @brief Get ID of given cache object
@ -221,13 +221,13 @@ uint32_t ocf_cache_get_core_count(ocf_cache_t cache);
int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info);
/**
* @brief Get UUID of data object associated with cache
* @brief Get UUID of volume associated with cache
*
* @param[in] cache Cache object
*
* @retval Data object UUID, NULL if detached.
* @retval Volume UUID, NULL if detached.
*/
const struct ocf_data_obj_uuid *ocf_cache_get_uuid(ocf_cache_t cache);
const struct ocf_volume_uuid *ocf_cache_get_uuid(ocf_cache_t cache);
/**
* @brief Get OCF context of given cache object
@ -239,12 +239,30 @@ const struct ocf_data_obj_uuid *ocf_cache_get_uuid(ocf_cache_t cache);
ocf_ctx_t ocf_cache_get_ctx(ocf_cache_t cache);
/**
* @brief Get data object type id of given cache object
* @brief Get volume type id of given cache object
*
* @param[in] cache Cache object
*
* @retval data object type id, -1 if device detached
* @retval volume type id, -1 if device detached
*/
uint8_t ocf_cache_get_type_id(ocf_cache_t cache);
/**
* @brief Set cache private data
*
* @param[in] cache Cache object
* @param[in] priv Private data
*/
void ocf_cache_set_priv(ocf_cache_t cache, void *priv);
/**
* @brief Get cache private data
*
* @param[in] cache Cache object
*
* @retval Private data
*/
void *ocf_cache_get_priv(ocf_cache_t cache);
#endif /* __OCF_CACHE_H__ */

View File

@ -12,7 +12,7 @@
#define __OCF_CORE_H__
#include "ocf_types.h"
#include "ocf_data_obj.h"
#include "ocf_volume.h"
#include "ocf_io.h"
#include "ocf_mngt.h"
@ -26,33 +26,33 @@
ocf_cache_t ocf_core_get_cache(ocf_core_t core);
/**
* @brief Obtain data object associated with core
* @brief Obtain volume associated with core
*
* @param[in] core Core object
*
* @retval Data object
* @retval Volume
*/
ocf_data_obj_t ocf_core_get_data_object(ocf_core_t core);
ocf_volume_t ocf_core_get_volume(ocf_core_t core);
/**
* @brief Obtain data object of the core
* @brief Obtain volume of the core
*
* @param[in] core Core object
*
* @retval Front data object
* @retval Front volume
*/
ocf_data_obj_t ocf_core_get_front_data_object(ocf_core_t core);
ocf_volume_t ocf_core_get_front_volume(ocf_core_t core);
/**
* @brief Get UUID of data object associated with core
* @brief Get UUID of volume associated with core
*
* @param[in] core Core object
*
* @retval Data object UUID
* @retval Volume UUID
*/
static inline const struct ocf_data_obj_uuid *ocf_core_get_uuid(ocf_core_t core)
static inline const struct ocf_volume_uuid *ocf_core_get_uuid(ocf_core_t core)
{
return ocf_dobj_get_uuid(ocf_core_get_data_object(core));
return ocf_volume_get_uuid(ocf_core_get_volume(core));
}
/**
@ -61,9 +61,10 @@ static inline const struct ocf_data_obj_uuid *ocf_core_get_uuid(ocf_core_t core)
* @param[in] core Core object
* @param[in] uuid new core uuid
*
* @retval Data object UUID
* @retval 0 Success
* @retval Non-zero Fail
*/
int ocf_core_set_uuid(ocf_core_t core, const struct ocf_data_obj_uuid *uuid);
int ocf_core_set_uuid(ocf_core_t core, const struct ocf_volume_uuid *uuid);
/**
* @brief Get sequential cutoff threshold of given core object
@ -167,9 +168,9 @@ int ocf_core_get_user_metadata(ocf_core_t core, void *data, size_t size);
*/
static inline struct ocf_io *ocf_core_new_io(ocf_core_t core)
{
ocf_data_obj_t obj = ocf_core_get_front_data_object(core);
ocf_volume_t volume = ocf_core_get_front_volume(core);
return ocf_dobj_new_io(obj);
return ocf_volume_new_io(volume);
}
/**
@ -187,7 +188,7 @@ void ocf_core_submit_io_mode(struct ocf_io *io, ocf_cache_mode_t cache_mode);
*/
static inline void ocf_core_submit_io(struct ocf_io *io)
{
ocf_dobj_submit_io(io);
ocf_volume_submit_io(io);
}
/**
@ -208,7 +209,7 @@ int ocf_core_submit_io_fast(struct ocf_io *io);
*/
static inline void ocf_core_submit_flush(struct ocf_io *io)
{
ocf_dobj_submit_flush(io);
ocf_volume_submit_flush(io);
}
/**
@ -218,7 +219,7 @@ static inline void ocf_core_submit_flush(struct ocf_io *io)
*/
static inline void ocf_core_submit_discard(struct ocf_io *io)
{
ocf_dobj_submit_discard(io);
ocf_volume_submit_discard(io);
}
/**

View File

@ -12,7 +12,7 @@
*/
#include "ocf_types.h"
#include "ocf_data_obj.h"
#include "ocf_volume.h"
#include "ocf_logger.h"
/**
@ -268,65 +268,65 @@ struct ocf_ctx_config {
};
/**
* @brief Register data object interface
* @brief Register volume interface
*
* @note Type of data object operations is unique and cannot be repeated.
* @note Type of volume operations is unique and cannot be repeated.
*
* @param[in] ctx OCF context
* @param[in] properties Reference to data object properties
* @param[in] type_id Type id of data object operations
* @param[in] properties Reference to volume properties
* @param[in] type_id Type id of volume operations
*
* @retval 0 Data object operations registered successfully
* @retval Non-zero Data object registration failure
* @retval 0 Volume operations registered successfully
* @retval Non-zero Volume registration failure
*/
int ocf_ctx_register_data_obj_type(ocf_ctx_t ctx, uint8_t type_id,
const struct ocf_data_obj_properties *properties);
int ocf_ctx_register_volume_type(ocf_ctx_t ctx, uint8_t type_id,
const struct ocf_volume_properties *properties);
/**
* @brief Unregister data object interface
* @brief Unregister volume interface
*
* @param[in] ctx OCF context
* @param[in] type_id Type id of data object operations
* @param[in] type_id Type id of volume operations
*/
void ocf_ctx_unregister_data_obj_type(ocf_ctx_t ctx, uint8_t type_id);
void ocf_ctx_unregister_volume_type(ocf_ctx_t ctx, uint8_t type_id);
/**
* @brief Get data object type operations by type id
* @brief Get volume type operations by type id
*
* @param[in] ctx OCF context
* @param[in] type_id Type id of data object operations which were registered
* @param[in] type_id Type id of volume operations which were registered
*
* @return Data object type
* @retval NULL When data object operations were not registered
* @return Volume type
* @retval NULL When volume operations were not registered
* for requested type
*/
ocf_data_obj_type_t ocf_ctx_get_data_obj_type(ocf_ctx_t ctx, uint8_t type_id);
ocf_volume_type_t ocf_ctx_get_volume_type(ocf_ctx_t ctx, uint8_t type_id);
/**
* @brief Get data object type id by type
* @brief Get volume type id by type
*
* @param[in] ctx OCF context
* @param[in] type Type of data object operations which were registered
* @param[in] type Type of volume operations which were registered
*
* @return Data object type id
* @retval -1 When data object operations were not registered
* @return Volume type id
* @retval -1 When volume operations were not registered
* for requested type
*/
int ocf_ctx_get_data_obj_type_id(ocf_ctx_t ctx, ocf_data_obj_type_t type);
int ocf_ctx_get_volume_type_id(ocf_ctx_t ctx, ocf_volume_type_t type);
/**
* @brief Create data object of given type
* @brief Create volume of given type
*
* @param[in] ctx handle to object designating ocf context
* @param[out] obj data object handle
* @param[in] uuid OCF data object UUID
* @param[in] type_id cache/core object type id
* @param[out] volume volume handle
* @param[in] uuid OCF volume UUID
* @param[in] type_id cache/core volume type id
*
* @return Zero when success, othewise en error
*/
int ocf_ctx_data_obj_create(ocf_ctx_t ctx, ocf_data_obj_t *obj,
struct ocf_data_obj_uuid *uuid, uint8_t type_id);
int ocf_ctx_volume_create(ocf_ctx_t ctx, ocf_volume_t *volume,
struct ocf_volume_uuid *uuid, uint8_t type_id);
/**
* @brief Initialize OCF context

View File

@ -1,318 +0,0 @@
/*
* Copyright(c) 2012-2018 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __OCF_DATA_OBJ_H__
#define __OCF_DATA_OBJ_H__
/**
* @file
* @brief OCF data object API
*/
#include "ocf_types.h"
#include "ocf_env.h"
#include "ocf_err.h"
struct ocf_io;
/**
* @brief OCF data object UUID maximum allowed size
*/
#define OCF_DATA_OBJ_UUID_MAX_SIZE (4096UL - sizeof(uint32_t))
/**
* @brief OCF data object UUID
*/
struct ocf_data_obj_uuid {
size_t size;
/*!< UUID data size */
const void *data;
/*!< UUID data content */
};
/**
* @brief This structure describes data object capabilities
*/
struct ocf_data_obj_caps {
uint32_t atomic_writes : 1;
/*!< Data object supports atomic writes */
};
/**
* @brief OCF data object interface declaration
*/
struct ocf_data_obj_ops {
/**
* @brief Submit IO on this data object
*
* @param[in] io IO to be submitted
*/
void (*submit_io)(struct ocf_io *io);
/**
* @brief Submit IO with flush command
*
* @param[in] io IO to be submitted
*/
void (*submit_flush)(struct ocf_io *io);
/**
* @brief Submit IO with metadata
*
* @param[in] io IO to be submitted
*/
void (*submit_metadata)(struct ocf_io *io);
/**
* @brief Submit IO with discard command
*
* @param[in] io IO to be submitted
*/
void (*submit_discard)(struct ocf_io *io);
/**
* @brief Submit operation to write zeroes to target address (including
* metadata extended LBAs in atomic mode)
*
* @param[in] io IO description (addr, size)
*/
void (*submit_write_zeroes)(struct ocf_io *io);
/**
* @brief Open data object
*
* @note This function performs data object initialization and should
* be called before any other operation on data object
*
* @param[in] obj Data object
*/
int (*open)(ocf_data_obj_t obj);
/**
* @brief Close data object
*
* @param[in] obj Data object
*/
void (*close)(ocf_data_obj_t obj);
/**
* @brief Close data object
*
* @param[in] obj Data object
*/
unsigned int (*get_max_io_size)(ocf_data_obj_t obj);
/**
* @brief Close data object
*
* @param[in] obj Data object
*/
uint64_t (*get_length)(ocf_data_obj_t obj);
};
/**
* @brief This structure describes data object properties
*/
struct ocf_data_obj_properties {
const char *name;
/*!< The name of data object operations */
uint32_t io_priv_size;
/*!< Size of io private context structure */
uint32_t dobj_priv_size;
/*!< Size of data object private context structure */
struct ocf_data_obj_caps caps;
/*!< Data object capabilities */
struct ocf_data_obj_ops ops;
/*!< Data object operations */
struct ocf_io_ops io_ops;
/*!< IO operations */
};
/**
* @brief Initialize UUID from string
*
* @param[in] uuid UUID to be initialized
* @param[in] str NULL-terminated string
*
* @return Zero when success, othewise error
*/
static inline int ocf_uuid_set_str(ocf_uuid_t uuid, char *str)
{
size_t len = env_strnlen(str, OCF_DATA_OBJ_UUID_MAX_SIZE);
if (len >= OCF_DATA_OBJ_UUID_MAX_SIZE)
return -OCF_ERR_INVAL;
uuid->data = str;
uuid->size = len + 1;
return 0;
}
/**
* @brief Obtain string from UUID
* @param[in] uuid pointer to UUID
* @return String contained within UUID
*/
static inline const char *ocf_uuid_to_str(const struct ocf_data_obj_uuid *uuid)
{
return uuid->data;
}
/**
* @brief Initialize data object
*
* @param[in] obj data object handle
* @param[in] type cache/core object type
* @param[in] uuid OCF data object UUID
* @param[in] uuid_copy crate copy of uuid data
*
* @return Zero when success, othewise error
*/
int ocf_dobj_init(ocf_data_obj_t obj, ocf_data_obj_type_t type,
struct ocf_data_obj_uuid *uuid, bool uuid_copy);
/**
* @brief Deinitialize data object
*
* @param[in] obj data object handle
*/
void ocf_dobj_deinit(ocf_data_obj_t obj);
/**
* @brief Allocate and initialize data object
*
* @param[out] obj pointer to data object handle
* @param[in] type cache/core object type
* @param[in] uuid OCF data object UUID
*
* @return Zero when success, othewise en error
*/
int ocf_dobj_create(ocf_data_obj_t *obj, ocf_data_obj_type_t type,
struct ocf_data_obj_uuid *uuid);
/**
* @brief Deinitialize and free data object
*
* @param[in] obj data object handle
*/
void ocf_dobj_destroy(ocf_data_obj_t obj);
/**
* @brief Get data object type
*
* @param[in] obj Data object
*
* @return Data object type
*/
ocf_data_obj_type_t ocf_dobj_get_type(ocf_data_obj_t obj);
/**
* @brief Get data object UUID
*
* @param[in] obj Data object
*
* @return UUID of data object
*/
const struct ocf_data_obj_uuid *ocf_dobj_get_uuid(ocf_data_obj_t obj);
/**
* @brief Get private context of data object
*
* @param[in] obj Data object
*
* @return Data object private context
*/
void *ocf_dobj_get_priv(ocf_data_obj_t obj);
/**
* @brief Get cache handle for given data object
*
* @param obj data object handle
*
* @return Handle to cache for which data object belongs to
*/
ocf_cache_t ocf_dobj_get_cache(ocf_data_obj_t obj);
/**
* @brief Check if data object supports atomic mode
*
* @param[in] obj Data object
*
* @return Non-zero value if data object is atomic, otherwise zero
*/
int ocf_dobj_is_atomic(ocf_data_obj_t obj);
/**
* @brief Allocate new io
*
* @param[in] io IO
*
* @return ocf_io on success atomic, otherwise NULL
*/
struct ocf_io *ocf_dobj_new_io(ocf_data_obj_t obj);
/**
* @brief Submit io to data object
*
* @param[in] io IO
*/
void ocf_dobj_submit_io(struct ocf_io *io);
/**
* @brief Submit flush to data object
*
* @param[in] io IO
*/
void ocf_dobj_submit_flush(struct ocf_io *io);
/**
* @brief Submit discard to data object
*
* @param[in] io IO
*/
void ocf_dobj_submit_discard(struct ocf_io *io);
/**
* @brief Open data object
*
* @param[in] obj Data object
*
* @return Zero when success, othewise en error
*/
int ocf_dobj_open(ocf_data_obj_t obj);
/**
* @brief Get data object max io size
*
* @param[in] obj Data object
*/
void ocf_dobj_close(ocf_data_obj_t obj);
/**
* @brief Get data object max io size
*
* @param[in] obj Data object
*
* @return Data object max io size in bytes
*/
unsigned int ocf_dobj_get_max_io_size(ocf_data_obj_t obj);
/**
* @brief Get data object length
*
* @param[in] obj Data object
*
* @return Length of data object in bytes
*/
uint64_t ocf_dobj_get_length(ocf_data_obj_t obj);
#endif /* __OCF_DATA_OBJ_H__ */

View File

@ -18,8 +18,8 @@ typedef enum {
/** Invalid input parameter value */
OCF_ERR_INVAL = 1000000,
/** Invalid data object type */
OCF_ERR_INVAL_DATA_OBJ_TYPE,
/** Invalid volume type */
OCF_ERR_INVAL_VOLUME_TYPE,
/** Operation interrupted */
OCF_ERR_INTR,

View File

@ -49,9 +49,9 @@ typedef void (*ocf_end_io_t)(struct ocf_io *io, int error);
*/
struct ocf_io {
/**
* @brief OCF IO destination data object
* @brief OCF IO destination volume
*/
ocf_data_obj_t obj;
ocf_volume_t volume;
/**
* @brief Operations set for this OCF IO

View File

@ -10,7 +10,7 @@
* @file
* @brief OCF metadata helper function
*
* Those functions can be used by data object implementation.
* Those functions can be used by volume implementation.
*/
/**
@ -38,7 +38,7 @@ struct ocf_atomic_metadata {
* @brief Get metadata entry (cache mapping) for specified sector of cache
* device
*
* Metadata has sector granularity. It might be used by data object which
* Metadata has sector granularity. It might be used by volume which
* supports atomic writes - (write of data and metadata in one buffer)
*
* @param[in] cache OCF cache instance
@ -55,7 +55,7 @@ int ocf_metadata_get_atomic_entry(ocf_cache_t cache, uint64_t addr,
* @brief Probe cache device
*
* @param[in] ctx handle to object designating ocf context
* @param[in] cache_obj Cache data object
* @param[in] cache_volume Cache volume
* @param[out] clean_shutdown Cache was graceful stopped
* @param[out] cache_dirty Cache is dirty
*
@ -63,13 +63,13 @@ int ocf_metadata_get_atomic_entry(ocf_cache_t cache, uint64_t addr,
* @retval -ENODATA Cache has not been detected
* @retval Non-zero ERROR
*/
int ocf_metadata_probe(ocf_ctx_t ctx, ocf_data_obj_t cache_obj,
int ocf_metadata_probe(ocf_ctx_t ctx, ocf_volume_t cache_volume,
bool *clean_shutdown, bool *cache_dirty);
/**
* @brief Check if sectors in cache line before given address are invalid
*
* It might be used by data object which supports
* It might be used by volume which supports
* atomic writes - (write of data and metadata in one buffer)
*
* @param[in] cache OCF cache instance
@ -83,7 +83,7 @@ int ocf_metadata_check_invalid_before(ocf_cache_t cache, uint64_t addr);
/**
* @brief Check if sectors in cache line after given end address are invalid
*
* It might be used by data object which supports
* It might be used by volume which supports
* atomic writes - (write of data and metadata in one buffer)
*
* @param[in] cache OCF cache instance

View File

@ -20,14 +20,14 @@
*/
struct ocf_mngt_core_config {
/**
* @brief OCF core data object UUID
* @brief OCF core volume UUID
*/
struct ocf_data_obj_uuid uuid;
struct ocf_volume_uuid uuid;
/**
* @brief OCF core data object type
* @brief OCF core volume type
*/
uint8_t data_obj_type;
uint8_t volume_type;
/**
* @brief OCF core ID number
@ -269,14 +269,14 @@ struct ocf_mngt_cache_config {
*/
struct ocf_mngt_cache_device_config {
/**
* @brief Cache data object UUID
* @brief Cache volume UUID
*/
struct ocf_data_obj_uuid uuid;
struct ocf_volume_uuid uuid;
/**
* @brief Cache data object type
* @brief Cache volume type
*/
uint8_t data_obj_type;
uint8_t volume_type;
/**
* @brief Cache line size
@ -695,8 +695,8 @@ int ocf_mngt_core_pool_get_count(ocf_ctx_t ctx);
* @brief Add core to pool
*
* @param[in] ctx OCF context
* @param[in] uuid Cache data object UUID
* @param[in] type OCF core data object type
* @param[in] uuid Cache volume UUID
* @param[in] type OCF core volume type
*
* @retval 0 Core added to pool successfully
* @retval Non-zero Error occurred and adding core to poll failed
@ -707,14 +707,14 @@ int ocf_mngt_core_pool_add(ocf_ctx_t ctx, ocf_uuid_t uuid, uint8_t type);
* @brief Add core to pool
*
* @param[in] ctx OCF context
* @param[in] uuid Cache data object UUID
* @param[in] type OCF core data object type
* @param[in] uuid Cache volume UUID
* @param[in] type OCF core volume type
*
* @retval Handler to object with same UUID
* @retval NULL Not found object with that id
*/
ocf_data_obj_t ocf_mngt_core_pool_lookup(ocf_ctx_t ctx, ocf_uuid_t uuid,
ocf_data_obj_type_t type);
ocf_volume_t ocf_mngt_core_pool_lookup(ocf_ctx_t ctx, ocf_uuid_t uuid,
ocf_volume_type_t type);
/**
* @brief Iterate over all object in pool and call visitor callback
*
@ -729,15 +729,15 @@ int ocf_mngt_core_pool_visit(ocf_ctx_t ctx,
int (*visitor)(ocf_uuid_t, void *), void *visitor_ctx);
/**
* @brief Remove data object from pool
* @brief Remove volume from pool
*
* Important: This function destroys data object instance but doesn't close it,
* Important: This function destroys volume instance but doesn't close it,
* so it should be either moved or closed before calling this function.
*
* @param[in] ctx OCF context
* @param[in] obj Core data object
* @param[in] volume Core volume
*/
void ocf_mngt_core_pool_remove(ocf_ctx_t ctx, ocf_data_obj_t obj);
void ocf_mngt_core_pool_remove(ocf_ctx_t ctx, ocf_volume_t volume);
/**
* @brief Deinit core pool

View File

@ -129,19 +129,19 @@ struct ocf_stats_core {
/** Write requests statistics */
struct ocf_stats_req write_reqs;
/** Block requests for cache data object statistics */
struct ocf_stats_block cache_obj;
/** Block requests for cache volume statistics */
struct ocf_stats_block cache_volume;
/** Block requests for core data object statistics */
struct ocf_stats_block core_obj;
/** Block requests for core volume statistics */
struct ocf_stats_block core_volume;
/** Block requests submitted by user to this core */
struct ocf_stats_block core;
/** Cache data object error statistics */
/** Cache volume error statistics */
struct ocf_stats_error cache_errors;
/** Core data object error statistics */
/** Core volume error statistics */
struct ocf_stats_error core_errors;
/** Debug statistics */

View File

@ -95,13 +95,13 @@ struct ocf_stats_requests {
*
* Block statistics Count % Units
*
* Reads from core data object(s) 426 100.0 4KiB blocks
* Writes to core data object(s) 0 0.0 4KiB blocks
* Total to/from core data object (s) 426 100.0 4KiB blocks
* Reads from core volume(s) 426 100.0 4KiB blocks
* Writes to core volume(s) 0 0.0 4KiB blocks
* Total to/from core volume (s) 426 100.0 4KiB blocks
*
* Reads from cache data object 13 3.0 4KiB blocks
* Writes to cache data object 426 97.0 4KiB blocks
* Total to/from cache data object 439 100.0 4KiB blocks
* Reads from cache volume 13 3.0 4KiB blocks
* Writes to cache volume 426 97.0 4KiB blocks
* Total to/from cache volume 439 100.0 4KiB blocks
*
* Reads from core(s) 439 100.0 4KiB blocks
* Writes to core(s) 0 0.0 4KiB blocks
@ -110,12 +110,12 @@ struct ocf_stats_requests {
* </pre>
*/
struct ocf_stats_blocks {
struct ocf_stat core_obj_rd;
struct ocf_stat core_obj_wr;
struct ocf_stat core_obj_total;
struct ocf_stat cache_obj_rd;
struct ocf_stat cache_obj_wr;
struct ocf_stat cache_obj_total;
struct ocf_stat core_volume_rd;
struct ocf_stat core_volume_wr;
struct ocf_stat core_volume_total;
struct ocf_stat cache_volume_rd;
struct ocf_stat cache_volume_wr;
struct ocf_stat cache_volume_total;
struct ocf_stat volume_rd;
struct ocf_stat volume_wr;
struct ocf_stat volume_total;
@ -142,12 +142,12 @@ struct ocf_stats_blocks {
* </pre>
*/
struct ocf_stats_errors {
struct ocf_stat core_obj_rd;
struct ocf_stat core_obj_wr;
struct ocf_stat core_obj_total;
struct ocf_stat cache_obj_rd;
struct ocf_stat cache_obj_wr;
struct ocf_stat cache_obj_total;
struct ocf_stat core_volume_rd;
struct ocf_stat core_volume_wr;
struct ocf_stat core_volume_total;
struct ocf_stat cache_volume_rd;
struct ocf_stat cache_volume_wr;
struct ocf_stat cache_volume_total;
struct ocf_stat total;
};

View File

@ -54,23 +54,23 @@ struct ocf_core;
*/
typedef struct ocf_core *ocf_core_t;
struct ocf_data_obj;
struct ocf_volume;
/**
* @brief handle to object designating ocf data object
* @brief handle to object designating ocf volume
*/
typedef struct ocf_data_obj *ocf_data_obj_t;
typedef struct ocf_volume *ocf_volume_t;
struct ocf_data_obj_type;
struct ocf_volume_type;
/**
* @brief handle to data object type
* @brief handle to volume type
*/
typedef const struct ocf_data_obj_type *ocf_data_obj_type_t;
typedef const struct ocf_volume_type *ocf_volume_type_t;
/**
* @brief handle to data object uuid
* @brief handle to volume uuid
*/
typedef struct ocf_data_obj_uuid *ocf_uuid_t;
typedef struct ocf_volume_uuid *ocf_uuid_t;
/**
* @brief handle to object designating ocf context object

318
inc/ocf_volume.h Normal file
View File

@ -0,0 +1,318 @@
/*
* Copyright(c) 2012-2018 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __OCF_VOLUME_H__
#define __OCF_VOLUME_H__
/**
* @file
* @brief OCF volume API
*/
#include "ocf_types.h"
#include "ocf_env.h"
#include "ocf_err.h"
struct ocf_io;
/**
* @brief OCF volume UUID maximum allowed size
*/
#define OCF_VOLUME_UUID_MAX_SIZE (4096UL - sizeof(uint32_t))
/**
* @brief OCF volume UUID
*/
struct ocf_volume_uuid {
size_t size;
/*!< UUID data size */
const void *data;
/*!< UUID data content */
};
/**
* @brief This structure describes volume capabilities
*/
struct ocf_volume_caps {
uint32_t atomic_writes : 1;
/*!< Volume supports atomic writes */
};
/**
* @brief OCF volume interface declaration
*/
struct ocf_volume_ops {
/**
* @brief Submit IO on this volume
*
* @param[in] io IO to be submitted
*/
void (*submit_io)(struct ocf_io *io);
/**
* @brief Submit IO with flush command
*
* @param[in] io IO to be submitted
*/
void (*submit_flush)(struct ocf_io *io);
/**
* @brief Submit IO with metadata
*
* @param[in] io IO to be submitted
*/
void (*submit_metadata)(struct ocf_io *io);
/**
* @brief Submit IO with discard command
*
* @param[in] io IO to be submitted
*/
void (*submit_discard)(struct ocf_io *io);
/**
* @brief Submit operation to write zeroes to target address (including
* metadata extended LBAs in atomic mode)
*
* @param[in] io IO description (addr, size)
*/
void (*submit_write_zeroes)(struct ocf_io *io);
/**
* @brief Open volume
*
* @note This function performs volume initialization and should
* be called before any other operation on volume
*
* @param[in] volume Volume
*/
int (*open)(ocf_volume_t volume);
/**
* @brief Close volume
*
* @param[in] volume Volume
*/
void (*close)(ocf_volume_t volume);
/**
* @brief Close volume
*
* @param[in] volume Volume
*/
unsigned int (*get_max_io_size)(ocf_volume_t volume);
/**
* @brief Close volume
*
* @param[in] volume Volume
*/
uint64_t (*get_length)(ocf_volume_t volume);
};
/**
* @brief This structure describes volume properties
*/
struct ocf_volume_properties {
const char *name;
/*!< The name of volume operations */
uint32_t io_priv_size;
/*!< Size of io private context structure */
uint32_t volume_priv_size;
/*!< Size of volume private context structure */
struct ocf_volume_caps caps;
/*!< Volume capabilities */
struct ocf_volume_ops ops;
/*!< Volume operations */
struct ocf_io_ops io_ops;
/*!< IO operations */
};
/**
* @brief Initialize UUID from string
*
* @param[in] uuid UUID to be initialized
* @param[in] str NULL-terminated string
*
* @return Zero when success, othewise error
*/
static inline int ocf_uuid_set_str(ocf_uuid_t uuid, char *str)
{
size_t len = env_strnlen(str, OCF_VOLUME_UUID_MAX_SIZE);
if (len >= OCF_VOLUME_UUID_MAX_SIZE)
return -OCF_ERR_INVAL;
uuid->data = str;
uuid->size = len + 1;
return 0;
}
/**
* @brief Obtain string from UUID
* @param[in] uuid pointer to UUID
* @return String contained within UUID
*/
static inline const char *ocf_uuid_to_str(const struct ocf_volume_uuid *uuid)
{
return uuid->data;
}
/**
* @brief Initialize volume
*
* @param[in] volume volume handle
* @param[in] type cache/core volume type
* @param[in] uuid OCF volume UUID
* @param[in] uuid_copy crate copy of uuid data
*
* @return Zero when success, othewise error
*/
int ocf_volume_init(ocf_volume_t volume, ocf_volume_type_t type,
struct ocf_volume_uuid *uuid, bool uuid_copy);
/**
* @brief Deinitialize volume
*
* @param[in] volume volume handle
*/
void ocf_volume_deinit(ocf_volume_t volume);
/**
* @brief Allocate and initialize volume
*
* @param[out] volume pointer to volume handle
* @param[in] type cache/core volume type
* @param[in] uuid OCF volume UUID
*
* @return Zero when success, othewise en error
*/
int ocf_volume_create(ocf_volume_t *volume, ocf_volume_type_t type,
struct ocf_volume_uuid *uuid);
/**
* @brief Deinitialize and free volume
*
* @param[in] volume volume handle
*/
void ocf_volume_destroy(ocf_volume_t volume);
/**
* @brief Get volume type
*
* @param[in] volume Volume
*
* @return Volume type
*/
ocf_volume_type_t ocf_volume_get_type(ocf_volume_t volume);
/**
* @brief Get volume UUID
*
* @param[in] volume Volume
*
* @return UUID of volume
*/
const struct ocf_volume_uuid *ocf_volume_get_uuid(ocf_volume_t volume);
/**
* @brief Get private context of volume
*
* @param[in] volume Volume
*
* @return Volume private context
*/
void *ocf_volume_get_priv(ocf_volume_t volume);
/**
* @brief Get cache handle for given volume
*
* @param volume volume handle
*
* @return Handle to cache for which volume belongs to
*/
ocf_cache_t ocf_volume_get_cache(ocf_volume_t volume);
/**
* @brief Check if volume supports atomic mode
*
* @param[in] volume Volume
*
* @return Non-zero value if volume is atomic, otherwise zero
*/
int ocf_volume_is_atomic(ocf_volume_t volume);
/**
* @brief Allocate new io
*
* @param[in] volume Volume
*
* @return ocf_io on success atomic, otherwise NULL
*/
struct ocf_io *ocf_volume_new_io(ocf_volume_t volume);
/**
* @brief Submit io to volume
*
* @param[in] io IO
*/
void ocf_volume_submit_io(struct ocf_io *io);
/**
* @brief Submit flush to volume
*
* @param[in] io IO
*/
void ocf_volume_submit_flush(struct ocf_io *io);
/**
* @brief Submit discard to volume
*
* @param[in] io IO
*/
void ocf_volume_submit_discard(struct ocf_io *io);
/**
* @brief Open volume
*
* @param[in] volume Volume
*
* @return Zero when success, othewise en error
*/
int ocf_volume_open(ocf_volume_t volume);
/**
* @brief Get volume max io size
*
* @param[in] volume Volume
*/
void ocf_volume_close(ocf_volume_t volume);
/**
* @brief Get volume max io size
*
* @param[in] volume Volume
*
* @return Volume max io size in bytes
*/
unsigned int ocf_volume_get_max_io_size(ocf_volume_t volume);
/**
* @brief Get volume length
*
* @param[in] volume Volume
*
* @return Length of volume in bytes
*/
uint64_t ocf_volume_get_length(ocf_volume_t volume);
#endif /* __OCF_VOLUME_H__ */

View File

@ -83,7 +83,7 @@ static int _ocf_cleaner_run_check_dirty_inactive(struct ocf_cache *cache)
return 0;
for (i = 0; i < OCF_CORE_MAX; ++i) {
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
if (cache->core[i].opened && env_atomic_read(&(cache->

View File

@ -48,7 +48,7 @@ int ocf_io_d2c(struct ocf_request *req)
/* Get OCF request - increase reference counter */
ocf_req_get(req);
ocf_submit_obj_req(&core->obj, req, _ocf_d2c_completion);
ocf_submit_volume_req(&core->volume, req, _ocf_d2c_completion);
ocf_engine_update_block_stats(req);

View File

@ -65,7 +65,7 @@ static int _ocf_discard_core(struct ocf_request *req)
struct ocf_cache *cache = req->cache;
struct ocf_io *io;
io = ocf_dobj_new_io(&cache->core[req->core_id].obj);
io = ocf_volume_new_io(&cache->core[req->core_id].volume);
if (!io) {
_ocf_discard_complete_req(req, -ENOMEM);
return -ENOMEM;
@ -79,7 +79,7 @@ static int _ocf_discard_core(struct ocf_request *req)
ocf_io_set_data(io, req->data, 0);
ocf_io_set_queue(io, req->io_queue);
ocf_dobj_submit_discard(io);
ocf_volume_submit_discard(io);
return 0;
}
@ -105,7 +105,7 @@ static int _ocf_discard_flush_cache(struct ocf_request *req)
{
struct ocf_io *io;
io = ocf_dobj_new_io(&req->cache->device->obj);
io = ocf_volume_new_io(&req->cache->device->volume);
if (!io) {
ocf_metadata_error(req->cache);
_ocf_discard_complete_req(req, -ENOMEM);
@ -116,7 +116,7 @@ static int _ocf_discard_flush_cache(struct ocf_request *req)
ocf_io_set_cmpl(io, req, NULL, _ocf_discard_cache_flush_complete);
ocf_io_set_queue(io, req->io_queue);
ocf_dobj_submit_flush(io);
ocf_volume_submit_flush(io);
return 0;
}

View File

@ -50,7 +50,7 @@ static int _ocf_invalidate_do(struct ocf_request *req)
env_atomic_inc(&req->req_remaining);
if (ocf_dobj_is_atomic(&cache->device->obj) &&
if (ocf_volume_is_atomic(&cache->device->volume) &&
req->info.flush_metadata) {
/* Metadata flush IO */
ocf_metadata_flush_do_asynch(cache, req, _ocf_invalidate_req);

View File

@ -48,7 +48,7 @@ int ocf_engine_ops(struct ocf_request *req)
env_atomic_set(&req->req_remaining, 2);
/* Submit operation into core device */
ocf_submit_obj_req(&cache->core[req->core_id].obj, req,
ocf_submit_volume_req(&cache->core[req->core_id].volume, req,
_ocf_engine_ops_complete);
ocf_submit_cache_reqs(cache, req->map, req, req->rw,

View File

@ -50,7 +50,7 @@ static inline void _ocf_read_pt_submit(struct ocf_request *req)
OCF_DEBUG_RQ(req, "Submit");
/* Core read */
ocf_submit_obj_req(&cache->core[req->core_id].obj, req,
ocf_submit_volume_req(&cache->core[req->core_id].volume, req,
_ocf_read_pt_complete);
}

View File

@ -128,7 +128,7 @@ static inline void _ocf_read_generic_submit_miss(struct ocf_request *req)
goto err_alloc;
/* Submit read request to core device. */
ocf_submit_obj_req(&cache->core[req->core_id].obj, req,
ocf_submit_volume_req(&cache->core[req->core_id].volume, req,
_ocf_read_generic_miss_complete);
return;

View File

@ -72,7 +72,7 @@ int ocf_write_wa(struct ocf_request *req)
/* Submit write IO to the core */
env_atomic_set(&req->req_remaining, 1);
ocf_submit_obj_req(&cache->core[req->core_id].obj, req,
ocf_submit_volume_req(&cache->core[req->core_id].volume, req,
_ocf_read_wa_complete);
/* Update statistics */

View File

@ -111,7 +111,7 @@ static int _ocf_write_wi_do(struct ocf_request *req)
OCF_DEBUG_RQ(req, "Submit");
/* Submit write IO to the core */
ocf_submit_obj_req(&cache->core[req->core_id].obj, req,
ocf_submit_volume_req(&cache->core[req->core_id].volume, req,
_ocf_write_wi_core_complete);
/* Update statistics */

View File

@ -93,7 +93,7 @@ static inline void _ocf_write_wt_submit(struct ocf_request *req)
ocf_engine_io_count(req), _ocf_write_wt_cache_complete);
/* To core */
ocf_submit_obj_req(&cache->core[req->core_id].obj, req,
ocf_submit_volume_req(&cache->core[req->core_id].volume, req,
_ocf_write_wt_core_complete);
}

View File

@ -410,7 +410,7 @@ uint32_t evp_lru_req_clines(struct ocf_cache *cache, uint32_t io_queue,
ENV_BUG_ON(metadata_test_dirty(cache, curr_cline));
if (ocf_dobj_is_atomic(&cache->device->obj)) {
if (ocf_volume_is_atomic(&cache->device->volume)) {
/* atomic cache, we have to trim cache lines before
* eviction
*/

View File

@ -184,7 +184,8 @@ static inline int ocf_metadata_check_properties(void)
return 0;
}
static int ocf_metadata_read_properties(ocf_ctx_t ctx, ocf_data_obj_t cache_obj,
static int ocf_metadata_read_properties(ocf_ctx_t ctx,
ocf_volume_t cache_volume,
struct ocf_superblock_config *superblock)
{
ctx_data_t *data;
@ -195,7 +196,7 @@ static int ocf_metadata_read_properties(ocf_ctx_t ctx, ocf_data_obj_t cache_obj,
return -EINVAL;
/* Allocate resources for IO */
io = ocf_dobj_new_io(cache_obj);
io = ocf_volume_new_io(cache_volume);
data = ctx_data_alloc(ctx, 1);
/* Check allocation result */
@ -237,7 +238,7 @@ out:
/**
* @brief function loads individual properties from metadata set
* @param cache_obj object from which to load metadata
* @param cache_volume volume from which to load metadata
* @param variant - field to which save metadata variant; if NULL,
* metadata variant won't be read.
* @param cache mode; if NULL is passed it won't be read
@ -246,7 +247,7 @@ out:
* the cache
* @return 0 upon successful completion
*/
int ocf_metadata_load_properties(ocf_data_obj_t cache_obj,
int ocf_metadata_load_properties(ocf_volume_t cache_volume,
ocf_cache_line_size_t *line_size,
ocf_metadata_layout_t *layout,
ocf_cache_mode_t *cache_mode,
@ -259,28 +260,28 @@ int ocf_metadata_load_properties(ocf_data_obj_t cache_obj,
/* Allocate first page of super block */
superblock = env_zalloc(PAGE_SIZE, ENV_MEM_NORMAL);
if (!superblock) {
ocf_cache_log(cache_obj->cache, log_err,
ocf_cache_log(cache_volume->cache, log_err,
"Allocation memory error");
return -ENOMEM;
}
OCF_DEBUG_TRACE(cache);
err_value = ocf_metadata_read_properties(cache_obj->cache->owner,
cache_obj, superblock);
err_value = ocf_metadata_read_properties(cache_volume->cache->owner,
cache_volume, superblock);
if (err_value)
goto ocf_metadata_load_variant_ERROR;
if (superblock->magic_number != CACHE_MAGIC_NUMBER) {
err_value = -ENODATA;
ocf_cache_log(cache_obj->cache, log_info,
ocf_cache_log(cache_volume->cache, log_info,
"Can not detect pre-existing metadata\n");
goto ocf_metadata_load_variant_ERROR;
}
if (METADATA_VERSION() != superblock->metadata_version) {
err_value = -EBADF;
ocf_cache_log(cache_obj->cache, log_err,
ocf_cache_log(cache_volume->cache, log_err,
"Metadata version mismatch!\n");
goto ocf_metadata_load_variant_ERROR;
}
@ -290,7 +291,7 @@ int ocf_metadata_load_properties(ocf_data_obj_t cache_obj,
*line_size = superblock->line_size;
} else {
err_value = -EINVAL;
ocf_cache_log(cache_obj->cache, log_err,
ocf_cache_log(cache_volume->cache, log_err,
"ERROR: Invalid cache line size!\n");
}
}
@ -299,7 +300,7 @@ int ocf_metadata_load_properties(ocf_data_obj_t cache_obj,
if (superblock->metadata_layout >= ocf_metadata_layout_max ||
superblock->metadata_layout < 0) {
err_value = -EINVAL;
ocf_cache_log(cache_obj->cache, log_err,
ocf_cache_log(cache_volume->cache, log_err,
"ERROR: Invalid metadata layout!\n");
} else {
*layout = superblock->metadata_layout;
@ -310,7 +311,7 @@ int ocf_metadata_load_properties(ocf_data_obj_t cache_obj,
if (superblock->cache_mode < ocf_cache_mode_max) {
*cache_mode = superblock->cache_mode;
} else {
ocf_cache_log(cache_obj->cache, log_err,
ocf_cache_log(cache_volume->cache, log_err,
"ERROR: Invalid cache mode!\n");
err_value = -EINVAL;
}
@ -320,7 +321,7 @@ int ocf_metadata_load_properties(ocf_data_obj_t cache_obj,
if (superblock->clean_shutdown <= ocf_metadata_clean_shutdown) {
*shutdown_status = superblock->clean_shutdown;
} else {
ocf_cache_log(cache_obj->cache, log_err,
ocf_cache_log(cache_volume->cache, log_err,
"ERROR: Invalid shutdown status!\n");
err_value = -EINVAL;
}
@ -330,7 +331,7 @@ int ocf_metadata_load_properties(ocf_data_obj_t cache_obj,
if (superblock->dirty_flushed <= DIRTY_FLUSHED) {
*dirty_flushed = superblock->dirty_flushed;
} else {
ocf_cache_log(cache_obj->cache, log_err,
ocf_cache_log(cache_volume->cache, log_err,
"ERROR: Invalid flush status!\n");
err_value = -EINVAL;
}
@ -342,14 +343,14 @@ ocf_metadata_load_variant_ERROR:
return err_value;
}
int ocf_metadata_probe(ocf_ctx_t ctx, ocf_data_obj_t cache_obj,
int ocf_metadata_probe(ocf_ctx_t ctx, ocf_volume_t cache_volume,
bool *clean_shutdown, bool *cache_dirty)
{
struct ocf_superblock_config *superblock;
int result = 0;
OCF_CHECK_NULL(ctx);
OCF_CHECK_NULL(cache_obj);
OCF_CHECK_NULL(cache_volume);
/* Allocate first page of super block */
superblock = env_zalloc(PAGE_SIZE, ENV_MEM_NORMAL);
@ -360,7 +361,7 @@ int ocf_metadata_probe(ocf_ctx_t ctx, ocf_data_obj_t cache_obj,
OCF_DEBUG_TRACE(cache);
result = ocf_metadata_read_properties(ctx, cache_obj, superblock);
result = ocf_metadata_read_properties(ctx, cache_volume, superblock);
if (result)
goto ocf_metadata_probe_END;

View File

@ -306,7 +306,7 @@ static inline ocf_cache_line_t ocf_metadata_entries_hash(
return cache->metadata.iface.entries_hash(cache);
}
int ocf_metadata_load_properties(ocf_data_obj_t cache_obj,
int ocf_metadata_load_properties(ocf_volume_t cache_volume,
ocf_cache_line_size_t *line_size,
ocf_metadata_layout_t *layout,
ocf_cache_mode_t *cache_mode,

View File

@ -576,7 +576,7 @@ static int ocf_metadata_hash_init_variable_size(struct ocf_cache *cache,
if (cache->device->init_mode == ocf_init_mode_metadata_volatile) {
raw->raw_type = metadata_raw_type_volatile;
} else if (i == metadata_segment_collision &&
ocf_dobj_is_atomic(&cache->device->obj)) {
ocf_volume_is_atomic(&cache->device->volume)) {
raw->raw_type = metadata_raw_type_atomic;
}
@ -887,7 +887,7 @@ static int ocf_metadata_hash_load_superblock(struct ocf_cache *cache)
struct ocf_superblock_config *sb_config;
struct ocf_superblock_runtime *sb_runtime;
struct ocf_metadata_uuid *muuid;
struct ocf_data_obj_uuid uuid;
struct ocf_volume_uuid uuid;
OCF_DEBUG_TRACE(cache);
@ -973,9 +973,9 @@ static int ocf_metadata_hash_load_superblock(struct ocf_cache *cache)
uuid.data = muuid->data;
uuid.size = muuid->size;
/* Initialize core data object */
ocf_dobj_init(&cache->core[i].obj,
ocf_ctx_get_data_obj_type(cache->owner,
/* Initialize core volume */
ocf_volume_init(&cache->core[i].volume,
ocf_ctx_get_volume_type(cache->owner,
cache->core_conf_meta[i].type),
&uuid, false);
}
@ -1022,8 +1022,8 @@ static int ocf_metadata_hash_flush_superblock(struct ocf_cache *cache)
/* Synchronize core objects types */
for (i = 0; i < OCF_CORE_MAX; i++) {
cache->core_conf_meta[i].type = ocf_ctx_get_data_obj_type_id(
cache->owner, cache->core[i].obj.type);
cache->core_conf_meta[i].type = ocf_ctx_get_volume_type_id(
cache->owner, cache->core[i].volume.type);
}
/* Calculate checksum */
@ -1543,7 +1543,7 @@ static int ocf_metadata_hash_load_recovery(struct ocf_cache *cache)
OCF_DEBUG_TRACE(cache);
if (ocf_dobj_is_atomic(&cache->device->obj)) {
if (ocf_volume_is_atomic(&cache->device->volume)) {
result = _ocf_metadata_hash_load_recovery_atomic(cache);
rebuild_dirty_only = false;
} else {

View File

@ -46,7 +46,7 @@ static struct ocf_io_if meta_restart_if = {
*/
static uint32_t metadata_io_max_page(struct ocf_cache *cache)
{
return ocf_dobj_get_max_io_size(&cache->device->obj) / PAGE_SIZE;
return ocf_volume_get_max_io_size(&cache->device->volume) / PAGE_SIZE;
}
/*
@ -56,7 +56,7 @@ static void metadata_io_read_i_atomic_end(struct ocf_io *io, int error)
{
struct metadata_io_request_atomic *meta_atom_req = io->priv1;
OCF_DEBUG_TRACE(ocf_dobj_get_cache(io->obj));
OCF_DEBUG_TRACE(ocf_volume_get_cache(io->volume));
meta_atom_req->error |= error;
env_completion_complete(&meta_atom_req->complete);
@ -119,7 +119,7 @@ int metadata_io_read_i_atomic(struct ocf_cache *cache,
}
/* Submit IO */
ocf_dobj_submit_metadata(io);
ocf_volume_submit_metadata(io);
ocf_io_put(io);
/* Wait for completion of IO */
@ -194,7 +194,7 @@ static int ocf_restart_meta_io(struct ocf_request *req)
metadata_io_write_i_asynch_end(meta_io_req, ret);
return ret;
}
ocf_dobj_submit_io(io);
ocf_volume_submit_io(io);
return 0;
}
@ -376,7 +376,7 @@ int metadata_io_write_i_asynch(struct ocf_cache *cache, uint32_t queue,
break;
}
ocf_dobj_submit_io(io);
ocf_volume_submit_io(io);
}
count -= curr_count;
@ -507,7 +507,7 @@ static int metadata_submit_io(
/* Submit IO */
env_atomic_inc(&mio->req_remaining);
ocf_dobj_submit_io(io);
ocf_volume_submit_io(io);
return 0;

View File

@ -85,10 +85,10 @@ static int _raw_atomic_io_discard_do(struct ocf_cache *cache, void *context,
ocf_io_configure(io, start_addr, len, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, ctx, NULL, _raw_atomic_io_discard_end);
if (cache->device->obj.features.discard_zeroes)
ocf_dobj_submit_discard(io);
if (cache->device->volume.features.discard_zeroes)
ocf_volume_submit_discard(io);
else
ocf_dobj_submit_write_zeroes(io);
ocf_volume_submit_write_zeroes(io);
return req->error;
}

View File

@ -31,7 +31,7 @@ struct ocf_superblock_config {
ocf_metadata_layout_t metadata_layout;
uint32_t core_count;
unsigned long valid_object_bitmap[(OCF_CORE_MAX /
unsigned long valid_core_bitmap[(OCF_CORE_MAX /
(sizeof(unsigned long) * 8)) + 1];
ocf_cleaning_t cleaning_policy_type;

View File

@ -102,11 +102,11 @@ struct ocf_cachemng_attach_params {
struct ocf_cache *cache;
/*!< cache that is being initialized */
struct ocf_data_obj_uuid uuid;
/*!< Caching device data object UUID */
struct ocf_volume_uuid uuid;
/*!< Caching device volume UUID */
uint8_t device_type;
/*!< data object (block device) type */
/*!< volume (block device) type */
uint64_t device_size;
/*!< size of the device in cache lines */
@ -131,14 +131,14 @@ struct ocf_cachemng_attach_params {
bool device_alloc : 1;
/*!< data structure allocated */
bool data_obj_inited : 1;
bool volume_inited : 1;
/*!< uuid for cache device is allocated */
bool attached_metadata_inited : 1;
/*!< attached metadata sections initialized */
bool device_opened : 1;
/*!< underlying device object is open */
/*!< underlying device volume is open */
bool cleaner_started : 1;
/*!< Cleaner has been started */
@ -275,8 +275,8 @@ static void __init_cores(struct ocf_cache *cache)
{
/* No core devices yet */
cache->conf_meta->core_count = 0;
ENV_BUG_ON(env_memset(cache->conf_meta->valid_object_bitmap,
sizeof(cache->conf_meta->valid_object_bitmap), 0));
ENV_BUG_ON(env_memset(cache->conf_meta->valid_core_bitmap,
sizeof(cache->conf_meta->valid_core_bitmap), 0));
}
static void __init_metadata_version(struct ocf_cache *cache)
@ -357,22 +357,22 @@ static void _init_partitions(ocf_cache_t cache)
static void _ocf_mngt_close_all_uninitialized_cores(
struct ocf_cache *cache)
{
ocf_data_obj_t obj;
ocf_volume_t volume;
int j, i;
for (j = cache->conf_meta->core_count, i = 0; j > 0; ++i) {
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
obj = &(cache->core[i].obj);
ocf_dobj_close(obj);
volume = &(cache->core[i].volume);
ocf_volume_close(volume);
--j;
env_free(cache->core[i].counters);
cache->core[i].counters = NULL;
env_bit_clear(i, cache->conf_meta->valid_object_bitmap);
env_bit_clear(i, cache->conf_meta->valid_core_bitmap);
}
cache->conf_meta->core_count = 0;
@ -412,13 +412,13 @@ static int _ocf_mngt_init_instance_add_cores(
/* Check in metadata which cores were added into cache */
for (i = 0; i < OCF_CORE_MAX; i++) {
ocf_data_obj_t tobj = NULL;
ocf_volume_t tvolume = NULL;
ocf_core_t core = &cache->core[i];
if (!cache->core_conf_meta[i].added)
continue;
if (!cache->core[i].obj.type)
if (!cache->core[i].volume.type)
goto err;
ret = snprintf(core_name, sizeof(core_name), "core%d", i);
@ -429,21 +429,21 @@ static int _ocf_mngt_init_instance_add_cores(
if (ret)
goto err;
tobj = ocf_mngt_core_pool_lookup(ocf_cache_get_ctx(cache),
&core->obj.uuid, core->obj.type);
if (tobj) {
tvolume = ocf_mngt_core_pool_lookup(ocf_cache_get_ctx(cache),
&core->volume.uuid, core->volume.type);
if (tvolume) {
/*
* Attach bottom device to core structure
* in cache
*/
ocf_dobj_move(&core->obj, tobj);
ocf_mngt_core_pool_remove(cache->owner, tobj);
ocf_volume_move(&core->volume, tvolume);
ocf_mngt_core_pool_remove(cache->owner, tvolume);
core->opened = true;
ocf_cache_log(cache, log_info,
"Attached core %u from pool\n", i);
} else {
ret = ocf_dobj_open(&core->obj);
ret = ocf_volume_open(&core->volume);
if (ret == -OCF_ERR_NOT_OPEN_EXC) {
ocf_cache_log(cache, log_warn,
"Cannot open core %u. "
@ -456,11 +456,11 @@ static int _ocf_mngt_init_instance_add_cores(
}
}
env_bit_set(i, cache->conf_meta->valid_object_bitmap);
env_bit_set(i, cache->conf_meta->valid_core_bitmap);
cache->conf_meta->core_count++;
core->obj.cache = cache;
core->volume.cache = cache;
if (ocf_mngt_core_init_front_dobj(core))
if (ocf_mngt_core_init_front_volume(core))
goto err;
core->counters =
@ -479,8 +479,8 @@ static int _ocf_mngt_init_instance_add_cores(
}
hd_lines = ocf_bytes_2_lines(cache,
ocf_dobj_get_length(
&cache->core[i].obj));
ocf_volume_get_length(
&cache->core[i].volume));
if (hd_lines) {
ocf_cache_log(cache, log_info,
@ -621,7 +621,7 @@ static int _ocf_mngt_init_new_cache(struct ocf_cachemng_init_params *params)
static int _ocf_mngt_attach_cache_device(struct ocf_cache *cache,
struct ocf_cachemng_attach_params *attach_params)
{
ocf_data_obj_type_t type;
ocf_volume_type_t type;
int ret;
cache->device = env_vzalloc(sizeof(*cache->device));
@ -629,35 +629,35 @@ static int _ocf_mngt_attach_cache_device(struct ocf_cache *cache,
return -OCF_ERR_NO_MEM;
attach_params->flags.device_alloc = true;
cache->device->obj.cache = cache;
cache->device->volume.cache = cache;
/* Prepare UUID of cache data object */
type = ocf_ctx_get_data_obj_type(cache->owner,
/* Prepare UUID of cache volume */
type = ocf_ctx_get_volume_type(cache->owner,
attach_params->device_type);
if (!type) {
ret = -OCF_ERR_INVAL_DATA_OBJ_TYPE;
ret = -OCF_ERR_INVAL_VOLUME_TYPE;
goto err;
}
ret = ocf_dobj_init(&cache->device->obj, type,
ret = ocf_volume_init(&cache->device->volume, type,
&attach_params->uuid, true);
if (ret)
goto err;
attach_params->flags.data_obj_inited = true;
attach_params->flags.volume_inited = true;
/*
* Open cache device, It has to be done first because metadata service
* need to know size of cache device.
*/
ret = ocf_dobj_open(&cache->device->obj);
ret = ocf_volume_open(&cache->device->volume);
if (ret) {
ocf_cache_log(cache, log_err, "ERROR: Cache not available\n");
goto err;
}
attach_params->flags.device_opened = true;
attach_params->device_size = ocf_dobj_get_length(&cache->device->obj);
attach_params->device_size = ocf_volume_get_length(&cache->device->volume);
/* Check minimum size of cache device */
if (attach_params->device_size < OCF_CACHE_SIZE_MIN) {
@ -833,13 +833,13 @@ static int _ocf_mngt_init_test_device(struct ocf_cache *cache)
goto end;
}
if (!ocf_dobj_is_atomic(&cache->device->obj))
if (!ocf_volume_is_atomic(&cache->device->volume))
goto end;
/*
* Submit discard request
*/
ret = ocf_submit_obj_discard_wait(&cache->device->obj,
ret = ocf_submit_volume_discard_wait(&cache->device->volume,
reserved_lba_addr, PAGE_SIZE);
if (ret)
goto end;
@ -859,7 +859,7 @@ static int _ocf_mngt_init_test_device(struct ocf_cache *cache)
if (diff) {
/* discard does not cause target adresses to return 0 on
subsequent read */
cache->device->obj.features.discard_zeroes = 0;
cache->device->volume.features.discard_zeroes = 0;
}
end:
@ -887,7 +887,7 @@ static int _ocf_mngt_init_prepare_metadata(
if (cache->device->init_mode != ocf_init_mode_metadata_volatile) {
if (cache->device->init_mode == ocf_init_mode_load) {
attach_params->metadata.status = ocf_metadata_load_properties(
&cache->device->obj,
&cache->device->volume,
&line_size,
&cache->conf_meta->metadata_layout,
&cache->conf_meta->cache_mode,
@ -899,7 +899,7 @@ static int _ocf_mngt_init_prepare_metadata(
}
} else {
attach_params->metadata.status = ocf_metadata_load_properties(
&cache->device->obj,
&cache->device->volume,
NULL, NULL, NULL,
&attach_params->metadata.shutdown_status,
&attach_params->metadata.dirty_flushed);
@ -1093,13 +1093,13 @@ static void _ocf_mngt_attach_handle_error(
ocf_metadata_deinit_variable_size(cache);
if (attach_params->flags.device_opened)
ocf_dobj_close(&cache->device->obj);
ocf_volume_close(&cache->device->volume);
if (attach_params->flags.concurrency_inited)
ocf_concurrency_deinit(cache);
if (attach_params->flags.data_obj_inited)
ocf_dobj_deinit(&cache->device->obj);
if (attach_params->flags.volume_inited)
ocf_volume_deinit(&cache->device->volume);
if (attach_params->flags.device_alloc)
env_vfree(cache->device);
@ -1109,22 +1109,22 @@ static int _ocf_mngt_cache_discard_after_metadata(struct ocf_cache *cache)
{
int result;
uint64_t addr = cache->device->metadata_offset;
uint64_t length = ocf_dobj_get_length(
&cache->device->obj) - addr;
bool discard = cache->device->obj.features.discard_zeroes;
uint64_t length = ocf_volume_get_length(
&cache->device->volume) - addr;
bool discard = cache->device->volume.features.discard_zeroes;
if (!discard && ocf_dobj_is_atomic(&cache->device->obj)) {
if (!discard && ocf_volume_is_atomic(&cache->device->volume)) {
/* discard does not zero data - need to explicitly write
zeroes */
result = ocf_submit_write_zeroes_wait(
&cache->device->obj, addr, length);
&cache->device->volume, addr, length);
if (!result) {
result = ocf_submit_obj_flush_wait(
&cache->device->obj);
result = ocf_submit_volume_flush_wait(
&cache->device->volume);
}
} else {
/* Discard object after metadata */
result = ocf_submit_obj_discard_wait(&cache->device->obj, addr,
/* Discard volume after metadata */
result = ocf_submit_volume_discard_wait(&cache->device->volume, addr,
length);
}
@ -1133,7 +1133,7 @@ static int _ocf_mngt_cache_discard_after_metadata(struct ocf_cache *cache)
discard ? "Discarding whole cache device" :
"Overwriting cache with zeroes");
if (ocf_dobj_is_atomic(&cache->device->obj)) {
if (ocf_volume_is_atomic(&cache->device->volume)) {
ocf_cache_log(cache, log_err, "This step is required"
" for atomic mode!\n");
} else {
@ -1271,7 +1271,7 @@ static int _ocf_mngt_cache_add_cores_t_clean_pol(ocf_cache_t cache)
if (cleaning_policy_ops[clean_type].add_core) {
no = cache->conf_meta->core_count;
for (i = 0, j = 0; j < no && i < OCF_CORE_MAX; i++) {
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
result = cleaning_policy_ops[clean_type].add_core(cache, i);
if (result) {
@ -1288,7 +1288,7 @@ err:
return result;
while (i--) {
if (env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (env_bit_test(i, cache->conf_meta->valid_core_bitmap))
cleaning_policy_ops[clean_type].remove_core(cache, i);
};
@ -1315,7 +1315,7 @@ static int _ocf_mngt_cache_attach(ocf_cache_t cache,
attach_params.force = device_cfg->force;
attach_params.uuid = device_cfg->uuid;
attach_params.device_type = device_cfg->data_obj_type;
attach_params.device_type = device_cfg->volume_type;
attach_params.perform_test = device_cfg->perform_test;
attach_params.metadata.shutdown_status = ocf_metadata_clean_shutdown;
attach_params.metadata.dirty_flushed = DIRTY_FLUSHED;
@ -1341,7 +1341,7 @@ static int _ocf_mngt_cache_attach(ocf_cache_t cache,
goto _cache_mng_init_attach_ERROR;
/* Test device features */
cache->device->obj.features.discard_zeroes = 1;
cache->device->volume.features.discard_zeroes = 1;
if (attach_params.perform_test) {
result = _ocf_mngt_init_test_device(cache);
if (result)
@ -1422,7 +1422,7 @@ static int _ocf_mngt_cache_validate_device_cfg(
if (!device_cfg->uuid.data)
return -OCF_ERR_INVAL;
if (device_cfg->uuid.size > OCF_DATA_OBJ_UUID_MAX_SIZE)
if (device_cfg->uuid.size > OCF_VOLUME_UUID_MAX_SIZE)
return -OCF_ERR_INVAL;
if (device_cfg->cache_line_size &&
@ -1505,7 +1505,7 @@ int ocf_mngt_cache_attach(ocf_cache_t cache,
/**
* @brief Unplug caching device from cache instance. Variable size metadata
* containers are deinitialiazed as well as other cacheline related
* structures. Cache device object is closed.
* structures. Cache volume is closed.
*
* @param cache OCF cache instance
* @param stop - true if unplugging during stop - in this case we mark
@ -1548,12 +1548,12 @@ static int _ocf_mngt_cache_unplug(ocf_cache_t cache, bool stop)
result = ocf_metadata_flush_all(cache);
}
ocf_dobj_close(&cache->device->obj);
ocf_volume_close(&cache->device->volume);
ocf_metadata_deinit_variable_size(cache);
ocf_concurrency_deinit(cache);
ocf_dobj_deinit(&cache->device->obj);
ocf_volume_deinit(&cache->device->volume);
env_vfree(cache->device);
cache->device = NULL;
@ -1583,7 +1583,7 @@ static int _ocf_mngt_cache_stop(ocf_cache_t cache)
/* All exported objects removed, cleaning up rest. */
for (i = 0, j = 0; j < no && i < OCF_CORE_MAX; i++) {
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
cache_mng_core_remove_from_cache(cache, i);
if (ocf_cache_is_device_attached(cache))
@ -1742,7 +1742,7 @@ static int _cache_mng_set_cache_mode(ocf_cache_t cache, ocf_cache_mode_t mode,
int i;
for (i = 0; i != OCF_CORE_MAX; ++i) {
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
env_atomic_set(&cache->core_runtime_meta[i].
initial_dirty_clines,
@ -1871,7 +1871,7 @@ int ocf_mngt_cache_detach(ocf_cache_t cache)
/* remove cacheline metadata and cleaning policy meta for all cores */
for (i = 0, j = 0; j < no && i < OCF_CORE_MAX; i++) {
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
cache_mng_core_deinit_attached_meta(cache, i);
cache_mng_core_remove_from_cleaning_pol(cache, i);

View File

@ -22,7 +22,7 @@ int cache_mng_core_close(ocf_cache_t cache, ocf_core_id_t core_id)
if (!cache->core[core_id].opened)
return -OCF_ERR_CORE_IN_INACTIVE_STATE;
ocf_dobj_close(&cache->core[core_id].obj);
ocf_volume_close(&cache->core[core_id].volume);
cache->core[core_id].opened = false;
return 0;
@ -53,11 +53,11 @@ void cache_mng_core_deinit_attached_meta(struct ocf_cache *cache, int core_id)
int retry = 1;
uint64_t core_size = 0;
ocf_cleaning_t clean_pol_type;
ocf_data_obj_t core;
ocf_volume_t core;
core = &cache->core[core_id].obj;
core = &cache->core[core_id].volume;
core_size = ocf_dobj_get_length(core);
core_size = ocf_volume_get_length(core);
if (!core_size)
core_size = ~0ULL;
@ -107,7 +107,7 @@ void cache_mng_core_remove_from_cache(struct ocf_cache *cache, int core_id)
{
env_free(cache->core[core_id].counters);
cache->core[core_id].counters = NULL;
env_bit_clear(core_id, cache->conf_meta->valid_object_bitmap);
env_bit_clear(core_id, cache->conf_meta->valid_core_bitmap);
if (!cache->core[core_id].opened &&
--cache->ocf_core_inactive_count == 0) {

View File

@ -26,22 +26,22 @@ static int _ocf_mngt_cache_try_add_core(ocf_cache_t cache, ocf_core_t *core,
{
int result = 0;
ocf_core_t tmp_core;
ocf_data_obj_t obj;
ocf_volume_t volume;
tmp_core = &cache->core[cfg->core_id];
obj = &tmp_core->obj;
volume = &tmp_core->volume;
if (ocf_ctx_get_data_obj_type_id(cache->owner, obj->type) !=
cfg->data_obj_type) {
result = -OCF_ERR_INVAL_DATA_OBJ_TYPE;
if (ocf_ctx_get_volume_type_id(cache->owner, volume->type) !=
cfg->volume_type) {
result = -OCF_ERR_INVAL_VOLUME_TYPE;
goto error_out;
}
result = ocf_dobj_open(obj);
result = ocf_volume_open(volume);
if (result)
goto error_out;
if (!ocf_dobj_get_length(obj)) {
if (!ocf_volume_get_length(volume)) {
result = -OCF_ERR_CORE_NOT_AVAIL;
goto error_after_open;
}
@ -55,7 +55,7 @@ static int _ocf_mngt_cache_try_add_core(ocf_cache_t cache, ocf_core_t *core,
return 0;
error_after_open:
ocf_dobj_close(obj);
ocf_volume_close(volume);
error_out:
*core = NULL;
return result;
@ -65,31 +65,31 @@ static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
struct ocf_mngt_core_config *cfg)
{
ocf_core_t tmp_core;
struct ocf_data_obj_uuid new_uuid;
ocf_data_obj_t obj;
ocf_data_obj_type_t type;
struct ocf_volume_uuid new_uuid;
ocf_volume_t volume;
ocf_volume_type_t type;
ocf_seq_no_t core_sequence_no;
ocf_cleaning_t clean_type;
uint64_t length;
int result = 0;
tmp_core = &cache->core[cfg->core_id];
obj = &tmp_core->obj;
volume = &tmp_core->volume;
tmp_core->obj.cache = cache;
tmp_core->volume.cache = cache;
/* Set uuid */
result = ocf_metadata_set_core_uuid(tmp_core, &cfg->uuid, &new_uuid);
if (result)
return -OCF_ERR_INVAL;
type = ocf_ctx_get_data_obj_type(cache->owner, cfg->data_obj_type);
type = ocf_ctx_get_volume_type(cache->owner, cfg->volume_type);
if (!type) {
result = -OCF_ERR_INVAL_DATA_OBJ_TYPE;
result = -OCF_ERR_INVAL_VOLUME_TYPE;
goto error_out;
}
result = ocf_dobj_init(obj, type, &new_uuid, false);
result = ocf_volume_init(volume, type, &new_uuid, false);
if (result)
goto error_out;
@ -101,11 +101,11 @@ static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
goto error_out;
}
result = ocf_dobj_open(obj);
result = ocf_volume_open(volume);
if (result)
goto error_out;
length = ocf_dobj_get_length(obj);
length = ocf_volume_get_length(volume);
if (!length) {
result = -OCF_ERR_CORE_NOT_AVAIL;
goto error_after_open;
@ -138,7 +138,7 @@ static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
dirty_since, 0);
/* In metadata mark data this core was added into cache */
env_bit_set(cfg->core_id, cache->conf_meta->valid_object_bitmap);
env_bit_set(cfg->core_id, cache->conf_meta->valid_core_bitmap);
cache->core_conf_meta[cfg->core_id].added = true;
tmp_core->opened = true;
@ -169,7 +169,7 @@ static int _ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
return 0;
error_after_counters_allocation:
env_bit_clear(cfg->core_id, cache->conf_meta->valid_object_bitmap);
env_bit_clear(cfg->core_id, cache->conf_meta->valid_core_bitmap);
cache->core_conf_meta[cfg->core_id].added = false;
tmp_core->opened = false;
@ -190,7 +190,7 @@ error_after_clean_pol:
cleaning_policy_ops[clean_type].remove_core(cache, cfg->core_id);
error_after_open:
ocf_dobj_close(obj);
ocf_volume_close(volume);
error_out:
ocf_metadata_clear_core_uuid(tmp_core);
*core = NULL;
@ -240,19 +240,19 @@ static int __ocf_mngt_lookup_core_uuid(ocf_cache_t cache,
for (i = 0; i < OCF_CORE_MAX; i++) {
ocf_core_t core = &cache->core[i];
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
if (cache->core[i].opened)
continue;
if (ocf_ctx_get_data_obj_type_id(cache->owner, core->obj.type)
!= cfg->data_obj_type) {
if (ocf_ctx_get_volume_type_id(cache->owner, core->volume.type)
!= cfg->volume_type) {
continue;
}
if (!env_strncmp(core->obj.uuid.data, cfg->uuid.data,
OCF_MIN(core->obj.uuid.size,
if (!env_strncmp(core->volume.uuid.data, cfg->uuid.data,
OCF_MIN(core->volume.uuid.size,
cfg->uuid.size)))
return i;
}
@ -297,7 +297,7 @@ static int __ocf_mngt_find_core_id(ocf_cache_t cache,
/* Core is unspecified */
cfg->core_id = _ocf_mngt_find_first_free_core(
cache->conf_meta->valid_object_bitmap);
cache->conf_meta->valid_core_bitmap);
/* no need to check if find_first_zero_bit failed and
* *core_id == MAX_CORE_OBJS_PER_CACHE, as above there is check
* for core_count being greater or equal to
@ -306,7 +306,7 @@ static int __ocf_mngt_find_core_id(ocf_cache_t cache,
} else if (cfg->core_id < OCF_CORE_MAX) {
/* check if id is not used already */
if (env_bit_test(cfg->core_id,
cache->conf_meta->valid_object_bitmap)) {
cache->conf_meta->valid_core_bitmap)) {
ocf_cache_log(cache, log_debug,
"Core ID already allocated: %d.\n",
cfg->core_id);
@ -341,25 +341,25 @@ static int _ocf_mngt_find_core_id(ocf_cache_t cache,
return result;
}
int ocf_mngt_core_init_front_dobj(ocf_core_t core)
int ocf_mngt_core_init_front_volume(ocf_core_t core)
{
ocf_cache_t cache = ocf_core_get_cache(core);
ocf_data_obj_type_t type;
struct ocf_data_obj_uuid uuid = {
ocf_volume_type_t type;
struct ocf_volume_uuid uuid = {
.data = core,
.size = sizeof(core),
};
int ret;
type = ocf_ctx_get_data_obj_type(cache->owner, 0);
type = ocf_ctx_get_volume_type(cache->owner, 0);
if (!type)
return -OCF_ERR_INVAL;
ret = ocf_dobj_init(&core->front_obj, type, &uuid, false);
ret = ocf_volume_init(&core->front_volume, type, &uuid, false);
if (ret)
return ret;
return ocf_dobj_open(&core->front_obj);
return ocf_volume_open(&core->front_volume);
}
int ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
@ -402,7 +402,7 @@ int ocf_mngt_cache_add_core(ocf_cache_t cache, ocf_core_t *core,
if (result)
goto out;
result = ocf_mngt_core_init_front_dobj(*core);
result = ocf_mngt_core_init_front_volume(*core);
out:
if (!result) {
@ -421,7 +421,7 @@ out:
static int _ocf_mngt_cache_remove_core(ocf_core_t core, bool detach)
{
struct ocf_cache *cache = core->obj.cache;
struct ocf_cache *cache = core->volume.cache;
ocf_core_id_t core_id = ocf_core_get_id(core);
int status;
@ -435,7 +435,7 @@ static int _ocf_mngt_cache_remove_core(ocf_core_t core, bool detach)
return status;
}
ocf_dobj_close(&core->front_obj);
ocf_volume_close(&core->front_volume);
/* Deinit everything*/
if (ocf_cache_is_device_attached(cache)) {

View File

@ -28,24 +28,24 @@ 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)
{
ocf_data_obj_t obj;
ocf_volume_t volume;
int result = 0;
OCF_CHECK_NULL(ctx);
result = ocf_ctx_data_obj_create(ctx, &obj, uuid, type);
result = ocf_ctx_volume_create(ctx, &volume, uuid, type);
if (result)
return result;
result = ocf_dobj_open(obj);
result = ocf_volume_open(volume);
if (result) {
ocf_dobj_deinit(obj);
ocf_volume_deinit(volume);
return result;
}
env_mutex_lock(&ctx->lock);
list_add(&obj->core_pool_item, &ctx->core_pool.core_pool_head);
list_add(&volume->core_pool_item, &ctx->core_pool.core_pool_head);
ctx->core_pool.core_pool_count++;
env_mutex_unlock(&ctx->lock);
return result;
@ -55,15 +55,15 @@ int ocf_mngt_core_pool_visit(ocf_ctx_t ctx,
int (*visitor)(ocf_uuid_t, void *), void *visitor_ctx)
{
int result = 0;
ocf_data_obj_t sobj;
ocf_volume_t svolume;
OCF_CHECK_NULL(ctx);
OCF_CHECK_NULL(visitor);
env_mutex_lock(&ctx->lock);
list_for_each_entry(sobj, &ctx->core_pool.core_pool_head,
list_for_each_entry(svolume, &ctx->core_pool.core_pool_head,
core_pool_item) {
result = visitor(&sobj->uuid, visitor_ctx);
result = visitor(&svolume->uuid, visitor_ctx);
if (result)
break;
}
@ -71,46 +71,46 @@ int ocf_mngt_core_pool_visit(ocf_ctx_t ctx,
return result;
}
ocf_data_obj_t ocf_mngt_core_pool_lookup(ocf_ctx_t ctx, ocf_uuid_t uuid,
ocf_data_obj_type_t type)
ocf_volume_t ocf_mngt_core_pool_lookup(ocf_ctx_t ctx, ocf_uuid_t uuid,
ocf_volume_type_t type)
{
ocf_data_obj_t sobj;
ocf_volume_t svolume;
OCF_CHECK_NULL(ctx);
OCF_CHECK_NULL(uuid);
OCF_CHECK_NULL(uuid->data);
list_for_each_entry(sobj, &ctx->core_pool.core_pool_head,
list_for_each_entry(svolume, &ctx->core_pool.core_pool_head,
core_pool_item) {
if (sobj->type == type && !env_strncmp(sobj->uuid.data,
uuid->data, OCF_MIN(sobj->uuid.size, uuid->size))) {
return sobj;
if (svolume->type == type && !env_strncmp(svolume->uuid.data,
uuid->data, OCF_MIN(svolume->uuid.size, uuid->size))) {
return svolume;
}
}
return NULL;
}
void ocf_mngt_core_pool_remove(ocf_ctx_t ctx, ocf_data_obj_t obj)
void ocf_mngt_core_pool_remove(ocf_ctx_t ctx, ocf_volume_t volume)
{
OCF_CHECK_NULL(ctx);
OCF_CHECK_NULL(obj);
OCF_CHECK_NULL(volume);
env_mutex_lock(&ctx->lock);
ctx->core_pool.core_pool_count--;
list_del(&obj->core_pool_item);
list_del(&volume->core_pool_item);
env_mutex_unlock(&ctx->lock);
ocf_dobj_destroy(obj);
ocf_volume_destroy(volume);
}
void ocf_mngt_core_pool_deinit(ocf_ctx_t ctx)
{
ocf_data_obj_t sobj, tobj;
ocf_volume_t svolume, tvolume;
OCF_CHECK_NULL(ctx);
list_for_each_entry_safe(sobj, tobj, &ctx->core_pool.core_pool_head,
list_for_each_entry_safe(svolume, tvolume, &ctx->core_pool.core_pool_head,
core_pool_item) {
ocf_dobj_close(sobj);
ocf_mngt_core_pool_remove(ctx, sobj);
ocf_volume_close(svolume);
ocf_mngt_core_pool_remove(ctx, svolume);
}
}

View File

@ -8,6 +8,6 @@
#include "../ocf_core_priv.h"
int ocf_mngt_core_init_front_dobj(ocf_core_t core);
int ocf_mngt_core_init_front_volume(ocf_core_t core);
#endif /* __OCF_CORE_MNGT_PRIV_H__ */

View File

@ -159,7 +159,7 @@ static int _ocf_mngt_get_flush_containers(ocf_cache_t cache,
}
for (i = 0, j = 0; i < OCF_CORE_MAX; i++) {
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
fc[j].core_id = i;
@ -374,7 +374,7 @@ static int _ocf_mngt_flush_containers(ocf_cache_t cache,
static int _ocf_mngt_flush_core(ocf_core_t core, bool allow_interruption)
{
ocf_core_id_t core_id = ocf_core_get_id(core);
ocf_cache_t cache = core->obj.cache;
ocf_cache_t cache = core->volume.cache;
struct flush_container fc;
int ret;
@ -450,7 +450,7 @@ static int _ocf_mng_cache_flush(ocf_cache_t cache, bool interruption)
env_atomic_set(&cache->flush_in_progress, 0);
for (i = 0, j = 0; i < OCF_CORE_MAX; i++) {
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
env_atomic_set(&cache->core[i].flushed, 0);
@ -563,7 +563,7 @@ int ocf_mngt_core_purge(ocf_core_t core, bool interruption)
cache = ocf_core_get_cache(core);
core_id = ocf_core_get_id(core);
core_size = ocf_dobj_get_length(&cache->core[core_id].obj);
core_size = ocf_volume_get_length(&cache->core[core_id].volume);
core_size = core_size ?: ~0ULL;
_ocf_mngt_begin_flush(cache);

View File

@ -10,9 +10,9 @@
#include "ocf_priv.h"
#include "ocf_cache_priv.h"
ocf_data_obj_t ocf_cache_get_data_object(ocf_cache_t cache)
ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache)
{
return ocf_cache_is_device_attached(cache) ? &cache->device->obj : NULL;
return ocf_cache_is_device_attached(cache) ? &cache->device->volume : NULL;
}
ocf_cache_id_t ocf_cache_get_id(ocf_cache_t cache)
@ -87,8 +87,8 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info)
info->attached = ocf_cache_is_device_attached(cache);
if (info->attached) {
info->data_obj_type = ocf_ctx_get_data_obj_type_id(cache->owner,
cache->device->obj.type);
info->volume_type = ocf_ctx_get_volume_type_id(cache->owner,
cache->device->volume.type);
info->size = cache->conf_meta->cachelines;
}
info->core_count = cache->conf_meta->core_count;
@ -99,7 +99,7 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info)
* valid objects may be not continuous
*/
for (i = 0; i != OCF_CORE_MAX; ++i) {
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
/* If current dirty blocks exceeds saved initial dirty
@ -170,12 +170,12 @@ int ocf_cache_get_info(ocf_cache_t cache, struct ocf_cache_info *info)
return 0;
}
const struct ocf_data_obj_uuid *ocf_cache_get_uuid(ocf_cache_t cache)
const struct ocf_volume_uuid *ocf_cache_get_uuid(ocf_cache_t cache)
{
if (!ocf_cache_is_device_attached(cache))
return NULL;
return ocf_dobj_get_uuid(ocf_cache_get_data_object(cache));
return ocf_volume_get_uuid(ocf_cache_get_volume(cache));
}
uint8_t ocf_cache_get_type_id(ocf_cache_t cache)
@ -183,8 +183,8 @@ uint8_t ocf_cache_get_type_id(ocf_cache_t cache)
if (!ocf_cache_is_device_attached(cache))
return 0xff;
return ocf_ctx_get_data_obj_type_id(ocf_cache_get_ctx(cache),
ocf_dobj_get_type(ocf_cache_get_data_object(cache)));
return ocf_ctx_get_volume_type_id(ocf_cache_get_ctx(cache),
ocf_volume_get_type(ocf_cache_get_volume(cache)));
}
ocf_cache_line_size_t ocf_cache_get_line_size(ocf_cache_t cache)
@ -210,3 +210,15 @@ ocf_ctx_t ocf_cache_get_ctx(ocf_cache_t cache)
OCF_CHECK_NULL(cache);
return cache->owner;
}
void ocf_cache_set_priv(ocf_cache_t cache, void *priv)
{
OCF_CHECK_NULL(cache);
cache->priv = priv;
}
void *ocf_cache_get_priv(ocf_cache_t cache)
{
OCF_CHECK_NULL(cache);
return cache->priv;
}

View File

@ -8,7 +8,7 @@
#include "ocf/ocf.h"
#include "ocf_env.h"
#include "ocf_data_obj_priv.h"
#include "ocf_volume_priv.h"
#include "ocf_core_priv.h"
#include "metadata/metadata_structs.h"
#include "metadata/metadata_partition_structs.h"
@ -37,7 +37,7 @@ struct ocf_trace {
struct ocf_metadata_uuid {
uint32_t size;
uint8_t data[OCF_DATA_OBJ_UUID_MAX_SIZE];
uint8_t data[OCF_VOLUME_UUID_MAX_SIZE];
} __packed;
#define OCF_CORE_USER_DATA_SIZE 64
@ -111,7 +111,7 @@ enum ocf_mngt_cache_init_mode {
/* Cache device */
struct ocf_cache_device {
struct ocf_data_obj obj;
struct ocf_volume volume;
ocf_cache_line_t metadata_offset_line;
@ -226,6 +226,8 @@ struct ocf_cache {
void *cleaning_policy_context;
struct ocf_trace trace;
void *priv;
};
#define ocf_cache_log_prefix(cache, lvl, prefix, fmt, ...) \

View File

@ -15,26 +15,26 @@
#include "ocf_request.h"
#include "ocf_trace_priv.h"
struct ocf_core_dobj {
struct ocf_core_volume {
ocf_core_t core;
};
ocf_cache_t ocf_core_get_cache(ocf_core_t core)
{
OCF_CHECK_NULL(core);
return core->obj.cache;
return core->volume.cache;
}
ocf_data_obj_t ocf_core_get_data_object(ocf_core_t core)
ocf_volume_t ocf_core_get_volume(ocf_core_t core)
{
OCF_CHECK_NULL(core);
return &core->obj;
return &core->volume;
}
ocf_data_obj_t ocf_core_get_front_data_object(ocf_core_t core)
ocf_volume_t ocf_core_get_front_volume(ocf_core_t core)
{
OCF_CHECK_NULL(core);
return &core->front_obj;
return &core->front_volume;
}
ocf_core_id_t ocf_core_get_id(ocf_core_t core)
@ -44,7 +44,7 @@ ocf_core_id_t ocf_core_get_id(ocf_core_t core)
OCF_CHECK_NULL(core);
cache = core->obj.cache;
cache = core->volume.cache;
core_id = core - cache->core;
return core_id;
@ -80,7 +80,7 @@ bool ocf_core_is_valid(ocf_cache_t cache, ocf_core_id_t id)
if (id > OCF_CORE_ID_MAX || id < OCF_CORE_ID_MIN)
return false;
if (!env_bit_test(id, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(id, cache->conf_meta->valid_core_bitmap))
return false;
return true;
@ -97,10 +97,10 @@ int ocf_core_get(ocf_cache_t cache, ocf_core_id_t id, ocf_core_t *core)
return 0;
}
int ocf_core_set_uuid(ocf_core_t core, const struct ocf_data_obj_uuid *uuid)
int ocf_core_set_uuid(ocf_core_t core, const struct ocf_volume_uuid *uuid)
{
struct ocf_cache *cache;
struct ocf_data_obj_uuid *current_uuid;
struct ocf_volume_uuid *current_uuid;
int result;
int diff;
@ -108,8 +108,8 @@ int ocf_core_set_uuid(ocf_core_t core, const struct ocf_data_obj_uuid *uuid)
OCF_CHECK_NULL(uuid);
OCF_CHECK_NULL(uuid->data);
cache = core->obj.cache;
current_uuid = &ocf_core_get_data_object(core)->uuid;
cache = core->volume.cache;
current_uuid = &ocf_core_get_volume(core)->uuid;
result = env_memcmp(current_uuid->data, current_uuid->size,
uuid->data, uuid->size, &diff);
@ -125,7 +125,7 @@ int ocf_core_set_uuid(ocf_core_t core, const struct ocf_data_obj_uuid *uuid)
if (result)
return result;
ocf_dobj_set_uuid(&core->obj, uuid);
ocf_volume_set_uuid(&core->volume, uuid);
result = ocf_metadata_flush_superblock(cache);
if (result) {
@ -217,7 +217,7 @@ int ocf_core_visit(ocf_cache_t cache, ocf_core_visitor_t visitor, void *cntx,
return -OCF_ERR_INVAL;
for (id = 0; id < OCF_CORE_MAX; id++) {
if (!env_bit_test(id, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(id, cache->conf_meta->valid_core_bitmap))
continue;
if (only_opened && !cache->core[id].opened)
@ -238,11 +238,11 @@ static inline struct ocf_core_io *ocf_io_to_core_io(struct ocf_io *io)
return ocf_io_get_priv(io);
}
static inline ocf_core_t ocf_data_obj_to_core(ocf_data_obj_t obj)
static inline ocf_core_t ocf_volume_to_core(ocf_volume_t volume)
{
struct ocf_core_dobj *core_dobj = ocf_dobj_get_priv(obj);
struct ocf_core_volume *core_volume = ocf_volume_get_priv(volume);
return core_dobj->core;
return core_volume->core;
}
static inline void inc_dirty_req_counter(struct ocf_core_io *core_io,
@ -273,19 +273,19 @@ static inline void dec_counter_if_req_was_dirty(struct ocf_core_io *core_io,
static inline int ocf_core_validate_io(struct ocf_io *io)
{
ocf_core_t core = ocf_data_obj_to_core(io->obj);
ocf_core_t core = ocf_volume_to_core(io->volume);
ocf_cache_t cache = ocf_core_get_cache(core);
if (!io->obj)
if (!io->volume)
return -EINVAL;
if (!io->ops)
return -EINVAL;
if (io->addr >= ocf_dobj_get_length(io->obj))
if (io->addr >= ocf_volume_get_length(io->volume))
return -EINVAL;
if (io->addr + io->bytes > ocf_dobj_get_length(io->obj))
if (io->addr + io->bytes > ocf_volume_get_length(io->volume))
return -EINVAL;
if (io->io_class >= OCF_IO_CLASS_MAX)
@ -336,7 +336,7 @@ void ocf_core_submit_io_mode(struct ocf_io *io, ocf_cache_mode_t cache_mode)
core_io = ocf_io_to_core_io(io);
core = ocf_data_obj_to_core(io->obj);
core = ocf_volume_to_core(io->volume);
cache = ocf_core_get_cache(core);
ocf_trace_init_io(core_io, cache);
@ -418,7 +418,7 @@ int ocf_core_submit_io_fast(struct ocf_io *io)
core_io = ocf_io_to_core_io(io);
core = ocf_data_obj_to_core(io->obj);
core = ocf_volume_to_core(io->volume);
cache = ocf_core_get_cache(core);
if (unlikely(!env_bit_test(ocf_cache_state_running,
@ -502,12 +502,12 @@ int ocf_core_submit_io_fast(struct ocf_io *io)
return -EIO;
}
static void ocf_core_data_obj_submit_io(struct ocf_io *io)
static void ocf_core_volume_submit_io(struct ocf_io *io)
{
ocf_core_submit_io_mode(io, ocf_cache_mode_none);
}
static void ocf_core_data_obj_submit_flush(struct ocf_io *io)
static void ocf_core_volume_submit_flush(struct ocf_io *io)
{
struct ocf_core_io *core_io;
ocf_core_t core;
@ -524,7 +524,7 @@ static void ocf_core_data_obj_submit_flush(struct ocf_io *io)
core_io = ocf_io_to_core_io(io);
core = ocf_data_obj_to_core(io->obj);
core = ocf_volume_to_core(io->volume);
cache = ocf_core_get_cache(core);
if (unlikely(!env_bit_test(ocf_cache_state_running,
@ -550,7 +550,7 @@ static void ocf_core_data_obj_submit_flush(struct ocf_io *io)
ocf_engine_hndl_ops_req(core_io->req);
}
static void ocf_core_data_obj_submit_discard(struct ocf_io *io)
static void ocf_core_volume_submit_discard(struct ocf_io *io)
{
struct ocf_core_io *core_io;
ocf_core_t core;
@ -567,7 +567,7 @@ static void ocf_core_data_obj_submit_discard(struct ocf_io *io)
core_io = ocf_io_to_core_io(io);
core = ocf_data_obj_to_core(io->obj);
core = ocf_volume_to_core(io->volume);
cache = ocf_core_get_cache(core);
if (unlikely(!env_bit_test(ocf_cache_state_running,
@ -593,35 +593,35 @@ static void ocf_core_data_obj_submit_discard(struct ocf_io *io)
ocf_engine_hndl_discard_req(core_io->req);
}
/* *** DATA OBJECT OPS *** */
/* *** VOLUME OPS *** */
static int ocf_core_data_obj_open(ocf_data_obj_t obj)
static int ocf_core_volume_open(ocf_volume_t volume)
{
struct ocf_core_dobj *core_dobj = ocf_dobj_get_priv(obj);
const struct ocf_data_obj_uuid *uuid = ocf_dobj_get_uuid(obj);
struct ocf_core_volume *core_volume = ocf_volume_get_priv(volume);
const struct ocf_volume_uuid *uuid = ocf_volume_get_uuid(volume);
ocf_core_t core = (ocf_core_t)uuid->data;
core_dobj->core = core;
core_volume->core = core;
return 0;
}
static void ocf_core_data_obj_close(ocf_data_obj_t obj)
static void ocf_core_volume_close(ocf_volume_t volume)
{
}
static unsigned int ocf_core_data_obj_get_max_io_size(ocf_data_obj_t obj)
static unsigned int ocf_core_volume_get_max_io_size(ocf_volume_t volume)
{
ocf_core_t core = ocf_data_obj_to_core(obj);
ocf_core_t core = ocf_volume_to_core(volume);
return ocf_dobj_get_max_io_size(&core->obj);
return ocf_volume_get_max_io_size(&core->volume);
}
static uint64_t ocf_core_data_obj_get_byte_length(ocf_data_obj_t obj)
static uint64_t ocf_core_volume_get_byte_length(ocf_volume_t volume)
{
ocf_core_t core = ocf_data_obj_to_core(obj);
ocf_core_t core = ocf_volume_to_core(volume);
return ocf_dobj_get_length(&core->obj);
return ocf_volume_get_length(&core->volume);
}
@ -653,23 +653,23 @@ static ctx_data_t *ocf_core_io_get_data(struct ocf_io *io)
return core_io->data;
}
const struct ocf_data_obj_properties ocf_core_data_obj_properties = {
const struct ocf_volume_properties ocf_core_volume_properties = {
.name = "OCF Core",
.io_priv_size = sizeof(struct ocf_core_io),
.dobj_priv_size = sizeof(struct ocf_core_dobj),
.volume_priv_size = sizeof(struct ocf_core_volume),
.caps = {
.atomic_writes = 0,
},
.ops = {
.submit_io = ocf_core_data_obj_submit_io,
.submit_flush = ocf_core_data_obj_submit_flush,
.submit_discard = ocf_core_data_obj_submit_discard,
.submit_io = ocf_core_volume_submit_io,
.submit_flush = ocf_core_volume_submit_flush,
.submit_discard = ocf_core_volume_submit_discard,
.submit_metadata = NULL,
.open = ocf_core_data_obj_open,
.close = ocf_core_data_obj_close,
.get_max_io_size = ocf_core_data_obj_get_max_io_size,
.get_length = ocf_core_data_obj_get_byte_length,
.open = ocf_core_volume_open,
.close = ocf_core_volume_close,
.get_max_io_size = ocf_core_volume_get_max_io_size,
.get_length = ocf_core_volume_get_byte_length,
},
.io_ops = {
.set_data = ocf_core_io_set_data,
@ -677,13 +677,13 @@ const struct ocf_data_obj_properties ocf_core_data_obj_properties = {
},
};
int ocf_core_data_obj_type_init(ocf_ctx_t ctx)
int ocf_core_volume_type_init(ocf_ctx_t ctx)
{
return ocf_ctx_register_data_obj_type(ctx, 0,
&ocf_core_data_obj_properties);
return ocf_ctx_register_volume_type(ctx, 0,
&ocf_core_volume_properties);
}
void ocf_core_data_obj_type_deinit(ocf_ctx_t ctx)
void ocf_core_volume_type_deinit(ocf_ctx_t ctx)
{
ocf_ctx_unregister_data_obj_type(ctx, 0);
ocf_ctx_unregister_volume_type(ctx, 0);
}

View File

@ -9,7 +9,7 @@
#include "ocf/ocf.h"
#include "ocf_env.h"
#include "ocf_ctx_priv.h"
#include "ocf_data_obj_priv.h"
#include "ocf_volume_priv.h"
#define ocf_core_log_prefix(core, lvl, prefix, fmt, ...) \
ocf_cache_log_prefix(ocf_core_get_cache(core), lvl, ".%s" prefix, \
@ -35,8 +35,8 @@ struct ocf_core_io {
struct ocf_core {
char name[OCF_CORE_NAME_SIZE];
struct ocf_data_obj front_obj;
struct ocf_data_obj obj;
struct ocf_volume front_volume;
struct ocf_volume volume;
struct {
uint64_t last;
@ -56,8 +56,8 @@ bool ocf_core_is_valid(ocf_cache_t cache, ocf_core_id_t id);
int ocf_core_set_user_metadata_raw(ocf_core_t core, void *data, size_t size);
int ocf_core_data_obj_type_init(ocf_ctx_t ctx);
int ocf_core_volume_type_init(ocf_ctx_t ctx);
void ocf_core_data_obj_type_deinit(ocf_ctx_t ctx);
void ocf_core_volume_type_deinit(ocf_ctx_t ctx);
#endif /* __OCF_CORE_PRIV_H__ */

View File

@ -6,7 +6,7 @@
#include "ocf/ocf.h"
#include "ocf_ctx_priv.h"
#include "ocf_priv.h"
#include "ocf_data_obj_priv.h"
#include "ocf_volume_priv.h"
#include "ocf_utils.h"
#include "ocf_logger_priv.h"
#include "ocf_core_priv.h"
@ -14,8 +14,8 @@
/*
*
*/
int ocf_ctx_register_data_obj_type(ocf_ctx_t ctx, uint8_t type_id,
const struct ocf_data_obj_properties *properties)
int ocf_ctx_register_volume_type(ocf_ctx_t ctx, uint8_t type_id,
const struct ocf_volume_properties *properties)
{
int result = 0;
@ -24,14 +24,14 @@ int ocf_ctx_register_data_obj_type(ocf_ctx_t ctx, uint8_t type_id,
env_mutex_lock(&ctx->lock);
if (type_id >= OCF_DATA_OBJ_TYPE_MAX || ctx->data_obj_type[type_id]) {
if (type_id >= OCF_VOLUME_TYPE_MAX || ctx->volume_type[type_id]) {
env_mutex_unlock(&ctx->lock);
result = -EINVAL;
goto err;
}
ocf_data_obj_type_init(&ctx->data_obj_type[type_id], properties);
if (!ctx->data_obj_type[type_id])
ocf_volume_type_init(&ctx->volume_type[type_id], properties);
if (!ctx->volume_type[type_id])
result = -EINVAL;
env_mutex_unlock(&ctx->lock);
@ -39,12 +39,12 @@ int ocf_ctx_register_data_obj_type(ocf_ctx_t ctx, uint8_t type_id,
if (result)
goto err;
ocf_log(ctx, log_debug, "'%s' data object operations registered\n",
ocf_log(ctx, log_debug, "'%s' volume operations registered\n",
properties->name);
return 0;
err:
ocf_log(ctx, log_err, "Failed to register data object operations '%s'",
ocf_log(ctx, log_err, "Failed to register volume operations '%s'",
properties->name);
return result;
}
@ -52,15 +52,15 @@ err:
/*
*
*/
void ocf_ctx_unregister_data_obj_type(ocf_ctx_t ctx, uint8_t type_id)
void ocf_ctx_unregister_volume_type(ocf_ctx_t ctx, uint8_t type_id)
{
OCF_CHECK_NULL(ctx);
env_mutex_lock(&ctx->lock);
if (type_id < OCF_DATA_OBJ_TYPE_MAX && ctx->data_obj_type[type_id]) {
ocf_data_obj_type_deinit(ctx->data_obj_type[type_id]);
ctx->data_obj_type[type_id] = NULL;
if (type_id < OCF_VOLUME_TYPE_MAX && ctx->volume_type[type_id]) {
ocf_volume_type_deinit(ctx->volume_type[type_id]);
ctx->volume_type[type_id] = NULL;
}
env_mutex_unlock(&ctx->lock);
@ -69,27 +69,27 @@ void ocf_ctx_unregister_data_obj_type(ocf_ctx_t ctx, uint8_t type_id)
/*
*
*/
ocf_data_obj_type_t ocf_ctx_get_data_obj_type(ocf_ctx_t ctx, uint8_t type_id)
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_DATA_OBJ_TYPE_MAX)
if (type_id >= OCF_VOLUME_TYPE_MAX)
return NULL;
return ctx->data_obj_type[type_id];
return ctx->volume_type[type_id];
}
/*
*
*/
int ocf_ctx_get_data_obj_type_id(ocf_ctx_t ctx, ocf_data_obj_type_t type)
int ocf_ctx_get_volume_type_id(ocf_ctx_t ctx, ocf_volume_type_t type)
{
int i;
OCF_CHECK_NULL(ctx);
for (i = 0; i < OCF_DATA_OBJ_TYPE_MAX; ++i) {
if (ctx->data_obj_type[i] == type)
for (i = 0; i < OCF_VOLUME_TYPE_MAX; ++i) {
if (ctx->volume_type[i] == type)
return i;
}
@ -99,15 +99,15 @@ int ocf_ctx_get_data_obj_type_id(ocf_ctx_t ctx, ocf_data_obj_type_t type)
/*
*
*/
int ocf_ctx_data_obj_create(ocf_ctx_t ctx, ocf_data_obj_t *obj,
struct ocf_data_obj_uuid *uuid, uint8_t type_id)
int ocf_ctx_volume_create(ocf_ctx_t ctx, ocf_volume_t *volume,
struct ocf_volume_uuid *uuid, uint8_t type_id)
{
OCF_CHECK_NULL(ctx);
if (type_id >= OCF_DATA_OBJ_TYPE_MAX)
if (type_id >= OCF_VOLUME_TYPE_MAX)
return -EINVAL;
return ocf_dobj_create(obj, ctx->data_obj_type[type_id], uuid);
return ocf_volume_create(volume, ctx->volume_type[type_id], uuid);
}
/*
@ -143,7 +143,7 @@ int ocf_ctx_init(ocf_ctx_t *ctx, const struct ocf_ctx_config *cfg)
if (ret)
goto err_logger;
ret = ocf_core_data_obj_type_init(ocf_ctx);
ret = ocf_core_volume_type_init(ocf_ctx);
if (ret)
goto err_utils;
@ -177,7 +177,7 @@ int ocf_ctx_exit(ocf_ctx_t ctx)
if (result)
return result;
ocf_core_data_obj_type_deinit(ctx);
ocf_core_volume_type_deinit(ctx);
ocf_utils_deinit(ctx);
ocf_logger_close(&ctx->logger);

View File

@ -10,7 +10,7 @@
#include "ocf/ocf_ctx.h"
#include "ocf_logger_priv.h"
#define OCF_DATA_OBJ_TYPE_MAX 8
#define OCF_VOLUME_TYPE_MAX 8
/**
* @brief OCF main control structure
@ -19,7 +19,7 @@ struct ocf_ctx {
const struct ocf_ctx_ops *ops;
const struct ocf_ctx_config *cfg;
struct ocf_logger logger;
struct ocf_data_obj_type *data_obj_type[OCF_DATA_OBJ_TYPE_MAX];
struct ocf_volume_type *volume_type[OCF_VOLUME_TYPE_MAX];
env_mutex lock;
struct list_head caches;
struct {

View File

@ -1,310 +0,0 @@
/*
* Copyright(c) 2012-2018 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include "ocf/ocf.h"
#include "ocf_priv.h"
#include "ocf_data_obj_priv.h"
#include "ocf_io_priv.h"
#include "ocf_env.h"
/* *** Bottom interface *** */
/*
* Data object type
*/
int ocf_data_obj_type_init(struct ocf_data_obj_type **type,
const struct ocf_data_obj_properties *properties)
{
const struct ocf_data_obj_ops *ops = &properties->ops;
struct ocf_data_obj_type *new_type;
int ret;
if (!ops->submit_io || !ops->open || !ops->close ||
!ops->get_max_io_size || !ops->get_length) {
return -EINVAL;
}
if (properties->caps.atomic_writes && !ops->submit_metadata)
return -EINVAL;
new_type = env_zalloc(sizeof(**type), ENV_MEM_NORMAL);
if (!new_type)
return -OCF_ERR_NO_MEM;
new_type->allocator = ocf_io_allocator_create(
properties->io_priv_size, properties->name);
if (!new_type->allocator) {
ret = -ENOMEM;
goto err;
}
new_type->properties = properties;
*type = new_type;
return 0;
err:
env_free(new_type);
return ret;
}
void ocf_data_obj_type_deinit(struct ocf_data_obj_type *type)
{
ocf_io_allocator_destroy(type->allocator);
env_free(type);
}
/*
* Data object frontend API
*/
int ocf_dobj_init(ocf_data_obj_t obj, ocf_data_obj_type_t type,
struct ocf_data_obj_uuid *uuid, bool uuid_copy)
{
uint32_t priv_size = type->properties->dobj_priv_size;
void *data;
int ret;
if (!obj || !type)
return -OCF_ERR_INVAL;
obj->opened = false;
obj->type = type;
obj->priv = env_zalloc(priv_size, ENV_MEM_NORMAL);
if (!obj->priv)
return -OCF_ERR_NO_MEM;
if (!uuid) {
obj->uuid.size = 0;
obj->uuid.data = NULL;
obj->uuid_copy = false;
return 0;
}
obj->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);
goto err;
}
obj->uuid.data = data;
} else {
obj->uuid.data = uuid->data;
}
obj->uuid.size = uuid->size;
return 0;
err:
env_free(obj->priv);
return -OCF_ERR_NO_MEM;
}
void ocf_dobj_deinit(ocf_data_obj_t obj)
{
OCF_CHECK_NULL(obj);
env_free(obj->priv);
if (obj->uuid_copy && obj->uuid.data)
env_vfree(obj->uuid.data);
}
void ocf_dobj_move(ocf_data_obj_t obj, ocf_data_obj_t from)
{
OCF_CHECK_NULL(obj);
OCF_CHECK_NULL(from);
ocf_dobj_deinit(obj);
obj->opened = from->opened;
obj->type = from->type;
obj->uuid = from->uuid;
obj->uuid_copy = from->uuid_copy;
obj->priv = from->priv;
obj->cache = from->cache;
obj->features = from->features;
/*
* Deinitialize original object without freeing resources.
*/
from->opened = false;
from->priv = NULL;
}
int ocf_dobj_create(ocf_data_obj_t *obj, ocf_data_obj_type_t type,
struct ocf_data_obj_uuid *uuid)
{
ocf_data_obj_t tmp_obj;
int ret;
OCF_CHECK_NULL(obj);
tmp_obj = env_zalloc(sizeof(*tmp_obj), ENV_MEM_NORMAL);
if (!tmp_obj)
return -OCF_ERR_NO_MEM;
ret = ocf_dobj_init(tmp_obj, type, uuid, true);
if (ret) {
env_free(tmp_obj);
return ret;
}
*obj = tmp_obj;
return 0;
}
void ocf_dobj_destroy(ocf_data_obj_t obj)
{
OCF_CHECK_NULL(obj);
ocf_dobj_deinit(obj);
env_free(obj);
}
ocf_data_obj_type_t ocf_dobj_get_type(ocf_data_obj_t obj)
{
OCF_CHECK_NULL(obj);
return obj->type;
}
const struct ocf_data_obj_uuid *ocf_dobj_get_uuid(ocf_data_obj_t obj)
{
OCF_CHECK_NULL(obj);
return &obj->uuid;
}
void ocf_dobj_set_uuid(ocf_data_obj_t obj, const struct ocf_data_obj_uuid *uuid)
{
OCF_CHECK_NULL(obj);
if (obj->uuid_copy && obj->uuid.data)
env_vfree(obj->uuid.data);
obj->uuid.data = uuid->data;
obj->uuid.size = uuid->size;
}
void *ocf_dobj_get_priv(ocf_data_obj_t obj)
{
return obj->priv;
}
ocf_cache_t ocf_dobj_get_cache(ocf_data_obj_t obj)
{
OCF_CHECK_NULL(obj);
return obj->cache;
}
int ocf_dobj_is_atomic(ocf_data_obj_t obj)
{
return obj->type->properties->caps.atomic_writes;
}
struct ocf_io *ocf_dobj_new_io(ocf_data_obj_t obj)
{
if (!obj->opened)
return NULL;
return ocf_io_new(obj);
}
void ocf_dobj_submit_io(struct ocf_io *io)
{
ENV_BUG_ON(!io->obj->type->properties->ops.submit_io);
if (!io->obj->opened)
io->end(io, -EIO);
io->obj->type->properties->ops.submit_io(io);
}
void ocf_dobj_submit_flush(struct ocf_io *io)
{
ENV_BUG_ON(!io->obj->type->properties->ops.submit_flush);
if (!io->obj->opened)
io->end(io, -EIO);
if (!io->obj->type->properties->ops.submit_flush) {
ocf_io_end(io, 0);
return;
}
io->obj->type->properties->ops.submit_flush(io);
}
void ocf_dobj_submit_discard(struct ocf_io *io)
{
if (!io->obj->opened)
io->end(io, -EIO);
if (!io->obj->type->properties->ops.submit_discard) {
ocf_io_end(io, 0);
return;
}
io->obj->type->properties->ops.submit_discard(io);
}
int ocf_dobj_open(ocf_data_obj_t obj)
{
int ret;
ENV_BUG_ON(!obj->type->properties->ops.open);
ENV_BUG_ON(obj->opened);
ret = obj->type->properties->ops.open(obj);
if (ret)
return ret;
obj->opened = true;
return 0;
}
void ocf_dobj_close(ocf_data_obj_t obj)
{
ENV_BUG_ON(!obj->type->properties->ops.close);
ENV_BUG_ON(!obj->opened);
obj->type->properties->ops.close(obj);
obj->opened = false;
}
unsigned int ocf_dobj_get_max_io_size(ocf_data_obj_t obj)
{
ENV_BUG_ON(!obj->type->properties->ops.get_max_io_size);
if (!obj->opened)
return 0;
return obj->type->properties->ops.get_max_io_size(obj);
}
uint64_t ocf_dobj_get_length(ocf_data_obj_t obj)
{
ENV_BUG_ON(!obj->type->properties->ops.get_length);
if (!obj->opened)
return 0;
return obj->type->properties->ops.get_length(obj);
}

View File

@ -1,55 +0,0 @@
/*
* Copyright(c) 2012-2018 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __OCF_DATA_OBJ_PRIV_H__
#define __OCF_DATA_OBJ_PRIV_H__
#include "ocf_env.h"
#include "ocf_io_priv.h"
struct ocf_data_obj_type {
const struct ocf_data_obj_properties *properties;
env_allocator *allocator;
};
struct ocf_data_obj {
ocf_data_obj_type_t type;
struct ocf_data_obj_uuid uuid;
bool opened;
bool uuid_copy;
void *priv;
ocf_cache_t cache;
struct list_head core_pool_item;
struct {
unsigned discard_zeroes:1;
/* true if reading discarded pages returns 0 */
} features;
};
int ocf_data_obj_type_init(struct ocf_data_obj_type **type,
const struct ocf_data_obj_properties *properties);
void ocf_data_obj_type_deinit(struct ocf_data_obj_type *type);
void ocf_dobj_move(ocf_data_obj_t obj, ocf_data_obj_t from);
void ocf_dobj_set_uuid(ocf_data_obj_t obj,
const struct ocf_data_obj_uuid *uuid);
static inline void ocf_dobj_submit_metadata(struct ocf_io *io)
{
ENV_BUG_ON(!io->obj->type->properties->ops.submit_metadata);
io->obj->type->properties->ops.submit_metadata(io);
}
static inline void ocf_dobj_submit_write_zeroes(struct ocf_io *io)
{
ENV_BUG_ON(!io->obj->type->properties->ops.submit_write_zeroes);
io->obj->type->properties->ops.submit_write_zeroes(io);
}
#endif /*__OCF_DATA_OBJ_PRIV_H__ */

View File

@ -5,7 +5,7 @@
#include "ocf/ocf.h"
#include "ocf_io_priv.h"
#include "ocf_data_obj_priv.h"
#include "ocf_volume_priv.h"
/*
* This is io allocator dedicated for bottom devices.
@ -48,13 +48,13 @@ void *ocf_io_get_meta(struct ocf_io* io)
return (void *)io - sizeof(struct ocf_io_meta);
}
struct ocf_io *ocf_io_new(ocf_data_obj_t obj)
struct ocf_io *ocf_io_new(ocf_volume_t volume)
{
struct ocf_io *io;
struct ocf_io_meta *io_meta;
void *data;
data = env_allocator_new(obj->type->allocator);
data = env_allocator_new(volume->type->allocator);
if (!data)
return NULL;
@ -62,8 +62,8 @@ struct ocf_io *ocf_io_new(ocf_data_obj_t obj)
io_meta = ocf_io_get_meta(io);
io->obj = obj;
io->ops = &obj->type->properties->io_ops;
io->volume = volume;
io->ops = &volume->type->properties->io_ops;
env_atomic_set(&io_meta->ref_count, 1);
return io;
@ -92,6 +92,6 @@ void ocf_io_put(struct ocf_io *io)
if (env_atomic_dec_return(&io_meta->ref_count))
return;
env_allocator_del(io->obj->type->allocator,
env_allocator_del(io->volume->type->allocator,
(void *)io - sizeof(struct ocf_io_meta));
}

View File

@ -18,7 +18,7 @@ env_allocator *ocf_io_allocator_create(uint32_t size, const char *name);
void ocf_io_allocator_destroy(env_allocator *allocator);
struct ocf_io *ocf_io_new(ocf_data_obj_t obj);
struct ocf_io *ocf_io_new(ocf_volume_t volume);
static inline void ocf_io_start(struct ocf_io *io)
{

View File

@ -30,7 +30,7 @@ int ocf_metadata_get_atomic_entry(ocf_cache_t cache,
OCF_CHECK_NULL(cache);
OCF_CHECK_NULL(entry);
if (addr > ocf_dobj_get_length(&cache->device->obj))
if (addr > ocf_volume_get_length(&cache->device->volume))
return -EFAULT;
if (addr < cache->device->metadata_offset) {

View File

@ -97,7 +97,7 @@ void ocf_core_stats_initialize_all(ocf_cache_t cache)
ocf_core_id_t id;
for (id = 0; id < OCF_CORE_MAX; id++) {
if (!env_bit_test(id, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(id, cache->conf_meta->valid_core_bitmap))
continue;
ocf_core_stats_initialize(&cache->core[id]);
@ -234,8 +234,8 @@ int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats)
ENV_BUG_ON(env_memset(stats, sizeof(*stats), 0));
stats->core_size_bytes = ocf_dobj_get_length(
&cache->core[core_id].obj);
stats->core_size_bytes = ocf_volume_get_length(
&cache->core[core_id].volume);
stats->core_size = ocf_bytes_2_lines_round_up(cache,
stats->core_size_bytes);
stats->seq_cutoff_threshold = ocf_core_get_seq_cutoff_threshold(core);
@ -244,8 +244,8 @@ int ocf_core_get_stats(ocf_core_t core, struct ocf_stats_core *stats)
env_atomic_read(&cache->core_runtime_meta[core_id].cached_clines);
copy_block_stats(&stats->core_obj, &core_stats->core_blocks);
copy_block_stats(&stats->cache_obj, &core_stats->cache_blocks);
copy_block_stats(&stats->core_volume, &core_stats->core_blocks);
copy_block_stats(&stats->cache_volume, &core_stats->cache_blocks);
copy_error_stats(&stats->core_errors,
&core_stats->core_errors);

View File

@ -50,7 +50,7 @@ static uint64_t _get_cache_occupancy(ocf_cache_t cache)
uint32_t i;
for (i = 0; i != OCF_CORE_MAX; ++i) {
if (!env_bit_test(i, cache->conf_meta->valid_object_bitmap))
if (!env_bit_test(i, cache->conf_meta->valid_core_bitmap))
continue;
result += env_atomic_read(
@ -103,21 +103,21 @@ static void _fill_blocks(struct ocf_stats_blocks *blocks,
{
uint64_t rd, wr, total;
/* Core data object */
rd = _bytes4k(s->core_obj.read);
wr = _bytes4k(s->core_obj.write);
/* Core volume */
rd = _bytes4k(s->core_volume.read);
wr = _bytes4k(s->core_volume.write);
total = rd + wr;
_set(&blocks->core_obj_rd, rd, total);
_set(&blocks->core_obj_wr, wr, total);
_set(&blocks->core_obj_total, total, total);
_set(&blocks->core_volume_rd, rd, total);
_set(&blocks->core_volume_wr, wr, total);
_set(&blocks->core_volume_total, total, total);
/* Cache data object */
rd = _bytes4k(s->cache_obj.read);
wr = _bytes4k(s->cache_obj.write);
/* Cache volume */
rd = _bytes4k(s->cache_volume.read);
wr = _bytes4k(s->cache_volume.write);
total = rd + wr;
_set(&blocks->cache_obj_rd, rd, total);
_set(&blocks->cache_obj_wr, wr, total);
_set(&blocks->cache_obj_total, total, total);
_set(&blocks->cache_volume_rd, rd, total);
_set(&blocks->cache_volume_wr, wr, total);
_set(&blocks->cache_volume_total, total, total);
/* Core (cache volume) */
rd = _bytes4k(s->core.read);
@ -136,16 +136,16 @@ static void _fill_errors(struct ocf_stats_errors *errors,
rd = s->core_errors.read;
wr = s->core_errors.write;
total = rd + wr;
_set(&errors->core_obj_rd, rd, total);
_set(&errors->core_obj_wr, wr, total);
_set(&errors->core_obj_total, total, total);
_set(&errors->core_volume_rd, rd, total);
_set(&errors->core_volume_wr, wr, total);
_set(&errors->core_volume_total, total, total);
rd = s->cache_errors.read;
wr = s->cache_errors.write;
total = rd + wr;
_set(&errors->cache_obj_rd, rd, total);
_set(&errors->cache_obj_wr, wr, total);
_set(&errors->cache_obj_total, total, total);
_set(&errors->cache_volume_rd, rd, total);
_set(&errors->cache_volume_wr, wr, total);
_set(&errors->cache_volume_total, total, total);
total = s->core_errors.read + s->core_errors.write +
s->cache_errors.read + s->cache_errors.write;
@ -242,8 +242,8 @@ static int _accumulate_stats(ocf_core_t core, void *cntx)
if (result)
return result;
_accumulate_block(&total->cache_obj, &stats.cache_obj);
_accumulate_block(&total->core_obj, &stats.core_obj);
_accumulate_block(&total->cache_volume, &stats.cache_volume);
_accumulate_block(&total->core_volume, &stats.core_volume);
_accumulate_block(&total->core, &stats.core);
_accumulate_reqs(&total->read_reqs, &stats.read_reqs);

View File

@ -28,8 +28,8 @@ static int _ocf_core_desc(ocf_core_t core, void *ctx)
env_ticks_to_nsecs(env_get_tick_count()),
sizeof(core_desc));
core_desc.id = ocf_core_get_id(core);
core_desc.core_size = ocf_dobj_get_length(
ocf_core_get_data_object(core));
core_desc.core_size = ocf_volume_get_length(
ocf_core_get_volume(core));
ocf_trace_push(cache, visitor_ctx->io_queue,
&core_desc, sizeof(core_desc));
@ -54,8 +54,8 @@ static int _ocf_trace_cache_info(ocf_cache_t cache, uint32_t io_queue)
if (ocf_cache_is_device_attached(cache)) {
/* Attached cache */
cache_desc.cache_size = ocf_dobj_get_length(
ocf_cache_get_data_object(cache));
cache_desc.cache_size = ocf_volume_get_length(
ocf_cache_get_volume(cache));
} else {
cache_desc.cache_size = 0;
}

310
src/ocf_volume.c Normal file
View File

@ -0,0 +1,310 @@
/*
* Copyright(c) 2012-2018 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#include "ocf/ocf.h"
#include "ocf_priv.h"
#include "ocf_volume_priv.h"
#include "ocf_io_priv.h"
#include "ocf_env.h"
/* *** Bottom interface *** */
/*
* Volume type
*/
int ocf_volume_type_init(struct ocf_volume_type **type,
const struct ocf_volume_properties *properties)
{
const struct ocf_volume_ops *ops = &properties->ops;
struct ocf_volume_type *new_type;
int ret;
if (!ops->submit_io || !ops->open || !ops->close ||
!ops->get_max_io_size || !ops->get_length) {
return -EINVAL;
}
if (properties->caps.atomic_writes && !ops->submit_metadata)
return -EINVAL;
new_type = env_zalloc(sizeof(**type), ENV_MEM_NORMAL);
if (!new_type)
return -OCF_ERR_NO_MEM;
new_type->allocator = ocf_io_allocator_create(
properties->io_priv_size, properties->name);
if (!new_type->allocator) {
ret = -ENOMEM;
goto err;
}
new_type->properties = properties;
*type = new_type;
return 0;
err:
env_free(new_type);
return ret;
}
void ocf_volume_type_deinit(struct ocf_volume_type *type)
{
ocf_io_allocator_destroy(type->allocator);
env_free(type);
}
/*
* Volume frontend API
*/
int ocf_volume_init(ocf_volume_t volume, ocf_volume_type_t type,
struct ocf_volume_uuid *uuid, bool uuid_copy)
{
uint32_t priv_size = type->properties->volume_priv_size;
void *data;
int ret;
if (!volume || !type)
return -OCF_ERR_INVAL;
volume->opened = false;
volume->type = type;
volume->priv = env_zalloc(priv_size, ENV_MEM_NORMAL);
if (!volume->priv)
return -OCF_ERR_NO_MEM;
if (!uuid) {
volume->uuid.size = 0;
volume->uuid.data = NULL;
volume->uuid_copy = false;
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);
goto err;
}
volume->uuid.data = data;
} else {
volume->uuid.data = uuid->data;
}
volume->uuid.size = uuid->size;
return 0;
err:
env_free(volume->priv);
return -OCF_ERR_NO_MEM;
}
void ocf_volume_deinit(ocf_volume_t volume)
{
OCF_CHECK_NULL(volume);
env_free(volume->priv);
if (volume->uuid_copy && volume->uuid.data)
env_vfree(volume->uuid.data);
}
void ocf_volume_move(ocf_volume_t volume, ocf_volume_t from)
{
OCF_CHECK_NULL(volume);
OCF_CHECK_NULL(from);
ocf_volume_deinit(volume);
volume->opened = from->opened;
volume->type = from->type;
volume->uuid = from->uuid;
volume->uuid_copy = from->uuid_copy;
volume->priv = from->priv;
volume->cache = from->cache;
volume->features = from->features;
/*
* Deinitialize original volume without freeing resources.
*/
from->opened = false;
from->priv = NULL;
}
int ocf_volume_create(ocf_volume_t *volume, ocf_volume_type_t type,
struct ocf_volume_uuid *uuid)
{
ocf_volume_t tmp_volume;
int ret;
OCF_CHECK_NULL(volume);
tmp_volume = env_zalloc(sizeof(*tmp_volume), ENV_MEM_NORMAL);
if (!tmp_volume)
return -OCF_ERR_NO_MEM;
ret = ocf_volume_init(tmp_volume, type, uuid, true);
if (ret) {
env_free(tmp_volume);
return ret;
}
*volume = tmp_volume;
return 0;
}
void ocf_volume_destroy(ocf_volume_t volume)
{
OCF_CHECK_NULL(volume);
ocf_volume_deinit(volume);
env_free(volume);
}
ocf_volume_type_t ocf_volume_get_type(ocf_volume_t volume)
{
OCF_CHECK_NULL(volume);
return volume->type;
}
const struct ocf_volume_uuid *ocf_volume_get_uuid(ocf_volume_t volume)
{
OCF_CHECK_NULL(volume);
return &volume->uuid;
}
void ocf_volume_set_uuid(ocf_volume_t volume, const struct ocf_volume_uuid *uuid)
{
OCF_CHECK_NULL(volume);
if (volume->uuid_copy && volume->uuid.data)
env_vfree(volume->uuid.data);
volume->uuid.data = uuid->data;
volume->uuid.size = uuid->size;
}
void *ocf_volume_get_priv(ocf_volume_t volume)
{
return volume->priv;
}
ocf_cache_t ocf_volume_get_cache(ocf_volume_t volume)
{
OCF_CHECK_NULL(volume);
return volume->cache;
}
int ocf_volume_is_atomic(ocf_volume_t volume)
{
return volume->type->properties->caps.atomic_writes;
}
struct ocf_io *ocf_volume_new_io(ocf_volume_t volume)
{
if (!volume->opened)
return NULL;
return ocf_io_new(volume);
}
void ocf_volume_submit_io(struct ocf_io *io)
{
ENV_BUG_ON(!io->volume->type->properties->ops.submit_io);
if (!io->volume->opened)
io->end(io, -EIO);
io->volume->type->properties->ops.submit_io(io);
}
void ocf_volume_submit_flush(struct ocf_io *io)
{
ENV_BUG_ON(!io->volume->type->properties->ops.submit_flush);
if (!io->volume->opened)
io->end(io, -EIO);
if (!io->volume->type->properties->ops.submit_flush) {
ocf_io_end(io, 0);
return;
}
io->volume->type->properties->ops.submit_flush(io);
}
void ocf_volume_submit_discard(struct ocf_io *io)
{
if (!io->volume->opened)
io->end(io, -EIO);
if (!io->volume->type->properties->ops.submit_discard) {
ocf_io_end(io, 0);
return;
}
io->volume->type->properties->ops.submit_discard(io);
}
int ocf_volume_open(ocf_volume_t volume)
{
int ret;
ENV_BUG_ON(!volume->type->properties->ops.open);
ENV_BUG_ON(volume->opened);
ret = volume->type->properties->ops.open(volume);
if (ret)
return ret;
volume->opened = true;
return 0;
}
void ocf_volume_close(ocf_volume_t volume)
{
ENV_BUG_ON(!volume->type->properties->ops.close);
ENV_BUG_ON(!volume->opened);
volume->type->properties->ops.close(volume);
volume->opened = false;
}
unsigned int ocf_volume_get_max_io_size(ocf_volume_t volume)
{
ENV_BUG_ON(!volume->type->properties->ops.get_max_io_size);
if (!volume->opened)
return 0;
return volume->type->properties->ops.get_max_io_size(volume);
}
uint64_t ocf_volume_get_length(ocf_volume_t volume)
{
ENV_BUG_ON(!volume->type->properties->ops.get_length);
if (!volume->opened)
return 0;
return volume->type->properties->ops.get_length(volume);
}

55
src/ocf_volume_priv.h Normal file
View File

@ -0,0 +1,55 @@
/*
* Copyright(c) 2012-2018 Intel Corporation
* SPDX-License-Identifier: BSD-3-Clause-Clear
*/
#ifndef __OCF_VOLUME_PRIV_H__
#define __OCF_VOLUME_PRIV_H__
#include "ocf_env.h"
#include "ocf_io_priv.h"
struct ocf_volume_type {
const struct ocf_volume_properties *properties;
env_allocator *allocator;
};
struct ocf_volume {
ocf_volume_type_t type;
struct ocf_volume_uuid uuid;
bool opened;
bool uuid_copy;
void *priv;
ocf_cache_t cache;
struct list_head core_pool_item;
struct {
unsigned discard_zeroes:1;
/* true if reading discarded pages returns 0 */
} features;
};
int ocf_volume_type_init(struct ocf_volume_type **type,
const struct ocf_volume_properties *properties);
void ocf_volume_type_deinit(struct ocf_volume_type *type);
void ocf_volume_move(ocf_volume_t volume, ocf_volume_t from);
void ocf_volume_set_uuid(ocf_volume_t volume,
const struct ocf_volume_uuid *uuid);
static inline void ocf_volume_submit_metadata(struct ocf_io *io)
{
ENV_BUG_ON(!io->volume->type->properties->ops.submit_metadata);
io->volume->type->properties->ops.submit_metadata(io);
}
static inline void ocf_volume_submit_write_zeroes(struct ocf_io *io)
{
ENV_BUG_ON(!io->volume->type->properties->ops.submit_write_zeroes);
io->volume->type->properties->ops.submit_write_zeroes(io);
}
#endif /*__OCF_VOLUME_PRIV_H__ */

View File

@ -277,7 +277,7 @@ static int _ocf_cleaner_fire_flush_cache(struct ocf_request *req)
OCF_DEBUG_TRACE(req->cache);
io = ocf_dobj_new_io(&req->cache->device->obj);
io = ocf_volume_new_io(&req->cache->device->volume);
if (!io) {
ocf_metadata_error(req->cache);
req->error = -ENOMEM;
@ -287,7 +287,7 @@ static int _ocf_cleaner_fire_flush_cache(struct ocf_request *req)
ocf_io_configure(io, 0, 0, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, req, NULL, _ocf_cleaner_flush_cache_io_end);
ocf_dobj_submit_flush(io);
ocf_volume_submit_flush(io);
return 0;
}
@ -432,7 +432,7 @@ static int _ocf_cleaner_fire_flush_cores(struct ocf_request *req)
ocf_io_configure(io, 0, 0, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, iter, req, _ocf_cleaner_flush_cores_io_cmpl);
ocf_dobj_submit_flush(io);
ocf_volume_submit_flush(io);
}
/* Protect IO completion race */
@ -519,7 +519,7 @@ static void _ocf_cleaner_core_io_for_dirty_range(struct ocf_request *req,
env_atomic_inc(&req->req_remaining);
/* Send IO */
ocf_dobj_submit_io(io);
ocf_volume_submit_io(io);
return;
error:
@ -695,7 +695,7 @@ static int _ocf_cleaner_fire_cache(struct ocf_request *req)
env_atomic64_add(ocf_line_size(cache), &cache_stats->read_bytes);
ocf_dobj_submit_io(io);
ocf_volume_submit_io(io);
}
/* Protect IO completion race */

View File

@ -6,7 +6,7 @@
#ifndef UTILS_DEVICE_H_
#define UTILS_DEVICE_H_
static inline int _ocf_uuid_set(const struct ocf_data_obj_uuid *uuid,
static inline int _ocf_uuid_set(const struct ocf_volume_uuid *uuid,
struct ocf_metadata_uuid *muuid)
{
int result;
@ -36,8 +36,8 @@ static inline int _ocf_uuid_set(const struct ocf_data_obj_uuid *uuid,
}
static inline int ocf_metadata_set_core_uuid(ocf_core_t core,
const struct ocf_data_obj_uuid *uuid,
struct ocf_data_obj_uuid *new_uuid)
const struct ocf_volume_uuid *uuid,
struct ocf_volume_uuid *new_uuid)
{
ocf_cache_t cache = ocf_core_get_cache(core);
struct ocf_metadata_uuid *muuid = ocf_metadata_get_core_uuid(cache,
@ -56,7 +56,7 @@ static inline int ocf_metadata_set_core_uuid(ocf_core_t core,
static inline void ocf_metadata_clear_core_uuid(ocf_core_t core)
{
struct ocf_data_obj_uuid uuid = { .size = 0, };
struct ocf_volume_uuid uuid = { .size = 0, };
ocf_metadata_set_core_uuid(core, &uuid, NULL);
}

View File

@ -6,7 +6,7 @@
#include "ocf/ocf.h"
#include "../ocf_priv.h"
#include "../ocf_cache_priv.h"
#include "../ocf_data_obj_priv.h"
#include "../ocf_volume_priv.h"
#include "../ocf_request.h"
#include "utils_io.h"
#include "utils_cache_line.h"
@ -27,7 +27,7 @@ struct discard_io_request {
int error;
};
static void _ocf_obj_flush_end(struct ocf_io *io, int err)
static void _ocf_volume_flush_end(struct ocf_io *io, int err)
{
struct ocf_submit_io_wait_context *cntx = io->priv1;
cntx->error = err;
@ -36,7 +36,7 @@ static void _ocf_obj_flush_end(struct ocf_io *io, int err)
ocf_io_put(io);
}
int ocf_submit_obj_flush_wait(ocf_data_obj_t obj)
int ocf_submit_volume_flush_wait(ocf_volume_t volume)
{
struct ocf_submit_io_wait_context cntx = { };
struct ocf_io *io;
@ -44,14 +44,14 @@ int ocf_submit_obj_flush_wait(ocf_data_obj_t obj)
env_atomic_set(&cntx.req_remaining, 1);
env_completion_init(&cntx.complete);
io = ocf_dobj_new_io(obj);
io = ocf_volume_new_io(volume);
if (!io)
return -ENOMEM;
ocf_io_configure(io, 0, 0, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, &cntx, NULL, _ocf_obj_flush_end);
ocf_io_set_cmpl(io, &cntx, NULL, _ocf_volume_flush_end);
ocf_dobj_submit_flush(io);
ocf_volume_submit_flush(io);
env_completion_wait(&cntx.complete);
@ -59,7 +59,7 @@ int ocf_submit_obj_flush_wait(ocf_data_obj_t obj)
}
static void ocf_submit_obj_discard_wait_io(struct ocf_io *io, int error)
static void ocf_submit_volume_discard_wait_io(struct ocf_io *io, int error)
{
struct ocf_submit_io_wait_context *cntx = io->priv1;
@ -75,7 +75,7 @@ static void ocf_submit_obj_discard_wait_io(struct ocf_io *io, int error)
env_completion_complete(&cntx->complete);
}
int ocf_submit_obj_discard_wait(ocf_data_obj_t obj, uint64_t addr,
int ocf_submit_volume_discard_wait(ocf_volume_t volume, uint64_t addr,
uint64_t length)
{
struct ocf_submit_io_wait_context cntx = { };
@ -87,7 +87,7 @@ int ocf_submit_obj_discard_wait(ocf_data_obj_t obj, uint64_t addr,
env_completion_init(&cntx.complete);
while (length) {
struct ocf_io *io = ocf_dobj_new_io(obj);
struct ocf_io *io = ocf_volume_new_io(volume);
if (!io) {
cntx.error = -ENOMEM;
@ -100,8 +100,8 @@ int ocf_submit_obj_discard_wait(ocf_data_obj_t obj, uint64_t addr,
ocf_io_configure(io, addr, bytes, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, &cntx, NULL,
ocf_submit_obj_discard_wait_io);
ocf_dobj_submit_discard(io);
ocf_submit_volume_discard_wait_io);
ocf_volume_submit_discard(io);
addr += bytes;
length -= bytes;
@ -115,7 +115,7 @@ int ocf_submit_obj_discard_wait(ocf_data_obj_t obj, uint64_t addr,
return cntx.error;
}
static void ocf_submit_obj_zeroes_wait_io(struct ocf_io *io, int error)
static void ocf_submit_volume_zeroes_wait_io(struct ocf_io *io, int error)
{
struct ocf_submit_io_wait_context *cntx = io->priv1;
@ -125,7 +125,7 @@ static void ocf_submit_obj_zeroes_wait_io(struct ocf_io *io, int error)
env_completion_complete(&cntx->complete);
}
int ocf_submit_write_zeroes_wait(ocf_data_obj_t obj, uint64_t addr,
int ocf_submit_write_zeroes_wait(ocf_volume_t volume, uint64_t addr,
uint64_t length)
{
struct ocf_submit_io_wait_context cntx = { };
@ -134,7 +134,7 @@ int ocf_submit_write_zeroes_wait(ocf_data_obj_t obj, uint64_t addr,
uint32_t step = 0;
struct ocf_io *io;
io = ocf_dobj_new_io(obj);
io = ocf_volume_new_io(volume);
if (!io)
return -ENOMEM;
@ -145,8 +145,8 @@ int ocf_submit_write_zeroes_wait(ocf_data_obj_t obj, uint64_t addr,
ocf_io_configure(io, addr, bytes, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, &cntx, NULL,
ocf_submit_obj_zeroes_wait_io);
ocf_dobj_submit_write_zeroes(io);
ocf_submit_volume_zeroes_wait_io);
ocf_volume_submit_write_zeroes(io);
addr += bytes;
length -= bytes;
@ -171,7 +171,7 @@ int ocf_submit_cache_page(struct ocf_cache *cache, uint64_t addr,
int result = 0;
/* Allocate resources for IO */
io = ocf_dobj_new_io(&cache->device->obj);
io = ocf_volume_new_io(&cache->device->volume);
data = ctx_data_alloc(cache->owner, 1);
if (!io || !data) {
@ -201,7 +201,7 @@ end:
return result;
}
static void ocf_submit_obj_req_cmpl(struct ocf_io *io, int error)
static void ocf_submit_volume_req_cmpl(struct ocf_io *io, int error)
{
struct ocf_request *req = io->priv1;
ocf_req_end_t callback = io->priv2;
@ -242,7 +242,7 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
ocf_io_configure(io, addr, bytes, dir, class, flags);
ocf_io_set_queue(io, req->io_queue);
ocf_io_set_cmpl(io, req, callback, ocf_submit_obj_req_cmpl);
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
err = ocf_io_set_data(io, req->data, 0);
if (err) {
@ -251,7 +251,7 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
goto update_stats;
}
ocf_dobj_submit_io(io);
ocf_volume_submit_io(io);
total_bytes = req->byte_length;
goto update_stats;
@ -290,7 +290,7 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
ocf_io_configure(io, addr, bytes, dir, class, flags);
ocf_io_set_queue(io, req->io_queue);
ocf_io_set_cmpl(io, req, callback, ocf_submit_obj_req_cmpl);
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
err = ocf_io_set_data(io, req->data, total_bytes);
if (err) {
@ -300,7 +300,7 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
callback(req, err);
goto update_stats;
}
ocf_dobj_submit_io(io);
ocf_volume_submit_io(io);
total_bytes += bytes;
}
@ -311,7 +311,7 @@ update_stats:
env_atomic64_add(total_bytes, &cache_stats->read_bytes);
}
void ocf_submit_obj_req(ocf_data_obj_t obj, struct ocf_request *req,
void ocf_submit_volume_req(ocf_volume_t volume, struct ocf_request *req,
ocf_req_end_t callback)
{
struct ocf_cache *cache = req->cache;
@ -329,7 +329,7 @@ void ocf_submit_obj_req(ocf_data_obj_t obj, struct ocf_request *req,
else if (dir == OCF_READ)
env_atomic64_add(req->byte_length, &core_stats->read_bytes);
io = ocf_dobj_new_io(obj);
io = ocf_volume_new_io(volume);
if (!io) {
callback(req, -ENOMEM);
return;
@ -338,14 +338,14 @@ void ocf_submit_obj_req(ocf_data_obj_t obj, struct ocf_request *req,
ocf_io_configure(io, req->byte_position, req->byte_length, dir,
class, flags);
ocf_io_set_queue(io, req->io_queue);
ocf_io_set_cmpl(io, req, callback, ocf_submit_obj_req_cmpl);
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
err = ocf_io_set_data(io, req->data, 0);
if (err) {
ocf_io_put(io);
callback(req, err);
return;
}
ocf_dobj_submit_io(io);
ocf_volume_submit_io(io);
}
static void ocf_submit_io_wait_end(struct ocf_io *io, int error)
@ -365,7 +365,7 @@ int ocf_submit_io_wait(struct ocf_io *io)
context.error = 0;
ocf_io_set_cmpl(io, &context, NULL, ocf_submit_io_wait_end);
ocf_dobj_submit_io(io);
ocf_volume_submit_io(io);
env_completion_wait(&context.complete);
return context.error;
}

View File

@ -45,18 +45,18 @@ static inline int ocf_io_overlaps(uint32_t start1, uint32_t count1,
int ocf_submit_io_wait(struct ocf_io *io);
int ocf_submit_obj_flush_wait(ocf_data_obj_t obj);
int ocf_submit_volume_flush_wait(ocf_volume_t volume);
int ocf_submit_obj_discard_wait(ocf_data_obj_t obj, uint64_t addr,
int ocf_submit_volume_discard_wait(ocf_volume_t volume, uint64_t addr,
uint64_t length);
int ocf_submit_write_zeroes_wait(ocf_data_obj_t obj, uint64_t addr,
int ocf_submit_write_zeroes_wait(ocf_volume_t volume, uint64_t addr,
uint64_t length);
int ocf_submit_cache_page(struct ocf_cache *cache, uint64_t addr,
int dir, void *buffer);
void ocf_submit_obj_req(ocf_data_obj_t obj, struct ocf_request *req,
void ocf_submit_volume_req(ocf_volume_t volume, struct ocf_request *req,
ocf_req_end_t callback);
@ -66,7 +66,7 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
static inline struct ocf_io *ocf_new_cache_io(struct ocf_cache *cache)
{
return ocf_dobj_new_io(&cache->device->obj);
return ocf_volume_new_io(&cache->device->volume);
}
static inline struct ocf_io *ocf_new_core_io(struct ocf_cache *cache,
@ -74,7 +74,7 @@ static inline struct ocf_io *ocf_new_core_io(struct ocf_cache *cache,
{
ENV_BUG_ON(core_id >= OCF_CORE_MAX);
return ocf_dobj_new_io(&cache->core[core_id].obj);
return ocf_volume_new_io(&cache->core[core_id].volume);
}
#endif /* UTILS_IO_H_ */

View File

@ -73,7 +73,7 @@ int __wrap_ocf_io_set_data(struct ocf_io *io, ctx_data_t *data,
return mock();
}
void __wrap_ocf_dobj_submit_io(struct ocf_io *io)
void __wrap_ocf_volume_submit_io(struct ocf_io *io)
{
function_called();
}
@ -175,7 +175,7 @@ static void metadata_submit_io_test03(void **state)
expect_function_call(__wrap_env_atomic_inc);
expect_function_call(__wrap_ocf_dobj_submit_io);
expect_function_call(__wrap_ocf_volume_submit_io);
result = metadata_submit_io(&cache, &mio, count, written);