[PATCH v4 033/145] smb: smbdirect: introduce smbdirect_socket_wait_for_credits()

Stefan Metzmacher metze at samba.org
Tue Nov 25 17:54:39 UTC 2025


This is a copy of wait_for_credits() in the server, which
will be replaced by this soon.

This will allow us to share more common code between client
and server soon.

Cc: Steve French <smfrench at gmail.com>
Cc: Tom Talpey <tom at talpey.com>
Cc: Long Li <longli at microsoft.com>
Cc: Namjae Jeon <linkinjeon at kernel.org>
Cc: linux-cifs at vger.kernel.org
Cc: samba-technical at lists.samba.org
Signed-off-by: Stefan Metzmacher <metze at samba.org>
Signed-off-by: Steve French <stfrench at microsoft.com>
---
 fs/smb/common/smbdirect/smbdirect_internal.h |  7 +++++
 fs/smb/common/smbdirect/smbdirect_socket.c   | 29 ++++++++++++++++++++
 2 files changed, 36 insertions(+)

diff --git a/fs/smb/common/smbdirect/smbdirect_internal.h b/fs/smb/common/smbdirect/smbdirect_internal.h
index 7465a63118bd..43ef6e39f28e 100644
--- a/fs/smb/common/smbdirect/smbdirect_internal.h
+++ b/fs/smb/common/smbdirect/smbdirect_internal.h
@@ -33,6 +33,13 @@ static void __smbdirect_socket_schedule_cleanup(struct smbdirect_socket *sc,
 		__func__, __LINE__, __error, &__force_status); \
 } while (0)
 
+static int smbdirect_socket_wait_for_credits(struct smbdirect_socket *sc,
+					     enum smbdirect_socket_status expected_status,
+					     int unexpected_errno,
+					     wait_queue_head_t *waitq,
+					     atomic_t *total_credits,
+					     int needed);
+
 static void smbdirect_connection_idle_timer_work(struct work_struct *work);
 
 #endif /* __FS_SMB_COMMON_SMBDIRECT_INTERNAL_H__ */
diff --git a/fs/smb/common/smbdirect/smbdirect_socket.c b/fs/smb/common/smbdirect/smbdirect_socket.c
index c064cbcb6b5c..9093352d1a57 100644
--- a/fs/smb/common/smbdirect/smbdirect_socket.c
+++ b/fs/smb/common/smbdirect/smbdirect_socket.c
@@ -279,3 +279,32 @@ static void smbdirect_socket_cleanup_work(struct work_struct *work)
 	 */
 	smbdirect_socket_wake_up_all(sc);
 }
+
+__maybe_unused /* this is temporary while this file is included in others */
+static int smbdirect_socket_wait_for_credits(struct smbdirect_socket *sc,
+					     enum smbdirect_socket_status expected_status,
+					     int unexpected_errno,
+					     wait_queue_head_t *waitq,
+					     atomic_t *total_credits,
+					     int needed)
+{
+	int ret;
+
+	if (WARN_ON_ONCE(needed < 0))
+		return -EINVAL;
+
+	do {
+		if (atomic_sub_return(needed, total_credits) >= 0)
+			return 0;
+
+		atomic_add(needed, total_credits);
+		ret = wait_event_interruptible(*waitq,
+					       atomic_read(total_credits) >= needed ||
+					       sc->status != expected_status);
+
+		if (sc->status != expected_status)
+			return unexpected_errno;
+		else if (ret < 0)
+			return ret;
+	} while (true);
+}
-- 
2.43.0




More information about the samba-technical mailing list