summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2025-09-19 10:48:58 +0300
committerSteve French <stfrench@microsoft.com>2026-04-16 05:58:19 +0300
commit0ad03ed97da1761a8c42bf4fad559409dfbe0db7 (patch)
tree59d5cf5954b7dfa1ea48ab0aee9ea3b58b9ef301
parentdc01504c90d9613a83d6ecf8323800213495c966 (diff)
downloadlinux-0ad03ed97da1761a8c42bf4fad559409dfbe0db7.tar.xz
smb: smbdirect: introduce smbdirect_socket_wait_for_credits()
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@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> Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Steve French <stfrench@microsoft.com>
-rw-r--r--fs/smb/common/smbdirect/smbdirect_internal.h7
-rw-r--r--fs/smb/common/smbdirect/smbdirect_socket.c29
2 files changed, 36 insertions, 0 deletions
diff --git a/fs/smb/common/smbdirect/smbdirect_internal.h b/fs/smb/common/smbdirect/smbdirect_internal.h
index 2d7c69f71ee0..ff4db1c3f128 100644
--- a/fs/smb/common/smbdirect/smbdirect_internal.h
+++ b/fs/smb/common/smbdirect/smbdirect_internal.h
@@ -32,6 +32,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 05a284526aa2..bbd794fddc1e 100644
--- a/fs/smb/common/smbdirect/smbdirect_socket.c
+++ b/fs/smb/common/smbdirect/smbdirect_socket.c
@@ -250,3 +250,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);
+}