* [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait
@ 2025-08-08 16:48 Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 1/9] smb: client: return an error if rdma_connect does not return within 5 seconds Stefan Metzmacher
` (8 more replies)
0 siblings, 9 replies; 11+ messages in thread
From: Stefan Metzmacher @ 2025-08-08 16:48 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon
Hi,
this is the next step towards a common smbdirect layer
between cifs.ko and ksmbd.ko, with the aim to provide
a socket layer for userspace usage at the end of the road.
This patchset focuses on the client side.
The first one is a fix for very long timeouts against
unreachable servers.
The others prepare the use of a single wait_queue for state
changes. This removes a lot of special handling during
the connect and negotiate phases.
The last two move the state_wait queue into the common
smbdirect_socket.status_wait.
For the server I have only a single patch that also
uses smbdirect_socket.status_wait, but I'm skipping
the server patches today.
I used the following xfstests as regression tests:
cifs/001 generic/001 generic/002 generic/005 generic/006 generic/007 generic/010 generic/011
Between cifs.ko against ksmbd.ko via siw.ko.
V3:
smbd_disconnect_rdma_work() needed to handle more
than SMBDIRECT_SOCKET_CONNECTED in order to call
rdma_disconnect.
V2:
init_waitqueue_head(&info->status_wait); was moved
to the beginning so that it is correctly initialized
in smbd_create_id().
Stefan Metzmacher (9):
smb: client: return an error if rdma_connect does not return within 5
seconds
smb: client: improve logging in smbd_conn_upcall()
smb: client: don't call init_waitqueue_head(&info->conn_wait) twice in
_smbd_get_connection
smb: client: only use a single wait_queue to monitor smbdirect
connection status
smb: client/smbdirect: replace SMBDIRECT_SOCKET_CONNECTING with more
detailed states
smb: client: use status_wait and SMBDIRECT_SOCKET_NEGOTIATE_RUNNING
for completion
smb: client: use status_wait and
SMBDIRECT_SOCKET_RESOLVE_{ADDR,ROUTE}_RUNNING for completion
smb: smbdirect: introduce smbdirect_socket.status_wait
smb: client: make use of smbdirect_socket.status_wait
fs/smb/client/smbdirect.c | 167 +++++++++++++++------
fs/smb/client/smbdirect.h | 8 -
fs/smb/common/smbdirect/smbdirect_socket.h | 15 +-
3 files changed, 134 insertions(+), 56 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v3 1/9] smb: client: return an error if rdma_connect does not return within 5 seconds
2025-08-08 16:48 [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait Stefan Metzmacher
@ 2025-08-08 16:48 ` Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 2/9] smb: client: improve logging in smbd_conn_upcall() Stefan Metzmacher
` (7 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Stefan Metzmacher @ 2025-08-08 16:48 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, Steve French, Tom Talpey, Long Li, Steve French
This matches the timeout for tcp connections.
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Fixes: f198186aa9bb ("CIFS: SMBD: Establish SMB Direct connection")
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/smb/client/smbdirect.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index 6c2af00be44c..181349eda7a3 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -1653,8 +1653,10 @@ static struct smbd_connection *_smbd_get_connection(
goto rdma_connect_failed;
}
- wait_event_interruptible(
- info->conn_wait, sc->status != SMBDIRECT_SOCKET_CONNECTING);
+ wait_event_interruptible_timeout(
+ info->conn_wait,
+ sc->status != SMBDIRECT_SOCKET_CONNECTING,
+ msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
log_rdma_event(ERR, "rdma_connect failed port=%d\n", port);
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 2/9] smb: client: improve logging in smbd_conn_upcall()
2025-08-08 16:48 [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 1/9] smb: client: return an error if rdma_connect does not return within 5 seconds Stefan Metzmacher
@ 2025-08-08 16:48 ` Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 3/9] smb: client: don't call init_waitqueue_head(&info->conn_wait) twice in _smbd_get_connection Stefan Metzmacher
` (6 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Stefan Metzmacher @ 2025-08-08 16:48 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, Steve French, Tom Talpey, Long Li, Steve French
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/smb/client/smbdirect.c | 14 ++++++++++----
1 file changed, 10 insertions(+), 4 deletions(-)
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index 181349eda7a3..8ed4ab6f1d3a 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -178,9 +178,10 @@ static int smbd_conn_upcall(
{
struct smbd_connection *info = id->context;
struct smbdirect_socket *sc = &info->socket;
+ const char *event_name = rdma_event_msg(event->event);
- log_rdma_event(INFO, "event=%d status=%d\n",
- event->event, event->status);
+ log_rdma_event(INFO, "event=%s status=%d\n",
+ event_name, event->status);
switch (event->event) {
case RDMA_CM_EVENT_ADDR_RESOLVED:
@@ -190,17 +191,19 @@ static int smbd_conn_upcall(
break;
case RDMA_CM_EVENT_ADDR_ERROR:
+ log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
info->ri_rc = -EHOSTUNREACH;
complete(&info->ri_done);
break;
case RDMA_CM_EVENT_ROUTE_ERROR:
+ log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
info->ri_rc = -ENETUNREACH;
complete(&info->ri_done);
break;
case RDMA_CM_EVENT_ESTABLISHED:
- log_rdma_event(INFO, "connected event=%d\n", event->event);
+ log_rdma_event(INFO, "connected event=%s\n", event_name);
sc->status = SMBDIRECT_SOCKET_CONNECTED;
wake_up_interruptible(&info->conn_wait);
break;
@@ -208,7 +211,7 @@ static int smbd_conn_upcall(
case RDMA_CM_EVENT_CONNECT_ERROR:
case RDMA_CM_EVENT_UNREACHABLE:
case RDMA_CM_EVENT_REJECTED:
- log_rdma_event(INFO, "connecting failed event=%d\n", event->event);
+ log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
wake_up_interruptible(&info->conn_wait);
break;
@@ -217,6 +220,7 @@ static int smbd_conn_upcall(
case RDMA_CM_EVENT_DISCONNECTED:
/* This happens when we fail the negotiation */
if (sc->status == SMBDIRECT_SOCKET_NEGOTIATE_FAILED) {
+ log_rdma_event(ERR, "event=%s during negotiation\n", event_name);
sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
wake_up(&info->conn_wait);
break;
@@ -229,6 +233,8 @@ static int smbd_conn_upcall(
break;
default:
+ log_rdma_event(ERR, "unexpected event=%s status=%d\n",
+ event_name, event->status);
break;
}
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 3/9] smb: client: don't call init_waitqueue_head(&info->conn_wait) twice in _smbd_get_connection
2025-08-08 16:48 [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 1/9] smb: client: return an error if rdma_connect does not return within 5 seconds Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 2/9] smb: client: improve logging in smbd_conn_upcall() Stefan Metzmacher
@ 2025-08-08 16:48 ` Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 4/9] smb: client: only use a single wait_queue to monitor smbdirect connection status Stefan Metzmacher
` (5 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Stefan Metzmacher @ 2025-08-08 16:48 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, Steve French, Tom Talpey, Long Li, Steve French
It is already called long before we may hit this cleanup code path.
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/smb/client/smbdirect.c | 1 -
1 file changed, 1 deletion(-)
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index 8ed4ab6f1d3a..c819cc6dcc4f 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -1716,7 +1716,6 @@ static struct smbd_connection *_smbd_get_connection(
cancel_delayed_work_sync(&info->idle_timer_work);
destroy_caches_and_workqueue(info);
sc->status = SMBDIRECT_SOCKET_NEGOTIATE_FAILED;
- init_waitqueue_head(&info->conn_wait);
rdma_disconnect(sc->rdma.cm_id);
wait_event(info->conn_wait,
sc->status == SMBDIRECT_SOCKET_DISCONNECTED);
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 4/9] smb: client: only use a single wait_queue to monitor smbdirect connection status
2025-08-08 16:48 [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait Stefan Metzmacher
` (2 preceding siblings ...)
2025-08-08 16:48 ` [PATCH v3 3/9] smb: client: don't call init_waitqueue_head(&info->conn_wait) twice in _smbd_get_connection Stefan Metzmacher
@ 2025-08-08 16:48 ` Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 5/9] smb: client/smbdirect: replace SMBDIRECT_SOCKET_CONNECTING with more detailed states Stefan Metzmacher
` (4 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Stefan Metzmacher @ 2025-08-08 16:48 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, Steve French, Tom Talpey, Long Li, Steve French
There's no need for separate conn_wait and disconn_wait queues.
This will simplify the move to common code, the server code
already a single wait_queue for this.
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/smb/client/smbdirect.c | 17 ++++++++---------
fs/smb/client/smbdirect.h | 3 +--
2 files changed, 9 insertions(+), 11 deletions(-)
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index c819cc6dcc4f..c628e91c328b 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -205,7 +205,7 @@ static int smbd_conn_upcall(
case RDMA_CM_EVENT_ESTABLISHED:
log_rdma_event(INFO, "connected event=%s\n", event_name);
sc->status = SMBDIRECT_SOCKET_CONNECTED;
- wake_up_interruptible(&info->conn_wait);
+ wake_up_interruptible(&info->status_wait);
break;
case RDMA_CM_EVENT_CONNECT_ERROR:
@@ -213,7 +213,7 @@ static int smbd_conn_upcall(
case RDMA_CM_EVENT_REJECTED:
log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
- wake_up_interruptible(&info->conn_wait);
+ wake_up_interruptible(&info->status_wait);
break;
case RDMA_CM_EVENT_DEVICE_REMOVAL:
@@ -222,12 +222,12 @@ static int smbd_conn_upcall(
if (sc->status == SMBDIRECT_SOCKET_NEGOTIATE_FAILED) {
log_rdma_event(ERR, "event=%s during negotiation\n", event_name);
sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
- wake_up(&info->conn_wait);
+ wake_up(&info->status_wait);
break;
}
sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
- wake_up_interruptible(&info->disconn_wait);
+ wake_up_interruptible(&info->status_wait);
wake_up_interruptible(&sc->recv_io.reassembly.wait_queue);
wake_up_interruptible_all(&info->wait_send_queue);
break;
@@ -1325,7 +1325,7 @@ void smbd_destroy(struct TCP_Server_Info *server)
rdma_disconnect(sc->rdma.cm_id);
log_rdma_event(INFO, "wait for transport being disconnected\n");
wait_event_interruptible(
- info->disconn_wait,
+ info->status_wait,
sc->status == SMBDIRECT_SOCKET_DISCONNECTED);
}
@@ -1650,8 +1650,7 @@ static struct smbd_connection *_smbd_get_connection(
log_rdma_event(INFO, "connecting to IP %pI4 port %d\n",
&addr_in->sin_addr, port);
- init_waitqueue_head(&info->conn_wait);
- init_waitqueue_head(&info->disconn_wait);
+ init_waitqueue_head(&info->status_wait);
init_waitqueue_head(&sc->recv_io.reassembly.wait_queue);
rc = rdma_connect(sc->rdma.cm_id, &conn_param);
if (rc) {
@@ -1660,7 +1659,7 @@ static struct smbd_connection *_smbd_get_connection(
}
wait_event_interruptible_timeout(
- info->conn_wait,
+ info->status_wait,
sc->status != SMBDIRECT_SOCKET_CONNECTING,
msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
@@ -1717,7 +1716,7 @@ static struct smbd_connection *_smbd_get_connection(
destroy_caches_and_workqueue(info);
sc->status = SMBDIRECT_SOCKET_NEGOTIATE_FAILED;
rdma_disconnect(sc->rdma.cm_id);
- wait_event(info->conn_wait,
+ wait_event(info->status_wait,
sc->status == SMBDIRECT_SOCKET_DISCONNECTED);
allocate_cache_failed:
diff --git a/fs/smb/client/smbdirect.h b/fs/smb/client/smbdirect.h
index 0d4d45428c85..e45aa9ddd71d 100644
--- a/fs/smb/client/smbdirect.h
+++ b/fs/smb/client/smbdirect.h
@@ -47,8 +47,7 @@ struct smbd_connection {
int ri_rc;
struct completion ri_done;
- wait_queue_head_t conn_wait;
- wait_queue_head_t disconn_wait;
+ wait_queue_head_t status_wait;
struct completion negotiate_completion;
bool negotiate_done;
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 5/9] smb: client/smbdirect: replace SMBDIRECT_SOCKET_CONNECTING with more detailed states
2025-08-08 16:48 [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait Stefan Metzmacher
` (3 preceding siblings ...)
2025-08-08 16:48 ` [PATCH v3 4/9] smb: client: only use a single wait_queue to monitor smbdirect connection status Stefan Metzmacher
@ 2025-08-08 16:48 ` Stefan Metzmacher
2025-08-09 15:59 ` Steve French
2025-08-08 16:48 ` [PATCH v3 6/9] smb: client: use status_wait and SMBDIRECT_SOCKET_NEGOTIATE_RUNNING for completion Stefan Metzmacher
` (3 subsequent siblings)
8 siblings, 1 reply; 11+ messages in thread
From: Stefan Metzmacher @ 2025-08-08 16:48 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Steve French
The process of reaching a functional connection regresented by
SMBDIRECT_SOCKET_CONNECTED, is more complex than using a single
SMBDIRECT_SOCKET_CONNECTING state.
This will allow us to remove a lot of special variables and
completions in the following commits.
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: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/smb/client/smbdirect.c | 73 ++++++++++++++++++++--
fs/smb/common/smbdirect/smbdirect_socket.h | 14 ++++-
2 files changed, 79 insertions(+), 8 deletions(-)
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index c628e91c328b..1337d35a22f9 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -161,9 +161,36 @@ static void smbd_disconnect_rdma_work(struct work_struct *work)
container_of(work, struct smbd_connection, disconnect_work);
struct smbdirect_socket *sc = &info->socket;
- if (sc->status == SMBDIRECT_SOCKET_CONNECTED) {
+ switch (sc->status) {
+ case SMBDIRECT_SOCKET_NEGOTIATE_NEEDED:
+ case SMBDIRECT_SOCKET_NEGOTIATE_RUNNING:
+ case SMBDIRECT_SOCKET_NEGOTIATE_FAILED:
+ case SMBDIRECT_SOCKET_CONNECTED:
sc->status = SMBDIRECT_SOCKET_DISCONNECTING;
rdma_disconnect(sc->rdma.cm_id);
+ break;
+
+ case SMBDIRECT_SOCKET_CREATED:
+ case SMBDIRECT_SOCKET_RESOLVE_ADDR_NEEDED:
+ case SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING:
+ case SMBDIRECT_SOCKET_RESOLVE_ADDR_FAILED:
+ case SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED:
+ case SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING:
+ case SMBDIRECT_SOCKET_RESOLVE_ROUTE_FAILED:
+ case SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED:
+ case SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING:
+ case SMBDIRECT_SOCKET_RDMA_CONNECT_FAILED:
+ /*
+ * rdma_connect() never reached
+ * RDMA_CM_EVENT_ESTABLISHED
+ */
+ sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
+ break;
+
+ case SMBDIRECT_SOCKET_DISCONNECTING:
+ case SMBDIRECT_SOCKET_DISCONNECTED:
+ case SMBDIRECT_SOCKET_DESTROYED:
+ break;
}
}
@@ -185,26 +212,39 @@ static int smbd_conn_upcall(
switch (event->event) {
case RDMA_CM_EVENT_ADDR_RESOLVED:
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING);
+ sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED;
+ info->ri_rc = 0;
+ complete(&info->ri_done);
+ break;
+
case RDMA_CM_EVENT_ROUTE_RESOLVED:
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING);
+ sc->status = SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED;
info->ri_rc = 0;
complete(&info->ri_done);
break;
case RDMA_CM_EVENT_ADDR_ERROR:
log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING);
+ sc->status = SMBDIRECT_SOCKET_RESOLVE_ADDR_FAILED;
info->ri_rc = -EHOSTUNREACH;
complete(&info->ri_done);
break;
case RDMA_CM_EVENT_ROUTE_ERROR:
log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING);
+ sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_FAILED;
info->ri_rc = -ENETUNREACH;
complete(&info->ri_done);
break;
case RDMA_CM_EVENT_ESTABLISHED:
log_rdma_event(INFO, "connected event=%s\n", event_name);
- sc->status = SMBDIRECT_SOCKET_CONNECTED;
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING);
+ sc->status = SMBDIRECT_SOCKET_NEGOTIATE_NEEDED;
wake_up_interruptible(&info->status_wait);
break;
@@ -212,7 +252,8 @@ static int smbd_conn_upcall(
case RDMA_CM_EVENT_UNREACHABLE:
case RDMA_CM_EVENT_REJECTED:
log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
- sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING);
+ sc->status = SMBDIRECT_SOCKET_RDMA_CONNECT_FAILED;
wake_up_interruptible(&info->status_wait);
break;
@@ -481,6 +522,12 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
info->negotiate_done =
process_negotiation_response(response, wc->byte_len);
put_receive_buffer(info, response);
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_NEGOTIATE_RUNNING);
+ if (!info->negotiate_done)
+ sc->status = SMBDIRECT_SOCKET_NEGOTIATE_FAILED;
+ else
+ sc->status = SMBDIRECT_SOCKET_CONNECTED;
+
complete(&info->negotiate_completion);
return;
@@ -556,6 +603,7 @@ static struct rdma_cm_id *smbd_create_id(
struct smbd_connection *info,
struct sockaddr *dstaddr, int port)
{
+ struct smbdirect_socket *sc = &info->socket;
struct rdma_cm_id *id;
int rc;
__be16 *sport;
@@ -578,6 +626,8 @@ static struct rdma_cm_id *smbd_create_id(
init_completion(&info->ri_done);
info->ri_rc = -ETIMEDOUT;
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_NEEDED);
+ sc->status = SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING;
rc = rdma_resolve_addr(id, NULL, (struct sockaddr *)dstaddr,
RDMA_RESOLVE_TIMEOUT);
if (rc) {
@@ -598,6 +648,8 @@ static struct rdma_cm_id *smbd_create_id(
}
info->ri_rc = -ETIMEDOUT;
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED);
+ sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING;
rc = rdma_resolve_route(id, RDMA_RESOLVE_TIMEOUT);
if (rc) {
log_rdma_event(ERR, "rdma_resolve_route() failed %i\n", rc);
@@ -644,6 +696,9 @@ static int smbd_ia_open(
struct smbdirect_socket *sc = &info->socket;
int rc;
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_CREATED);
+ sc->status = SMBDIRECT_SOCKET_RESOLVE_ADDR_NEEDED;
+
sc->rdma.cm_id = smbd_create_id(info, dstaddr, port);
if (IS_ERR(sc->rdma.cm_id)) {
rc = PTR_ERR(sc->rdma.cm_id);
@@ -1085,6 +1140,9 @@ static int smbd_negotiate(struct smbd_connection *info)
int rc;
struct smbdirect_recv_io *response = get_receive_buffer(info);
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_NEGOTIATE_NEEDED);
+ sc->status = SMBDIRECT_SOCKET_NEGOTIATE_RUNNING;
+
sc->recv_io.expected = SMBDIRECT_EXPECT_NEGOTIATE_REP;
rc = smbd_post_recv(info, response);
log_rdma_event(INFO, "smbd_post_recv rc=%d iov.addr=0x%llx iov.length=%u iov.lkey=0x%x\n",
@@ -1540,7 +1598,7 @@ static struct smbd_connection *_smbd_get_connection(
sc = &info->socket;
sp = &sc->parameters;
- sc->status = SMBDIRECT_SOCKET_CONNECTING;
+ sc->status = SMBDIRECT_SOCKET_CREATED;
rc = smbd_ia_open(info, dstaddr, port);
if (rc) {
log_rdma_event(INFO, "smbd_ia_open rc=%d\n", rc);
@@ -1652,6 +1710,9 @@ static struct smbd_connection *_smbd_get_connection(
init_waitqueue_head(&info->status_wait);
init_waitqueue_head(&sc->recv_io.reassembly.wait_queue);
+
+ WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED);
+ sc->status = SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING;
rc = rdma_connect(sc->rdma.cm_id, &conn_param);
if (rc) {
log_rdma_event(ERR, "rdma_connect() failed with %i\n", rc);
@@ -1660,10 +1721,10 @@ static struct smbd_connection *_smbd_get_connection(
wait_event_interruptible_timeout(
info->status_wait,
- sc->status != SMBDIRECT_SOCKET_CONNECTING,
+ sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING,
msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
- if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
+ if (sc->status != SMBDIRECT_SOCKET_NEGOTIATE_NEEDED) {
log_rdma_event(ERR, "rdma_connect failed port=%d\n", port);
goto rdma_connect_failed;
}
diff --git a/fs/smb/common/smbdirect/smbdirect_socket.h b/fs/smb/common/smbdirect/smbdirect_socket.h
index 3c4a8d627aa3..f43eabdd413d 100644
--- a/fs/smb/common/smbdirect/smbdirect_socket.h
+++ b/fs/smb/common/smbdirect/smbdirect_socket.h
@@ -8,9 +8,19 @@
enum smbdirect_socket_status {
SMBDIRECT_SOCKET_CREATED,
- SMBDIRECT_SOCKET_CONNECTING,
- SMBDIRECT_SOCKET_CONNECTED,
+ SMBDIRECT_SOCKET_RESOLVE_ADDR_NEEDED,
+ SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING,
+ SMBDIRECT_SOCKET_RESOLVE_ADDR_FAILED,
+ SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED,
+ SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING,
+ SMBDIRECT_SOCKET_RESOLVE_ROUTE_FAILED,
+ SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED,
+ SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING,
+ SMBDIRECT_SOCKET_RDMA_CONNECT_FAILED,
+ SMBDIRECT_SOCKET_NEGOTIATE_NEEDED,
+ SMBDIRECT_SOCKET_NEGOTIATE_RUNNING,
SMBDIRECT_SOCKET_NEGOTIATE_FAILED,
+ SMBDIRECT_SOCKET_CONNECTED,
SMBDIRECT_SOCKET_DISCONNECTING,
SMBDIRECT_SOCKET_DISCONNECTED,
SMBDIRECT_SOCKET_DESTROYED
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 6/9] smb: client: use status_wait and SMBDIRECT_SOCKET_NEGOTIATE_RUNNING for completion
2025-08-08 16:48 [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait Stefan Metzmacher
` (4 preceding siblings ...)
2025-08-08 16:48 ` [PATCH v3 5/9] smb: client/smbdirect: replace SMBDIRECT_SOCKET_CONNECTING with more detailed states Stefan Metzmacher
@ 2025-08-08 16:48 ` Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 7/9] smb: client: use status_wait and SMBDIRECT_SOCKET_RESOLVE_{ADDR,ROUTE}_RUNNING " Stefan Metzmacher
` (2 subsequent siblings)
8 siblings, 0 replies; 11+ messages in thread
From: Stefan Metzmacher @ 2025-08-08 16:48 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, Steve French, Tom Talpey, Long Li, Steve French
We can use the state change from SMBDIRECT_SOCKET_NEGOTIATE_RUNNING to
SMBDIRECT_SOCKET_CONNECTED or SMBDIRECT_SOCKET_NEGOTIATE_FAILED in order
to notify the caller if the negotiation is over.
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/smb/client/smbdirect.c | 19 ++++++++++---------
fs/smb/client/smbdirect.h | 3 ---
2 files changed, 10 insertions(+), 12 deletions(-)
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index 1337d35a22f9..b3fc87886972 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -497,6 +497,7 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
struct smbd_connection *info =
container_of(sc, struct smbd_connection, socket);
int data_length = 0;
+ bool negotiate_done = false;
log_rdma_recv(INFO, "response=0x%p type=%d wc status=%d wc opcode %d byte_len=%d pkey_index=%u\n",
response, sc->recv_io.expected, wc->status, wc->opcode,
@@ -519,16 +520,16 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
case SMBDIRECT_EXPECT_NEGOTIATE_REP:
dump_smbdirect_negotiate_resp(smbdirect_recv_io_payload(response));
sc->recv_io.reassembly.full_packet_received = true;
- info->negotiate_done =
+ negotiate_done =
process_negotiation_response(response, wc->byte_len);
put_receive_buffer(info, response);
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_NEGOTIATE_RUNNING);
- if (!info->negotiate_done)
+ if (!negotiate_done)
sc->status = SMBDIRECT_SOCKET_NEGOTIATE_FAILED;
else
sc->status = SMBDIRECT_SOCKET_CONNECTED;
- complete(&info->negotiate_completion);
+ wake_up_interruptible(&info->status_wait);
return;
/* SMBD data transfer packet */
@@ -1151,17 +1152,17 @@ static int smbd_negotiate(struct smbd_connection *info)
if (rc)
return rc;
- init_completion(&info->negotiate_completion);
- info->negotiate_done = false;
rc = smbd_post_send_negotiate_req(info);
if (rc)
return rc;
- rc = wait_for_completion_interruptible_timeout(
- &info->negotiate_completion, SMBD_NEGOTIATE_TIMEOUT * HZ);
- log_rdma_event(INFO, "wait_for_completion_timeout rc=%d\n", rc);
+ rc = wait_event_interruptible_timeout(
+ info->status_wait,
+ sc->status != SMBDIRECT_SOCKET_NEGOTIATE_RUNNING,
+ secs_to_jiffies(SMBD_NEGOTIATE_TIMEOUT));
+ log_rdma_event(INFO, "wait_event_interruptible_timeout rc=%d\n", rc);
- if (info->negotiate_done)
+ if (sc->status == SMBDIRECT_SOCKET_CONNECTED)
return 0;
if (rc == 0)
diff --git a/fs/smb/client/smbdirect.h b/fs/smb/client/smbdirect.h
index e45aa9ddd71d..82505df4a751 100644
--- a/fs/smb/client/smbdirect.h
+++ b/fs/smb/client/smbdirect.h
@@ -49,9 +49,6 @@ struct smbd_connection {
struct completion ri_done;
wait_queue_head_t status_wait;
- struct completion negotiate_completion;
- bool negotiate_done;
-
struct work_struct disconnect_work;
struct work_struct post_send_credits_work;
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 7/9] smb: client: use status_wait and SMBDIRECT_SOCKET_RESOLVE_{ADDR,ROUTE}_RUNNING for completion
2025-08-08 16:48 [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait Stefan Metzmacher
` (5 preceding siblings ...)
2025-08-08 16:48 ` [PATCH v3 6/9] smb: client: use status_wait and SMBDIRECT_SOCKET_NEGOTIATE_RUNNING for completion Stefan Metzmacher
@ 2025-08-08 16:48 ` Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 8/9] smb: smbdirect: introduce smbdirect_socket.status_wait Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 9/9] smb: client: make use of smbdirect_socket.status_wait Stefan Metzmacher
8 siblings, 0 replies; 11+ messages in thread
From: Stefan Metzmacher @ 2025-08-08 16:48 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, Steve French, Tom Talpey, Long Li, Steve French
We can use the state change from
SMBDIRECT_SOCKET_RESOLVE_{ADDR,ROUTE}_RUNNING
to the next state in order to wake the caller to do the next step.
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/smb/client/smbdirect.c | 49 ++++++++++++++++++++++-----------------
fs/smb/client/smbdirect.h | 2 --
2 files changed, 28 insertions(+), 23 deletions(-)
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index b3fc87886972..ca6aa298d577 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -214,31 +214,27 @@ static int smbd_conn_upcall(
case RDMA_CM_EVENT_ADDR_RESOLVED:
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING);
sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED;
- info->ri_rc = 0;
- complete(&info->ri_done);
+ wake_up_interruptible(&info->status_wait);
break;
case RDMA_CM_EVENT_ROUTE_RESOLVED:
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING);
sc->status = SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED;
- info->ri_rc = 0;
- complete(&info->ri_done);
+ wake_up_interruptible(&info->status_wait);
break;
case RDMA_CM_EVENT_ADDR_ERROR:
log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING);
sc->status = SMBDIRECT_SOCKET_RESOLVE_ADDR_FAILED;
- info->ri_rc = -EHOSTUNREACH;
- complete(&info->ri_done);
+ wake_up_interruptible(&info->status_wait);
break;
case RDMA_CM_EVENT_ROUTE_ERROR:
log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING);
sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_FAILED;
- info->ri_rc = -ENETUNREACH;
- complete(&info->ri_done);
+ wake_up_interruptible(&info->status_wait);
break;
case RDMA_CM_EVENT_ESTABLISHED:
@@ -624,9 +620,6 @@ static struct rdma_cm_id *smbd_create_id(
*sport = htons(port);
- init_completion(&info->ri_done);
- info->ri_rc = -ETIMEDOUT;
-
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_NEEDED);
sc->status = SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING;
rc = rdma_resolve_addr(id, NULL, (struct sockaddr *)dstaddr,
@@ -635,20 +628,26 @@ static struct rdma_cm_id *smbd_create_id(
log_rdma_event(ERR, "rdma_resolve_addr() failed %i\n", rc);
goto out;
}
- rc = wait_for_completion_interruptible_timeout(
- &info->ri_done, msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
+ rc = wait_event_interruptible_timeout(
+ info->status_wait,
+ sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING,
+ msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
/* e.g. if interrupted returns -ERESTARTSYS */
if (rc < 0) {
log_rdma_event(ERR, "rdma_resolve_addr timeout rc: %i\n", rc);
goto out;
}
- rc = info->ri_rc;
- if (rc) {
+ if (sc->status == SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING) {
+ rc = -ETIMEDOUT;
+ log_rdma_event(ERR, "rdma_resolve_addr() completed %i\n", rc);
+ goto out;
+ }
+ if (sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED) {
+ rc = -EHOSTUNREACH;
log_rdma_event(ERR, "rdma_resolve_addr() completed %i\n", rc);
goto out;
}
- info->ri_rc = -ETIMEDOUT;
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED);
sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING;
rc = rdma_resolve_route(id, RDMA_RESOLVE_TIMEOUT);
@@ -656,15 +655,22 @@ static struct rdma_cm_id *smbd_create_id(
log_rdma_event(ERR, "rdma_resolve_route() failed %i\n", rc);
goto out;
}
- rc = wait_for_completion_interruptible_timeout(
- &info->ri_done, msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
+ rc = wait_event_interruptible_timeout(
+ info->status_wait,
+ sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING,
+ msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
/* e.g. if interrupted returns -ERESTARTSYS */
if (rc < 0) {
log_rdma_event(ERR, "rdma_resolve_addr timeout rc: %i\n", rc);
goto out;
}
- rc = info->ri_rc;
- if (rc) {
+ if (sc->status == SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING) {
+ rc = -ETIMEDOUT;
+ log_rdma_event(ERR, "rdma_resolve_route() completed %i\n", rc);
+ goto out;
+ }
+ if (sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED) {
+ rc = -ENETUNREACH;
log_rdma_event(ERR, "rdma_resolve_route() completed %i\n", rc);
goto out;
}
@@ -1599,6 +1605,8 @@ static struct smbd_connection *_smbd_get_connection(
sc = &info->socket;
sp = &sc->parameters;
+ init_waitqueue_head(&info->status_wait);
+
sc->status = SMBDIRECT_SOCKET_CREATED;
rc = smbd_ia_open(info, dstaddr, port);
if (rc) {
@@ -1709,7 +1717,6 @@ static struct smbd_connection *_smbd_get_connection(
log_rdma_event(INFO, "connecting to IP %pI4 port %d\n",
&addr_in->sin_addr, port);
- init_waitqueue_head(&info->status_wait);
init_waitqueue_head(&sc->recv_io.reassembly.wait_queue);
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED);
diff --git a/fs/smb/client/smbdirect.h b/fs/smb/client/smbdirect.h
index 82505df4a751..62458a8fd109 100644
--- a/fs/smb/client/smbdirect.h
+++ b/fs/smb/client/smbdirect.h
@@ -45,8 +45,6 @@ enum keep_alive_status {
struct smbd_connection {
struct smbdirect_socket socket;
- int ri_rc;
- struct completion ri_done;
wait_queue_head_t status_wait;
struct work_struct disconnect_work;
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 8/9] smb: smbdirect: introduce smbdirect_socket.status_wait
2025-08-08 16:48 [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait Stefan Metzmacher
` (6 preceding siblings ...)
2025-08-08 16:48 ` [PATCH v3 7/9] smb: client: use status_wait and SMBDIRECT_SOCKET_RESOLVE_{ADDR,ROUTE}_RUNNING " Stefan Metzmacher
@ 2025-08-08 16:48 ` Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 9/9] smb: client: make use of smbdirect_socket.status_wait Stefan Metzmacher
8 siblings, 0 replies; 11+ messages in thread
From: Stefan Metzmacher @ 2025-08-08 16:48 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, Steve French, Tom Talpey, Long Li, Namjae Jeon,
Steve French
This will be used by server and client soon.
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: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/smb/common/smbdirect/smbdirect_socket.h | 1 +
1 file changed, 1 insertion(+)
diff --git a/fs/smb/common/smbdirect/smbdirect_socket.h b/fs/smb/common/smbdirect/smbdirect_socket.h
index f43eabdd413d..aac4b040606b 100644
--- a/fs/smb/common/smbdirect/smbdirect_socket.h
+++ b/fs/smb/common/smbdirect/smbdirect_socket.h
@@ -28,6 +28,7 @@ enum smbdirect_socket_status {
struct smbdirect_socket {
enum smbdirect_socket_status status;
+ wait_queue_head_t status_wait;
/* RDMA related */
struct {
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v3 9/9] smb: client: make use of smbdirect_socket.status_wait
2025-08-08 16:48 [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait Stefan Metzmacher
` (7 preceding siblings ...)
2025-08-08 16:48 ` [PATCH v3 8/9] smb: smbdirect: introduce smbdirect_socket.status_wait Stefan Metzmacher
@ 2025-08-08 16:48 ` Stefan Metzmacher
8 siblings, 0 replies; 11+ messages in thread
From: Stefan Metzmacher @ 2025-08-08 16:48 UTC (permalink / raw)
To: linux-cifs, samba-technical
Cc: metze, Steve French, Tom Talpey, Long Li, Steve French
This will allow us to have common helper functions soon.
Cc: Steve French <smfrench@gmail.com>
Cc: Tom Talpey <tom@talpey.com>
Cc: Long Li <longli@microsoft.com>
Cc: linux-cifs@vger.kernel.org
Cc: samba-technical@lists.samba.org
Signed-off-by: Stefan Metzmacher <metze@samba.org>
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/smb/client/smbdirect.c | 32 ++++++++++++++++----------------
fs/smb/client/smbdirect.h | 2 --
2 files changed, 16 insertions(+), 18 deletions(-)
diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
index ca6aa298d577..fe7e138704fc 100644
--- a/fs/smb/client/smbdirect.c
+++ b/fs/smb/client/smbdirect.c
@@ -214,34 +214,34 @@ static int smbd_conn_upcall(
case RDMA_CM_EVENT_ADDR_RESOLVED:
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING);
sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED;
- wake_up_interruptible(&info->status_wait);
+ wake_up_interruptible(&sc->status_wait);
break;
case RDMA_CM_EVENT_ROUTE_RESOLVED:
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING);
sc->status = SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED;
- wake_up_interruptible(&info->status_wait);
+ wake_up_interruptible(&sc->status_wait);
break;
case RDMA_CM_EVENT_ADDR_ERROR:
log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING);
sc->status = SMBDIRECT_SOCKET_RESOLVE_ADDR_FAILED;
- wake_up_interruptible(&info->status_wait);
+ wake_up_interruptible(&sc->status_wait);
break;
case RDMA_CM_EVENT_ROUTE_ERROR:
log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING);
sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_FAILED;
- wake_up_interruptible(&info->status_wait);
+ wake_up_interruptible(&sc->status_wait);
break;
case RDMA_CM_EVENT_ESTABLISHED:
log_rdma_event(INFO, "connected event=%s\n", event_name);
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING);
sc->status = SMBDIRECT_SOCKET_NEGOTIATE_NEEDED;
- wake_up_interruptible(&info->status_wait);
+ wake_up_interruptible(&sc->status_wait);
break;
case RDMA_CM_EVENT_CONNECT_ERROR:
@@ -250,7 +250,7 @@ static int smbd_conn_upcall(
log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING);
sc->status = SMBDIRECT_SOCKET_RDMA_CONNECT_FAILED;
- wake_up_interruptible(&info->status_wait);
+ wake_up_interruptible(&sc->status_wait);
break;
case RDMA_CM_EVENT_DEVICE_REMOVAL:
@@ -259,12 +259,12 @@ static int smbd_conn_upcall(
if (sc->status == SMBDIRECT_SOCKET_NEGOTIATE_FAILED) {
log_rdma_event(ERR, "event=%s during negotiation\n", event_name);
sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
- wake_up(&info->status_wait);
+ wake_up(&sc->status_wait);
break;
}
sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
- wake_up_interruptible(&info->status_wait);
+ wake_up_interruptible(&sc->status_wait);
wake_up_interruptible(&sc->recv_io.reassembly.wait_queue);
wake_up_interruptible_all(&info->wait_send_queue);
break;
@@ -525,7 +525,7 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
else
sc->status = SMBDIRECT_SOCKET_CONNECTED;
- wake_up_interruptible(&info->status_wait);
+ wake_up_interruptible(&sc->status_wait);
return;
/* SMBD data transfer packet */
@@ -629,7 +629,7 @@ static struct rdma_cm_id *smbd_create_id(
goto out;
}
rc = wait_event_interruptible_timeout(
- info->status_wait,
+ sc->status_wait,
sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING,
msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
/* e.g. if interrupted returns -ERESTARTSYS */
@@ -656,7 +656,7 @@ static struct rdma_cm_id *smbd_create_id(
goto out;
}
rc = wait_event_interruptible_timeout(
- info->status_wait,
+ sc->status_wait,
sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING,
msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
/* e.g. if interrupted returns -ERESTARTSYS */
@@ -1163,7 +1163,7 @@ static int smbd_negotiate(struct smbd_connection *info)
return rc;
rc = wait_event_interruptible_timeout(
- info->status_wait,
+ sc->status_wait,
sc->status != SMBDIRECT_SOCKET_NEGOTIATE_RUNNING,
secs_to_jiffies(SMBD_NEGOTIATE_TIMEOUT));
log_rdma_event(INFO, "wait_event_interruptible_timeout rc=%d\n", rc);
@@ -1390,7 +1390,7 @@ void smbd_destroy(struct TCP_Server_Info *server)
rdma_disconnect(sc->rdma.cm_id);
log_rdma_event(INFO, "wait for transport being disconnected\n");
wait_event_interruptible(
- info->status_wait,
+ sc->status_wait,
sc->status == SMBDIRECT_SOCKET_DISCONNECTED);
}
@@ -1605,7 +1605,7 @@ static struct smbd_connection *_smbd_get_connection(
sc = &info->socket;
sp = &sc->parameters;
- init_waitqueue_head(&info->status_wait);
+ init_waitqueue_head(&sc->status_wait);
sc->status = SMBDIRECT_SOCKET_CREATED;
rc = smbd_ia_open(info, dstaddr, port);
@@ -1728,7 +1728,7 @@ static struct smbd_connection *_smbd_get_connection(
}
wait_event_interruptible_timeout(
- info->status_wait,
+ sc->status_wait,
sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING,
msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
@@ -1785,7 +1785,7 @@ static struct smbd_connection *_smbd_get_connection(
destroy_caches_and_workqueue(info);
sc->status = SMBDIRECT_SOCKET_NEGOTIATE_FAILED;
rdma_disconnect(sc->rdma.cm_id);
- wait_event(info->status_wait,
+ wait_event(sc->status_wait,
sc->status == SMBDIRECT_SOCKET_DISCONNECTED);
allocate_cache_failed:
diff --git a/fs/smb/client/smbdirect.h b/fs/smb/client/smbdirect.h
index 62458a8fd109..79ab43b7ac19 100644
--- a/fs/smb/client/smbdirect.h
+++ b/fs/smb/client/smbdirect.h
@@ -45,8 +45,6 @@ enum keep_alive_status {
struct smbd_connection {
struct smbdirect_socket socket;
- wait_queue_head_t status_wait;
-
struct work_struct disconnect_work;
struct work_struct post_send_credits_work;
--
2.43.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH v3 5/9] smb: client/smbdirect: replace SMBDIRECT_SOCKET_CONNECTING with more detailed states
2025-08-08 16:48 ` [PATCH v3 5/9] smb: client/smbdirect: replace SMBDIRECT_SOCKET_CONNECTING with more detailed states Stefan Metzmacher
@ 2025-08-09 15:59 ` Steve French
0 siblings, 0 replies; 11+ messages in thread
From: Steve French @ 2025-08-09 15:59 UTC (permalink / raw)
To: Stefan Metzmacher
Cc: linux-cifs, samba-technical, Tom Talpey, Long Li, Namjae Jeon,
Steve French
merged patches 5 to 9 into cifs-2.6.git for-next (the others are
already upstream) pending more review and testing.
Let me know if updated versions of those 5 patches, or other
RDMA/smbdirect ones that belong in for-next
On Fri, Aug 8, 2025 at 11:49 AM Stefan Metzmacher <metze@samba.org> wrote:
>
> The process of reaching a functional connection regresented by
> SMBDIRECT_SOCKET_CONNECTED, is more complex than using a single
> SMBDIRECT_SOCKET_CONNECTING state.
>
> This will allow us to remove a lot of special variables and
> completions in the following commits.
>
> 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: linux-cifs@vger.kernel.org
> Cc: samba-technical@lists.samba.org
> Signed-off-by: Stefan Metzmacher <metze@samba.org>
> Signed-off-by: Steve French <stfrench@microsoft.com>
> ---
> fs/smb/client/smbdirect.c | 73 ++++++++++++++++++++--
> fs/smb/common/smbdirect/smbdirect_socket.h | 14 ++++-
> 2 files changed, 79 insertions(+), 8 deletions(-)
>
> diff --git a/fs/smb/client/smbdirect.c b/fs/smb/client/smbdirect.c
> index c628e91c328b..1337d35a22f9 100644
> --- a/fs/smb/client/smbdirect.c
> +++ b/fs/smb/client/smbdirect.c
> @@ -161,9 +161,36 @@ static void smbd_disconnect_rdma_work(struct work_struct *work)
> container_of(work, struct smbd_connection, disconnect_work);
> struct smbdirect_socket *sc = &info->socket;
>
> - if (sc->status == SMBDIRECT_SOCKET_CONNECTED) {
> + switch (sc->status) {
> + case SMBDIRECT_SOCKET_NEGOTIATE_NEEDED:
> + case SMBDIRECT_SOCKET_NEGOTIATE_RUNNING:
> + case SMBDIRECT_SOCKET_NEGOTIATE_FAILED:
> + case SMBDIRECT_SOCKET_CONNECTED:
> sc->status = SMBDIRECT_SOCKET_DISCONNECTING;
> rdma_disconnect(sc->rdma.cm_id);
> + break;
> +
> + case SMBDIRECT_SOCKET_CREATED:
> + case SMBDIRECT_SOCKET_RESOLVE_ADDR_NEEDED:
> + case SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING:
> + case SMBDIRECT_SOCKET_RESOLVE_ADDR_FAILED:
> + case SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED:
> + case SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING:
> + case SMBDIRECT_SOCKET_RESOLVE_ROUTE_FAILED:
> + case SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED:
> + case SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING:
> + case SMBDIRECT_SOCKET_RDMA_CONNECT_FAILED:
> + /*
> + * rdma_connect() never reached
> + * RDMA_CM_EVENT_ESTABLISHED
> + */
> + sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
> + break;
> +
> + case SMBDIRECT_SOCKET_DISCONNECTING:
> + case SMBDIRECT_SOCKET_DISCONNECTED:
> + case SMBDIRECT_SOCKET_DESTROYED:
> + break;
> }
> }
>
> @@ -185,26 +212,39 @@ static int smbd_conn_upcall(
>
> switch (event->event) {
> case RDMA_CM_EVENT_ADDR_RESOLVED:
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING);
> + sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED;
> + info->ri_rc = 0;
> + complete(&info->ri_done);
> + break;
> +
> case RDMA_CM_EVENT_ROUTE_RESOLVED:
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING);
> + sc->status = SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED;
> info->ri_rc = 0;
> complete(&info->ri_done);
> break;
>
> case RDMA_CM_EVENT_ADDR_ERROR:
> log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING);
> + sc->status = SMBDIRECT_SOCKET_RESOLVE_ADDR_FAILED;
> info->ri_rc = -EHOSTUNREACH;
> complete(&info->ri_done);
> break;
>
> case RDMA_CM_EVENT_ROUTE_ERROR:
> log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING);
> + sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_FAILED;
> info->ri_rc = -ENETUNREACH;
> complete(&info->ri_done);
> break;
>
> case RDMA_CM_EVENT_ESTABLISHED:
> log_rdma_event(INFO, "connected event=%s\n", event_name);
> - sc->status = SMBDIRECT_SOCKET_CONNECTED;
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING);
> + sc->status = SMBDIRECT_SOCKET_NEGOTIATE_NEEDED;
> wake_up_interruptible(&info->status_wait);
> break;
>
> @@ -212,7 +252,8 @@ static int smbd_conn_upcall(
> case RDMA_CM_EVENT_UNREACHABLE:
> case RDMA_CM_EVENT_REJECTED:
> log_rdma_event(ERR, "connecting failed event=%s\n", event_name);
> - sc->status = SMBDIRECT_SOCKET_DISCONNECTED;
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING);
> + sc->status = SMBDIRECT_SOCKET_RDMA_CONNECT_FAILED;
> wake_up_interruptible(&info->status_wait);
> break;
>
> @@ -481,6 +522,12 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
> info->negotiate_done =
> process_negotiation_response(response, wc->byte_len);
> put_receive_buffer(info, response);
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_NEGOTIATE_RUNNING);
> + if (!info->negotiate_done)
> + sc->status = SMBDIRECT_SOCKET_NEGOTIATE_FAILED;
> + else
> + sc->status = SMBDIRECT_SOCKET_CONNECTED;
> +
> complete(&info->negotiate_completion);
> return;
>
> @@ -556,6 +603,7 @@ static struct rdma_cm_id *smbd_create_id(
> struct smbd_connection *info,
> struct sockaddr *dstaddr, int port)
> {
> + struct smbdirect_socket *sc = &info->socket;
> struct rdma_cm_id *id;
> int rc;
> __be16 *sport;
> @@ -578,6 +626,8 @@ static struct rdma_cm_id *smbd_create_id(
> init_completion(&info->ri_done);
> info->ri_rc = -ETIMEDOUT;
>
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ADDR_NEEDED);
> + sc->status = SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING;
> rc = rdma_resolve_addr(id, NULL, (struct sockaddr *)dstaddr,
> RDMA_RESOLVE_TIMEOUT);
> if (rc) {
> @@ -598,6 +648,8 @@ static struct rdma_cm_id *smbd_create_id(
> }
>
> info->ri_rc = -ETIMEDOUT;
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED);
> + sc->status = SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING;
> rc = rdma_resolve_route(id, RDMA_RESOLVE_TIMEOUT);
> if (rc) {
> log_rdma_event(ERR, "rdma_resolve_route() failed %i\n", rc);
> @@ -644,6 +696,9 @@ static int smbd_ia_open(
> struct smbdirect_socket *sc = &info->socket;
> int rc;
>
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_CREATED);
> + sc->status = SMBDIRECT_SOCKET_RESOLVE_ADDR_NEEDED;
> +
> sc->rdma.cm_id = smbd_create_id(info, dstaddr, port);
> if (IS_ERR(sc->rdma.cm_id)) {
> rc = PTR_ERR(sc->rdma.cm_id);
> @@ -1085,6 +1140,9 @@ static int smbd_negotiate(struct smbd_connection *info)
> int rc;
> struct smbdirect_recv_io *response = get_receive_buffer(info);
>
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_NEGOTIATE_NEEDED);
> + sc->status = SMBDIRECT_SOCKET_NEGOTIATE_RUNNING;
> +
> sc->recv_io.expected = SMBDIRECT_EXPECT_NEGOTIATE_REP;
> rc = smbd_post_recv(info, response);
> log_rdma_event(INFO, "smbd_post_recv rc=%d iov.addr=0x%llx iov.length=%u iov.lkey=0x%x\n",
> @@ -1540,7 +1598,7 @@ static struct smbd_connection *_smbd_get_connection(
> sc = &info->socket;
> sp = &sc->parameters;
>
> - sc->status = SMBDIRECT_SOCKET_CONNECTING;
> + sc->status = SMBDIRECT_SOCKET_CREATED;
> rc = smbd_ia_open(info, dstaddr, port);
> if (rc) {
> log_rdma_event(INFO, "smbd_ia_open rc=%d\n", rc);
> @@ -1652,6 +1710,9 @@ static struct smbd_connection *_smbd_get_connection(
>
> init_waitqueue_head(&info->status_wait);
> init_waitqueue_head(&sc->recv_io.reassembly.wait_queue);
> +
> + WARN_ON_ONCE(sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED);
> + sc->status = SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING;
> rc = rdma_connect(sc->rdma.cm_id, &conn_param);
> if (rc) {
> log_rdma_event(ERR, "rdma_connect() failed with %i\n", rc);
> @@ -1660,10 +1721,10 @@ static struct smbd_connection *_smbd_get_connection(
>
> wait_event_interruptible_timeout(
> info->status_wait,
> - sc->status != SMBDIRECT_SOCKET_CONNECTING,
> + sc->status != SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING,
> msecs_to_jiffies(RDMA_RESOLVE_TIMEOUT));
>
> - if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
> + if (sc->status != SMBDIRECT_SOCKET_NEGOTIATE_NEEDED) {
> log_rdma_event(ERR, "rdma_connect failed port=%d\n", port);
> goto rdma_connect_failed;
> }
> diff --git a/fs/smb/common/smbdirect/smbdirect_socket.h b/fs/smb/common/smbdirect/smbdirect_socket.h
> index 3c4a8d627aa3..f43eabdd413d 100644
> --- a/fs/smb/common/smbdirect/smbdirect_socket.h
> +++ b/fs/smb/common/smbdirect/smbdirect_socket.h
> @@ -8,9 +8,19 @@
>
> enum smbdirect_socket_status {
> SMBDIRECT_SOCKET_CREATED,
> - SMBDIRECT_SOCKET_CONNECTING,
> - SMBDIRECT_SOCKET_CONNECTED,
> + SMBDIRECT_SOCKET_RESOLVE_ADDR_NEEDED,
> + SMBDIRECT_SOCKET_RESOLVE_ADDR_RUNNING,
> + SMBDIRECT_SOCKET_RESOLVE_ADDR_FAILED,
> + SMBDIRECT_SOCKET_RESOLVE_ROUTE_NEEDED,
> + SMBDIRECT_SOCKET_RESOLVE_ROUTE_RUNNING,
> + SMBDIRECT_SOCKET_RESOLVE_ROUTE_FAILED,
> + SMBDIRECT_SOCKET_RDMA_CONNECT_NEEDED,
> + SMBDIRECT_SOCKET_RDMA_CONNECT_RUNNING,
> + SMBDIRECT_SOCKET_RDMA_CONNECT_FAILED,
> + SMBDIRECT_SOCKET_NEGOTIATE_NEEDED,
> + SMBDIRECT_SOCKET_NEGOTIATE_RUNNING,
> SMBDIRECT_SOCKET_NEGOTIATE_FAILED,
> + SMBDIRECT_SOCKET_CONNECTED,
> SMBDIRECT_SOCKET_DISCONNECTING,
> SMBDIRECT_SOCKET_DISCONNECTED,
> SMBDIRECT_SOCKET_DESTROYED
> --
> 2.43.0
>
--
Thanks,
Steve
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2025-08-09 15:59 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-08 16:48 [PATCH v3 0/9] smb: client/smbdirect: connect bug fixes/cleanups and smbdirect_socket.status_wait Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 1/9] smb: client: return an error if rdma_connect does not return within 5 seconds Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 2/9] smb: client: improve logging in smbd_conn_upcall() Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 3/9] smb: client: don't call init_waitqueue_head(&info->conn_wait) twice in _smbd_get_connection Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 4/9] smb: client: only use a single wait_queue to monitor smbdirect connection status Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 5/9] smb: client/smbdirect: replace SMBDIRECT_SOCKET_CONNECTING with more detailed states Stefan Metzmacher
2025-08-09 15:59 ` Steve French
2025-08-08 16:48 ` [PATCH v3 6/9] smb: client: use status_wait and SMBDIRECT_SOCKET_NEGOTIATE_RUNNING for completion Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 7/9] smb: client: use status_wait and SMBDIRECT_SOCKET_RESOLVE_{ADDR,ROUTE}_RUNNING " Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 8/9] smb: smbdirect: introduce smbdirect_socket.status_wait Stefan Metzmacher
2025-08-08 16:48 ` [PATCH v3 9/9] smb: client: make use of smbdirect_socket.status_wait Stefan Metzmacher
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).