diff --git a/doc/HOME.md b/doc/HOME.md index 3129928..caad482 100644 --- a/doc/HOME.md +++ b/doc/HOME.md @@ -263,19 +263,17 @@ void read_end(struct ocf_io *io, int error) 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 */ - 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) { /* Cannot allocate IO */ 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 */ 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 */ - ocf_submit_io(io); + ocf_core_submit_io(io); /* Just it */ return 0; diff --git a/example/simple/src/main.c b/example/simple/src/main.c index 308c4ad..9cd3506 100644 --- a/example/simple/src/main.c +++ b/example/simple/src/main.c @@ -260,16 +260,12 @@ int submit_io(ocf_core_t core, struct volume_data *data, struct ocf_io *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) return -ENOMEM; - /* Setup io address, lenght, direction, flags and ioclass */ - ocf_io_configure(io, addr, len, dir, 0, 0); /* Assign data to io */ ocf_io_set_data(io, data, 0); - /* Setup io queue to */ - ocf_io_set_queue(io, cache_priv->io_queue); /* Setup completion function */ ocf_io_set_cmpl(io, NULL, NULL, cmpl); /* Submit io */ diff --git a/inc/ocf_core.h b/inc/ocf_core.h index 4275596..d7825f5 100644 --- a/inc/ocf_core.h +++ b/inc/ocf_core.h @@ -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 * * @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 */ -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); - return ocf_volume_new_io(volume); + return ocf_volume_new_io(volume, queue, addr, bytes, dir, + io_class, flags); } /** diff --git a/inc/ocf_io.h b/inc/ocf_io.h index 281c6e1..f268320 100644 --- a/inc/ocf_io.h +++ b/inc/ocf_io.h @@ -140,26 +140,6 @@ struct ocf_io_ops { */ 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 * @@ -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); -/** - * @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 * diff --git a/inc/ocf_volume.h b/inc/ocf_volume.h index e074b5e..bd7fa3b 100644 --- a/inc/ocf_volume.h +++ b/inc/ocf_volume.h @@ -256,10 +256,19 @@ int ocf_volume_is_atomic(ocf_volume_t volume); * @brief Allocate new io * * @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 */ -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 diff --git a/src/engine/engine_discard.c b/src/engine/engine_discard.c index 4b80573..f23938f 100644 --- a/src/engine/engine_discard.c +++ b/src/engine/engine_discard.c @@ -69,19 +69,17 @@ static int _ocf_discard_core(struct ocf_request *req) { 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) { _ocf_discard_complete_req(req, -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_data(io, req->data, 0); - ocf_io_set_queue(io, req->io_queue); ocf_volume_submit_discard(io); @@ -109,16 +107,15 @@ static int _ocf_discard_flush_cache(struct ocf_request *req) { 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) { ocf_metadata_error(req->cache); _ocf_discard_complete_req(req, -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_queue(io, req->io_queue); ocf_volume_submit_flush(io); diff --git a/src/metadata/metadata.c b/src/metadata/metadata.c index f7984e5..6fdfb5d 100644 --- a/src/metadata/metadata.c +++ b/src/metadata/metadata.c @@ -199,7 +199,8 @@ static int ocf_metadata_read_sb(ocf_ctx_t ctx, ocf_volume_t volume, context->priv2 = priv2; /* 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) { ocf_log(ctx, log_err, "Memory allocation error"); 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; } - 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_volume_submit_io(io); diff --git a/src/metadata/metadata_hash.c b/src/metadata/metadata_hash.c index 0788ee1..44f4a01 100644 --- a/src/metadata/metadata_hash.c +++ b/src/metadata/metadata_hash.c @@ -711,18 +711,16 @@ static int ocf_metadata_query_cores_io(ocf_volume_t volume, env_atomic_inc(&context->count); /* 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) { err = -OCF_ERR_NO_MEM; goto exit_error; } /* 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_metadata_query_cores_end_io); err = ocf_io_set_data(io, data, PAGES_TO_BYTES(offset)); diff --git a/src/metadata/metadata_io.c b/src/metadata/metadata_io.c index 29eabfe..35183a3 100644 --- a/src/metadata/metadata_io.c +++ b/src/metadata/metadata_io.c @@ -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); /* 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) { metadata_io_read_i_atomic_complete(context, -OCF_ERR_NO_MEM); return 0; } /* 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); result = ocf_io_set_data(io, context->data, 0); if (result) { @@ -231,19 +230,16 @@ static int ocf_restart_meta_io(struct ocf_request *req) metadata_io_req_fill(meta_io_req); 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) { metadata_io_i_asynch_end(meta_io_req, -OCF_ERR_NO_MEM); return 0; } /* 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); ret = ocf_io_set_data(io, meta_io_req->data, 0); 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]); if (ret == 0) { /* 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) { error = -OCF_ERR_NO_MEM; 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]); /* 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, metadata_io_i_asynch_cmpl); error = ocf_io_set_data(io, a_req->reqs[i].data, 0); diff --git a/src/metadata/metadata_raw_atomic.c b/src/metadata/metadata_raw_atomic.c index 370ed4c..46e2907 100644 --- a/src/metadata/metadata_raw_atomic.c +++ b/src/metadata/metadata_raw_atomic.c @@ -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) { 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) { req->error = -OCF_ERR_NO_MEM; 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); - 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->volume.features.discard_zeroes) diff --git a/src/metadata/metadata_raw_dynamic.c b/src/metadata/metadata_raw_dynamic.c index 25905a2..9da8d0b 100644 --- a/src/metadata/metadata_raw_dynamic.c +++ b/src/metadata/metadata_raw_dynamic.c @@ -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); /* 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) { raw_dynamic_load_all_complete(context, -OCF_ERR_NO_MEM); return 0; @@ -349,11 +352,6 @@ static int raw_dynamic_load_all_read(struct ocf_request *req) raw_dynamic_load_all_complete(context, result); 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, raw_dynamic_load_all_read_end); diff --git a/src/ocf_cache.c b/src/ocf_cache.c index 02470ef..1e4b110 100644 --- a/src/ocf_cache.c +++ b/src/ocf_cache.c @@ -14,7 +14,7 @@ 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) diff --git a/src/ocf_io.c b/src/ocf_io.c index 8aaad76..fd12b35 100644 --- a/src/ocf_io.c +++ b/src/ocf_io.c @@ -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); } -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; @@ -65,6 +67,13 @@ struct ocf_io *ocf_io_new(ocf_volume_t volume) ioi->meta.ops = &volume->type->properties->io_ops; 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; } diff --git a/src/ocf_io_priv.h b/src/ocf_io_priv.h index 948e0b3..42ce735 100644 --- a/src/ocf_io_priv.h +++ b/src/ocf_io_priv.h @@ -25,7 +25,9 @@ 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_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) { diff --git a/src/ocf_request.h b/src/ocf_request.h index 44590b2..605216e 100644 --- a/src/ocf_request.h +++ b/src/ocf_request.h @@ -7,6 +7,7 @@ #define __OCF_REQUEST_H__ #include "ocf_env.h" +#include "ocf_io_priv.h" struct ocf_req_allocator; diff --git a/src/ocf_volume.c b/src/ocf_volume.c index 96aa042..a141059 100644 --- a/src/ocf_volume.c +++ b/src/ocf_volume.c @@ -227,9 +227,11 @@ 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) +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) diff --git a/src/utils/utils_cleaner.c b/src/utils/utils_cleaner.c index 8c20d02..c20265e 100644 --- a/src/utils/utils_cleaner.c +++ b/src/utils/utils_cleaner.c @@ -270,16 +270,14 @@ static int _ocf_cleaner_fire_flush_cache(struct ocf_request *req) 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) { ocf_metadata_error(req->cache); req->error = -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_queue(io, req->io_queue); 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; struct ocf_cache *cache = req->cache; struct ocf_map_info *iter = req->map; + ocf_core_t core; struct ocf_io *io; 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); - 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) { _ocf_cleaner_flush_cores_io_end(iter, req, -OCF_ERR_NO_MEM); 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_queue(io, req->io_queue); 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; 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_counters_block *core_stats = &cache->core[iter->core_id].counters->core_blocks; ocf_part_id_t part_id = ocf_metadata_get_partition_id(cache, iter->coll_idx); - io = ocf_new_core_io(cache, iter->core_id); - if (!io) - goto error; - addr = (ocf_line_size(cache) * iter->core_line) + SECTORS_TO_BYTES(begin); offset = (ocf_line_size(cache) * iter->hash_key) + SECTORS_TO_BYTES(begin); - ocf_io_configure(io, addr, SECTORS_TO_BYTES(end - begin), OCF_WRITE, - part_id, 0); - ocf_io_set_queue(io, req->io_queue); + io = ocf_new_core_io(core, req->io_queue, addr, + SECTORS_TO_BYTES(end - begin), OCF_WRITE, part_id, 0); + if (!io) + goto error; + err = ocf_io_set_data(io, req->data, offset); if (err) { 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]. 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) { /* Allocation error */ 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); 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); if (err) { ocf_io_put(io); diff --git a/src/utils/utils_io.c b/src/utils/utils_io.c index ff405c8..c658a47 100644 --- a/src/utils/utils_io.c +++ b/src/utils/utils_io.c @@ -31,11 +31,10 @@ void ocf_submit_volume_flush(ocf_volume_t volume, { 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) 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_volume_submit_flush(io); @@ -74,7 +73,10 @@ void ocf_submit_volume_discard(ocf_volume_t volume, uint64_t addr, context->priv = priv; 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) { context->error = -OCF_ERR_NO_MEM; break; @@ -82,9 +84,6 @@ void ocf_submit_volume_discard(ocf_volume_t volume, uint64_t addr, 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_volume_submit_discard(io); @@ -116,7 +115,10 @@ void ocf_submit_write_zeros(ocf_volume_t volume, uint64_t addr, context->priv = priv; 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) { context->error = -OCF_ERR_NO_MEM; break; @@ -124,9 +126,6 @@ void ocf_submit_write_zeros(ocf_volume_t volume, uint64_t addr, 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_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->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) { result = -OCF_ERR_NO_MEM; goto err_io; @@ -200,7 +199,6 @@ void ocf_submit_cache_page(ocf_cache_t cache, uint64_t addr, int dir, if (result) 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_volume_submit_io(io); @@ -245,12 +243,6 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache, cache_stats = &req->core->counters->cache_blocks; 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, req->map[first_cl].coll_idx); 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)); bytes = size; - ocf_io_configure(io, addr, bytes, dir, class, flags); - ocf_io_set_queue(io, req->io_queue); + io = ocf_new_cache_io(cache, 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); 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. */ 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, req->map[first_cl + i].coll_idx); 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); ENV_BUG_ON(bytes == 0); - ocf_io_configure(io, addr, bytes, dir, class, flags); - ocf_io_set_queue(io, req->io_queue); + io = ocf_new_cache_io(cache, 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); 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) 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) { callback(req, -OCF_ERR_NO_MEM); 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); err = ocf_io_set_data(io, req->data, 0); if (err) { diff --git a/src/utils/utils_io.h b/src/utils/utils_io.h index b1a5d47..418491c 100644 --- a/src/utils/utils_io.h +++ b/src/utils/utils_io.h @@ -64,17 +64,21 @@ void ocf_submit_cache_reqs(struct ocf_cache *cache, struct ocf_request *req, int dir, uint64_t offset, 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, - ocf_core_id_t core_id) +static inline struct ocf_io *ocf_new_core_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) { - ENV_BUG_ON(core_id >= OCF_CORE_MAX); - - return ocf_volume_new_io(&cache->core[core_id].volume); + return ocf_volume_new_io(ocf_core_get_volume(core), queue, + addr, bytes, dir, io_class, flags); } #endif /* UTILS_IO_H_ */