From 58afa58a000dcb2040e65395e33e886814269e06 Mon Sep 17 00:00:00 2001 From: Ben Walker Date: Tue, 9 May 2017 14:32:49 -0700 Subject: [PATCH] bdev: Simplify spdk_bdev_get_io_buf This was implemented as two functions, but it is much simpler as one. Also, the public function was way at the bottom of the file instead of near spdk_bdev_put_io_buf. Change-Id: I3a90688910b0542cc77b6333bab15132cf514eeb Signed-off-by: Ben Walker --- lib/bdev/bdev.c | 76 +++++++++++++++++++++++-------------------------- 1 file changed, 36 insertions(+), 40 deletions(-) diff --git a/lib/bdev/bdev.c b/lib/bdev/bdev.c index ad1da4271..47ac4bcaf 100644 --- a/lib/bdev/bdev.c +++ b/lib/bdev/bdev.c @@ -40,6 +40,7 @@ #include #include "spdk/env.h" #include "spdk/io_channel.h" +#include "spdk/likely.h" #include "spdk/queue.h" #include "spdk/nvme_spec.h" #include "spdk/scsi_spec.h" @@ -167,6 +168,41 @@ spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io) } } +void +spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb) +{ + uint64_t len = bdev_io->u.read.len; + struct spdk_mempool *pool; + need_buf_tailq_t *tailq; + void *buf = NULL; + + assert(cb != NULL); + assert(bdev_io->u.read.iovs != NULL); + + if (spdk_unlikely(bdev_io->u.read.iovs[0].iov_base != NULL)) { + /* Buffer already present */ + cb(bdev_io->ch->channel, bdev_io); + return; + } + + bdev_io->get_buf_cb = cb; + if (len <= SPDK_BDEV_SMALL_BUF_MAX_SIZE) { + pool = g_bdev_mgr.buf_small_pool; + tailq = &g_bdev_mgr.need_buf_small[rte_lcore_id()]; + } else { + pool = g_bdev_mgr.buf_large_pool; + tailq = &g_bdev_mgr.need_buf_large[rte_lcore_id()]; + } + + buf = spdk_mempool_get(pool); + + if (!buf) { + TAILQ_INSERT_TAIL(tailq, bdev_io, buf_link); + } else { + spdk_bdev_io_set_buf(bdev_io, buf); + } +} + static int spdk_bdev_module_get_max_ctx_size(void) { @@ -346,32 +382,6 @@ spdk_bdev_put_io(struct spdk_bdev_io *bdev_io) spdk_mempool_put(g_bdev_mgr.bdev_io_pool, (void *)bdev_io); } -static void -_spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io) -{ - uint64_t len = bdev_io->u.read.len; - struct spdk_mempool *pool; - need_buf_tailq_t *tailq; - void *buf = NULL; - - if (len <= SPDK_BDEV_SMALL_BUF_MAX_SIZE) { - pool = g_bdev_mgr.buf_small_pool; - tailq = &g_bdev_mgr.need_buf_small[rte_lcore_id()]; - } else { - pool = g_bdev_mgr.buf_large_pool; - tailq = &g_bdev_mgr.need_buf_large[rte_lcore_id()]; - } - - buf = spdk_mempool_get(pool); - - if (!buf) { - TAILQ_INSERT_TAIL(tailq, bdev_io, buf_link); - } else { - spdk_bdev_io_set_buf(bdev_io, buf); - } -} - - static void spdk_bdev_cleanup_pending_buf_io(struct spdk_bdev *bdev) { @@ -1076,20 +1086,6 @@ spdk_bdev_unclaim(struct spdk_bdev *bdev) } } -void -spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb) -{ - assert(cb != NULL); - assert(bdev_io->u.read.iovs != NULL); - - if (bdev_io->u.read.iovs[0].iov_base == NULL) { - bdev_io->get_buf_cb = cb; - _spdk_bdev_io_get_buf(bdev_io); - } else { - cb(bdev_io->ch->channel, bdev_io); - } -} - void spdk_bdev_io_get_iovec(struct spdk_bdev_io *bdev_io, struct iovec **iovp, int *iovcntp) {