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 <james.r.harris@intel.com>
Change-Id: I5858ccd6cff916b6c80fda7d2c9fce96fb39ef89

Reviewed-on: https://review.gerrithub.io/378858
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Daniel Verkamp <daniel.verkamp@intel.com>
This commit is contained in:
Jim Harris 2017-09-15 17:17:57 -07:00
parent 49cf3861d1
commit a0d7056f11
7 changed files with 33 additions and 33 deletions

View File

@ -50,10 +50,10 @@ int spdk_copy_engine_initialize(void);
int spdk_copy_engine_finish(void); int spdk_copy_engine_finish(void);
struct spdk_io_channel *spdk_copy_engine_get_io_channel(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, 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); 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, 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); void *dst, uint8_t fill, uint64_t nbytes, spdk_copy_completion_cb cb);
size_t spdk_copy_task_size(void); size_t spdk_copy_task_size(void);
#endif #endif

View File

@ -112,9 +112,9 @@ int spdk_ioat_detach(struct spdk_ioat_chan *ioat);
* \param src Source virtual address. * \param src Source virtual address.
* \param nbytes Number of bytes to copy. * \param nbytes Number of bytes to copy.
*/ */
int64_t spdk_ioat_submit_copy(struct spdk_ioat_chan *chan, int spdk_ioat_submit_copy(struct spdk_ioat_chan *chan,
void *cb_arg, spdk_ioat_req_cb cb_fn, void *cb_arg, spdk_ioat_req_cb cb_fn,
void *dst, const void *src, uint64_t nbytes); void *dst, const void *src, uint64_t nbytes);
/** /**
* Submit a DMA engine memory fill request. * 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 fill_pattern Repeating eight-byte pattern to use for memory fill.
* \param nbytes Number of bytes to fill. * \param nbytes Number of bytes to fill.
*/ */
int64_t spdk_ioat_submit_fill(struct spdk_ioat_chan *chan, int spdk_ioat_submit_fill(struct spdk_ioat_chan *chan,
void *cb_arg, spdk_ioat_req_cb cb_fn, void *cb_arg, spdk_ioat_req_cb cb_fn,
void *dst, uint64_t fill_pattern, uint64_t nbytes); void *dst, uint64_t fill_pattern, uint64_t nbytes);
/** /**
* Check for completed requests on an I/OAT channel. * Check for completed requests on an I/OAT channel.

View File

@ -45,9 +45,9 @@ struct spdk_copy_task {
}; };
struct spdk_copy_engine { 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); 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); uint64_t nbytes, spdk_copy_completion_cb cb);
struct spdk_io_channel *(*get_io_channel)(void); struct spdk_io_channel *(*get_io_channel)(void);
}; };

View File

@ -185,8 +185,8 @@ bdev_malloc_readv(struct malloc_disk *mdisk, struct spdk_io_channel *ch,
ch, iov[i].iov_base, ch, iov[i].iov_base,
src, iov[i].iov_len, malloc_done); src, iov[i].iov_len, malloc_done);
if (res != (int64_t)iov[i].iov_len) { if (res != 0) {
malloc_done(__copy_task_from_malloc_task(task), -1); malloc_done(__copy_task_from_malloc_task(task), res);
} }
src += iov[i].iov_len; 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, ch, dst, iov[i].iov_base,
iov[i].iov_len, malloc_done); iov[i].iov_len, malloc_done);
if (res != (int64_t)iov[i].iov_len) { if (res != 0) {
malloc_done(__copy_task_from_malloc_task(task), -1); malloc_done(__copy_task_from_malloc_task(task), res);
} }
dst += iov[i].iov_len; 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) 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); spdk_bdev_io_complete(bdev_io, SPDK_BDEV_IO_STATUS_FAILED);
} }
} }

View File

@ -75,7 +75,7 @@ copy_engine_done(void *ref, int status)
req->cb(req, status); req->cb(req, status);
} }
int64_t int
spdk_copy_submit(struct spdk_copy_task *copy_req, struct spdk_io_channel *ch, 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) 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); copy_engine_done);
} }
int64_t int
spdk_copy_submit_fill(struct spdk_copy_task *copy_req, struct spdk_io_channel *ch, 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) 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 */ /* 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, mem_copy_submit(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, uint64_t nbytes,
spdk_copy_completion_cb cb) 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 - copy_req = (struct spdk_copy_task *)((uintptr_t)cb_arg -
offsetof(struct spdk_copy_task, offload_ctx)); offsetof(struct spdk_copy_task, offload_ctx));
cb(copy_req, 0); 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, mem_copy_fill(void *cb_arg, struct spdk_io_channel *ch, void *dst, uint8_t fill, uint64_t nbytes,
spdk_copy_completion_cb cb) 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)); offsetof(struct spdk_copy_task, offload_ctx));
cb(copy_req, 0); cb(copy_req, 0);
return nbytes; return 0;
} }
static struct spdk_io_channel *mem_get_io_channel(void); static struct spdk_io_channel *mem_get_io_channel(void);

View File

@ -145,7 +145,7 @@ ioat_done(void *cb_arg)
ioat_task->cb(copy_req, 0); 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, ioat_copy_submit(void *cb_arg, struct spdk_io_channel *ch, void *dst, void *src, uint64_t nbytes,
spdk_copy_completion_cb cb) 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); 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, 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) uint64_t nbytes, spdk_copy_completion_cb cb)
{ {

View File

@ -573,7 +573,7 @@ spdk_ioat_detach(struct spdk_ioat_chan *ioat)
#define _2MB_PAGE(ptr) ((ptr) & ~(0x200000 - 1)) #define _2MB_PAGE(ptr) ((ptr) & ~(0x200000 - 1))
#define _2MB_OFFSET(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, 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) 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; uint32_t orig_head;
if (!ioat) { if (!ioat) {
return -1; return -EINVAL;
} }
orig_head = ioat->head; 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. * in case we managed to fill out any descriptors.
*/ */
ioat->head = orig_head; ioat->head = orig_head;
return -1; return -ENOMEM;
} }
ioat_flush(ioat); 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, 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) 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; uint32_t orig_head;
if (!ioat) { if (!ioat) {
return -1; return -EINVAL;
} }
if (!(ioat->dma_capabilities & SPDK_IOAT_ENGINE_FILL_SUPPORTED)) { 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. * in case we managed to fill out any descriptors.
*/ */
ioat->head = orig_head; ioat->head = orig_head;
return -1; return -ENOMEM;
} }
ioat_flush(ioat); ioat_flush(ioat);
return nbytes; return 0;
} }
uint32_t uint32_t