Skip to content

Commit 2adc820

Browse files
sprasad-microsoftsmfrench
authored andcommitted
cifs: add server conn_id to fscache client cookie
The fscache client cookie uses the server address (and port) as the cookie key. This is a problem when nosharesock is used. Two different connections will use duplicate cookies. Avoid this by adding server->conn_id to the key, so that it's guaranteed that cookie will not be duplicated. Also, for secondary channels of a session, copy the fscache pointer from the primary channel. The primary channel is guaranteed not to go away as long as secondary channels are in use. Also addresses minor problem found by kernel test robot. Reported-by: kernel test robot <lkp@intel.com> Signed-off-by: Shyam Prasad N <sprasad@microsoft.com> Reviewed-by: Paulo Alcantara (SUSE) <pc@cjr.nz> Signed-off-by: Steve French <stfrench@microsoft.com>
1 parent 5bf91ef commit 2adc820

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

fs/cifs/connect.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1562,6 +1562,10 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,
15621562
/* fscache server cookies are based on primary channel only */
15631563
if (!CIFS_SERVER_IS_CHAN(tcp_ses))
15641564
cifs_fscache_get_client_cookie(tcp_ses);
1565+
#ifdef CONFIG_CIFS_FSCACHE
1566+
else
1567+
tcp_ses->fscache = tcp_ses->primary_server->fscache;
1568+
#endif /* CONFIG_CIFS_FSCACHE */
15651569

15661570
/* queue echo request delayed work */
15671571
queue_delayed_work(cifsiod_wq, &tcp_ses->echo, tcp_ses->echo_interval);

fs/cifs/fscache.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ struct cifs_server_key {
2424
struct in_addr ipv4_addr;
2525
struct in6_addr ipv6_addr;
2626
};
27+
__u64 conn_id;
2728
} __packed;
2829

2930
/*
@@ -37,6 +38,14 @@ void cifs_fscache_get_client_cookie(struct TCP_Server_Info *server)
3738
struct cifs_server_key key;
3839
uint16_t key_len = sizeof(key.hdr);
3940

41+
/*
42+
* Check if cookie was already initialized so don't reinitialize it.
43+
* In the future, as we integrate with newer fscache features,
44+
* we may want to instead add a check if cookie has changed
45+
*/
46+
if (server->fscache)
47+
return;
48+
4049
memset(&key, 0, sizeof(key));
4150

4251
/*
@@ -62,6 +71,7 @@ void cifs_fscache_get_client_cookie(struct TCP_Server_Info *server)
6271
server->fscache = NULL;
6372
return;
6473
}
74+
key.conn_id = server->conn_id;
6575

6676
server->fscache =
6777
fscache_acquire_cookie(cifs_fscache_netfs.primary_index,

0 commit comments

Comments
 (0)