The TCP connect binds the socket to the local address given with the srcaddr= mount option in bind_socket(), but SMB Direct ignored it, so rdma_resolve_addr() picked the source address and with it the RDMA device from the routing table. Bind the smbdirect socket to srcaddr before connecting, so that rdma_resolve_addr() uses it. rdma_bind_addr() fails if it isn't a local address (anymore), like the bind() of the TCP connect, or if there is no RDMA device for it, and smbdirect_connect() fails with -EAFNOSUPPORT if it has another family than the server address, since the previous patch. Note that this changes the behavior of existing mounts with rdma and a srcaddr= that has no RDMA device, e.g. an address of another NIC: they connected before, as srcaddr= was ignored, now they fail with -ENODEV. As such a srcaddr= never had an effect, this should be rare. This also lets the following patch, which checks whether there is a usable route to the server with the source address after a reconnect attempt failed, look at the address actually used for SMB Direct. Fixes: 2f8946464b11 ("CIFS: SMBD: Upper layer connects to SMBDirect session") Cc: stable@vger.kernel.org Cc: Paulo Alcantara Cc: Namjae Jeon Cc: Ronnie Sahlberg Cc: Shyam Prasad N Cc: Tom Talpey Cc: Bharath SM Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Cc: linux-kernel@vger.kernel.org Signed-off-by: Stefan Metzmacher --- fs/smb/client/smbdirect.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c index 5cc199fca558..bb2ffb1601c5 100644 --- a/fs/smb/client/smbdirect.c +++ b/fs/smb/client/smbdirect.c @@ -343,6 +343,21 @@ static struct smbd_connection *_smbd_get_connection( *sport = htons(port); + /* + * Use the local address given with the srcaddr= mount option, + * like the TCP connect in bind_socket(). rdma_bind_addr() fails + * if it's not a local address (anymore). + */ + if (server->srcaddr.ss_family != AF_UNSPEC) { + ret = smbdirect_socket_bind(sc, + (struct sockaddr *)&server->srcaddr); + if (ret) { + log_rdma_event(ERR, "bind to %pISpsfc failed: %1pe\n", + &server->srcaddr, ERR_PTR(ret)); + goto bind_failed; + } + } + ret = smbdirect_connect_sync(sc, dstaddr); if (ret) { log_rdma_event(ERR, "connect to %pISpsfc failed: %1pe\n", @@ -354,6 +369,7 @@ static struct smbd_connection *_smbd_get_connection( return info; connect_failed: +bind_failed: set_settings_failed: set_params_failed: smbdirect_socket_release(sc); -- 2.43.0