bdev: Simplify get/set/put buf functions
Also make the iov_len always set to the used length, not the total length of the buffer. Change-Id: I7ebb5b63c6ca7570369f4af0131a23c520c1f7b0 Signed-off-by: Ben Walker <benjamin.walker@intel.com> Reviewed-on: https://review.gerrithub.io/419025 Chandler-Test-Pool: SPDK Automated Test System <sys_sgsw@intel.com> Tested-by: SPDK CI Jenkins <sys_sgci@intel.com> Reviewed-by: Maciej Szwed <maciej.szwed@intel.com> Reviewed-by: Dariusz Stojaczyk <dariuszx.stojaczyk@intel.com> Reviewed-by: Jim Harris <james.r.harris@intel.com> Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
This commit is contained in:
parent
37e6827a85
commit
844aedf8ad
@ -616,9 +616,8 @@ void spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb
|
||||
* \param buf The buffer to set as the active data buffer.
|
||||
* \param len The length of the buffer.
|
||||
*
|
||||
* \return The usable size of the buffer, after adjustments of alignment.
|
||||
*/
|
||||
size_t spdk_bdev_io_set_buf(struct spdk_bdev_io *bdev_io, void *buf, size_t len);
|
||||
void spdk_bdev_io_set_buf(struct spdk_bdev_io *bdev_io, void *buf, size_t len);
|
||||
|
||||
/**
|
||||
* Complete a bdev_io
|
||||
|
@ -377,33 +377,18 @@ spdk_bdev_get_by_name(const char *bdev_name)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t
|
||||
void
|
||||
spdk_bdev_io_set_buf(struct spdk_bdev_io *bdev_io, void *buf, size_t len)
|
||||
{
|
||||
struct iovec **iovs;
|
||||
int *iovcnt;
|
||||
void *aligned_buf;
|
||||
struct iovec *iovs;
|
||||
|
||||
iovs = &bdev_io->u.bdev.iovs;
|
||||
iovcnt = &bdev_io->u.bdev.iovcnt;
|
||||
iovs = bdev_io->u.bdev.iovs;
|
||||
|
||||
if (*iovs == NULL || *iovcnt == 0) {
|
||||
*iovs = &bdev_io->iov;
|
||||
*iovcnt = 1;
|
||||
}
|
||||
assert(iovs != NULL);
|
||||
assert(bdev_io->u.bdev.iovcnt >= 1);
|
||||
|
||||
if (buf != NULL) {
|
||||
aligned_buf = (void *)(((uintptr_t)buf + 511) & ~511UL);
|
||||
len = len - ((uintptr_t)aligned_buf - (uintptr_t)buf);
|
||||
} else {
|
||||
aligned_buf = NULL;
|
||||
assert(len == 0);
|
||||
}
|
||||
|
||||
(*iovs)[0].iov_base = aligned_buf;
|
||||
(*iovs)[0].iov_len = len;
|
||||
|
||||
return len;
|
||||
iovs[0].iov_base = buf;
|
||||
iovs[0].iov_len = len;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -411,38 +396,34 @@ spdk_bdev_io_put_buf(struct spdk_bdev_io *bdev_io)
|
||||
{
|
||||
struct spdk_mempool *pool;
|
||||
struct spdk_bdev_io *tmp;
|
||||
void *buf;
|
||||
void *buf, *aligned_buf;
|
||||
bdev_io_stailq_t *stailq;
|
||||
struct spdk_bdev_mgmt_channel *ch;
|
||||
size_t len;
|
||||
|
||||
assert(bdev_io->u.bdev.iovcnt == 1);
|
||||
|
||||
buf = bdev_io->internal.buf;
|
||||
ch = bdev_io->internal.ch->shared_resource->mgmt_ch;
|
||||
|
||||
bdev_io->internal.buf = NULL;
|
||||
|
||||
if (bdev_io->internal.buf_len <= SPDK_BDEV_SMALL_BUF_MAX_SIZE) {
|
||||
pool = g_bdev_mgr.buf_small_pool;
|
||||
stailq = &ch->need_buf_small;
|
||||
len = SPDK_BDEV_SMALL_BUF_MAX_SIZE + 512;
|
||||
} else {
|
||||
pool = g_bdev_mgr.buf_large_pool;
|
||||
stailq = &ch->need_buf_large;
|
||||
len = SPDK_BDEV_LARGE_BUF_MAX_SIZE + 512;
|
||||
}
|
||||
|
||||
if (STAILQ_EMPTY(stailq)) {
|
||||
spdk_mempool_put(pool, buf);
|
||||
} else {
|
||||
tmp = STAILQ_FIRST(stailq);
|
||||
|
||||
aligned_buf = (void *)(((uintptr_t)buf + 511) & ~511UL);
|
||||
spdk_bdev_io_set_buf(bdev_io, aligned_buf, tmp->internal.buf_len);
|
||||
|
||||
STAILQ_REMOVE_HEAD(stailq, internal.buf_link);
|
||||
len = spdk_bdev_io_set_buf(tmp, buf, len);
|
||||
if (len < tmp->internal.buf_len) {
|
||||
SPDK_ERRLOG("Unable to use buffer due to alignment\n");
|
||||
spdk_mempool_put(pool, buf);
|
||||
spdk_bdev_io_set_buf(tmp, NULL, 0);
|
||||
return;
|
||||
}
|
||||
tmp->internal.buf = buf;
|
||||
tmp->internal.get_buf_cb(tmp->internal.ch->channel, tmp);
|
||||
}
|
||||
@ -453,9 +434,8 @@ spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb, u
|
||||
{
|
||||
struct spdk_mempool *pool;
|
||||
bdev_io_stailq_t *stailq;
|
||||
void *buf = NULL;
|
||||
void *buf, *aligned_buf;
|
||||
struct spdk_bdev_mgmt_channel *mgmt_ch;
|
||||
size_t buf_len;
|
||||
|
||||
assert(cb != NULL);
|
||||
assert(bdev_io->u.bdev.iovs != NULL);
|
||||
@ -474,11 +454,9 @@ spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb, u
|
||||
if (len <= SPDK_BDEV_SMALL_BUF_MAX_SIZE) {
|
||||
pool = g_bdev_mgr.buf_small_pool;
|
||||
stailq = &mgmt_ch->need_buf_small;
|
||||
buf_len = SPDK_BDEV_SMALL_BUF_MAX_SIZE + 512;
|
||||
} else {
|
||||
pool = g_bdev_mgr.buf_large_pool;
|
||||
stailq = &mgmt_ch->need_buf_large;
|
||||
buf_len = SPDK_BDEV_LARGE_BUF_MAX_SIZE + 512;
|
||||
}
|
||||
|
||||
buf = spdk_mempool_get(pool);
|
||||
@ -486,16 +464,8 @@ spdk_bdev_io_get_buf(struct spdk_bdev_io *bdev_io, spdk_bdev_io_get_buf_cb cb, u
|
||||
if (!buf) {
|
||||
STAILQ_INSERT_TAIL(stailq, bdev_io, internal.buf_link);
|
||||
} else {
|
||||
size_t aligned_len;
|
||||
|
||||
aligned_len = spdk_bdev_io_set_buf(bdev_io, buf, buf_len);
|
||||
if (aligned_len < len) {
|
||||
SPDK_ERRLOG("Unable to use buffer after alignment calculations.\n");
|
||||
spdk_mempool_put(pool, buf);
|
||||
spdk_bdev_io_set_buf(bdev_io, NULL, 0);
|
||||
STAILQ_INSERT_TAIL(stailq, bdev_io, internal.buf_link);
|
||||
return;
|
||||
}
|
||||
aligned_buf = (void *)(((uintptr_t)buf + 511) & ~511UL);
|
||||
spdk_bdev_io_set_buf(bdev_io, aligned_buf, len);
|
||||
|
||||
bdev_io->internal.buf = buf;
|
||||
bdev_io->internal.get_buf_cb(bdev_io->internal.ch->channel, bdev_io);
|
||||
|
Loading…
Reference in New Issue
Block a user