smbd_get_connection() returned NULL on failure, so the callers had to make up an error: mount returned -ENOENT ("No such file or directory") and smbd_reconnect() as well, which hides the real reason, e.g. -ECONNREFUSED or -ENODEV if the route to the server uses a netdev without an RDMA device. Return an ERR_PTR() instead. If both ports fail, return the error of SMBD_PORT, unless it's -ENODEV, which is what the attempt with the wrong device type returns, as SMBD_PORT only allows iWarp devices and SMB_PORT doesn't allow them. 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: Long Li Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Signed-off-by: Stefan Metzmacher --- fs/smb/client/connect.c | 5 ++-- fs/smb/client/smbdirect.c | 48 +++++++++++++++++++++++---------------- fs/smb/client/smbdirect.h | 2 +- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/fs/smb/client/connect.c b/fs/smb/client/connect.c index 750b5bb72dc7..e79f9afe4128 100644 --- a/fs/smb/client/connect.c +++ b/fs/smb/client/connect.c @@ -1890,12 +1890,13 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx, #endif tcp_ses->smbd_conn = smbd_get_connection( tcp_ses, (struct sockaddr *)&ctx->dstaddr); - if (tcp_ses->smbd_conn) { + if (!IS_ERR(tcp_ses->smbd_conn)) { cifs_dbg(VFS, "RDMA transport established\n"); rc = 0; goto smbd_connected; } else { - rc = -ENOENT; + rc = PTR_ERR(tcp_ses->smbd_conn); + tcp_ses->smbd_conn = NULL; goto out_err_crypto_release; } } diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c index 563ef488a225..d05d90482e74 100644 --- a/fs/smb/client/smbdirect.c +++ b/fs/smb/client/smbdirect.c @@ -220,6 +220,8 @@ void smbd_destroy(struct TCP_Server_Info *server) */ int smbd_reconnect(struct TCP_Server_Info *server) { + struct smbd_connection *conn; + log_rdma_event(INFO, "reconnecting rdma session\n"); if (!server->smbd_conn) { @@ -236,16 +238,17 @@ int smbd_reconnect(struct TCP_Server_Info *server) create_conn: log_rdma_event(INFO, "creating rdma session\n"); - server->smbd_conn = smbd_get_connection( - server, (struct sockaddr *) &server->dstaddr); - - if (server->smbd_conn) { - cifs_dbg(VFS, "RDMA transport re-established\n"); - trace_smb3_smbd_connect_done(server->hostname, server->conn_id, &server->dstaddr); - return 0; + conn = smbd_get_connection(server, (struct sockaddr *)&server->dstaddr); + if (IS_ERR(conn)) { + server->smbd_conn = NULL; + trace_smb3_smbd_connect_err(server->hostname, server->conn_id, &server->dstaddr); + return PTR_ERR(conn); } - trace_smb3_smbd_connect_err(server->hostname, server->conn_id, &server->dstaddr); - return -ENOENT; + + server->smbd_conn = conn; + cifs_dbg(VFS, "RDMA transport re-established\n"); + trace_smb3_smbd_connect_done(server->hostname, server->conn_id, &server->dstaddr); + return 0; } /* Create a SMBD connection, called by upper layer */ @@ -302,7 +305,7 @@ static struct smbd_connection *_smbd_get_connection( info = kzalloc_obj(*info); if (!info) - return NULL; + return ERR_PTR(-ENOMEM); ret = smbdirect_socket_create_kern(net, &sc); if (ret) goto socket_init_failed; @@ -337,7 +340,7 @@ static struct smbd_connection *_smbd_get_connection( smbdirect_socket_release(sc); socket_init_failed: kfree(info); - return NULL; + return ERR_PTR(ret); } const struct smbdirect_socket_parameters *smbd_get_parameters(struct smbd_connection *conn) @@ -356,18 +359,25 @@ struct smbd_connection *smbd_get_connection( { struct smbd_connection *ret; const struct smbdirect_socket_parameters *sp; - int port = SMBD_PORT; -try_again: - ret = _smbd_get_connection(server, dstaddr, port); + ret = _smbd_get_connection(server, dstaddr, SMBD_PORT); /* Try SMB_PORT if SMBD_PORT doesn't work */ - if (!ret && port == SMBD_PORT) { - port = SMB_PORT; - goto try_again; + if (IS_ERR(ret)) { + struct smbd_connection *ret2; + + ret2 = _smbd_get_connection(server, dstaddr, SMB_PORT); + /* + * SMBD_PORT only allows iWarp devices and SMB_PORT + * doesn't allow them, the attempt with the wrong + * device type fails with -ENODEV, so we return + * the error of the other one. + */ + if (!IS_ERR(ret2) || PTR_ERR(ret) == -ENODEV) + ret = ret2; } - if (!ret) - return NULL; + if (IS_ERR(ret)) + return ret; sp = smbd_get_parameters(ret); diff --git a/fs/smb/client/smbdirect.h b/fs/smb/client/smbdirect.h index be205ec02077..52fef7354f2a 100644 --- a/fs/smb/client/smbdirect.h +++ b/fs/smb/client/smbdirect.h @@ -57,7 +57,7 @@ void smbd_debug_proc_show(struct TCP_Server_Info *server, struct seq_file *m); #define cifs_rdma_enabled(server) 0 struct smbd_connection {}; static inline void *smbd_get_connection( - struct TCP_Server_Info *server, struct sockaddr *dstaddr) {return NULL;} + struct TCP_Server_Info *server, struct sockaddr *dstaddr) {return ERR_PTR(-EOPNOTSUPP); } static inline int smbd_reconnect(struct TCP_Server_Info *server) {return -1; } static inline void smbd_destroy(struct TCP_Server_Info *server) {} static inline int smbd_recv(struct smbd_connection *info, struct msghdr *msg) {return -1; } -- 2.43.0