Skip to content

Commit 7d07722

Browse files
metze-sambagregkh
authored andcommitted
smb: smbdirect: introduce SMBDIRECT_CHECK_STATUS_{WARN,DISCONNECT}()
[ Upstream commit 1adb2da ] 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: Stefan Metzmacher <metze@samba.org> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com> Stable-dep-of: 425c327 ("smb: server: relax WARN_ON_ONCE(SMBDIRECT_SOCKET_*) checks in recv_done() and smb_direct_cm_handler()") Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent c9ae246 commit 7d07722

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

fs/smb/common/smbdirect/smbdirect_socket.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -394,6 +394,44 @@ static __always_inline void smbdirect_socket_init(struct smbdirect_socket *sc)
394394
init_waitqueue_head(&sc->mr_io.cleanup.wait_queue);
395395
}
396396

397+
#define __SMBDIRECT_CHECK_STATUS_FAILED(__sc, __expected_status, __error_cmd, __unexpected_cmd) ({ \
398+
bool __failed = false; \
399+
if (unlikely((__sc)->first_error)) { \
400+
__failed = true; \
401+
__error_cmd \
402+
} else if (unlikely((__sc)->status != (__expected_status))) { \
403+
__failed = true; \
404+
__unexpected_cmd \
405+
} \
406+
__failed; \
407+
})
408+
409+
#define __SMBDIRECT_CHECK_STATUS_WARN(__sc, __expected_status, __unexpected_cmd) \
410+
__SMBDIRECT_CHECK_STATUS_FAILED(__sc, __expected_status, \
411+
, \
412+
{ \
413+
const struct sockaddr_storage *__src = NULL; \
414+
const struct sockaddr_storage *__dst = NULL; \
415+
if ((__sc)->rdma.cm_id) { \
416+
__src = &(__sc)->rdma.cm_id->route.addr.src_addr; \
417+
__dst = &(__sc)->rdma.cm_id->route.addr.dst_addr; \
418+
} \
419+
WARN_ONCE(1, \
420+
"expected[%s] != %s first_error=%1pe local=%pISpsfc remote=%pISpsfc\n", \
421+
smbdirect_socket_status_string(__expected_status), \
422+
smbdirect_socket_status_string((__sc)->status), \
423+
SMBDIRECT_DEBUG_ERR_PTR((__sc)->first_error), \
424+
__src, __dst); \
425+
__unexpected_cmd \
426+
})
427+
428+
#define SMBDIRECT_CHECK_STATUS_WARN(__sc, __expected_status) \
429+
__SMBDIRECT_CHECK_STATUS_WARN(__sc, __expected_status, /* nothing */)
430+
431+
#define SMBDIRECT_CHECK_STATUS_DISCONNECT(__sc, __expected_status) \
432+
__SMBDIRECT_CHECK_STATUS_WARN(__sc, __expected_status, \
433+
__SMBDIRECT_SOCKET_DISCONNECT(__sc);)
434+
397435
struct smbdirect_send_io {
398436
struct smbdirect_socket *socket;
399437
struct ib_cqe cqe;

0 commit comments

Comments
 (0)