From 7f45a1263667f1b0d862b54718a6dfbe99496fda Mon Sep 17 00:00:00 2001 From: Konrad Sztyber Date: Mon, 13 Jan 2020 15:16:11 +0100 Subject: [PATCH] lib/ftl: use iovecs instead of single data pointer Allow ftl_io initialization with a iovec array instead of a single data pointer. It'll make it possible to use the vector version of the IO commands. Change-Id: I34c1e398cea681f59321605e081366785aa29128 Signed-off-by: Konrad Sztyber Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/894 Tested-by: SPDK CI Jenkins Reviewed-by: Wojciech Malikowski Reviewed-by: Shuhei Matsumoto Reviewed-by: Maciej Szczepaniak Reviewed-by: Aleksey Marchuk Reviewed-by: Jim Harris --- lib/ftl/ftl_band.c | 16 ++++++++++++++-- lib/ftl/ftl_core.c | 16 ++++++++++++++-- lib/ftl/ftl_io.c | 16 +++++++++------- lib/ftl/ftl_io.h | 6 ++++-- lib/ftl/ftl_reloc.c | 8 +++++++- lib/ftl/ftl_restore.c | 16 ++++++++++++++-- test/unit/lib/ftl/ftl_reloc.c/ftl_reloc_ut.c | 3 ++- 7 files changed, 64 insertions(+), 17 deletions(-) diff --git a/lib/ftl/ftl_band.c b/lib/ftl/ftl_band.c index 20c8e5b56..647158c43 100644 --- a/lib/ftl/ftl_band.c +++ b/lib/ftl/ftl_band.c @@ -705,7 +705,13 @@ ftl_io_init_md_read(struct spdk_ftl_dev *dev, struct ftl_addr addr, .type = FTL_IO_READ, .num_blocks = num_blocks, .cb_fn = fn, - .data = buf, + .iovs = { + { + .iov_base = buf, + .iov_len = num_blocks * FTL_BLOCK_SIZE, + } + }, + .iovcnt = 1, }; io = (struct ftl_md_io *)ftl_io_init_internal(&opts); @@ -735,7 +741,13 @@ ftl_io_init_md_write(struct spdk_ftl_dev *dev, struct ftl_band *band, .type = FTL_IO_WRITE, .num_blocks = num_blocks, .cb_fn = cb, - .data = data, + .iovs = { + { + .iov_base = data, + .iov_len = num_blocks * FTL_BLOCK_SIZE, + } + }, + .iovcnt = 1, .md = NULL, }; diff --git a/lib/ftl/ftl_core.c b/lib/ftl/ftl_core.c index db5fe01ee..7cd40b76a 100644 --- a/lib/ftl/ftl_core.c +++ b/lib/ftl/ftl_core.c @@ -1183,7 +1183,13 @@ ftl_alloc_io_nv_cache(struct ftl_io *parent, size_t num_blocks) struct ftl_io_init_opts opts = { .dev = parent->dev, .parent = parent, - .data = ftl_io_iovec_addr(parent), + .iovs = { + { + .iov_base = ftl_io_iovec_addr(parent), + .iov_len = num_blocks * FTL_BLOCK_SIZE, + } + }, + .iovcnt = 1, .num_blocks = num_blocks, .flags = parent->flags | FTL_IO_CACHE, }; @@ -1530,7 +1536,13 @@ ftl_io_init_child_write(struct ftl_io *parent, struct ftl_addr addr, .type = parent->type, .num_blocks = dev->xfer_size, .cb_fn = cb, - .data = data, + .iovs = { + { + .iov_base = data, + .iov_len = dev->xfer_size * FTL_BLOCK_SIZE, + } + }, + .iovcnt = 1, .md = md, }; diff --git a/lib/ftl/ftl_io.c b/lib/ftl/ftl_io.c index fee522a15..8a3552fe5 100644 --- a/lib/ftl/ftl_io.c +++ b/lib/ftl/ftl_io.c @@ -275,10 +275,6 @@ ftl_io_init_internal(const struct ftl_io_init_opts *opts) struct ftl_io *io = opts->io; struct ftl_io *parent = opts->parent; struct spdk_ftl_dev *dev = opts->dev; - struct iovec iov = { - .iov_base = opts->data, - .iov_len = opts->num_blocks * FTL_BLOCK_SIZE - }; if (!io) { if (parent) { @@ -307,7 +303,7 @@ ftl_io_init_internal(const struct ftl_io_init_opts *opts) } } - if (ftl_io_init_iovec(io, &iov, 1, opts->num_blocks)) { + if (ftl_io_init_iovec(io, opts->iovs, opts->iovcnt, opts->num_blocks)) { if (!opts->io) { ftl_io_free(io); } @@ -340,7 +336,13 @@ ftl_io_rwb_init(struct spdk_ftl_dev *dev, struct ftl_addr addr, struct ftl_band .type = FTL_IO_WRITE, .num_blocks = dev->xfer_size, .cb_fn = cb, - .data = ftl_rwb_batch_get_data(batch), + .iovs = { + { + .iov_base = ftl_rwb_batch_get_data(batch), + .iov_len = dev->xfer_size * FTL_BLOCK_SIZE, + } + }, + .iovcnt = 1, .md = ftl_rwb_batch_get_md(batch), }; @@ -368,7 +370,7 @@ ftl_io_erase_init(struct ftl_band *band, size_t num_blocks, ftl_io_fn cb) .type = FTL_IO_ERASE, .num_blocks = 1, .cb_fn = cb, - .data = NULL, + .iovcnt = 0, .md = NULL, }; diff --git a/lib/ftl/ftl_io.h b/lib/ftl/ftl_io.h index 241d877d2..cb5778188 100644 --- a/lib/ftl/ftl_io.h +++ b/lib/ftl/ftl_io.h @@ -81,6 +81,8 @@ enum ftl_io_type { FTL_IO_ERASE, }; +#define FTL_IO_MAX_IOVEC 64 + struct ftl_io_init_opts { struct spdk_ftl_dev *dev; @@ -109,7 +111,8 @@ struct ftl_io_init_opts { size_t num_blocks; /* Data */ - void *data; + struct iovec iovs[FTL_IO_MAX_IOVEC]; + int iovcnt; /* Metadata */ void *md; @@ -164,7 +167,6 @@ struct ftl_io { /* Number of blocks */ size_t num_blocks; -#define FTL_IO_MAX_IOVEC 64 struct iovec iov[FTL_IO_MAX_IOVEC]; /* Metadata */ diff --git a/lib/ftl/ftl_reloc.c b/lib/ftl/ftl_reloc.c index 5583bee94..f764ad30a 100644 --- a/lib/ftl/ftl_reloc.c +++ b/lib/ftl/ftl_reloc.c @@ -433,7 +433,13 @@ ftl_reloc_io_init(struct ftl_band_reloc *breloc, struct ftl_reloc_move *move, .flags = flags | FTL_IO_INTERNAL | FTL_IO_PHYSICAL_MODE, .type = io_type, .num_blocks = move->num_blocks, - .data = move->data, + .iovs = { + { + .iov_base = move->data, + .iov_len = move->num_blocks * FTL_BLOCK_SIZE, + } + }, + .iovcnt = 1, .cb_fn = fn, }; diff --git a/lib/ftl/ftl_restore.c b/lib/ftl/ftl_restore.c index 52639311c..f7eb3f084 100644 --- a/lib/ftl/ftl_restore.c +++ b/lib/ftl/ftl_restore.c @@ -706,7 +706,13 @@ ftl_nv_cache_alloc_io(struct ftl_nv_cache_block *block, uint64_t lba) .num_blocks = 1, .cb_fn = ftl_nv_cache_write_cb, .cb_ctx = block, - .data = block->buf, + .iovs = { + { + .iov_base = block->buf, + .iov_len = FTL_BLOCK_SIZE, + } + }, + .iovcnt = 1, }; struct ftl_io *io; @@ -1136,7 +1142,13 @@ ftl_restore_init_pad_io(struct ftl_restore_band *rband, void *buffer, .num_blocks = dev->xfer_size, .cb_fn = ftl_pad_zone_cb, .cb_ctx = rband, - .data = buffer, + .iovs = { + { + .iov_base = buffer, + .iov_len = dev->xfer_size * FTL_BLOCK_SIZE, + } + }, + .iovcnt = 1, .parent = NULL, }; struct ftl_io *io; diff --git a/test/unit/lib/ftl/ftl_reloc.c/ftl_reloc_ut.c b/test/unit/lib/ftl/ftl_reloc.c/ftl_reloc_ut.c index 2c4427a06..b7a1abbe0 100644 --- a/test/unit/lib/ftl/ftl_reloc.c/ftl_reloc_ut.c +++ b/test/unit/lib/ftl/ftl_reloc.c/ftl_reloc_ut.c @@ -143,7 +143,8 @@ ftl_io_init_internal(const struct ftl_io_init_opts *opts) io->cb_fn = opts->cb_fn; io->cb_ctx = io; io->num_blocks = opts->num_blocks; - io->iov[0].iov_base = opts->data; + memcpy(&io->iov, &opts->iovs, sizeof(io->iov)); + io->iov_cnt = opts->iovcnt; if (opts->flags & FTL_IO_VECTOR_LBA) { io->lba.vector = calloc(io->num_blocks, sizeof(uint64_t));