Commit 5f1e93c8 authored by Ben Walker's avatar Ben Walker Committed by Jim Harris
Browse files

sock/uring: Improve error handling cases



Break the error handing up by opcode since it is going to be different
for each. For this patch, this duplicates a lot of code. But the cases
will all diverge later in this series.

Change-Id: I12d5d88c41ca4b7063293dd143000212fe6d2156
Signed-off-by: default avatarBen Walker <benjamin.walker@intel.com>
Reviewed-on: https://review.spdk.io/gerrit/c/spdk/spdk/+/17736


Reviewed-by: default avatarJim Harris <james.r.harris@intel.com>
Reviewed-by: default avatarKonrad Sztyber <konrad.sztyber@intel.com>
Community-CI: Mellanox Build Bot
Tested-by: default avatarSPDK CI Jenkins <sys_sgci@intel.com>
parent c5b497f2
Loading
Loading
Loading
Loading
+80 −29
Original line number Diff line number Diff line
@@ -801,9 +801,16 @@ uring_sock_read(struct spdk_uring_sock *sock)
}

static int
uring_sock_recv_next(struct spdk_sock *sock, void **buf, void **ctx)
uring_sock_recv_next(struct spdk_sock *_sock, void **_buf, void **ctx)
{
	errno = ENOTSUP;
	struct spdk_uring_sock *sock = __uring_sock(_sock);

	if (sock->connection_status < 0) {
		errno = -sock->connection_status;
		return -1;
	}

	errno = -ENOTSUP;
	return -1;
}

@@ -814,6 +821,11 @@ uring_sock_readv(struct spdk_sock *_sock, struct iovec *iov, int iovcnt)
	int rc, i;
	size_t len;

	if (sock->connection_status < 0) {
		errno = -sock->connection_status;
		return -1;
	}

	if (sock->recv_pipe == NULL) {
		return sock_readv(sock->fd, iov, iovcnt);
	}
@@ -1194,13 +1206,11 @@ sock_uring_group_reap(struct spdk_uring_sock_group_impl *group, int max, int max

		task->status = SPDK_URING_SOCK_TASK_NOT_IN_USE;

		if (spdk_unlikely(status < 0)) {
			if (status == -EAGAIN || status == -EWOULDBLOCK ||
			    (status == -ENOBUFS && sock->zcopy) ||
			    status == -ECANCELED) {
		switch (task->type) {
		case SPDK_SOCK_TASK_READ:
			if (status == -EAGAIN || status == -EWOULDBLOCK || status == -ECANCELED) {
				continue;
			}

			} else if (spdk_unlikely(status < 0)) {
				sock->connection_status = status;
				spdk_sock_abort_requests(&sock->base);

@@ -1210,13 +1220,9 @@ sock_uring_group_reap(struct spdk_uring_sock_group_impl *group, int max, int max
					sock->pending_recv = true;
					TAILQ_INSERT_TAIL(&group->pending_recv, sock, link);
				}
			} else {
				assert((status & POLLIN) == POLLIN);

			continue;
		}

		switch (task->type) {
		case SPDK_SOCK_TASK_READ:
			if ((status & POLLIN) == POLLIN) {
				if (sock->base.cb_fn != NULL &&
				    sock->pending_recv == false) {
					sock->pending_recv = true;
@@ -1226,21 +1232,66 @@ sock_uring_group_reap(struct spdk_uring_sock_group_impl *group, int max, int max
			break;
		case SPDK_SOCK_TASK_POLLERR:
#ifdef SPDK_ZEROCOPY
			if ((status & POLLERR) == POLLERR) {
			if (status == -EAGAIN || status == -EWOULDBLOCK || status == -ECANCELED) {
				continue;
			} else if (spdk_unlikely(status < 0)) {
				sock->connection_status = status;
				spdk_sock_abort_requests(&sock->base);

				/* The user needs to be notified that this socket is dead. */
				if (sock->base.cb_fn != NULL &&
				    sock->pending_recv == false) {
					sock->pending_recv = true;
					TAILQ_INSERT_TAIL(&group->pending_recv, sock, link);
				}
			} else {
				assert((status & POLLERR) == POLLERR);
				_sock_prep_errqueue(&sock->base);
			}
#endif
			break;
		case SPDK_SOCK_TASK_WRITE:
			if (status == -EAGAIN || status == -EWOULDBLOCK ||
			    (status == -ENOBUFS && sock->zcopy) ||
			    status == -ECANCELED) {
				continue;
			} else if (spdk_unlikely(status) < 0) {
				sock->connection_status = status;
				spdk_sock_abort_requests(&sock->base);

				/* The user needs to be notified that this socket is dead. */
				if (sock->base.cb_fn != NULL &&
				    sock->pending_recv == false) {
					sock->pending_recv = true;
					TAILQ_INSERT_TAIL(&group->pending_recv, sock, link);
				}
			} else {
				task->last_req = NULL;
				task->iov_cnt = 0;
				is_zcopy = task->is_zcopy;
				task->is_zcopy = false;
				sock_complete_write_reqs(&sock->base, status, is_zcopy);
			}

			break;
#ifdef SPDK_ZEROCOPY
		case SPDK_SOCK_TASK_ERRQUEUE:
			if (status == -EAGAIN || status == -EWOULDBLOCK || status == -ECANCELED) {
				continue;
			} else if (spdk_unlikely(status < 0)) {
				sock->connection_status = status;
				spdk_sock_abort_requests(&sock->base);

				/* The user needs to be notified that this socket is dead. */
				if (sock->base.cb_fn != NULL &&
				    sock->pending_recv == false) {
					sock->pending_recv = true;
					TAILQ_INSERT_TAIL(&group->pending_recv, sock, link);
				}
				break;
			} else {
				_sock_check_zcopy(&sock->base, status);
			}
			break;
#endif
		case SPDK_SOCK_TASK_CANCEL: