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:
parent
f34ce6fb07
commit
6d3506d893
@ -739,14 +739,43 @@ uring_sock_writev(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
|
|||||||
return writev(sock->fd, iov, 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
|
static int
|
||||||
sock_complete_write_reqs(struct spdk_sock *_sock, ssize_t rc, bool is_zcopy)
|
sock_complete_write_reqs(struct spdk_sock *_sock, ssize_t rc, bool is_zcopy)
|
||||||
{
|
{
|
||||||
struct spdk_uring_sock *sock = __uring_sock(_sock);
|
struct spdk_uring_sock *sock = __uring_sock(_sock);
|
||||||
struct spdk_sock_request *req;
|
struct spdk_sock_request *req;
|
||||||
int i, retval;
|
int retval;
|
||||||
unsigned int offset;
|
|
||||||
size_t len;
|
|
||||||
|
|
||||||
if (is_zcopy) {
|
if (is_zcopy) {
|
||||||
/* Handling overflow case, because we use psock->sendmsg_idx - 1 for the
|
/* Handling overflow case, because we use psock->sendmsg_idx - 1 for the
|
||||||
@ -761,32 +790,15 @@ sock_complete_write_reqs(struct spdk_sock *_sock, ssize_t rc, bool is_zcopy)
|
|||||||
/* Consume the requests that were actually written */
|
/* Consume the requests that were actually written */
|
||||||
req = TAILQ_FIRST(&_sock->queued_reqs);
|
req = TAILQ_FIRST(&_sock->queued_reqs);
|
||||||
while (req) {
|
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 true when the whole req or part of it is sent with zerocopy */
|
||||||
req->internal.is_zcopy = is_zcopy;
|
req->internal.is_zcopy = is_zcopy;
|
||||||
|
|
||||||
for (i = 0; i < req->iovcnt; i++) {
|
rc = sock_request_advance_offset(req, rc);
|
||||||
/* Advance by the offset first */
|
if (rc < 0) {
|
||||||
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. */
|
/* This element was partially sent. */
|
||||||
req->internal.offset += rc;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = 0;
|
|
||||||
req->internal.offset += len;
|
|
||||||
rc -= len;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Handled a full request. */
|
/* Handled a full request. */
|
||||||
spdk_sock_request_pend(_sock, req);
|
spdk_sock_request_pend(_sock, req);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user