From 58734f5222608e503a39503ea3ead27b84b3a3c7 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 9 May 2017 13:32:20 -0700 Subject: [PATCH] bdev: Generalize buffer allocation Make the buffer allocation work for all types of commands, not just read. Change-Id: I72d8f67a724566630e7c4a74759fcb08449f7de4 Signed-off-by: Ben Walker --- include/spdk_internal/bdev.h | 14 +++++--------- lib/bdev/bdev.c | 13 ++++--------- lib/bdev/malloc/blockdev_malloc.c | 1 - 3 files changed, 9 insertions(+), 19 deletions(-) diff --git a/include/spdk_internal/bdev.h b/include/spdk_internal/bdev.h index 9de340454..76784c117 100644 --- a/include/spdk_internal/bdev.h +++ b/include/spdk_internal/bdev.h @@ -157,15 +157,14 @@ struct spdk_bdev_io { /** Generation value for each I/O. */ uint32_t gencnt; + /** bdev allocated memory associated with this request */ + void *buf; + /** Enumerated value representing the I/O type. */ enum spdk_bdev_io_type type; union { struct { - - /** The unaligned buf originally allocated. */ - void *buf_unaligned; - /** For basic read case, use our own iovec element. */ struct iovec iov; @@ -175,14 +174,11 @@ struct spdk_bdev_io { /** For SG buffer cases, number of iovecs in iovec array. */ int iovcnt; - /** For SG buffer cases, total size of data to be transferred. */ + /** Total size of data to be transferred. */ size_t len; /** Starting offset (in bytes) of the blockdev for this I/O. */ uint64_t offset; - - /** Indicate whether the blockdev layer to put buf or not. */ - bool put_buf; } read; struct { /** For basic write case, use our own iovec element */ @@ -194,7 +190,7 @@ struct spdk_bdev_io { /** For SG buffer cases, number of iovecs in iovec array. */ int iovcnt; - /** For SG buffer cases, total size of data to be transferred. */ + /** Total size of data to be transferred. */ size_t len; /** Starting offset (in bytes) of the blockdev for this I/O. */ diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index 6c5132d7e..2ee376b52 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -120,10 +120,9 @@ spdk_bdev_io_set_buf(struct spdk_bdev_io *bdev_io, void *buf) assert(buf != NULL); assert(bdev_io->u.read.iovs != NULL); - bdev_io->u.read.buf_unaligned = buf; + bdev_io->buf = buf; bdev_io->u.read.iovs[0].iov_base = (void *)((unsigned long)((char *)buf + 512) & ~511UL); bdev_io->u.read.iovs[0].iov_len = bdev_io->u.read.len; - bdev_io->u.read.put_buf = true; bdev_io->get_buf_cb(bdev_io->ch->channel, bdev_io); } @@ -139,7 +138,7 @@ spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io) assert(bdev_io->u.read.iovcnt == 1); length = bdev_io->u.read.len; - buf = bdev_io->u.read.buf_unaligned; + buf = bdev_io->buf; if (length <= SPDK_BDEV_SMALL_BUF_MAX_SIZE) { pool = g_buf_small_pool; @@ -344,7 +343,7 @@ spdk_bdev_put_io(struct spdk_bdev_io *bdev_io) return; } - if (bdev_io->type == SPDK_BDEV_IO_TYPE_READ && bdev_io->u.read.put_buf) { + if (bdev_io->buf != NULL) { spdk_bdev_io_put_buf(bdev_io); } @@ -476,9 +475,7 @@ spdk_bdev_get_child_io(struct spdk_bdev_io *parent, child->type = parent->type; memcpy(&child->u, &parent->u, sizeof(child->u)); - if (child->type == SPDK_BDEV_IO_TYPE_READ) { - child->u.read.put_buf = false; - } + child->buf = NULL; child->get_buf_cb = NULL; child->parent = parent; @@ -580,7 +577,6 @@ spdk_bdev_read(struct spdk_bdev *bdev, struct spdk_io_channel *ch, bdev_io->u.read.iovcnt = 1; bdev_io->u.read.len = nbytes; bdev_io->u.read.offset = offset; - bdev_io->u.read.put_buf = false; spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb); rc = spdk_bdev_io_submit(bdev_io); @@ -619,7 +615,6 @@ spdk_bdev_readv(struct spdk_bdev *bdev, struct spdk_io_channel *ch, bdev_io->u.read.iovcnt = iovcnt; bdev_io->u.read.len = nbytes; bdev_io->u.read.offset = offset; - bdev_io->u.read.put_buf = false; spdk_bdev_io_init(bdev_io, bdev, cb_arg, cb); rc = spdk_bdev_io_submit(bdev_io); diff --git a/lib/bdev/malloc/blockdev_malloc.c b/lib/bdev/malloc/blockdev_malloc.c index 897521cb7..02c7a6dfc 100644 --- a/lib/bdev/malloc/blockdev_malloc.c +++ b/lib/bdev/malloc/blockdev_malloc.c @@ -280,7 +280,6 @@ static int _blockdev_malloc_submit_request(struct spdk_io_channel *ch, struct sp ((struct malloc_disk *)bdev_io->bdev->ctxt)->malloc_buf + bdev_io->u.read.offset; bdev_io->u.read.iovs[0].iov_len = bdev_io->u.read.len; - bdev_io->u.read.put_buf = false; spdk_bdev_io_complete(spdk_bdev_io_from_ctx(bdev_io->driver_ctx), SPDK_BDEV_IO_STATUS_SUCCESS); return 0;