From: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
To: Pavel Shilovsky <piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Subject: Re: [PATCH v2 10/11] CIFS: Expand CurrentMid field
Date: Mon, 19 Mar 2012 16:24:10 -0400 [thread overview]
Message-ID: <20120319162410.42b95f13@redhat.com> (raw)
In-Reply-To: <1331910574-998-11-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
On Fri, 16 Mar 2012 18:09:33 +0300
Pavel Shilovsky <piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org> wrote:
> While in CIFS/SMB we have 16 bit mid, in SMB2 it is 64 bit.
> Convert the existing field to 64 bit and mask off higher bits
> for CIFS/SMB.
>
> Signed-off-by: Pavel Shilovsky <piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
> ---
> fs/cifs/cifsglob.h | 2 +-
> fs/cifs/cifsproto.h | 2 +-
> fs/cifs/misc.c | 84 ++++++++++++++++++++++++++++-----------------------
> 3 files changed, 48 insertions(+), 40 deletions(-)
>
> diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
> index a403398..b213458 100644
> --- a/fs/cifs/cifsglob.h
> +++ b/fs/cifs/cifsglob.h
> @@ -282,7 +282,7 @@ struct TCP_Server_Info {
> vcnumbers */
> int capabilities; /* allow selective disabling of caps by smb sess */
> int timeAdj; /* Adjust for difference in server time zone in sec */
> - __u16 CurrentMid; /* multiplex id - rotating counter */
> + __u64 CurrentMid; /* multiplex id - rotating counter */
It occurs to me that a simpler way to do this might be to turn this
into a union with a u16 and u64 field. This works just as well though...
> char cryptkey[CIFS_CRYPTO_KEY_SIZE]; /* used by ntlm, ntlmv2 etc */
> /* 16th byte of RFC1001 workstation name is always null */
> char workstation_RFC1001_name[RFC1001_NAME_LEN_WITH_NULL];
> diff --git a/fs/cifs/cifsproto.h b/fs/cifs/cifsproto.h
> index db38a40..8958721 100644
> --- a/fs/cifs/cifsproto.h
> +++ b/fs/cifs/cifsproto.h
> @@ -115,7 +115,7 @@ extern int small_smb_init_no_tc(const int smb_cmd, const int wct,
> void **request_buf);
> extern int CIFS_SessSetup(unsigned int xid, struct cifs_ses *ses,
> const struct nls_table *nls_cp);
> -extern __u16 GetNextMid(struct TCP_Server_Info *server);
> +extern __u64 GetNextMid(struct TCP_Server_Info *server);
> extern struct timespec cifs_NTtimeToUnix(__le64 utc_nanoseconds_since_1601);
> extern u64 cifs_UnixTimeToNT(struct timespec);
> extern struct timespec cnvrtDosUnixTm(__le16 le_date, __le16 le_time,
> diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
> index 88459d0..0b743b7 100644
> --- a/fs/cifs/misc.c
> +++ b/fs/cifs/misc.c
> @@ -213,54 +213,61 @@ cifs_small_buf_release(void *buf_to_free)
> }
>
> /*
> - Find a free multiplex id (SMB mid). Otherwise there could be
> - mid collisions which might cause problems, demultiplexing the
> - wrong response to this request. Multiplex ids could collide if
> - one of a series requests takes much longer than the others, or
> - if a very large number of long lived requests (byte range
> - locks or FindNotify requests) are pending. No more than
> - 64K-1 requests can be outstanding at one time. If no
> - mids are available, return zero. A future optimization
> - could make the combination of mids and uid the key we use
> - to demultiplex on (rather than mid alone).
> - In addition to the above check, the cifs demultiplex
> - code already used the command code as a secondary
> - check of the frame and if signing is negotiated the
> - response would be discarded if the mid were the same
> - but the signature was wrong. Since the mid is not put in the
> - pending queue until later (when it is about to be dispatched)
> - we do have to limit the number of outstanding requests
> - to somewhat less than 64K-1 although it is hard to imagine
> - so many threads being in the vfs at one time.
> -*/
> -__u16 GetNextMid(struct TCP_Server_Info *server)
> + * Find a free multiplex id (SMB mid). Otherwise there could be
> + * mid collisions which might cause problems, demultiplexing the
> + * wrong response to this request. Multiplex ids could collide if
> + * one of a series requests takes much longer than the others, or
> + * if a very large number of long lived requests (byte range
> + * locks or FindNotify requests) are pending. No more than
> + * 64K-1 requests can be outstanding at one time. If no
> + * mids are available, return zero. A future optimization
> + * could make the combination of mids and uid the key we use
> + * to demultiplex on (rather than mid alone).
> + * In addition to the above check, the cifs demultiplex
> + * code already used the command code as a secondary
> + * check of the frame and if signing is negotiated the
> + * response would be discarded if the mid were the same
> + * but the signature was wrong. Since the mid is not put in the
> + * pending queue until later (when it is about to be dispatched)
> + * we do have to limit the number of outstanding requests
> + * to somewhat less than 64K-1 although it is hard to imagine
> + * so many threads being in the vfs at one time.
> + */
> +__u64 GetNextMid(struct TCP_Server_Info *server)
> {
> - __u16 mid = 0;
> - __u16 last_mid;
> + __u64 mid = 0;
> + __u16 last_mid, cur_mid;
> bool collision;
>
> spin_lock(&GlobalMid_Lock);
> - last_mid = server->CurrentMid; /* we do not want to loop forever */
> - server->CurrentMid++;
> - /* This nested loop looks more expensive than it is.
> - In practice the list of pending requests is short,
> - fewer than 50, and the mids are likely to be unique
> - on the first pass through the loop unless some request
> - takes longer than the 64 thousand requests before it
> - (and it would also have to have been a request that
> - did not time out) */
> - while (server->CurrentMid != last_mid) {
> +
> + /* mid is 16 bit only for CIFS/SMB */
> + cur_mid = (__u16)((server->CurrentMid) & 0xffff);
> + /* we do not want to loop forever */
> + last_mid = cur_mid;
> + cur_mid++;
> +
> + /*
> + * This nested loop looks more expensive than it is.
> + * In practice the list of pending requests is short,
> + * fewer than 50, and the mids are likely to be unique
> + * on the first pass through the loop unless some request
> + * takes longer than the 64 thousand requests before it
> + * (and it would also have to have been a request that
> + * did not time out).
> + */
> + while (cur_mid != last_mid) {
> struct mid_q_entry *mid_entry;
> unsigned int num_mids;
>
> collision = false;
> - if (server->CurrentMid == 0)
> - server->CurrentMid++;
> + if (cur_mid == 0)
> + cur_mid++;
>
> num_mids = 0;
> list_for_each_entry(mid_entry, &server->pending_mid_q, qhead) {
> ++num_mids;
> - if (mid_entry->mid == server->CurrentMid &&
> + if (mid_entry->mid == cur_mid &&
> mid_entry->midState == MID_REQUEST_SUBMITTED) {
> /* This mid is in use, try a different one */
> collision = true;
> @@ -282,10 +289,11 @@ __u16 GetNextMid(struct TCP_Server_Info *server)
> server->tcpStatus = CifsNeedReconnect;
>
> if (!collision) {
> - mid = server->CurrentMid;
> + mid = (__u64)cur_mid;
> + server->CurrentMid = mid;
> break;
> }
> - server->CurrentMid++;
> + cur_mid++;
> }
> spin_unlock(&GlobalMid_Lock);
> return mid;
Not directly related to this patch, but should we move all of these mid
operations under the req_lock instead of the GlobalMid_Lock? The global
spinlock is a bottleneck and all of the structures involved should be
per-server anyway.
Anyway, I think this looks ok
Reviewed-by: Jeff Layton <jlayton-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
next prev parent reply other threads:[~2012-03-19 20:24 UTC|newest]
Thread overview: 43+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-03-16 15:09 [PATCH v2 00/11] Prepare transport code for future SMB2 usage Pavel Shilovsky
[not found] ` <1331910574-998-1-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-16 15:09 ` [PATCH v2 01/11] CIFS: Respect negotiated MaxMpxCount Pavel Shilovsky
[not found] ` <1331910574-998-2-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-17 11:12 ` Jeff Layton
[not found] ` <20120317071201.7f28683b-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2012-03-17 14:53 ` Pavel Shilovsky
[not found] ` <CAKywueTDsGhcHiGM_uX6V0dnY3m_W4kD2qcb+JWRq=UVnBnvPw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-17 15:20 ` Steve French
[not found] ` <CAH2r5msMKiEyS2-ak2+tQoRFommSHRcCNwp-J+XtgovmSae7-A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-18 10:33 ` Jeff Layton
2012-03-18 10:50 ` Jeff Layton
[not found] ` <20120318065059.62592afb-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2012-03-18 18:23 ` Pavel Shilovsky
[not found] ` <CAKywueSrGVvwqHbTK3sNLsHDx3vR6U0Ca712ZXKNTnjnOgPGDA-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-19 15:04 ` Jeff Layton
[not found] ` <20120319110437.635ea546-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2012-03-19 19:04 ` Pavel Shilovsky
[not found] ` <CAKywueR2mWNKxNDhhj_0i0TfiPz3nmvVBXbxGMZ+Lrbgts3cDQ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-19 19:32 ` Steve French
[not found] ` <CAH2r5mvhTYPxvDRFCpQ0ULmDn2TNQ80ODbnvTmgFurptYukR1Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-19 19:39 ` Jeff Layton
2012-03-16 15:09 ` [PATCH v2 02/11] CIFS: Simplify inFlight logic Pavel Shilovsky
[not found] ` <1331910574-998-3-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-17 11:07 ` Jeff Layton
2012-03-16 15:09 ` [PATCH v2 03/11] CIFS: Introduce credit-based flow control Pavel Shilovsky
[not found] ` <1331910574-998-4-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-17 10:32 ` Jeff Layton
[not found] ` <20120317063258.77618c0e-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2012-03-17 14:56 ` Pavel Shilovsky
2012-03-16 15:09 ` [PATCH v2 04/11] CIFS: Make wait_for_free_request killable Pavel Shilovsky
[not found] ` <1331910574-998-5-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-17 11:13 ` Jeff Layton
2012-03-16 15:09 ` [PATCH v2 05/11] CIFS: Prepare credits code for a slot reservation Pavel Shilovsky
[not found] ` <1331910574-998-6-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-19 19:27 ` Jeff Layton
[not found] ` <20120319152702.3eee1608-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-03-20 7:03 ` Pavel Shilovsky
2012-03-16 15:09 ` [PATCH v2 06/11] CIFS: Delete echo_retries module parm Pavel Shilovsky
[not found] ` <1331910574-998-7-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-18 10:30 ` Jeff Layton
2012-03-16 15:09 ` [PATCH v2 07/11] CIFS: Separate protocol-specific code from transport routines Pavel Shilovsky
[not found] ` <1331910574-998-8-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-19 19:31 ` Jeff Layton
2012-03-16 15:09 ` [PATCH v2 08/11] CIFS: Separate protocol-specific code from demultiplex code Pavel Shilovsky
[not found] ` <1331910574-998-9-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-19 19:41 ` Jeff Layton
[not found] ` <20120319154150.03713caf-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-03-20 7:29 ` Pavel Shilovsky
[not found] ` <CAKywueTxicF658ys1yBzC_95qw0v8R+6pxuhZ_zc+aRKyRLFdw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-20 10:22 ` Jeff Layton
2012-03-16 15:09 ` [PATCH v2 09/11] CIFS: Separate protocol-specific code from cifs_readv_receive code Pavel Shilovsky
[not found] ` <1331910574-998-10-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-19 20:17 ` Jeff Layton
[not found] ` <20120319161728.1f8cec40-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-03-20 7:33 ` Pavel Shilovsky
[not found] ` <CAKywueSvsb+BP7ktb0QEgL3WmrO8j42bicvd-WjWNro6qGRc7w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-20 10:24 ` Jeff Layton
[not found] ` <20120320062414.554a033c-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2012-03-20 10:54 ` Pavel Shilovsky
2012-03-16 15:09 ` [PATCH v2 10/11] CIFS: Expand CurrentMid field Pavel Shilovsky
[not found] ` <1331910574-998-11-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-19 20:24 ` Jeff Layton [this message]
[not found] ` <20120319162410.42b95f13-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2012-03-19 20:48 ` Steve French
[not found] ` <CAH2r5mujZook3O2Ojvu+vjx5Y5uYuormbtbDW69iOLEf1XVQgg-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-20 7:37 ` Pavel Shilovsky
[not found] ` <CAKywueTpa6Hmz7oQ=8S1ViRU9ky7wqhKN+f=eaWrJY1457X86w-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2012-03-20 10:28 ` Jeff Layton
[not found] ` <20120320062843.1cd218ed-9yPaYZwiELC+kQycOl6kW4xkIHaj4LzF@public.gmane.org>
2012-03-20 22:21 ` Steve French
2012-03-16 15:09 ` [PATCH v2 11/11] CIFS: Change mid_q_entry structure fields Pavel Shilovsky
[not found] ` <1331910574-998-12-git-send-email-piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org>
2012-03-19 20:28 ` Jeff Layton
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=20120319162410.42b95f13@redhat.com \
--to=jlayton-h+wxahxf7alqt0dzr+alfa@public.gmane.org \
--cc=linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=piastry-7qunaywFIewox3rIn2DAYQ@public.gmane.org \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.