@@ -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 }
0 commit comments