mirror of
https://github.com/torvalds/linux.git
synced 2026-05-30 10:04:04 +02:00
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>
This commit is contained in:
parent
dc01504c90
commit
0ad03ed97d
|
|
@ -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__ */
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user