sock/uring: extract advancing req's offset to a function

It'll make it possible to reuse this code for asynchronous read
requests.

Signed-off-by: Konrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I56dab62587884e2e37fad11b5f0d12df92e175ea
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12590
Tested-by: SPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: Ben Walker <benjamin.walker@intel.com>
Reviewed-by: Shuhei Matsumoto <smatsumoto@nvidia.com>
This commit is contained in:
Konrad Sztyber 2022-04-25 14:36:31 +02:00 committed by Tomasz Zawadzki
parent f34ce6fb07
commit 6d3506d893

View File

@ -739,14 +739,43 @@ uring_sock_writev(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
return writev(sock->fd, iov, iovcnt);
}
static ssize_t
sock_request_advance_offset(struct spdk_sock_request *req, ssize_t rc)
{
unsigned int offset;
size_t len;
int i;
offset = req->internal.offset;
for (i = 0; i < req->iovcnt; i++) {
/* Advance by the offset first */
if (offset >= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len) {
offset -= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len;
continue;
}
/* Calculate the remaining length of this element */
len = SPDK_SOCK_REQUEST_IOV(req, i)->iov_len - offset;
if (len > (size_t)rc) {
req->internal.offset += rc;
return -1;
}
offset = 0;
req->internal.offset += len;
rc -= len;
}
return rc;
}
static int
sock_complete_write_reqs(struct spdk_sock *_sock, ssize_t rc, bool is_zcopy)
{
struct spdk_uring_sock *sock = __uring_sock(_sock);
struct spdk_sock_request *req;
int i, retval;
unsigned int offset;
size_t len;
int retval;
if (is_zcopy) {
/* Handling overflow case, because we use psock->sendmsg_idx - 1 for the
@ -761,30 +790,13 @@ sock_complete_write_reqs(struct spdk_sock *_sock, ssize_t rc, bool is_zcopy)
/* Consume the requests that were actually written */
req = TAILQ_FIRST(&_sock->queued_reqs);
while (req) {
offset = req->internal.offset;
/* req->internal.is_zcopy is true when the whole req or part of it is sent with zerocopy */
req->internal.is_zcopy = is_zcopy;
for (i = 0; i < req->iovcnt; i++) {
/* Advance by the offset first */
if (offset >= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len) {
offset -= SPDK_SOCK_REQUEST_IOV(req, i)->iov_len;
continue;
}
/* Calculate the remaining length of this element */
len = SPDK_SOCK_REQUEST_IOV(req, i)->iov_len - offset;
if (len > (size_t)rc) {
/* This element was partially sent. */
req->internal.offset += rc;
return 0;
}
offset = 0;
req->internal.offset += len;
rc -= len;
rc = sock_request_advance_offset(req, rc);
if (rc < 0) {
/* This element was partially sent. */
return 0;
}
/* Handled a full request. */