From a0d7056f11a3ebca37cb60e56b59f3ef880cc83b Mon Sep 17 00:00:00 2001 From: Jim Harris Date: Fri, 15 Sep 2017 17:17:57 -0700 Subject: [PATCH] copy: return 0 on success and appropriate errno on failure This code was still using an old paradigm of returning the number of bytes associated with a successful submission. Just return 0 on success instead - if caller needs the number of bytes for some reason they have the information to get it. While here, return an appropriate negated errno where possible - we especially want ENOMEM returned when an ioat channel runs out of descriptors. Signed-off-by: Jim Harris Change-Id: I5858ccd6cff916b6c80fda7d2c9fce96fb39ef89 Reviewed-on: https://review.gerrithub.io/378858 Tested-by: SPDK Automated Test System Reviewed-by: Daniel Verkamp --- include/spdk/copy_engine.h | 8 ++++---- include/spdk/ioat.h | 12 ++++++------ include/spdk_internal/copy_engine.h | 4 ++-- lib/bdev/malloc/bdev_malloc.c | 10 +++++----- lib/copy/copy_engine.c | 12 ++++++------ lib/copy/ioat/copy_engine_ioat.c | 4 ++-- lib/ioat/ioat.c | 16 ++++++++-------- 7 files changed, 33 insertions(+), 33 deletions(-) diff --git a/include/spdk/copy_engine.h b/include/spdk/copy_engine.h index decbef550..aa4824e37 100644 --- a/include/spdk/copy_engine.h +++ b/include/spdk/copy_engine.h @@ -50,10 +50,10 @@ int spdk_copy_engine_initialize(void); int spdk_copy_engine_finish(void); struct spdk_io_channel *spdk_copy_engine_get_io_channel(void); -int64_t spdk_copy_submit(struct spdk_copy_task *copy_req, struct spdk_io_channel *ch, void *dst, - void *src, uint64_t nbytes, spdk_copy_completion_cb cb); -int64_t spdk_copy_submit_fill(struct spdk_copy_task *copy_req, struct spdk_io_channel *ch, - void *dst, uint8_t fill, uint64_t nbytes, spdk_copy_completion_cb cb); +int spdk_copy_submit(struct spdk_copy_task *copy_req, struct spdk_io_channel *ch, void *dst, + void *src, uint64_t nbytes, spdk_copy_completion_cb cb); +int spdk_copy_submit_fill(struct spdk_copy_task *copy_req, struct spdk_io_channel *ch, + void *dst, uint8_t fill, uint64_t nbytes, spdk_copy_completion_cb cb); size_t spdk_copy_task_size(void); #endif diff --git a/include/spdk/ioat.h b/include/spdk/ioat.h index d366c9efe..5529c0fad 100644 --- a/include/spdk/ioat.h +++ b/include/spdk/ioat.h @@ -112,9 +112,9 @@ int spdk_ioat_detach(struct spdk_ioat_chan *ioat); * \param src Source virtual address. * \param nbytes Number of bytes to copy. */ -int64_t spdk_ioat_submit_copy(struct spdk_ioat_chan *chan, - void *cb_arg, spdk_ioat_req_cb cb_fn, - void *dst, const void *src, uint64_t nbytes); +int spdk_ioat_submit_copy(struct spdk_ioat_chan *chan, + void *cb_arg, spdk_ioat_req_cb cb_fn, + void *dst, const void *src, uint64_t nbytes); /** * Submit a DMA engine memory fill request. @@ -126,9 +126,9 @@ int64_t spdk_ioat_submit_copy(struct spdk_ioat_chan *chan, * \param fill_pattern Repeating eight-byte pattern to use for memory fill. * \param nbytes Number of bytes to fill. */ -int64_t spdk_ioat_submit_fill(struct spdk_ioat_chan *chan, - void *cb_arg, spdk_ioat_req_cb cb_fn, - void *dst, uint64_t fill_pattern, uint64_t nbytes); +int spdk_ioat_submit_fill(struct spdk_ioat_chan *chan, + void *cb_arg, spdk_ioat_req_cb cb_fn, + void *dst, uint64_t fill_pattern, uint64_t nbytes); /** * Check for completed requests on an I/OAT channel. diff --git a/include/spdk_internal/copy_engine.h b/include/spdk_internal/copy_engine.h index b8d475f24..132597333 100644 --- a/include/spdk_internal/copy_engine.h +++ b/include/spdk_internal/copy_engine.h @@ -45,9 +45,9 @@ struct spdk_copy_task { }; struct spdk_copy_engine { - int64_t (*copy)(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, + int (*copy)(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, uint64_t nbytes, spdk_copy_completion_cb cb); - int64_t (*fill)(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_t fill, + int (*fill)(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_t fill, uint64_t nbytes, spdk_copy_completion_cb cb); struct spdk_io_channel *(*get_io_channel)(void); }; diff --git a/lib/bdev/malloc/bdev_malloc.c b/lib/bdev/malloc/bdev_malloc.c index 51dc3642d..1b6200dfe 100644 --- a/lib/bdev/malloc/bdev_malloc.c +++ b/lib/bdev/malloc/bdev_malloc.c @@ -185,8 +185,8 @@ bdev_malloc_readv(struct malloc_disk *mdisk, struct spdk_io_channel *ch, ch, iov[i].iov_base, src, iov[i].iov_len, malloc_done); - if (res != (int64_t)iov[i].iov_len) { - malloc_done(__copy_task_from_malloc_task(task), -1); + if (res != 0) { + malloc_done(__copy_task_from_malloc_task(task), res); } src += iov[i].iov_len; @@ -220,8 +220,8 @@ bdev_malloc_writev(struct malloc_disk *mdisk, struct spdk_io_channel *ch, ch, dst, iov[i].iov_base, iov[i].iov_len, malloc_done); - if (res != (int64_t)iov[i].iov_len) { - malloc_done(__copy_task_from_malloc_task(task), -1); + if (res != 0) { + malloc_done(__copy_task_from_malloc_task(task), res); } dst += iov[i].iov_len; @@ -328,7 +328,7 @@ static int _bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_b static void bdev_malloc_submit_request(struct spdk_io_channel *ch, struct spdk_bdev_io *bdev_io) { - if (_bdev_malloc_submit_request(ch, bdev_io) < 0) { + if (_bdev_malloc_submit_request(ch, bdev_io) != 0) { spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED); } } diff --git a/lib/copy/copy_engine.c b/lib/copy/copy_engine.c index 00558c8b0..3fc6035df 100644 --- a/lib/copy/copy_engine.c +++ b/lib/copy/copy_engine.c @@ -75,7 +75,7 @@ copy_engine_done(void *ref, int status) req->cb(req, status); } -int64_t +int spdk_copy_submit(struct spdk_copy_task *copy_req, struct spdk_io_channel *ch, void *dst, void *src, uint64_t nbytes, spdk_copy_completion_cb cb) { @@ -87,7 +87,7 @@ spdk_copy_submit(struct spdk_copy_task *copy_req, struct spdk_io_channel *ch, copy_engine_done); } -int64_t +int spdk_copy_submit_fill(struct spdk_copy_task *copy_req, struct spdk_io_channel *ch, void *dst, uint8_t fill, uint64_t nbytes, spdk_copy_completion_cb cb) { @@ -100,7 +100,7 @@ spdk_copy_submit_fill(struct spdk_copy_task *copy_req, struct spdk_io_channel *c } /* memcpy default copy engine */ -static int64_t +static int mem_copy_submit(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, uint64_t nbytes, spdk_copy_completion_cb cb) { @@ -111,10 +111,10 @@ mem_copy_submit(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, copy_req = (struct spdk_copy_task *)((uintptr_t)cb_arg - offsetof(struct spdk_copy_task, offload_ctx)); cb(copy_req, 0); - return nbytes; + return 0; } -static int64_t +static int mem_copy_fill(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_t fill, uint64_t nbytes, spdk_copy_completion_cb cb) { @@ -125,7 +125,7 @@ mem_copy_fill(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_t fill, offsetof(struct spdk_copy_task, offload_ctx)); cb(copy_req, 0); - return nbytes; + return 0; } static struct spdk_io_channel *mem_get_io_channel(void); diff --git a/lib/copy/ioat/copy_engine_ioat.c b/lib/copy/ioat/copy_engine_ioat.c index a72448003..c67f52ea8 100644 --- a/lib/copy/ioat/copy_engine_ioat.c +++ b/lib/copy/ioat/copy_engine_ioat.c @@ -145,7 +145,7 @@ ioat_done(void *cb_arg) ioat_task->cb(copy_req, 0); } -static int64_t +static int ioat_copy_submit(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, uint64_t nbytes, spdk_copy_completion_cb cb) { @@ -159,7 +159,7 @@ ioat_copy_submit(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, return spdk_ioat_submit_copy(ioat_ch->ioat_ch, ioat_task, ioat_done, dst, src, nbytes); } -static int64_t +static int ioat_copy_submit_fill(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_t fill, uint64_t nbytes, spdk_copy_completion_cb cb) { diff --git a/lib/ioat/ioat.c b/lib/ioat/ioat.c index fea1625b0..8e53ec900 100644 --- a/lib/ioat/ioat.c +++ b/lib/ioat/ioat.c @@ -573,7 +573,7 @@ spdk_ioat_detach(struct spdk_ioat_chan *ioat) #define _2MB_PAGE(ptr) ((ptr) & ~(0x200000 - 1)) #define _2MB_OFFSET(ptr) ((ptr) & (0x200000 - 1)) -int64_t +int spdk_ioat_submit_copy(struct spdk_ioat_chan *ioat, void *cb_arg, spdk_ioat_req_cb cb_fn, void *dst, const void *src, uint64_t nbytes) { @@ -585,7 +585,7 @@ spdk_ioat_submit_copy(struct spdk_ioat_chan *ioat, void *cb_arg, spdk_ioat_req_c uint32_t orig_head; if (!ioat) { - return -1; + return -EINVAL; } orig_head = ioat->head; @@ -639,14 +639,14 @@ spdk_ioat_submit_copy(struct spdk_ioat_chan *ioat, void *cb_arg, spdk_ioat_req_c * in case we managed to fill out any descriptors. */ ioat->head = orig_head; - return -1; + return -ENOMEM; } ioat_flush(ioat); - return nbytes; + return 0; } -int64_t +int spdk_ioat_submit_fill(struct spdk_ioat_chan *ioat, void *cb_arg, spdk_ioat_req_cb cb_fn, void *dst, uint64_t fill_pattern, uint64_t nbytes) { @@ -656,7 +656,7 @@ spdk_ioat_submit_fill(struct spdk_ioat_chan *ioat, void *cb_arg, spdk_ioat_req_c uint32_t orig_head; if (!ioat) { - return -1; + return -EINVAL; } if (!(ioat->dma_capabilities & SPDK_IOAT_ENGINE_FILL_SUPPORTED)) { @@ -695,11 +695,11 @@ spdk_ioat_submit_fill(struct spdk_ioat_chan *ioat, void *cb_arg, spdk_ioat_req_c * in case we managed to fill out any descriptors. */ ioat->head = orig_head; - return -1; + return -ENOMEM; } ioat_flush(ioat); - return nbytes; + return 0; } uint32_t