Skip to content

Commit bb848d2

Browse files
metze-sambasmfrench
authored andcommitted
smb: client: port and use the wait_for_credits logic used by server
This simplifies the logic and prepares the use of smbdirect_send_batch in order to make sure all messages in a multi fragment send are grouped together. We'll add the smbdirect_send_batch processin in a later patch. Cc: <stable@vger.kernel.org> # 6.18.x 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>
1 parent 8bfe3fd commit bb848d2

1 file changed

Lines changed: 43 additions & 27 deletions

File tree

fs/smb/client/smbdirect.c

Lines changed: 43 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1137,6 +1137,44 @@ static int smbd_post_send(struct smbdirect_socket *sc,
11371137
return rc;
11381138
}
11391139

1140+
static int wait_for_credits(struct smbdirect_socket *sc,
1141+
wait_queue_head_t *waitq, atomic_t *total_credits,
1142+
int needed)
1143+
{
1144+
int ret;
1145+
1146+
do {
1147+
if (atomic_sub_return(needed, total_credits) >= 0)
1148+
return 0;
1149+
1150+
atomic_add(needed, total_credits);
1151+
ret = wait_event_interruptible(*waitq,
1152+
atomic_read(total_credits) >= needed ||
1153+
sc->status != SMBDIRECT_SOCKET_CONNECTED);
1154+
1155+
if (sc->status != SMBDIRECT_SOCKET_CONNECTED)
1156+
return -ENOTCONN;
1157+
else if (ret < 0)
1158+
return ret;
1159+
} while (true);
1160+
}
1161+
1162+
static int wait_for_send_lcredit(struct smbdirect_socket *sc)
1163+
{
1164+
return wait_for_credits(sc,
1165+
&sc->send_io.lcredits.wait_queue,
1166+
&sc->send_io.lcredits.count,
1167+
1);
1168+
}
1169+
1170+
static int wait_for_send_credits(struct smbdirect_socket *sc)
1171+
{
1172+
return wait_for_credits(sc,
1173+
&sc->send_io.credits.wait_queue,
1174+
&sc->send_io.credits.count,
1175+
1);
1176+
}
1177+
11401178
static int smbd_post_send_iter(struct smbdirect_socket *sc,
11411179
struct iov_iter *iter,
11421180
int *_remaining_data_length)
@@ -1149,41 +1187,19 @@ static int smbd_post_send_iter(struct smbdirect_socket *sc,
11491187
struct smbdirect_data_transfer *packet;
11501188
int new_credits = 0;
11511189

1152-
wait_lcredit:
1153-
/* Wait for local send credits */
1154-
rc = wait_event_interruptible(sc->send_io.lcredits.wait_queue,
1155-
atomic_read(&sc->send_io.lcredits.count) > 0 ||
1156-
sc->status != SMBDIRECT_SOCKET_CONNECTED);
1157-
if (rc)
1158-
goto err_wait_lcredit;
1159-
1160-
if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
1161-
log_outgoing(ERR, "disconnected not sending on wait_credit\n");
1190+
rc = wait_for_send_lcredit(sc);
1191+
if (rc) {
1192+
log_outgoing(ERR, "disconnected not sending on wait_lcredit\n");
11621193
rc = -EAGAIN;
11631194
goto err_wait_lcredit;
11641195
}
1165-
if (unlikely(atomic_dec_return(&sc->send_io.lcredits.count) < 0)) {
1166-
atomic_inc(&sc->send_io.lcredits.count);
1167-
goto wait_lcredit;
1168-
}
11691196

1170-
wait_credit:
1171-
/* Wait for send credits. A SMBD packet needs one credit */
1172-
rc = wait_event_interruptible(sc->send_io.credits.wait_queue,
1173-
atomic_read(&sc->send_io.credits.count) > 0 ||
1174-
sc->status != SMBDIRECT_SOCKET_CONNECTED);
1175-
if (rc)
1176-
goto err_wait_credit;
1177-
1178-
if (sc->status != SMBDIRECT_SOCKET_CONNECTED) {
1197+
rc = wait_for_send_credits(sc);
1198+
if (rc) {
11791199
log_outgoing(ERR, "disconnected not sending on wait_credit\n");
11801200
rc = -EAGAIN;
11811201
goto err_wait_credit;
11821202
}
1183-
if (unlikely(atomic_dec_return(&sc->send_io.credits.count) < 0)) {
1184-
atomic_inc(&sc->send_io.credits.count);
1185-
goto wait_credit;
1186-
}
11871203

11881204
request = mempool_alloc(sc->send_io.mem.pool, GFP_KERNEL);
11891205
if (!request) {

0 commit comments

Comments
 (0)