Commit 1adb2dab authored by Stefan Metzmacher's avatar Stefan Metzmacher Committed by Steve French
Browse files

smb: smbdirect: introduce SMBDIRECT_CHECK_STATUS_{WARN,DISCONNECT}()



These will be used in various places in order to assert
the current status mostly during the connect and negotiation
phase. It will replace the WARN_ON_ONCE(sc->status != ...)
calls, which are very useless in order to identify the
problem that happened.

As a start client and server will need to define their own
__SMBDIRECT_SOCKET_DISCONNECT(__sc) macro in order to use
SMBDIRECT_CHECK_STATUS_DISCONNECT().

Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: Namjae Jeon <linkinjeon@kernel.org>
Cc: Paulo Alcantara <pc@manguebit.org>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: default avatarStefan Metzmacher <metze@samba.org>
Acked-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent 1f3fd108
Loading
Loading
Loading
Loading
+38 −0
Original line number Diff line number Diff line
@@ -394,6 +394,44 @@ static __always_inline void smbdirect_socket_init(struct smbdirect_socket *sc)
	init_waitqueue_head(&sc->mr_io.cleanup.wait_queue);
}

#define __SMBDIRECT_CHECK_STATUS_FAILED(__sc, __expected_status, __error_cmd, __unexpected_cmd) ({ \
	bool __failed = false; \
	if (unlikely((__sc)->first_error)) { \
		__failed = true; \
		__error_cmd \
	} else if (unlikely((__sc)->status != (__expected_status))) { \
		__failed = true; \
		__unexpected_cmd \
	} \
	__failed; \
})

#define __SMBDIRECT_CHECK_STATUS_WARN(__sc, __expected_status, __unexpected_cmd) \
	__SMBDIRECT_CHECK_STATUS_FAILED(__sc, __expected_status, \
	, \
	{ \
		const struct sockaddr_storage *__src = NULL; \
		const struct sockaddr_storage *__dst = NULL; \
		if ((__sc)->rdma.cm_id) { \
			__src = &(__sc)->rdma.cm_id->route.addr.src_addr; \
			__dst = &(__sc)->rdma.cm_id->route.addr.dst_addr; \
		} \
		WARN_ONCE(1, \
			"expected[%s] != %s first_error=%1pe local=%pISpsfc remote=%pISpsfc\n", \
			smbdirect_socket_status_string(__expected_status), \
			smbdirect_socket_status_string((__sc)->status), \
			SMBDIRECT_DEBUG_ERR_PTR((__sc)->first_error), \
			__src, __dst); \
		__unexpected_cmd \
	})

#define SMBDIRECT_CHECK_STATUS_WARN(__sc, __expected_status) \
	__SMBDIRECT_CHECK_STATUS_WARN(__sc, __expected_status, /* nothing */)

#define SMBDIRECT_CHECK_STATUS_DISCONNECT(__sc, __expected_status) \
	__SMBDIRECT_CHECK_STATUS_WARN(__sc, __expected_status, \
		__SMBDIRECT_SOCKET_DISCONNECT(__sc);)

struct smbdirect_send_io {
	struct smbdirect_socket *socket;
	struct ib_cqe cqe;