Skip to content

Commit 5fb9b45

Browse files
metze-sambasmfrench
authored andcommitted
smb: client: count the number of posted recv_io messages in order to calculated credits
(At least for me) the logic maintaining the count of posted recv_io messages and the count of granted credits is much easier to understand. From there we can easily calculate the number of new_credits we'll grant to the peer in outgoing send_io messages. This will simplify the move to common logic that can be shared between client and server in the following patches. Cc: Steve French <smfrench@gmail.com> Cc: Tom Talpey <tom@talpey.com> Cc: Long Li <longli@microsoft.com> Cc: linux-cifs@vger.kernel.org Cc: samba-technical@lists.samba.org Acked-by: Namjae Jeon <linkinjeon@kernel.org> Signed-off-by: Stefan Metzmacher <metze@samba.org> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 9219f8c commit 5fb9b45

File tree

2 files changed

+15
-19
lines changed

2 files changed

+15
-19
lines changed

fs/smb/client/smbdirect.c

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,7 @@ static bool process_negotiation_response(
492492
atomic_set(&sc->send_io.credits.count, le16_to_cpu(packet->credits_granted));
493493

494494
atomic_set(&info->receive_credits, 0);
495+
atomic_set(&info->receive_posted, 0);
495496

496497
if (le32_to_cpu(packet->preferred_send_size) > sp->max_recv_size) {
497498
log_rdma_event(ERR, "error: preferred_send_size=%d\n",
@@ -533,7 +534,6 @@ static bool process_negotiation_response(
533534

534535
static void smbd_post_send_credits(struct work_struct *work)
535536
{
536-
int ret = 0;
537537
int rc;
538538
struct smbdirect_recv_io *response;
539539
struct smbd_connection *info =
@@ -561,14 +561,10 @@ static void smbd_post_send_credits(struct work_struct *work)
561561
break;
562562
}
563563

564-
ret++;
564+
atomic_inc(&info->receive_posted);
565565
}
566566
}
567567

568-
spin_lock(&info->lock_new_credits_offered);
569-
info->new_credits_offered += ret;
570-
spin_unlock(&info->lock_new_credits_offered);
571-
572568
/* Promptly send an immediate packet as defined in [MS-SMBD] 3.1.1.1 */
573569
info->send_immediate = true;
574570
if (atomic_read(&info->receive_credits) <
@@ -665,6 +661,7 @@ static void recv_done(struct ib_cq *cq, struct ib_wc *wc)
665661
sc->recv_io.reassembly.full_packet_received = true;
666662
}
667663

664+
atomic_dec(&info->receive_posted);
668665
atomic_dec(&info->receive_credits);
669666
old_recv_credit_target = info->receive_credit_target;
670667
info->receive_credit_target =
@@ -965,10 +962,16 @@ static int manage_credits_prior_sending(struct smbd_connection *info)
965962
{
966963
int new_credits;
967964

968-
spin_lock(&info->lock_new_credits_offered);
969-
new_credits = info->new_credits_offered;
970-
info->new_credits_offered = 0;
971-
spin_unlock(&info->lock_new_credits_offered);
965+
if (atomic_read(&info->receive_credits) >= info->receive_credit_target)
966+
return 0;
967+
968+
new_credits = atomic_read(&info->receive_posted);
969+
if (new_credits == 0)
970+
return 0;
971+
972+
new_credits -= atomic_read(&info->receive_credits);
973+
if (new_credits <= 0)
974+
return 0;
972975

973976
return new_credits;
974977
}
@@ -1177,10 +1180,7 @@ static int smbd_post_send_iter(struct smbd_connection *info,
11771180
DMA_TO_DEVICE);
11781181
mempool_free(request, sc->send_io.mem.pool);
11791182

1180-
/* roll back receive credits and credits to be offered */
1181-
spin_lock(&info->lock_new_credits_offered);
1182-
info->new_credits_offered += new_credits;
1183-
spin_unlock(&info->lock_new_credits_offered);
1183+
/* roll back the granted receive credits */
11841184
atomic_sub(new_credits, &info->receive_credits);
11851185

11861186
err_alloc:
@@ -1866,8 +1866,6 @@ static struct smbd_connection *_smbd_get_connection(
18661866
msecs_to_jiffies(sp->keepalive_interval_msec));
18671867

18681868
INIT_WORK(&info->post_send_credits_work, smbd_post_send_credits);
1869-
info->new_credits_offered = 0;
1870-
spin_lock_init(&info->lock_new_credits_offered);
18711869

18721870
rc = smbd_negotiate(info);
18731871
if (rc) {

fs/smb/client/smbdirect.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ struct smbd_connection {
4646
struct smbdirect_socket socket;
4747

4848
struct work_struct post_send_credits_work;
49-
50-
spinlock_t lock_new_credits_offered;
51-
int new_credits_offered;
49+
atomic_t receive_posted;
5250

5351
/* dynamic connection parameters defined in [MS-SMBD] 3.1.1.1 */
5452
enum keep_alive_status keep_alive_requested;

0 commit comments

Comments
 (0)