Linux CIFS filesystem development
 help / color / mirror / Atom feed
From: Tom Talpey <tom@talpey.com>
To: Shyam Prasad N <nspmangalore@gmail.com>,
	linux-cifs@vger.kernel.org, smfrench@gmail.com, pc@cjr.nz,
	bharathsm.hsk@gmail.com
Cc: Shyam Prasad N <sprasad@microsoft.com>
Subject: Re: [PATCH 5/6] cifs: fix max_credits implementation
Date: Fri, 23 Jun 2023 12:00:49 -0400	[thread overview]
Message-ID: <b44d580c-6237-bccb-a9e1-2d5bdd2db35f@talpey.com> (raw)
In-Reply-To: <20230609174659.60327-5-sprasad@microsoft.com>

On 6/9/2023 1:46 PM, Shyam Prasad N wrote:
> The current implementation of max_credits on the client does
> not work because the CreditRequest logic for several commands
> does not take max_credits into account.
> 
> Still, we can end up asking the server for more credits, depending
> on the number of credits in flight. For this, we need to
> limit the credits while parsing the responses too.
> 
> Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
> ---
>   fs/smb/client/smb2ops.c |  2 ++
>   fs/smb/client/smb2pdu.c | 32 ++++++++++++++++++++++++++++----
>   2 files changed, 30 insertions(+), 4 deletions(-)
> 
> diff --git a/fs/smb/client/smb2ops.c b/fs/smb/client/smb2ops.c
> index 43162915e03c..18faf267c54d 100644
> --- a/fs/smb/client/smb2ops.c
> +++ b/fs/smb/client/smb2ops.c
> @@ -34,6 +34,8 @@ static int
>   change_conf(struct TCP_Server_Info *server)
>   {
>   	server->credits += server->echo_credits + server->oplock_credits;
> +	if (server->credits > server->max_credits)
> +		server->credits = server->max_credits;
>   	server->oplock_credits = server->echo_credits = 0;
>   	switch (server->credits) {
>   	case 0:
> diff --git a/fs/smb/client/smb2pdu.c b/fs/smb/client/smb2pdu.c
> index 7063b395d22f..17fe212ab895 100644
> --- a/fs/smb/client/smb2pdu.c
> +++ b/fs/smb/client/smb2pdu.c
> @@ -1305,7 +1305,12 @@ SMB2_sess_alloc_buffer(struct SMB2_sess_data *sess_data)
>   	}
>   
>   	/* enough to enable echos and oplocks and one max size write */
> -	req->hdr.CreditRequest = cpu_to_le16(130);
> +	if (server->credits >= server->max_credits)
> +		req->hdr.CreditRequest = cpu_to_le16(0);
> +	else
> +		req->hdr.CreditRequest = cpu_to_le16(
> +			min_t(int, server->max_credits -
> +			      server->credits, 130));

This identical processing appears several times below. It would be
very bad if the copies got out of sync. Let's factor these as a
single function, perhaps inline but it might make sense as a client
common entry.

Tom.


>   	/* only one of SMB2 signing flags may be set in SMB2 request */
>   	if (server->sign)
> @@ -1899,7 +1904,12 @@ SMB2_tcon(const unsigned int xid, struct cifs_ses *ses, const char *tree,
>   	rqst.rq_nvec = 2;
>   
>   	/* Need 64 for max size write so ask for more in case not there yet */
> -	req->hdr.CreditRequest = cpu_to_le16(64);
> +	if (server->credits >= server->max_credits)
> +		req->hdr.CreditRequest = cpu_to_le16(0);
> +	else
> +		req->hdr.CreditRequest = cpu_to_le16(
> +			min_t(int, server->max_credits -
> +			      server->credits, 64));
>   
>   	rc = cifs_send_recv(xid, ses, server,
>   			    &rqst, &resp_buftype, flags, &rsp_iov);
> @@ -4227,6 +4237,7 @@ smb2_async_readv(struct cifs_readdata *rdata)
>   	struct TCP_Server_Info *server;
>   	struct cifs_tcon *tcon = tlink_tcon(rdata->cfile->tlink);
>   	unsigned int total_len;
> +	int credit_request;
>   
>   	cifs_dbg(FYI, "%s: offset=%llu bytes=%u\n",
>   		 __func__, rdata->offset, rdata->bytes);
> @@ -4258,7 +4269,13 @@ smb2_async_readv(struct cifs_readdata *rdata)
>   	if (rdata->credits.value > 0) {
>   		shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(rdata->bytes,
>   						SMB2_MAX_BUFFER_SIZE));
> -		shdr->CreditRequest = cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 8);
> +		credit_request = le16_to_cpu(shdr->CreditCharge) + 8;
> +		if (server->credits >= server->max_credits)
> +			shdr->CreditRequest = cpu_to_le16(0);
> +		else
> +			shdr->CreditRequest = cpu_to_le16(
> +				min_t(int, server->max_credits -
> +						server->credits, credit_request));
>   
>   		rc = adjust_credits(server, &rdata->credits, rdata->bytes);
>   		if (rc)
> @@ -4468,6 +4485,7 @@ smb2_async_writev(struct cifs_writedata *wdata,
>   	unsigned int total_len;
>   	struct cifs_io_parms _io_parms;
>   	struct cifs_io_parms *io_parms = NULL;
> +	int credit_request;
>   
>   	if (!wdata->server)
>   		server = wdata->server = cifs_pick_channel(tcon->ses);
> @@ -4572,7 +4590,13 @@ smb2_async_writev(struct cifs_writedata *wdata,
>   	if (wdata->credits.value > 0) {
>   		shdr->CreditCharge = cpu_to_le16(DIV_ROUND_UP(wdata->bytes,
>   						    SMB2_MAX_BUFFER_SIZE));
> -		shdr->CreditRequest = cpu_to_le16(le16_to_cpu(shdr->CreditCharge) + 8);
> +		credit_request = le16_to_cpu(shdr->CreditCharge) + 8;
> +		if (server->credits >= server->max_credits)
> +			shdr->CreditRequest = cpu_to_le16(0);
> +		else
> +			shdr->CreditRequest = cpu_to_le16(
> +				min_t(int, server->max_credits -
> +						server->credits, credit_request));
>   
>   		rc = adjust_credits(server, &wdata->credits, io_parms->length);
>   		if (rc)

  reply	other threads:[~2023-06-23 16:01 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-09 17:46 [PATCH 1/6] cifs: fix status checks in cifs_tree_connect Shyam Prasad N
2023-06-09 17:46 ` [PATCH 2/6] cifs: print all credit counters in DebugData Shyam Prasad N
2023-06-10 19:48   ` Steve French
2023-06-09 17:46 ` [PATCH 3/6] cifs: add a warning when the in-flight count goes negative Shyam Prasad N
2023-06-10 19:49   ` Steve French
2023-06-11  8:01     ` Shyam Prasad N
2023-06-23 16:22       ` Tom Talpey
2023-06-26  6:33         ` Shyam Prasad N
2023-06-27 19:40           ` Tom Talpey
2023-06-09 17:46 ` [PATCH 4/6] cifs: display the endpoint IP details in DebugData Shyam Prasad N
2023-06-09 18:02   ` Enzo Matsumiya
2023-06-11  8:02     ` Shyam Prasad N
2023-06-12  7:59       ` Shyam Prasad N
2023-06-12  7:59         ` Shyam Prasad N
2023-06-12 14:03           ` Enzo Matsumiya
2023-06-12 13:52         ` Enzo Matsumiya
2023-06-12 15:25         ` Paulo Alcantara
2023-06-12 15:29           ` Enzo Matsumiya
2023-06-23  4:21             ` Shyam Prasad N
2023-06-23 15:51               ` Steve French
2023-06-23 15:54               ` Tom Talpey
2023-06-27 12:17                 ` Shyam Prasad N
2023-06-28 10:20                   ` Shyam Prasad N
2023-06-28 13:39                     ` Tom Talpey
2023-06-28 16:24                       ` Steve French
2023-06-28 16:51                     ` Steve French
2023-06-28 17:07                     ` Steve French
2023-06-28 17:11                     ` Steve French
2023-06-29 15:35                       ` Shyam Prasad N
2023-06-09 17:46 ` [PATCH 5/6] cifs: fix max_credits implementation Shyam Prasad N
2023-06-23 16:00   ` Tom Talpey [this message]
2023-06-26  5:40     ` Shyam Prasad N
2023-06-09 17:46 ` [PATCH 6/6] cifs: fix sockaddr comparison in iface_cmp Shyam Prasad N
2023-06-23 16:09   ` Tom Talpey
2023-06-26 11:12     ` Dan Carpenter
2023-06-27 19:37       ` Tom Talpey
2023-06-10 19:45 ` [PATCH 1/6] cifs: fix status checks in cifs_tree_connect Steve French

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=b44d580c-6237-bccb-a9e1-2d5bdd2db35f@talpey.com \
    --to=tom@talpey.com \
    --cc=bharathsm.hsk@gmail.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=nspmangalore@gmail.com \
    --cc=pc@cjr.nz \
    --cc=smfrench@gmail.com \
    --cc=sprasad@microsoft.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox