Commit 58afa58a authored by Ben Walker's avatar Ben Walker
Browse files

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: default avatarBen Walker <benjamin.walker@intel.com>
parent 812ffaf1
Loading
Loading
Loading
Loading
+36 −40
Original line number Diff line number Diff line
@@ -40,6 +40,7 @@
#include <rte_lcore.h>
#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)
{