Commit 6d3506d8 authored by Konrad Sztyber's avatar Konrad Sztyber Committed by Tomasz Zawadzki
Browse files

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: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Change-Id: I56dab62587884e2e37fad11b5f0d12df92e175ea
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/12590


Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
Community-CI: Broadcom CI <spdk-ci.pdl@broadcom.com>
Community-CI: Mellanox Build Bot
Reviewed-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-by: default avatarShuhei Matsumoto <smatsumoto@nvidia.com>
parent f34ce6fb
Loading
Loading
Loading
Loading
+36 −24
Original line number Diff line number Diff line
@@ -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,32 +790,15 @@ 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) {
		rc = sock_request_advance_offset(req, rc);
		if (rc < 0) {
			/* This element was partially sent. */
				req->internal.offset += rc;
			return 0;
		}

			offset = 0;
			req->internal.offset += len;
			rc -= len;
		}

		/* Handled a full request. */
		spdk_sock_request_pend(_sock, req);