Commit 6b4317e4 authored by Jacek Kalwas's avatar Jacek Kalwas Committed by Tomasz Zawadzki
Browse files

sock: remove sync fallback from spdk_sock_connect_async



Invoking the callback before the function returns (in the sync fallback
case) is very error-prone. The user can fall back to the synchronous
version of connect on their own if async is not supported by the module.

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


Reviewed-by: default avatarTomasz Zawadzki <tomasz@tzawadzki.com>
Tested-by: default avatarSPDK Automated Test System <spdkbot@gmail.com>
Reviewed-by: default avatarKonrad Sztyber <ksztyber@nvidia.com>
Community-CI: Mellanox Build Bot
parent e9d07361
Loading
Loading
Loading
Loading
+1 −3
Original line number Diff line number Diff line
@@ -349,9 +349,7 @@ typedef void (*spdk_sock_connect_cb_fn)(void *cb_arg, int status);
 * errno values if connection failed.
 *
 * Callback function \p cb_fn is invoked only if this function returns a non-NULL value.
 * However, if async connect is not supported by the \p impl_name it fallbacks to the sync
 * version and \p cb_fn will be invoked only if sync connect is successful and before
 * returning control to the the user.
 * If async connect is not supported by the \p impl_name specified then NULL is returned.
 *
 * \param ip IP address of the server.
 * \param port Port number of the server.
+6 −7
Original line number Diff line number Diff line
@@ -640,6 +640,11 @@ sock_connect_ext(const char *ip, int port, const char *_impl_name, struct spdk_s
		return NULL;
	}

	if (async && !impl->connect_async) {
		SPDK_ERRLOG("Asynchronous connect is not supported by %s\n", impl->name);
		return NULL;
	}

	SPDK_DEBUGLOG(sock, "Creating a client socket using impl %s\n", impl->name);
	sock_init_opts(&opts_local, opts);
	if (opts_local.connect_timeout > INT_MAX) {
@@ -647,7 +652,7 @@ sock_connect_ext(const char *ip, int port, const char *_impl_name, struct spdk_s
		return NULL;
	}

	if (async && impl->connect_async) {
	if (async) {
		sock = impl->connect_async(ip, port, &opts_local, cb_fn, cb_arg);
	} else {
		sock = impl->connect(ip, port, &opts_local);
@@ -665,12 +670,6 @@ sock_connect_ext(const char *ip, int port, const char *_impl_name, struct spdk_s
	sock->net_impl = impl;
	TAILQ_INIT(&sock->queued_reqs);
	TAILQ_INIT(&sock->pending_reqs);

	/* Invoke cb_fn only in case of fallback to sync version. */
	if (cb_fn && async && !impl->connect_async) {
		cb_fn(cb_arg, 0);
	}

	return sock;
}