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 <benjamin.walker@intel.com>
This commit is contained in:
Ben Walker 2017-05-09 13:32:20 -07:00 committed by Daniel Verkamp
parent 8ff1c0298d
commit 58734f5222
3 changed files with 9 additions and 19 deletions

View File

@ -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. */

View File

@ -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);

View File

@ -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;