Commit 0ad03ed9 authored by Stefan Metzmacher's avatar Stefan Metzmacher Committed by Steve French
Browse files

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: default avatarStefan Metzmacher <metze@samba.org>
Acked-by: default avatarNamjae Jeon <linkinjeon@kernel.org>
Signed-off-by: default avatarSteve French <stfrench@microsoft.com>
parent dc01504c
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
@@ -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__ */
+29 −0
Original line number Diff line number Diff line
@@ -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);
}