Commit 5631eb65 authored by Jacek Kalwas's avatar Jacek Kalwas Committed by Tomasz Zawadzki
Browse files

sock: stop returning 1 on spdk_sock_posix_fd_connect*



It was a reasonable hint for the user to try another address if
available; however, it complicates usage and error handling. It is
preferable to continue on failure if another address is available.
In the case of a critical failure, it will be encountered again quickly.

Additionally, by returning 1, we lose the actual error code. This change
is also a prework for a future change where, instead of returning -1, a
more specific errno will be returned.

Change-Id: Ia6fa3c6af5f80129adb708dbd5971a3711a9b6bd
Signed-off-by: default avatarJacek Kalwas <jacek.kalwas@nutanix.com>
Reviewed-on: https://review.spdk.io/c/spdk/spdk/+/26106


Reviewed-by: default avatarJim Harris <jim.harris@nvidia.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarTomasz Zawadzki <tomasz@tzawadzki.com>
parent 5dc69b17
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -409,7 +409,7 @@ int spdk_sock_posix_fd_create(struct addrinfo *res, struct spdk_sock_opts *opts,
 *
 * On success O_NONBLOCK is cleared otherwise property value is undefined.
 *
 * \return 0 on success, -1 on failure, 1 to retry with different address if available.
 * \return 0 on success, -1 on failure.
 */
int spdk_sock_posix_fd_connect(int fd, struct addrinfo *res, struct spdk_sock_opts *opts);

@@ -420,14 +420,14 @@ int spdk_sock_posix_fd_connect(int fd, struct addrinfo *res, struct spdk_sock_op
 *
 * User must use \ref spdk_sock_posix_fd_connect_poll_async to determine connection status.
 *
 * \return 0 on success, -1 on failure, 1 to retry with different address if available.
 * \return 0 on success, -1 on failure.
 */
int spdk_sock_posix_fd_connect_async(int fd, struct addrinfo *res, struct spdk_sock_opts *opts);

/**
 * Polls the socket connection status.
 *
 * \return 0 on connect success, -1 on failure, 1 to retry with different address if available and -EAGAIN to retry later.
 * \return 0 on connect success, -1 on failure and -EAGAIN to retry later.
 */
int spdk_sock_posix_fd_connect_poll_async(int fd);

+2 −2
Original line number Diff line number Diff line
@@ -495,7 +495,7 @@ sock_posix_fd_connect_poll(int fd, struct spdk_sock_opts *opts, bool block)

	if (err) {
		SPDK_ERRLOG("connect() failed, err = %d\n", err);
		return 1;
		return -1;
	}

	if (!(pfd.revents & POLLOUT)) {
@@ -563,7 +563,7 @@ sock_posix_fd_connect(int fd, struct addrinfo *res, struct spdk_sock_opts *opts,
	rc = connect(fd, res->ai_addr, res->ai_addrlen);
	if (rc != 0 && errno != EINPROGRESS) {
		SPDK_ERRLOG("connect() failed, errno = %d\n", errno);
		return 1;
		return -1;
	}

	if (!block) {
+5 −6
Original line number Diff line number Diff line
@@ -958,19 +958,18 @@ _sock_posix_connect(struct posix_connect_ctx *ctx)
	int rc, fd = -1;

	for (; ctx->next_res != NULL; ctx->next_res = ctx->next_res->ai_next) {
		fd = spdk_sock_posix_fd_create(ctx->next_res, &ctx->opts, &ctx->impl_opts);
		if (fd < 0) {
		rc = spdk_sock_posix_fd_create(ctx->next_res, &ctx->opts, &ctx->impl_opts);
		if (rc < 0) {
			continue;
		}

		fd = rc;
		rc = spdk_sock_posix_fd_connect(fd, ctx->next_res, &ctx->opts);
		if (rc) {
		if (rc < 0) {
			close(fd);
			fd = -1;
			if (rc == 1) {
			continue;
		}
		}

		break;
	}