Merge new_io and configure into one function

Signed-off-by: Robert Baldyga <robert.baldyga@intel.com>
This commit is contained in:
Robert Baldyga 2019-05-31 14:51:06 +02:00
parent 1454b75c0f
commit e254c9b587
19 changed files with 130 additions and 156 deletions

View File

@ -263,19 +263,17 @@ void read_end(struct ocf_io *io, int error)
ocf_io_put(io); ocf_io_put(io);
} }
int read(ocf_core_t core, void *data, addr, uint32_t length) int read(ocf_core_t core, ocf_queue_t queue, void *data, addr, uint32_t length)
{ {
/* Allocate IO */ /* Allocate IO */
struct ocf_io *io = ocf_new_io(core); struct ocf_io *io;
io = ocf_core_new_io(core, queue, addr, length, OCF_READ, 0, 0);
if (!io) { if (!io) {
/* Cannot allocate IO */ /* Cannot allocate IO */
return -ENOMEM; return -ENOMEM;
} }
/* Configure IO, set address, flags, IO class, and etc... */
ocf_io_configure(io, addr, length, OCF_READ, 0, 0);
/* Set completion context and function */ /* Set completion context and function */
ocf_io_set_cmpl(io, NULL, NULL, read_end); ocf_io_set_cmpl(io, NULL, NULL, read_end);
@ -286,7 +284,7 @@ int read(ocf_core_t core, void *data, addr, uint32_t length)
} }
/* Send IO requests to the cache */ /* Send IO requests to the cache */
ocf_submit_io(io); ocf_core_submit_io(io);
/* Just it */ /* Just it */
return 0; return 0;

View File

@ -260,16 +260,12 @@ int submit_io(ocf_core_t core, struct volume_data *data,
struct ocf_io *io; struct ocf_io *io;
/* Allocate new io */ /* Allocate new io */
io = ocf_core_new_io(core); io = ocf_core_new_io(core, cache_priv->io_queue, addr, len, dir, 0, 0);
if (!io) if (!io)
return -ENOMEM; return -ENOMEM;
/* Setup io address, lenght, direction, flags and ioclass */
ocf_io_configure(io, addr, len, dir, 0, 0);
/* Assign data to io */ /* Assign data to io */
ocf_io_set_data(io, data, 0); ocf_io_set_data(io, data, 0);
/* Setup io queue to */
ocf_io_set_queue(io, cache_priv->io_queue);
/* Setup completion function */ /* Setup completion function */
ocf_io_set_cmpl(io, NULL, NULL, cmpl); ocf_io_set_cmpl(io, NULL, NULL, cmpl);
/* Submit io */ /* Submit io */

View File

@ -128,14 +128,23 @@ int ocf_core_get(ocf_cache_t cache, ocf_core_id_t id, ocf_core_t *core);
* @brief Allocate new ocf_io * @brief Allocate new ocf_io
* *
* @param[in] core Core object * @param[in] core Core object
* @param[in] queue IO queue handle
* @param[in] addr OCF IO destination address
* @param[in] bytes OCF IO size in bytes
* @param[in] dir OCF IO direction
* @param[in] io_class OCF IO destination class
* @param[in] flags OCF IO flags
* *
* @retval ocf_io object * @retval ocf_io object
*/ */
static inline struct ocf_io *ocf_core_new_io(ocf_core_t core) static inline struct ocf_io *ocf_core_new_io(ocf_core_t core, ocf_queue_t queue,
uint64_t addr, uint32_t bytes, uint32_t dir,
uint32_t io_class, uint64_t flags)
{ {
ocf_volume_t volume = ocf_core_get_front_volume(core); ocf_volume_t volume = ocf_core_get_front_volume(core);
return ocf_volume_new_io(volume); return ocf_volume_new_io(volume, queue, addr, bytes, dir,
io_class, flags);
} }
/** /**

View File

@ -140,26 +140,6 @@ struct ocf_io_ops {
*/ */
void *ocf_io_get_priv(struct ocf_io *io); void *ocf_io_get_priv(struct ocf_io *io);
/**
* @brief Configure OCF IO
*
* @param[in] io OCF IO
* @param[in] addr OCF IO destination address
* @param[in] bytes OCF IO size in bytes
* @param[in] dir OCF IO direction
* @param[in] io_class OCF IO destination class
* @param[in] flags OCF IO flags
*/
static inline void ocf_io_configure(struct ocf_io *io, uint64_t addr,
uint32_t bytes, uint32_t dir, uint32_t io_class, uint64_t flags)
{
io->addr = addr;
io->bytes = bytes;
io->io_class = io_class;
io->flags = flags;
io->dir = dir;
}
/** /**
* @brief Increase reference counter in OCF IO * @brief Increase reference counter in OCF IO
* *
@ -240,17 +220,6 @@ int ocf_io_set_data(struct ocf_io *io, ctx_data_t *data, uint32_t offset);
*/ */
ctx_data_t *ocf_io_get_data(struct ocf_io *io); ctx_data_t *ocf_io_get_data(struct ocf_io *io);
/**
* @brief Set queue to which IO should be submitted
*
* @param[in] io OCF IO to set up
* @param[in] queue IO queue handle
*/
static inline void ocf_io_set_queue(struct ocf_io *io, ocf_queue_t queue)
{
io->io_queue = queue;
}
/** /**
* @brief Handle IO in cache engine * @brief Handle IO in cache engine
* *

View File

@ -256,10 +256,19 @@ int ocf_volume_is_atomic(ocf_volume_t volume);
* @brief Allocate new io * @brief Allocate new io
* *
* @param[in] volume Volume * @param[in] volume Volume
* @param[in] queue IO queue handle
* @param[in] addr OCF IO destination address
* @param[in] bytes OCF IO size in bytes
* @param[in] dir OCF IO direction
* @param[in] io_class OCF IO destination class
* @param[in] flags OCF IO flags
* *
* @return ocf_io on success atomic, otherwise NULL * @return ocf_io on success atomic, otherwise NULL
*/ */
struct ocf_io *ocf_volume_new_io(ocf_volume_t volume); struct ocf_io *ocf_volume_new_io(ocf_volume_t volume, ocf_queue_t queue,
uint64_t addr, uint32_t bytes, uint32_t dir,
uint32_t io_class, uint64_t flags);
/** /**
* @brief Submit io to volume * @brief Submit io to volume

View File

@ -69,19 +69,17 @@ static int _ocf_discard_core(struct ocf_request *req)
{ {
struct ocf_io *io; struct ocf_io *io;
io = ocf_volume_new_io(&req->core->volume); io = ocf_volume_new_io(&req->core->volume, req->io_queue,
SECTORS_TO_BYTES(req->discard.sector),
SECTORS_TO_BYTES(req->discard.nr_sects),
OCF_WRITE, 0, 0);
if (!io) { if (!io) {
_ocf_discard_complete_req(req, -OCF_ERR_NO_MEM); _ocf_discard_complete_req(req, -OCF_ERR_NO_MEM);
return -OCF_ERR_NO_MEM; return -OCF_ERR_NO_MEM;
} }
ocf_io_configure(io, SECTORS_TO_BYTES(req->discard.sector),
SECTORS_TO_BYTES(req->discard.nr_sects),
OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, req, NULL, _ocf_discard_core_complete); ocf_io_set_cmpl(io, req, NULL, _ocf_discard_core_complete);
ocf_io_set_data(io, req->data, 0); ocf_io_set_data(io, req->data, 0);
ocf_io_set_queue(io, req->io_queue);
ocf_volume_submit_discard(io); ocf_volume_submit_discard(io);
@ -109,16 +107,15 @@ static int _ocf_discard_flush_cache(struct ocf_request *req)
{ {
struct ocf_io *io; struct ocf_io *io;
io = ocf_volume_new_io(&req->cache->device->volume); io = ocf_volume_new_io(&req->cache->device->volume, req->io_queue,
0, 0, OCF_WRITE, 0, 0);
if (!io) { if (!io) {
ocf_metadata_error(req->cache); ocf_metadata_error(req->cache);
_ocf_discard_complete_req(req, -OCF_ERR_NO_MEM); _ocf_discard_complete_req(req, -OCF_ERR_NO_MEM);
return -OCF_ERR_NO_MEM; return -OCF_ERR_NO_MEM;
} }
ocf_io_configure(io, 0, 0, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, req, NULL, _ocf_discard_cache_flush_complete); ocf_io_set_cmpl(io, req, NULL, _ocf_discard_cache_flush_complete);
ocf_io_set_queue(io, req->io_queue);
ocf_volume_submit_flush(io); ocf_volume_submit_flush(io);

View File

@ -199,7 +199,8 @@ static int ocf_metadata_read_sb(ocf_ctx_t ctx, ocf_volume_t volume,
context->priv2 = priv2; context->priv2 = priv2;
/* Allocate resources for IO */ /* Allocate resources for IO */
io = ocf_volume_new_io(volume); io = ocf_volume_new_io(volume, NULL, 0, sb_pages * PAGE_SIZE,
OCF_READ, 0, 0);
if (!io) { if (!io) {
ocf_log(ctx, log_err, "Memory allocation error"); ocf_log(ctx, log_err, "Memory allocation error");
result = -OCF_ERR_NO_MEM; result = -OCF_ERR_NO_MEM;
@ -224,8 +225,6 @@ static int ocf_metadata_read_sb(ocf_ctx_t ctx, ocf_volume_t volume,
goto err_set_data; goto err_set_data;
} }
ocf_io_configure(io, 0, sb_pages * PAGE_SIZE, OCF_READ, 0, 0);
ocf_io_set_cmpl(io, context, NULL, ocf_metadata_read_sb_complete); ocf_io_set_cmpl(io, context, NULL, ocf_metadata_read_sb_complete);
ocf_volume_submit_io(io); ocf_volume_submit_io(io);

View File

@ -711,18 +711,16 @@ static int ocf_metadata_query_cores_io(ocf_volume_t volume,
env_atomic_inc(&context->count); env_atomic_inc(&context->count);
/* Allocate new IO */ /* Allocate new IO */
io = ocf_volume_new_io(volume); io = ocf_volume_new_io(volume, NULL,
PAGES_TO_BYTES(page),
PAGES_TO_BYTES(num_pages),
OCF_READ, 0, 0);
if (!io) { if (!io) {
err = -OCF_ERR_NO_MEM; err = -OCF_ERR_NO_MEM;
goto exit_error; goto exit_error;
} }
/* Setup IO */ /* Setup IO */
ocf_io_configure(io,
PAGES_TO_BYTES(page),
PAGES_TO_BYTES(num_pages),
OCF_READ, 0, 0);
ocf_io_set_cmpl(io, context, NULL, ocf_io_set_cmpl(io, context, NULL,
ocf_metadata_query_cores_end_io); ocf_metadata_query_cores_end_io);
err = ocf_io_set_data(io, data, PAGES_TO_BYTES(offset)); err = ocf_io_set_data(io, data, PAGES_TO_BYTES(offset));

View File

@ -99,18 +99,17 @@ int metadata_io_read_i_atomic_step(struct ocf_request *req)
ctx_data_seek(cache->owner, context->data, ctx_data_seek_begin, 0); ctx_data_seek(cache->owner, context->data, ctx_data_seek_begin, 0);
/* Allocate new IO */ /* Allocate new IO */
io = ocf_new_cache_io(cache); io = ocf_new_cache_io(cache, req->io_queue,
cache->device->metadata_offset +
SECTORS_TO_BYTES(context->curr_offset),
SECTORS_TO_BYTES(context->curr_count), OCF_READ, 0, 0);
if (!io) { if (!io) {
metadata_io_read_i_atomic_complete(context, -OCF_ERR_NO_MEM); metadata_io_read_i_atomic_complete(context, -OCF_ERR_NO_MEM);
return 0; return 0;
} }
/* Setup IO */ /* Setup IO */
ocf_io_configure(io, cache->device->metadata_offset +
SECTORS_TO_BYTES(context->curr_offset),
SECTORS_TO_BYTES(context->curr_count), OCF_READ, 0, 0);
ocf_io_set_queue(io, req->io_queue);
ocf_io_set_cmpl(io, context, NULL, metadata_io_read_i_atomic_step_end); ocf_io_set_cmpl(io, context, NULL, metadata_io_read_i_atomic_step_end);
result = ocf_io_set_data(io, context->data, 0); result = ocf_io_set_data(io, context->data, 0);
if (result) { if (result) {
@ -231,19 +230,16 @@ static int ocf_restart_meta_io(struct ocf_request *req)
metadata_io_req_fill(meta_io_req); metadata_io_req_fill(meta_io_req);
OCF_METADATA_UNLOCK_RD(); OCF_METADATA_UNLOCK_RD();
io = ocf_new_cache_io(cache); io = ocf_new_cache_io(cache, req->io_queue,
PAGES_TO_BYTES(meta_io_req->page),
PAGES_TO_BYTES(meta_io_req->count),
OCF_WRITE, 0, 0);
if (!io) { if (!io) {
metadata_io_i_asynch_end(meta_io_req, -OCF_ERR_NO_MEM); metadata_io_i_asynch_end(meta_io_req, -OCF_ERR_NO_MEM);
return 0; return 0;
} }
/* Setup IO */ /* Setup IO */
ocf_io_configure(io,
PAGES_TO_BYTES(meta_io_req->page),
PAGES_TO_BYTES(meta_io_req->count),
OCF_WRITE, 0, 0);
ocf_io_set_queue(io, req->io_queue);
ocf_io_set_cmpl(io, meta_io_req, NULL, metadata_io_i_asynch_cmpl); ocf_io_set_cmpl(io, meta_io_req, NULL, metadata_io_i_asynch_cmpl);
ret = ocf_io_set_data(io, meta_io_req->data, 0); ret = ocf_io_set_data(io, meta_io_req->data, 0);
if (ret) { if (ret) {
@ -415,7 +411,10 @@ static int metadata_io_i_asynch(ocf_cache_t cache, ocf_queue_t queue, int dir,
ret = metadata_updater_check_overlaps(cache, &a_req->reqs[i]); ret = metadata_updater_check_overlaps(cache, &a_req->reqs[i]);
if (ret == 0) { if (ret == 0) {
/* Allocate new IO */ /* Allocate new IO */
io = ocf_new_cache_io(cache); io = ocf_new_cache_io(cache, queue,
PAGES_TO_BYTES(a_req->reqs[i].page),
PAGES_TO_BYTES(a_req->reqs[i].count),
dir, 0, 0);
if (!io) { if (!io) {
error = -OCF_ERR_NO_MEM; error = -OCF_ERR_NO_MEM;
metadata_io_req_error(cache, a_req, i, error); metadata_io_req_error(cache, a_req, i, error);
@ -426,12 +425,6 @@ static int metadata_io_i_asynch(ocf_cache_t cache, ocf_queue_t queue, int dir,
metadata_io_req_fill(&a_req->reqs[i]); metadata_io_req_fill(&a_req->reqs[i]);
/* Setup IO */ /* Setup IO */
ocf_io_configure(io,
PAGES_TO_BYTES(a_req->reqs[i].page),
PAGES_TO_BYTES(a_req->reqs[i].count),
dir, 0, 0);
ocf_io_set_queue(io, queue);
ocf_io_set_cmpl(io, &a_req->reqs[i], NULL, ocf_io_set_cmpl(io, &a_req->reqs[i], NULL,
metadata_io_i_asynch_cmpl); metadata_io_i_asynch_cmpl);
error = ocf_io_set_data(io, a_req->reqs[i].data, 0); error = ocf_io_set_data(io, a_req->reqs[i].data, 0);

View File

@ -70,8 +70,9 @@ static int _raw_atomic_io_discard_do(struct ocf_cache *cache, void *context,
uint64_t start_addr, uint32_t len, struct _raw_atomic_flush_ctx *ctx) uint64_t start_addr, uint32_t len, struct _raw_atomic_flush_ctx *ctx)
{ {
struct ocf_request *req = context; struct ocf_request *req = context;
struct ocf_io *io = ocf_new_cache_io(cache); struct ocf_io *io;
io = ocf_new_cache_io(cache, NULL, start_addr, len, OCF_WRITE, 0, 0);
if (!io) { if (!io) {
req->error = -OCF_ERR_NO_MEM; req->error = -OCF_ERR_NO_MEM;
return req->error; return req->error;
@ -82,7 +83,6 @@ static int _raw_atomic_io_discard_do(struct ocf_cache *cache, void *context,
env_atomic_inc(&ctx->flush_req_cnt); env_atomic_inc(&ctx->flush_req_cnt);
ocf_io_configure(io, start_addr, len, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, ctx, NULL, _raw_atomic_io_discard_end); ocf_io_set_cmpl(io, ctx, NULL, _raw_atomic_io_discard_end);
if (cache->device->volume.features.discard_zeroes) if (cache->device->volume.features.discard_zeroes)

View File

@ -336,7 +336,10 @@ static int raw_dynamic_load_all_read(struct ocf_request *req)
count = OCF_MIN(RAW_DYNAMIC_LOAD_PAGES, raw->ssd_pages - context->i); count = OCF_MIN(RAW_DYNAMIC_LOAD_PAGES, raw->ssd_pages - context->i);
/* Allocate IO */ /* Allocate IO */
context->io = ocf_new_cache_io(context->cache); context->io = ocf_new_cache_io(context->cache, req->io_queue,
PAGES_TO_BYTES(raw->ssd_pages_offset + context->i),
PAGES_TO_BYTES(count), OCF_READ, 0, 0);
if (!context->io) { if (!context->io) {
raw_dynamic_load_all_complete(context, -OCF_ERR_NO_MEM); raw_dynamic_load_all_complete(context, -OCF_ERR_NO_MEM);
return 0; return 0;
@ -349,11 +352,6 @@ static int raw_dynamic_load_all_read(struct ocf_request *req)
raw_dynamic_load_all_complete(context, result); raw_dynamic_load_all_complete(context, result);
return 0; return 0;
} }
ocf_io_configure(context->io,
PAGES_TO_BYTES(raw->ssd_pages_offset + context->i),
PAGES_TO_BYTES(count), OCF_READ, 0, 0);
ocf_io_set_queue(context->io, req->io_queue);
ocf_io_set_cmpl(context->io, context, NULL, ocf_io_set_cmpl(context->io, context, NULL,
raw_dynamic_load_all_read_end); raw_dynamic_load_all_read_end);

View File

@ -14,7 +14,7 @@
ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache) ocf_volume_t ocf_cache_get_volume(ocf_cache_t cache)
{ {
return ocf_cache_is_device_attached(cache) ? &cache->device->volume : NULL; return cache->device ? &cache->device->volume : NULL;
} }
ocf_cache_id_t ocf_cache_get_id(ocf_cache_t cache) ocf_cache_id_t ocf_cache_get_id(ocf_cache_t cache)

View File

@ -48,7 +48,9 @@ static struct ocf_io_internal *ocf_io_get_internal(struct ocf_io* io)
return container_of(io, struct ocf_io_internal, io); return container_of(io, struct ocf_io_internal, io);
} }
struct ocf_io *ocf_io_new(ocf_volume_t volume) struct ocf_io *ocf_io_new(ocf_volume_t volume, ocf_queue_t queue,
uint64_t addr, uint32_t bytes, uint32_t dir,
uint32_t io_class, uint64_t flags)
{ {
struct ocf_io_internal *ioi; struct ocf_io_internal *ioi;
@ -65,6 +67,13 @@ struct ocf_io *ocf_io_new(ocf_volume_t volume)
ioi->meta.ops = &volume->type->properties->io_ops; ioi->meta.ops = &volume->type->properties->io_ops;
env_atomic_set(&ioi->meta.ref_count, 1); env_atomic_set(&ioi->meta.ref_count, 1);
ioi->io.io_queue = queue;
ioi->io.addr = addr;
ioi->io.bytes = bytes;
ioi->io.dir = dir;
ioi->io.io_class = io_class;
ioi->io.flags = flags;
return &ioi->io; return &ioi->io;
} }

View File

@ -25,7 +25,9 @@ env_allocator *ocf_io_allocator_create(uint32_t size, const char *name);
void ocf_io_allocator_destroy(env_allocator *allocator); void ocf_io_allocator_destroy(env_allocator *allocator);
struct ocf_io *ocf_io_new(ocf_volume_t volume); struct ocf_io *ocf_io_new(ocf_volume_t volume, ocf_queue_t queue,
uint64_t addr, uint32_t bytes, uint32_t dir,
uint32_t io_class, uint64_t flags);
static inline void ocf_io_start(struct ocf_io *io) static inline void ocf_io_start(struct ocf_io *io)
{ {

View File

@ -7,6 +7,7 @@
#define __OCF_REQUEST_H__ #define __OCF_REQUEST_H__
#include "ocf_env.h" #include "ocf_env.h"
#include "ocf_io_priv.h"
struct ocf_req_allocator; struct ocf_req_allocator;

View File

@ -227,9 +227,11 @@ int ocf_volume_is_atomic(ocf_volume_t volume)
return volume->type->properties->caps.atomic_writes; return volume->type->properties->caps.atomic_writes;
} }
struct ocf_io *ocf_volume_new_io(ocf_volume_t volume) struct ocf_io *ocf_volume_new_io(ocf_volume_t volume, ocf_queue_t queue,
uint64_t addr, uint32_t bytes, uint32_t dir,
uint32_t io_class, uint64_t flags)
{ {
return ocf_io_new(volume); return ocf_io_new(volume, queue, addr, bytes, dir, io_class, flags);
} }
void ocf_volume_submit_io(struct ocf_io *io) void ocf_volume_submit_io(struct ocf_io *io)

View File

@ -270,16 +270,14 @@ static int _ocf_cleaner_fire_flush_cache(struct ocf_request *req)
OCF_DEBUG_TRACE(req->cache); OCF_DEBUG_TRACE(req->cache);
io = ocf_volume_new_io(&req->cache->device->volume); io = ocf_new_cache_io(req->cache, req->io_queue, 0, 0, OCF_WRITE, 0, 0);
if (!io) { if (!io) {
ocf_metadata_error(req->cache); ocf_metadata_error(req->cache);
req->error = -OCF_ERR_NO_MEM; req->error = -OCF_ERR_NO_MEM;
return -OCF_ERR_NO_MEM; return -OCF_ERR_NO_MEM;
} }
ocf_io_configure(io, 0, 0, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, req, NULL, _ocf_cleaner_flush_cache_io_end); ocf_io_set_cmpl(io, req, NULL, _ocf_cleaner_flush_cache_io_end);
ocf_io_set_queue(io, req->io_queue);
ocf_volume_submit_flush(io); ocf_volume_submit_flush(io);
@ -395,6 +393,7 @@ static int _ocf_cleaner_fire_flush_cores(struct ocf_request *req)
ocf_core_id_t core_id = OCF_CORE_MAX; ocf_core_id_t core_id = OCF_CORE_MAX;
struct ocf_cache *cache = req->cache; struct ocf_cache *cache = req->cache;
struct ocf_map_info *iter = req->map; struct ocf_map_info *iter = req->map;
ocf_core_t core;
struct ocf_io *io; struct ocf_io *io;
OCF_DEBUG_TRACE(req->cache); OCF_DEBUG_TRACE(req->cache);
@ -419,15 +418,15 @@ static int _ocf_cleaner_fire_flush_cores(struct ocf_request *req)
env_atomic_inc(&req->req_remaining); env_atomic_inc(&req->req_remaining);
io = ocf_new_core_io(cache, core_id); core = ocf_cache_get_core(cache, core_id);
io = ocf_new_core_io(core, req->io_queue, 0, 0,
OCF_WRITE, 0, 0);
if (!io) { if (!io) {
_ocf_cleaner_flush_cores_io_end(iter, req, -OCF_ERR_NO_MEM); _ocf_cleaner_flush_cores_io_end(iter, req, -OCF_ERR_NO_MEM);
continue; continue;
} }
ocf_io_configure(io, 0, 0, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, iter, req, _ocf_cleaner_flush_cores_io_cmpl); ocf_io_set_cmpl(io, iter, req, _ocf_cleaner_flush_cores_io_cmpl);
ocf_io_set_queue(io, req->io_queue);
ocf_volume_submit_flush(io); ocf_volume_submit_flush(io);
} }
@ -480,25 +479,24 @@ static void _ocf_cleaner_core_io_for_dirty_range(struct ocf_request *req,
{ {
uint64_t addr, offset; uint64_t addr, offset;
int err; int err;
struct ocf_cache *cache = req->cache; ocf_cache_t cache = req->cache;
ocf_core_t core = ocf_cache_get_core(cache, iter->core_id);
struct ocf_io *io; struct ocf_io *io;
struct ocf_counters_block *core_stats = struct ocf_counters_block *core_stats =
&cache->core[iter->core_id].counters->core_blocks; &cache->core[iter->core_id].counters->core_blocks;
ocf_part_id_t part_id = ocf_metadata_get_partition_id(cache, ocf_part_id_t part_id = ocf_metadata_get_partition_id(cache,
iter->coll_idx); iter->coll_idx);
io = ocf_new_core_io(cache, iter->core_id);
if (!io)
goto error;
addr = (ocf_line_size(cache) * iter->core_line) addr = (ocf_line_size(cache) * iter->core_line)
+ SECTORS_TO_BYTES(begin); + SECTORS_TO_BYTES(begin);
offset = (ocf_line_size(cache) * iter->hash_key) offset = (ocf_line_size(cache) * iter->hash_key)
+ SECTORS_TO_BYTES(begin); + SECTORS_TO_BYTES(begin);
ocf_io_configure(io, addr, SECTORS_TO_BYTES(end - begin), OCF_WRITE, io = ocf_new_core_io(core, req->io_queue, addr,
part_id, 0); SECTORS_TO_BYTES(end - begin), OCF_WRITE, part_id, 0);
ocf_io_set_queue(io, req->io_queue); if (!io)
goto error;
err = ocf_io_set_data(io, req->data, offset); err = ocf_io_set_data(io, req->data, offset);
if (err) { if (err) {
ocf_io_put(io); ocf_io_put(io);
@ -660,7 +658,9 @@ static int _ocf_cleaner_fire_cache(struct ocf_request *req)
cache_stats = &cache->core[iter->core_id]. cache_stats = &cache->core[iter->core_id].
counters->cache_blocks; counters->cache_blocks;
io = ocf_new_cache_io(cache); io = ocf_new_cache_io(cache, req->io_queue,
addr, ocf_line_size(cache),
OCF_READ, part_id, 0);
if (!io) { if (!io) {
/* Allocation error */ /* Allocation error */
iter->invalid = true; iter->invalid = true;
@ -681,9 +681,6 @@ static int _ocf_cleaner_fire_cache(struct ocf_request *req)
part_id = ocf_metadata_get_partition_id(cache, iter->coll_idx); part_id = ocf_metadata_get_partition_id(cache, iter->coll_idx);
ocf_io_set_cmpl(io, iter, req, _ocf_cleaner_cache_io_cmpl); ocf_io_set_cmpl(io, iter, req, _ocf_cleaner_cache_io_cmpl);
ocf_io_configure(io, addr, ocf_line_size(cache), OCF_READ,
part_id, 0);
ocf_io_set_queue(io, req->io_queue);
err = ocf_io_set_data(io, req->data, offset); err = ocf_io_set_data(io, req->data, offset);
if (err) { if (err) {
ocf_io_put(io); ocf_io_put(io);

View File

@ -31,11 +31,10 @@ void ocf_submit_volume_flush(ocf_volume_t volume,
{ {
struct ocf_io *io; struct ocf_io *io;
io = ocf_volume_new_io(volume); io = ocf_volume_new_io(volume, NULL, 0, 0, OCF_WRITE, 0, 0);
if (!io) if (!io)
OCF_CMPL_RET(priv, -OCF_ERR_NO_MEM); OCF_CMPL_RET(priv, -OCF_ERR_NO_MEM);
ocf_io_configure(io, 0, 0, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, cmpl, priv, _ocf_volume_flush_end); ocf_io_set_cmpl(io, cmpl, priv, _ocf_volume_flush_end);
ocf_volume_submit_flush(io); ocf_volume_submit_flush(io);
@ -74,7 +73,10 @@ void ocf_submit_volume_discard(ocf_volume_t volume, uint64_t addr,
context->priv = priv; context->priv = priv;
while (length) { while (length) {
io = ocf_volume_new_io(volume); bytes = OCF_MIN(length, max_length);
io = ocf_volume_new_io(volume, NULL, addr, bytes,
OCF_WRITE, 0, 0);
if (!io) { if (!io) {
context->error = -OCF_ERR_NO_MEM; context->error = -OCF_ERR_NO_MEM;
break; break;
@ -82,9 +84,6 @@ void ocf_submit_volume_discard(ocf_volume_t volume, uint64_t addr,
env_atomic_inc(&context->req_remaining); env_atomic_inc(&context->req_remaining);
bytes = OCF_MIN(length, max_length);
ocf_io_configure(io, addr, bytes, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, context, NULL, ocf_submit_volume_end); ocf_io_set_cmpl(io, context, NULL, ocf_submit_volume_end);
ocf_volume_submit_discard(io); ocf_volume_submit_discard(io);
@ -116,7 +115,10 @@ void ocf_submit_write_zeros(ocf_volume_t volume, uint64_t addr,
context->priv = priv; context->priv = priv;
while (length) { while (length) {
io = ocf_volume_new_io(volume); bytes = OCF_MIN(length, max_length);
io = ocf_volume_new_io(volume, NULL, addr, bytes,
OCF_WRITE, 0, 0);
if (!io) { if (!io) {
context->error = -OCF_ERR_NO_MEM; context->error = -OCF_ERR_NO_MEM;
break; break;
@ -124,9 +126,6 @@ void ocf_submit_write_zeros(ocf_volume_t volume, uint64_t addr,
env_atomic_inc(&context->req_remaining); env_atomic_inc(&context->req_remaining);
bytes = OCF_MIN(length, max_length);
ocf_io_configure(io, addr, bytes, OCF_WRITE, 0, 0);
ocf_io_set_cmpl(io, context, NULL, ocf_submit_volume_end); ocf_io_set_cmpl(io, context, NULL, ocf_submit_volume_end);
ocf_volume_submit_write_zeroes(io); ocf_volume_submit_write_zeroes(io);
@ -181,7 +180,7 @@ void ocf_submit_cache_page(ocf_cache_t cache, uint64_t addr, int dir,
context->cmpl = cmpl; context->cmpl = cmpl;
context->priv = priv; context->priv = priv;
io = ocf_volume_new_io(&cache->device->volume); io = ocf_new_cache_io(cache, NULL, addr, PAGE_SIZE, dir, 0, 0);
if (!io) { if (!io) {
result = -OCF_ERR_NO_MEM; result = -OCF_ERR_NO_MEM;
goto err_io; goto err_io;
@ -200,7 +199,6 @@ void ocf_submit_cache_page(ocf_cache_t cache, uint64_t addr, int dir,
if (result) if (result)
goto err_set_data; goto err_set_data;
ocf_io_configure(io, addr, PAGE_SIZE, dir, 0, 0);
ocf_io_set_cmpl(io, context, NULL, ocf_submit_cache_page_end); ocf_io_set_cmpl(io, context, NULL, ocf_submit_cache_page_end);
ocf_volume_submit_io(io); ocf_volume_submit_io(io);
@ -245,12 +243,6 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
cache_stats = &req->core->counters->cache_blocks; cache_stats = &req->core->counters->cache_blocks;
if (reqs == 1) { if (reqs == 1) {
io = ocf_new_cache_io(cache);
if (!io) {
callback(req, -OCF_ERR_NO_MEM);
goto update_stats;
}
addr = ocf_metadata_map_lg2phy(cache, addr = ocf_metadata_map_lg2phy(cache,
req->map[first_cl].coll_idx); req->map[first_cl].coll_idx);
addr *= ocf_line_size(cache); addr *= ocf_line_size(cache);
@ -258,8 +250,13 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
addr += ((req->byte_position + offset) % ocf_line_size(cache)); addr += ((req->byte_position + offset) % ocf_line_size(cache));
bytes = size; bytes = size;
ocf_io_configure(io, addr, bytes, dir, class, flags); io = ocf_new_cache_io(cache, req->io_queue,
ocf_io_set_queue(io, req->io_queue); addr, bytes, dir, class, flags);
if (!io) {
callback(req, -OCF_ERR_NO_MEM);
goto update_stats;
}
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl); ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
err = ocf_io_set_data(io, req->data, offset); err = ocf_io_set_data(io, req->data, offset);
@ -277,15 +274,6 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
/* Issue requests to cache. */ /* Issue requests to cache. */
for (i = 0; i < reqs; i++) { for (i = 0; i < reqs; i++) {
io = ocf_new_cache_io(cache);
if (!io) {
/* Finish all IOs which left with ERROR */
for (; i < reqs; i++)
callback(req, -OCF_ERR_NO_MEM);
goto update_stats;
}
addr = ocf_metadata_map_lg2phy(cache, addr = ocf_metadata_map_lg2phy(cache,
req->map[first_cl + i].coll_idx); req->map[first_cl + i].coll_idx);
addr *= ocf_line_size(cache); addr *= ocf_line_size(cache);
@ -309,8 +297,15 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
bytes = OCF_MIN(bytes, size - total_bytes); bytes = OCF_MIN(bytes, size - total_bytes);
ENV_BUG_ON(bytes == 0); ENV_BUG_ON(bytes == 0);
ocf_io_configure(io, addr, bytes, dir, class, flags); io = ocf_new_cache_io(cache, req->io_queue,
ocf_io_set_queue(io, req->io_queue); addr, bytes, dir, class, flags);
if (!io) {
/* Finish all IOs which left with ERROR */
for (; i < reqs; i++)
callback(req, -OCF_ERR_NO_MEM);
goto update_stats;
}
ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl); ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
err = ocf_io_set_data(io, req->data, offset + total_bytes); err = ocf_io_set_data(io, req->data, offset + total_bytes);
@ -350,15 +345,13 @@ void ocf_submit_volume_req(ocf_volume_t volume, struct ocf_request *req,
else if (dir == OCF_READ) else if (dir == OCF_READ)
env_atomic64_add(req->byte_length, &core_stats->read_bytes); env_atomic64_add(req->byte_length, &core_stats->read_bytes);
io = ocf_volume_new_io(volume); io = ocf_volume_new_io(volume, req->io_queue, req->byte_position,
req->byte_length, dir, class, flags);
if (!io) { if (!io) {
callback(req, -OCF_ERR_NO_MEM); callback(req, -OCF_ERR_NO_MEM);
return; return;
} }
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_volume_req_cmpl); ocf_io_set_cmpl(io, req, callback, ocf_submit_volume_req_cmpl);
err = ocf_io_set_data(io, req->data, 0); err = ocf_io_set_data(io, req->data, 0);
if (err) { if (err) {

View File

@ -64,17 +64,21 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache,
struct ocf_request *req, int dir, uint64_t offset, struct ocf_request *req, int dir, uint64_t offset,
uint64_t size, unsigned int reqs, ocf_req_end_t callback); uint64_t size, unsigned int reqs, ocf_req_end_t callback);
static inline struct ocf_io *ocf_new_cache_io(struct ocf_cache *cache) static inline struct ocf_io *ocf_new_cache_io(ocf_cache_t cache,
ocf_queue_t queue, uint64_t addr, uint32_t bytes,
uint32_t dir, uint32_t io_class, uint64_t flags)
{ {
return ocf_volume_new_io(&cache->device->volume); return ocf_volume_new_io(ocf_cache_get_volume(cache), queue,
addr, bytes, dir, io_class, flags);
} }
static inline struct ocf_io *ocf_new_core_io(struct ocf_cache *cache, static inline struct ocf_io *ocf_new_core_io(ocf_core_t core,
ocf_core_id_t core_id) ocf_queue_t queue, uint64_t addr, uint32_t bytes,
uint32_t dir, uint32_t io_class, uint64_t flags)
{ {
ENV_BUG_ON(core_id >= OCF_CORE_MAX); return ocf_volume_new_io(ocf_core_get_volume(core), queue,
addr, bytes, dir, io_class, flags);
return ocf_volume_new_io(&cache->core[core_id].volume);
} }
#endif /* UTILS_IO_H_ */ #endif /* UTILS_IO_H_ */