Skip to content

Commit a05885c

Browse files
sprasad-microsoftSteve French
authored andcommitted
cifs: fix the connection state transitions with multichannel
Recent changes to multichannel required some adjustments in the way connection states transitioned during/after reconnect. Also some minor fixes: 1. A pending switch of GlobalMid_Lock to cifs_tcp_ses_lock 2. Relocations of the code that logs reconnect 3. Changed some code in allocate_mid to suit the new scheme Signed-off-by: Shyam Prasad N <sprasad@microsoft.com> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 3663c90 commit a05885c

File tree

4 files changed

+28
-28
lines changed

4 files changed

+28
-28
lines changed

fs/cifs/connect.c

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,16 @@ cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server,
181181
server->maxBuf = 0;
182182
server->max_read = 0;
183183

184-
cifs_dbg(FYI, "Mark tcp session as need reconnect\n");
185-
trace_smb3_reconnect(server->CurrentMid, server->conn_id, server->hostname);
186184
/*
187185
* before reconnecting the tcp session, mark the smb session (uid) and the tid bad so they
188186
* are not used until reconnected.
189187
*/
190-
cifs_dbg(FYI, "%s: marking sessions and tcons for reconnect\n", __func__);
188+
cifs_dbg(FYI, "%s: marking necessary sessions and tcons for reconnect\n", __func__);
191189

192190
/* If server is a channel, select the primary channel */
193191
pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
194192

193+
195194
spin_lock(&cifs_tcp_ses_lock);
196195
list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
197196
spin_lock(&ses->chan_lock);
@@ -218,13 +217,8 @@ cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server,
218217
}
219218
spin_unlock(&cifs_tcp_ses_lock);
220219

221-
/*
222-
* before reconnecting the tcp session, mark the smb session (uid)
223-
* and the tid bad so they are not used until reconnected
224-
*/
225-
cifs_dbg(FYI, "%s: marking sessions and tcons for reconnect and tearing down socket\n",
226-
__func__);
227220
/* do not want to be sending data on a socket we are freeing */
221+
cifs_dbg(FYI, "%s: tearing down socket\n", __func__);
228222
mutex_lock(&server->srv_mutex);
229223
if (server->ssocket) {
230224
cifs_dbg(FYI, "State: 0x%x Flags: 0x%lx\n", server->ssocket->state,
@@ -280,7 +274,12 @@ static bool cifs_tcp_ses_needs_reconnect(struct TCP_Server_Info *server, int num
280274
wake_up(&server->response_q);
281275
return false;
282276
}
277+
278+
cifs_dbg(FYI, "Mark tcp session as need reconnect\n");
279+
trace_smb3_reconnect(server->CurrentMid, server->conn_id,
280+
server->hostname);
283281
server->tcpStatus = CifsNeedReconnect;
282+
284283
spin_unlock(&cifs_tcp_ses_lock);
285284
return true;
286285
}
@@ -634,7 +633,6 @@ cifs_readv_from_socket(struct TCP_Server_Info *server, struct msghdr *smb_msg)
634633

635634
if (server->tcpStatus == CifsNeedReconnect) {
636635
spin_unlock(&cifs_tcp_ses_lock);
637-
cifs_reconnect(server, false);
638636
return -ECONNABORTED;
639637
}
640638
spin_unlock(&cifs_tcp_ses_lock);
@@ -3885,6 +3883,11 @@ cifs_negotiate_protocol(const unsigned int xid, struct cifs_ses *ses,
38853883
else
38863884
rc = -EHOSTDOWN;
38873885
spin_unlock(&cifs_tcp_ses_lock);
3886+
} else {
3887+
spin_lock(&cifs_tcp_ses_lock);
3888+
if (server->tcpStatus == CifsInNegotiate)
3889+
server->tcpStatus = CifsNeedNegotiate;
3890+
spin_unlock(&cifs_tcp_ses_lock);
38883891
}
38893892

38903893
return rc;
@@ -3931,8 +3934,18 @@ cifs_setup_session(const unsigned int xid, struct cifs_ses *ses,
39313934
if (server->ops->sess_setup)
39323935
rc = server->ops->sess_setup(xid, ses, server, nls_info);
39333936

3934-
if (rc)
3937+
if (rc) {
39353938
cifs_server_dbg(VFS, "Send error in SessSetup = %d\n", rc);
3939+
spin_lock(&cifs_tcp_ses_lock);
3940+
if (server->tcpStatus == CifsInSessSetup)
3941+
server->tcpStatus = CifsNeedSessSetup;
3942+
spin_unlock(&cifs_tcp_ses_lock);
3943+
} else {
3944+
spin_lock(&cifs_tcp_ses_lock);
3945+
if (server->tcpStatus == CifsInSessSetup)
3946+
server->tcpStatus = CifsGood;
3947+
spin_unlock(&cifs_tcp_ses_lock);
3948+
}
39363949

39373950
return rc;
39383951
}
@@ -4279,9 +4292,8 @@ static int __tree_connect_dfs_target(const unsigned int xid, struct cifs_tcon *t
42794292

42804293
/* only send once per connect */
42814294
spin_lock(&cifs_tcp_ses_lock);
4282-
if (tcon->ses->status != CifsGood ||
4283-
(tcon->tidStatus != CifsNew &&
4284-
tcon->tidStatus != CifsNeedTcon)) {
4295+
if (tcon->tidStatus != CifsNew &&
4296+
tcon->tidStatus != CifsNeedTcon) {
42854297
spin_unlock(&cifs_tcp_ses_lock);
42864298
return 0;
42874299
}

fs/cifs/sess.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1054,7 +1054,6 @@ sess_establish_session(struct sess_data *sess_data)
10541054

10551055
/* Even if one channel is active, session is in good state */
10561056
spin_lock(&cifs_tcp_ses_lock);
1057-
server->tcpStatus = CifsGood;
10581057
ses->status = CifsGood;
10591058
spin_unlock(&cifs_tcp_ses_lock);
10601059

fs/cifs/smb2pdu.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1393,7 +1393,6 @@ SMB2_sess_establish_session(struct SMB2_sess_data *sess_data)
13931393

13941394
/* Even if one channel is active, session is in good state */
13951395
spin_lock(&cifs_tcp_ses_lock);
1396-
server->tcpStatus = CifsGood;
13971396
ses->status = CifsGood;
13981397
spin_unlock(&cifs_tcp_ses_lock);
13991398

fs/cifs/transport.c

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,8 @@ __smb_send_rqst(struct TCP_Server_Info *server, int num_rqst,
431431
* socket so the server throws away the partial SMB
432432
*/
433433
spin_lock(&cifs_tcp_ses_lock);
434-
server->tcpStatus = CifsNeedReconnect;
434+
if (server->tcpStatus != CifsExiting)
435+
server->tcpStatus = CifsNeedReconnect;
435436
spin_unlock(&cifs_tcp_ses_lock);
436437
trace_smb3_partial_send_reconnect(server->CurrentMid,
437438
server->conn_id, server->hostname);
@@ -729,17 +730,6 @@ static int allocate_mid(struct cifs_ses *ses, struct smb_hdr *in_buf,
729730
struct mid_q_entry **ppmidQ)
730731
{
731732
spin_lock(&cifs_tcp_ses_lock);
732-
if (ses->server->tcpStatus == CifsExiting) {
733-
spin_unlock(&cifs_tcp_ses_lock);
734-
return -ENOENT;
735-
}
736-
737-
if (ses->server->tcpStatus == CifsNeedReconnect) {
738-
spin_unlock(&cifs_tcp_ses_lock);
739-
cifs_dbg(FYI, "tcp session dead - return to caller to retry\n");
740-
return -EAGAIN;
741-
}
742-
743733
if (ses->status == CifsNew) {
744734
if ((in_buf->Command != SMB_COM_SESSION_SETUP_ANDX) &&
745735
(in_buf->Command != SMB_COM_NEGOTIATE)) {

0 commit comments

Comments
 (0)