cifs: use a different reconnect helper for non-cifsd threads
authorShyam Prasad N <sprasad@microsoft.com>
Tue, 15 Feb 2022 13:55:40 +0000 (13:55 +0000)
committerSteve French <stfrench@microsoft.com>
Sat, 19 Mar 2022 04:12:03 +0000 (23:12 -0500)
The cifs_demultiplexer_thread should only call cifs_reconnect.
If any other thread wants to trigger a reconnect, they can do
so by updating the server tcpStatus to CifsNeedReconnect.

The last patch attempted to use the same helper function for
both types of threads, but that causes other issues
with lock dependencies.

This patch creates a new helper for non-cifsd threads, that
will indicate to cifsd that the server needs reconnect.

Fixes: 2a05137a0575 ("cifs: mark sessions for reconnection in helper function")
Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
Signed-off-by: Steve French <stfrench@microsoft.com>
fs/cifs/cifs_swn.c
fs/cifs/cifsproto.h
fs/cifs/connect.c
fs/cifs/dfs_cache.c
fs/cifs/smb1ops.c
fs/cifs/transport.c

index cdce160..180c234 100644 (file)
@@ -396,11 +396,11 @@ static int cifs_swn_resource_state_changed(struct cifs_swn_reg *swnreg, const ch
        switch (state) {
        case CIFS_SWN_RESOURCE_STATE_UNAVAILABLE:
                cifs_dbg(FYI, "%s: resource name '%s' become unavailable\n", __func__, name);
-               cifs_mark_tcp_ses_conns_for_reconnect(swnreg->tcon->ses->server, true);
+               cifs_signal_cifsd_for_reconnect(swnreg->tcon->ses->server, true);
                break;
        case CIFS_SWN_RESOURCE_STATE_AVAILABLE:
                cifs_dbg(FYI, "%s: resource name '%s' become available\n", __func__, name);
-               cifs_mark_tcp_ses_conns_for_reconnect(swnreg->tcon->ses->server, true);
+               cifs_signal_cifsd_for_reconnect(swnreg->tcon->ses->server, true);
                break;
        case CIFS_SWN_RESOURCE_STATE_UNKNOWN:
                cifs_dbg(FYI, "%s: resource name '%s' changed to unknown state\n", __func__, name);
@@ -498,7 +498,7 @@ static int cifs_swn_reconnect(struct cifs_tcon *tcon, struct sockaddr_storage *a
                goto unlock;
        }
 
-       cifs_mark_tcp_ses_conns_for_reconnect(tcon->ses->server, false);
+       cifs_signal_cifsd_for_reconnect(tcon->ses->server, false);
 
 unlock:
        mutex_unlock(&tcon->ses->server->srv_mutex);
index d370129..0df3b24 100644 (file)
@@ -132,6 +132,9 @@ extern int SendReceiveBlockingLock(const unsigned int xid,
                        struct smb_hdr *out_buf,
                        int *bytes_returned);
 void
+cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server,
+                                     bool all_channels);
+void
 cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server,
                                      bool mark_smb_session);
 extern int cifs_reconnect(struct TCP_Server_Info *server,
index d3020ab..9964c36 100644 (file)
@@ -163,10 +163,50 @@ static void cifs_resolve_server(struct work_struct *work)
 }
 
 /*
+ * Update the tcpStatus for the server.
+ * This is used to signal the cifsd thread to call cifs_reconnect
+ * ONLY cifsd thread should call cifs_reconnect. For any other
+ * thread, use this function
+ *
+ * @server: the tcp ses for which reconnect is needed
+ * @all_channels: if this needs to be done for all channels
+ */
+void
+cifs_signal_cifsd_for_reconnect(struct TCP_Server_Info *server,
+                               bool all_channels)
+{
+       struct TCP_Server_Info *pserver;
+       struct cifs_ses *ses;
+       int i;
+
+       /* If server is a channel, select the primary channel */
+       pserver = CIFS_SERVER_IS_CHAN(server) ? server->primary_server : server;
+
+       spin_lock(&cifs_tcp_ses_lock);
+       if (!all_channels) {
+               pserver->tcpStatus = CifsNeedReconnect;
+               spin_unlock(&cifs_tcp_ses_lock);
+               return;
+       }
+
+       list_for_each_entry(ses, &pserver->smb_ses_list, smb_ses_list) {
+               spin_lock(&ses->chan_lock);
+               for (i = 0; i < ses->chan_count; i++)
+                       ses->chans[i].server->tcpStatus = CifsNeedReconnect;
+               spin_unlock(&ses->chan_lock);
+       }
+       spin_unlock(&cifs_tcp_ses_lock);
+}
+
+/*
  * Mark all sessions and tcons for reconnect.
+ * IMPORTANT: make sure that this gets called only from
+ * cifsd thread. For any other thread, use
+ * cifs_signal_cifsd_for_reconnect
  *
+ * @server: the tcp ses for which reconnect is needed
  * @server needs to be previously set to CifsNeedReconnect.
- *
+ * @mark_smb_session: whether even sessions need to be marked
  */
 void
 cifs_mark_tcp_ses_conns_for_reconnect(struct TCP_Server_Info *server,
index 831f424..30e040d 100644 (file)
@@ -1355,7 +1355,7 @@ static void mark_for_reconnect_if_needed(struct cifs_tcon *tcon, struct dfs_cach
        }
 
        cifs_dbg(FYI, "%s: no cached or matched targets. mark dfs share for reconnect.\n", __func__);
-       cifs_mark_tcp_ses_conns_for_reconnect(tcon->ses->server, true);
+       cifs_signal_cifsd_for_reconnect(tcon->ses->server, true);
 }
 
 /* Refresh dfs referral of tcon and mark it for reconnect if needed */
index b2fb7bd..c71c9a4 100644 (file)
@@ -228,7 +228,7 @@ cifs_get_next_mid(struct TCP_Server_Info *server)
        spin_unlock(&GlobalMid_Lock);
 
        if (reconnect) {
-               cifs_mark_tcp_ses_conns_for_reconnect(server, false);
+               cifs_signal_cifsd_for_reconnect(server, false);
        }
 
        return mid;
index a4c3e02..eeb1a69 100644 (file)
@@ -430,7 +430,7 @@ unmask:
                 * be taken as the remainder of this one. We need to kill the
                 * socket so the server throws away the partial SMB
                 */
-               cifs_mark_tcp_ses_conns_for_reconnect(server, false);
+               cifs_signal_cifsd_for_reconnect(server, false);
                trace_smb3_partial_send_reconnect(server->CurrentMid,
                                                  server->conn_id, server->hostname);
        }