Skip to contentSkip to conversation

cifs: Fix lookup of SMB connections on multichannel

PATCH In review Paulo Alcantara (SUSE) 2 participants 2 messages Dec 4, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 cifs: Fix lookup of SMB connections on multichannel

With the addition of SMB session channels, we introduced new TCP server pointers that have no sessions or tcons associated with them.

In this case, when we started looking for TCP connections, we might end up picking session channel rather than the master connection, hence failing to get either a session or a tcon.

In order to fix that, this patch introduces a new "is_channel" field to TCP_Server_Info structure so we can skip session channels during lookup of connections.

---
 fs/cifs/cifsglob.h | 1 +
 fs/cifs/connect.c  | 6 +++++-
 fs/cifs/sess.c     | 3 +++
 3 files changed, 9 insertions(+), 1 deletion(-)
fs/cifs/cifsglob.h +1 -0
index 5b976e01dd6b..fd0262ce5ad5 100644
@@ -777,6 +777,7 @@ struct TCP_Server_Info {
 	 */
 	int nr_targets;
 	bool noblockcnt; /* use non-blocking connect() */
+	bool is_channel; /* if a session channel */
 };
 
 struct cifs_credits {
fs/cifs/connect.c +5 -1
index 86d1baedf21c..05ea0e2b7e0e 100644
@@ -2712,7 +2712,11 @@ cifs_find_tcp_session(struct smb_vol *vol)
 
 	spin_lock(&cifs_tcp_ses_lock);
 	list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
-		if (!match_server(server, vol))
+		/*
+		 * Skip ses channels since they're only handled in lower layers
+		 * (e.g. cifs_send_recv).
+		 */
+		if (server->is_channel || !match_server(server, vol))
 			continue;
 
 		++server->srv_count;
fs/cifs/sess.c +3 -0
index fb3bdc44775c..d95137304224 100644
@@ -213,6 +213,9 @@ cifs_ses_add_channel(struct cifs_ses *ses, struct cifs_server_iface *iface)
 		chan->server = NULL;
 		goto out;
 	}
+	spin_lock(&cifs_tcp_ses_lock);
+	chan->server->is_channel = true;
+	spin_unlock(&cifs_tcp_ses_lock);
 
 	/*
 	 * We need to allocate the server crypto now as we will need
Signature · 1 line
2.24.0
#1 lore raw

tentatively merged to cifs-2.6.git for-next and buildbot github tree pending more testing

Quoted 66 lines · Paulo Alcantara (SUSE)

With the addition of SMB session channels, we introduced new TCP server pointers that have no sessions or tcons associated with them.

In this case, when we started looking for TCP connections, we might end up picking session channel rather than the master connection, hence failing to get either a session or a tcon.

In order to fix that, this patch introduces a new "is_channel" field to TCP_Server_Info structure so we can skip session channels during lookup of connections.

---
 fs/cifs/cifsglob.h | 1 +
 fs/cifs/connect.c  | 6 +++++-
 fs/cifs/sess.c     | 3 +++
 3 files changed, 9 insertions(+), 1 deletion(-)
fs/cifs/cifsglob.h +1 -0
index 5b976e01dd6b..fd0262ce5ad5 100644
@@ -777,6 +777,7 @@ struct TCP_Server_Info {
         */
        int nr_targets;
        bool noblockcnt; /* use non-blocking connect() */
+       bool is_channel; /* if a session channel */
 };
 
 struct cifs_credits {
fs/cifs/connect.c +5 -1
index 86d1baedf21c..05ea0e2b7e0e 100644
@@ -2712,7 +2712,11 @@ cifs_find_tcp_session(struct smb_vol *vol)
 
        spin_lock(&cifs_tcp_ses_lock);
        list_for_each_entry(server, &cifs_tcp_ses_list, tcp_ses_list) {
-               if (!match_server(server, vol))
+               /*
+                * Skip ses channels since they're only handled in lower layers
+                * (e.g. cifs_send_recv).
+                */
+               if (server->is_channel || !match_server(server, vol))
                        continue;
 
                ++server->srv_count;
fs/cifs/sess.c +3 -1
index fb3bdc44775c..d95137304224 100644
@@ -213,6 +213,9 @@ cifs_ses_add_channel(struct cifs_ses *ses, struct cifs_server_iface *iface)
                chan->server = NULL;
                goto out;
        }
+       spin_lock(&cifs_tcp_ses_lock);
+       chan->server->is_channel = true;
+       spin_unlock(&cifs_tcp_ses_lock);
 
        /*
         * We need to allocate the server crypto now as we will need
--

2.24.0

Signature · 3 lines
Thanks,

Steve