* [PATCH][SMB3 client] cifs: Don't need state locking in smb2_get_mid_entry()
@ 2025-08-06 23:22 Steve French
0 siblings, 0 replies; only message in thread
From: Steve French @ 2025-08-06 23:22 UTC (permalink / raw)
To: CIFS; +Cc: David Howells
[-- Attachment #1: Type: text/plain, Size: 489 bytes --]
An attempt to rebase one of David's patches to current for-next.
There might be value in this cleanup. Any opinions? See attached.
There's no need to get ->srv_lock or ->ses_lock in smb2_get_mid_entry() as
all that happens of relevance (to the lock) inside the locked sections is
the reading of one status value in each.
Replace the locking with READ_ONCE() and use a switch instead of a chain of
if-statements.
Signed-off-by: David Howells <dhowells@redhat.com>
--
Thanks,
Steve
[-- Attachment #2: 0001-cifs-Don-t-need-state-locking-in-smb2_get_mid_entry.patch --]
[-- Type: text/x-patch, Size: 2699 bytes --]
From 469464ba8e225aa715677eb632fae92eba0bd288 Mon Sep 17 00:00:00 2001
From: Steve French <stfrench@microsoft.com>
Date: Wed, 6 Aug 2025 18:17:07 -0500
Subject: [PATCH] cifs: Don't need state locking in smb2_get_mid_entry()
There's no need to get ->srv_lock or ->ses_lock in smb2_get_mid_entry() as
all that happens of relevance (to the lock) inside the locked sections is
the reading of one status value in each.
Replace the locking with READ_ONCE() and use a switch instead of a chain of
if-statements.
Signed-off-by: David Howells <dhowells@redhat.com>
cc: Paulo Alcantara <pc@manguebit.org>
cc: Shyam Prasad N <sprasad@microsoft.com>
cc: Tom Talpey <tom@talpey.com>
cc: linux-cifs@vger.kernel.org
Signed-off-by: Steve French <stfrench@microsoft.com>
---
fs/smb/client/smb2transport.c | 44 ++++++++++++++---------------------
1 file changed, 18 insertions(+), 26 deletions(-)
diff --git a/fs/smb/client/smb2transport.c b/fs/smb/client/smb2transport.c
index ff9ef7fcd010..956173a930b7 100644
--- a/fs/smb/client/smb2transport.c
+++ b/fs/smb/client/smb2transport.c
@@ -799,43 +799,35 @@ static int
smb2_get_mid_entry(struct cifs_ses *ses, struct TCP_Server_Info *server,
struct smb2_hdr *shdr, struct mid_q_entry **mid)
{
- spin_lock(&server->srv_lock);
- if (server->tcpStatus == CifsExiting) {
- spin_unlock(&server->srv_lock);
+ switch (READ_ONCE(server->tcpStatus)) {
+ case CifsExiting:
return -ENOENT;
- }
-
- if (server->tcpStatus == CifsNeedReconnect) {
- spin_unlock(&server->srv_lock);
+ case CifsNeedReconnect:
cifs_dbg(FYI, "tcp session dead - return to caller to retry\n");
return -EAGAIN;
+ case CifsNeedNegotiate:
+ if (shdr->Command != SMB2_NEGOTIATE)
+ return -EAGAIN;
+ break;
+ default:
+ break;
}
- if (server->tcpStatus == CifsNeedNegotiate &&
- shdr->Command != SMB2_NEGOTIATE) {
- spin_unlock(&server->srv_lock);
- return -EAGAIN;
- }
- spin_unlock(&server->srv_lock);
-
- spin_lock(&ses->ses_lock);
- if (ses->ses_status == SES_NEW) {
+ switch (READ_ONCE(ses->ses_status)) {
+ case SES_NEW:
if ((shdr->Command != SMB2_SESSION_SETUP) &&
- (shdr->Command != SMB2_NEGOTIATE)) {
- spin_unlock(&ses->ses_lock);
+ (shdr->Command != SMB2_NEGOTIATE))
return -EAGAIN;
- }
/* else ok - we are setting up session */
- }
-
- if (ses->ses_status == SES_EXITING) {
- if (shdr->Command != SMB2_LOGOFF) {
- spin_unlock(&ses->ses_lock);
+ break;
+ case SES_EXITING:
+ if (shdr->Command != SMB2_LOGOFF)
return -EAGAIN;
- }
/* else ok - we are shutting down the session */
+ break;
+ default:
+ break;
}
- spin_unlock(&ses->ses_lock);
*mid = smb2_mid_entry_alloc(shdr, server);
if (*mid == NULL)
--
2.43.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2025-08-06 23:22 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-06 23:22 [PATCH][SMB3 client] cifs: Don't need state locking in smb2_get_mid_entry() Steve French
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).