Skip to content

Commit ee36a3b

Browse files
sprasad-microsoftSteve French
authored andcommitted
cifs: make sure that channel scaling is done only once
Following a successful cifs_tree_connect, we have the code to scale up/down the number of channels in the session. However, it is not protected by a lock today. As a result, this code can be executed by several processes that select the same channel. The core functions handle this well, as they pick chan_lock. However, we've seen cases where smb2_reconnect throws some warnings. To fix that, this change introduces a flags bitmap inside the cifs_ses structure. A new flag type is used to ensure that only one process enters this section at any time. Signed-off-by: Shyam Prasad N <[email protected]> Signed-off-by: Steve French <[email protected]>
1 parent 41bccc9 commit ee36a3b

File tree

2 files changed

+20
-3
lines changed

2 files changed

+20
-3
lines changed

fs/smb/client/cifsglob.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,8 @@ struct cifs_chan {
10321032
__u8 signkey[SMB3_SIGN_KEY_SIZE];
10331033
};
10341034

1035+
#define CIFS_SES_FLAG_SCALE_CHANNELS (0x1)
1036+
10351037
/*
10361038
* Session structure. One of these for each uid session with a particular host
10371039
*/
@@ -1064,6 +1066,7 @@ struct cifs_ses {
10641066
enum securityEnum sectype; /* what security flavor was specified? */
10651067
bool sign; /* is signing required? */
10661068
bool domainAuto:1;
1069+
unsigned int flags;
10671070
__u16 session_flags;
10681071
__u8 smb3signingkey[SMB3_SIGN_KEY_SIZE];
10691072
__u8 smb3encryptionkey[SMB3_ENC_DEC_KEY_SIZE];

fs/smb/client/smb2pdu.c

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,15 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
399399
goto out;
400400
}
401401

402+
spin_lock(&ses->ses_lock);
403+
if (ses->flags & CIFS_SES_FLAG_SCALE_CHANNELS) {
404+
spin_unlock(&ses->ses_lock);
405+
mutex_unlock(&ses->session_mutex);
406+
goto skip_add_channels;
407+
}
408+
ses->flags |= CIFS_SES_FLAG_SCALE_CHANNELS;
409+
spin_unlock(&ses->ses_lock);
410+
402411
if (!rc &&
403412
(server->capabilities & SMB2_GLOBAL_CAP_MULTI_CHANNEL)) {
404413
mutex_unlock(&ses->session_mutex);
@@ -428,17 +437,22 @@ smb2_reconnect(__le16 smb2_command, struct cifs_tcon *tcon,
428437
if (ses->chan_max > ses->chan_count &&
429438
ses->iface_count &&
430439
!SERVER_IS_CHAN(server)) {
431-
if (ses->chan_count == 1)
440+
if (ses->chan_count == 1) {
432441
cifs_server_dbg(VFS, "supports multichannel now\n");
442+
queue_delayed_work(cifsiod_wq, &tcon->query_interfaces,
443+
(SMB_INTERFACE_POLL_INTERVAL * HZ));
444+
}
433445

434446
cifs_try_adding_channels(ses);
435-
queue_delayed_work(cifsiod_wq, &tcon->query_interfaces,
436-
(SMB_INTERFACE_POLL_INTERVAL * HZ));
437447
}
438448
} else {
439449
mutex_unlock(&ses->session_mutex);
440450
}
451+
441452
skip_add_channels:
453+
spin_lock(&ses->ses_lock);
454+
ses->flags &= ~CIFS_SES_FLAG_SCALE_CHANNELS;
455+
spin_unlock(&ses->ses_lock);
442456

443457
if (smb2_command != SMB2_INTERNAL_CMD)
444458
mod_delayed_work(cifsiod_wq, &server->reconnect, 0);

0 commit comments

Comments
 (0)