All of lore.kernel.org
 help / color / mirror / Atom feed
From: Shyam Prasad N <nspmangalore@gmail.com>
To: David Howells <dhowells@redhat.com>,
	Jeff Layton <jlayton@redhat.com>,
	Steve French <smfrench@gmail.com>, Paulo Alcantara <pc@cjr.nz>,
	CIFS <linux-cifs@vger.kernel.org>,
	linux-cachefs@redhat.com
Subject: [PATCH] cifs: add server conn_id to fscache client cookie
Date: Fri, 3 Dec 2021 14:58:34 +0530	[thread overview]
Message-ID: <CANT5p=pqb7MmFe+kQU67Eytm98tZB1ztr0d5Rwq44oxAq81+Dw@mail.gmail.com> (raw)

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.

Signed-off-by: Shyam Prasad N <sprasad@microsoft.com>
---
 fs/cifs/connect.c |  2 ++
 fs/cifs/fscache.c | 10 ++++++++++
 2 files changed, 12 insertions(+)

diff --git a/fs/cifs/connect.c b/fs/cifs/connect.c
index eee994b0925f..d8822e835cc4 100644
--- a/fs/cifs/connect.c
+++ b/fs/cifs/connect.c
@@ -1562,6 +1562,8 @@ cifs_get_tcp_session(struct smb3_fs_context *ctx,
  /* fscache server cookies are based on primary channel only */
  if (!CIFS_SERVER_IS_CHAN(tcp_ses))
  cifs_fscache_get_client_cookie(tcp_ses);
+ else
+ tcp_ses->fscache = tcp_ses->primary_server->fscache;

  /* queue echo request delayed work */
  queue_delayed_work(cifsiod_wq, &tcp_ses->echo, tcp_ses->echo_interval);
diff --git a/fs/cifs/fscache.c b/fs/cifs/fscache.c
index f4da693760c1..1db3437f3b7d 100644
--- a/fs/cifs/fscache.c
+++ b/fs/cifs/fscache.c
@@ -24,6 +24,7 @@ struct cifs_server_key {
  struct in_addr ipv4_addr;
  struct in6_addr ipv6_addr;
  };
+ __u64 conn_id;
 } __packed;

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

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

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

  server->fscache =
  fscache_acquire_cookie(cifs_fscache_netfs.primary_index,

             reply	other threads:[~2021-12-03  9:28 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-12-03  9:28 Shyam Prasad N [this message]
2021-12-03 18:41 ` [PATCH] cifs: add server conn_id to fscache client cookie Steve French

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANT5p=pqb7MmFe+kQU67Eytm98tZB1ztr0d5Rwq44oxAq81+Dw@mail.gmail.com' \
    --to=nspmangalore@gmail.com \
    --cc=dhowells@redhat.com \
    --cc=jlayton@redhat.com \
    --cc=linux-cachefs@redhat.com \
    --cc=linux-cifs@vger.kernel.org \
    --cc=pc@cjr.nz \
    --cc=smfrench@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.