Skip to contentSkip to conversation

cifs: define server-level cache index objects and register them with FS-Cache

RFC PATCH In review Suresh Jayaraman 3 participants 4 messages Jun 22, 2010 – Jun 23, 2010 1 message not in the archive

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

RFC PATCH 4/10 cifs: define server-level cache index objects and register them with FS-Cache

Define server-level cache index objects (as managed by TCP_ServerInfo structs). Each server object is created in the CIFS top-level index object and is itself an index into which superblock-level objects are inserted.

Currently, the server objects are keyed by hostname.

---
 fs/cifs/Makefile   |    2 +-
 fs/cifs/cache.c    |   25 +++++++++++++++++++++++++
 fs/cifs/cifsglob.h |    3 +++
 fs/cifs/connect.c  |    4 ++++
 fs/cifs/fscache.c  |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/cifs/fscache.h  |   12 ++++++++++++
 6 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 fs/cifs/fscache.c
fs/cifs/Makefile +1 -1
Index: cifs-2.6/fs/cifs/Makefile
===================================================================
@@ -12,4 +12,4 @@ cifs-$(CONFIG_CIFS_UPCALL) += cifs_spneg
 
 cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o
 
-cifs-$(CONFIG_CIFS_FSCACHE) += cache.o
+cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o
fs/cifs/cache.c +25 -0
Index: cifs-2.6/fs/cifs/cache.c
===================================================================
@@ -51,3 +51,28 @@ void cifs_fscache_unregister(void)
 	fscache_unregister_netfs(&cifs_fscache_netfs);
 }
 
+/*
+ * Server object currently keyed by hostname
+ */
+static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
+				   void *buffer, uint16_t maxbuf)
+{
+	const struct TCP_Server_Info *server = cookie_netfs_data;
+	uint16_t len = strnlen(server->hostname, sizeof(server->hostname));
+
+	if (len > maxbuf)
+		return 0;
+
+	memcpy(buffer, server->hostname, len);
+
+	return len;
+}
+
+/*
+ * Server object for FS-Cache
+ */
+const struct fscache_cookie_def cifs_fscache_server_index_def = {
+	.name = "CIFS.server",
+	.type = FSCACHE_COOKIE_TYPE_INDEX,
+	.get_key = cifs_server_get_key,
+};
fs/cifs/cifsglob.h +3 -0
Index: cifs-2.6/fs/cifs/cifsglob.h
===================================================================
@@ -193,6 +193,9 @@ struct TCP_Server_Info {
 	bool	sec_mskerberos;		/* supports legacy MS Kerberos */
 	bool	sec_kerberosu2u;	/* supports U2U Kerberos */
 	bool	sec_ntlmssp;		/* supports NTLMSSP */
+#ifdef CONFIG_CIFS_FSCACHE
+	struct fscache_cookie   *fscache; /* client index cache cookie */
+#endif
 };
 
 /*
fs/cifs/connect.c +4 -0
Index: cifs-2.6/fs/cifs/connect.c
===================================================================
@@ -48,6 +48,7 @@
 #include "nterr.h"
 #include "rfc1002pdu.h"
 #include "cn_cifs.h"
+#include "fscache.h"
 
 #define CIFS_PORT 445
 #define RFC1001_PORT 139
@@ -1453,6 +1454,8 @@ cifs_put_tcp_session(struct TCP_Server_I
 		return;
 	}
 
+	cifs_fscache_release_client_cookie(server);
+
 	list_del_init(&server->tcp_ses_list);
 	write_unlock(&cifs_tcp_ses_lock);
 
@@ -1572,6 +1575,7 @@ cifs_get_tcp_session(struct smb_vol *vol
 		goto out_err;
 	}
 
+	cifs_fscache_get_client_cookie(tcp_ses);
 	/* thread spawned, put it on the list */
 	write_lock(&cifs_tcp_ses_lock);
 	list_add(&tcp_ses->tcp_ses_list, &cifs_tcp_ses_list);
fs/cifs/fscache.c new file +47 -0

47 lines not on this page · raw message

fs/cifs/fscache.h +12 -0
Index: cifs-2.6/fs/cifs/fscache.h
===================================================================
@@ -27,14 +27,26 @@
 #ifdef CONFIG_CIFS_FSCACHE
 
 extern struct fscache_netfs cifs_fscache_netfs;
+extern const struct fscache_cookie_def cifs_fscache_server_index_def;
 
 extern int cifs_fscache_register(void);
 extern void cifs_fscache_unregister(void);
 
+/*
+ * fscache.c
+ */
+extern void cifs_fscache_get_client_cookie(struct TCP_Server_Info *);
+extern void cifs_fscache_release_client_cookie(struct TCP_Server_Info *);
+
 #else /* CONFIG_CIFS_FSCACHE */
 static inline int cifs_fscache_register(void) { return 0; }
 static inline void cifs_fscache_unregister(void) {}
 
+static inline void
+cifs_fscache_get_client_cookie(struct TCP_Server_Info *server) {}
+static inline void
+cifs_fscache_get_client_cookie(struct TCP_Server_Info *server); {}
+
 #endif /* CONFIG_CIFS_FSCACHE */
 
 #endif /* _CIFS_FSCACHE_H */
#1 lore raw
Quoted 34 lines · On Tue, 22 Jun 2010 20:53:18 +0530 Suresh Jayaraman <[email protected]> wrote:

Define server-level cache index objects (as managed by TCP_ServerInfo structs). Each server object is created in the CIFS top-level index object and is itself an index into which superblock-level objects are inserted.

Currently, the server objects are keyed by hostname.

---
 fs/cifs/Makefile   |    2 +-
 fs/cifs/cache.c    |   25 +++++++++++++++++++++++++
 fs/cifs/cifsglob.h |    3 +++
 fs/cifs/connect.c  |    4 ++++
 fs/cifs/fscache.c  |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/cifs/fscache.h  |   12 ++++++++++++
 6 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 fs/cifs/fscache.c

Index: cifs-2.6/fs/cifs/Makefile
===================================================================

fs/cifs/Makefile +1 -1
@@ -12,4 +12,4 @@ cifs-$(CONFIG_CIFS_UPCALL) += cifs_spneg
 
 cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o
 
-cifs-$(CONFIG_CIFS_FSCACHE) += cache.o
+cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o

Index: cifs-2.6/fs/cifs/cache.c
===================================================================

fs/cifs/cache.c +0 -0
@@ -51,3 +51,28 @@ void cifs_fscache_unregister(void)
 	fscache_unregister_netfs(&cifs_fscache_netfs);
 }

fs/cifs/cache.c void cifs_fscache_unregister(void) · line 62

Quoted 10 lines
fs/cifs/cache.c +9 -0
 
+/*
+ * Server object currently keyed by hostname
+ */
+static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
+				   void *buffer, uint16_t maxbuf)
+{
+	const struct TCP_Server_Info *server = cookie_netfs_data;
+	uint16_t len = strnlen(server->hostname, sizeof(server->hostname));
+

Would a tuple of address/family/port be a better choice here? Imagine I mount "foo" and then later mount "foor.bar.baz". If they are the same address and only the UNC differs, then you won't get the benefit of the cache, right?

Quoted 147 lines
fs/cifs/cache.c +16 -0
+	if (len > maxbuf)
+		return 0;
+
+	memcpy(buffer, server->hostname, len);
+
+	return len;
+}
+
+/*
+ * Server object for FS-Cache
+ */
+const struct fscache_cookie_def cifs_fscache_server_index_def = {
+	.name = "CIFS.server",
+	.type = FSCACHE_COOKIE_TYPE_INDEX,
+	.get_key = cifs_server_get_key,
+};

Index: cifs-2.6/fs/cifs/cifsglob.h
===================================================================

fs/cifs/cifsglob.h +3 -0
@@ -193,6 +193,9 @@ struct TCP_Server_Info {
 	bool	sec_mskerberos;		/* supports legacy MS Kerberos */
 	bool	sec_kerberosu2u;	/* supports U2U Kerberos */
 	bool	sec_ntlmssp;		/* supports NTLMSSP */
+#ifdef CONFIG_CIFS_FSCACHE
+	struct fscache_cookie   *fscache; /* client index cache cookie */
+#endif
 };
 
 /*

Index: cifs-2.6/fs/cifs/connect.c
===================================================================

fs/cifs/connect.c +4 -0
@@ -48,6 +48,7 @@
 #include "nterr.h"
 #include "rfc1002pdu.h"
 #include "cn_cifs.h"
+#include "fscache.h"
 
 #define CIFS_PORT 445
 #define RFC1001_PORT 139
@@ -1453,6 +1454,8 @@ cifs_put_tcp_session(struct TCP_Server_I
 		return;
 	}
 
+	cifs_fscache_release_client_cookie(server);
+
 	list_del_init(&server->tcp_ses_list);
 	write_unlock(&cifs_tcp_ses_lock);
 
@@ -1572,6 +1575,7 @@ cifs_get_tcp_session(struct smb_vol *vol
 		goto out_err;
 	}
 
+	cifs_fscache_get_client_cookie(tcp_ses);
 	/* thread spawned, put it on the list */
 	write_lock(&cifs_tcp_ses_lock);
 	list_add(&tcp_ses->tcp_ses_list, &cifs_tcp_ses_list);

Index: cifs-2.6/fs/cifs/fscache.c
===================================================================

fs/cifs/fscache.c new file +47 -0
@@ -0,0 +1,47 @@
+/*
+ *   fs/cifs/fscache.c - CIFS filesystem cache interface
+ *
+ *   Copyright (c) 2010 Novell, Inc.
+ *   Authors(s): Suresh Jayaraman ([email protected]>
+ *
+ *   This library is free software; you can redistribute it and/or modify
+ *   it under the terms of the GNU Lesser General Public License as published
+ *   by the Free Software Foundation; either version 2.1 of the License, or
+ *   (at your option) any later version.
+ *
+ *   This library is distributed in the hope that it will be useful,
+ *   but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ *   the GNU Lesser General Public License for more details.
+ *
+ *   You should have received a copy of the GNU Lesser General Public License
+ *   along with this library; if not, write to the Free Software
+ *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <linux/init.h>
+#include <linux/kernel.h>
+#include <linux/sched.h>
+#include <linux/mm.h>
+#include <linux/in6.h>
+
+#include "fscache.h"
+#include "cifsglob.h"
+#include "cifs_debug.h"
+
+void cifs_fscache_get_client_cookie(struct TCP_Server_Info *server)
+{
+	server->fscache =
+		fscache_acquire_cookie(cifs_fscache_netfs.primary_index,
+				&cifs_fscache_server_index_def, server);
+	cFYI(1, "CIFS: get client cookie (0x%p/0x%p)\n",
+				server, server->fscache);
+}
+
+void cifs_fscache_release_client_cookie(struct TCP_Server_Info *server)
+{
+	cFYI(1, "CIFS: release client cookie (0x%p/0x%p)\n",
+				server, server->fscache);
+	fscache_relinquish_cookie(server->fscache, 0);
+	server->fscache = NULL;
+}
+

Index: cifs-2.6/fs/cifs/fscache.h
===================================================================

fs/cifs/fscache.h +12 -1
@@ -27,14 +27,26 @@
 #ifdef CONFIG_CIFS_FSCACHE
 
 extern struct fscache_netfs cifs_fscache_netfs;
+extern const struct fscache_cookie_def cifs_fscache_server_index_def;
 
 extern int cifs_fscache_register(void);
 extern void cifs_fscache_unregister(void);
 
+/*
+ * fscache.c
+ */
+extern void cifs_fscache_get_client_cookie(struct TCP_Server_Info *);
+extern void cifs_fscache_release_client_cookie(struct TCP_Server_Info *);
+
 #else /* CONFIG_CIFS_FSCACHE */
 static inline int cifs_fscache_register(void) { return 0; }
 static inline void cifs_fscache_unregister(void) {}
 
+static inline void
+cifs_fscache_get_client_cookie(struct TCP_Server_Info *server) {}
+static inline void
+cifs_fscache_get_client_cookie(struct TCP_Server_Info *server); {}
+
 #endif /* CONFIG_CIFS_FSCACHE */
 
 #endif /* _CIFS_FSCACHE_H */
--

To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Jeff Layton <[email protected]>

A message that is not in the archive (sent off-list or not yet received): 20100622175214.4c56234f-4QP7MXygkU+dMjc06nkz3ljfA9RmPOcC@public.gmane.org

#3 lore raw
Quoted 38 lines · Jeff Layton
Quoted 35 lines · On Tue, 22 Jun 2010 20:53:18 +0530 Suresh Jayaraman…

Define server-level cache index objects (as managed by TCP_ServerInfo structs). Each server object is created in the CIFS top-level index object and is itself an index into which superblock-level objects are inserted.

Currently, the server objects are keyed by hostname.

---
 fs/cifs/Makefile   |    2 +-
 fs/cifs/cache.c    |   25 +++++++++++++++++++++++++
 fs/cifs/cifsglob.h |    3 +++
 fs/cifs/connect.c  |    4 ++++
 fs/cifs/fscache.c  |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 fs/cifs/fscache.h  |   12 ++++++++++++
 6 files changed, 92 insertions(+), 1 deletion(-)
 create mode 100644 fs/cifs/fscache.c

Index: cifs-2.6/fs/cifs/Makefile
===================================================================

fs/cifs/Makefile +1 -1
@@ -12,4 +12,4 @@ cifs-$(CONFIG_CIFS_UPCALL) += cifs_spneg
 
 cifs-$(CONFIG_CIFS_DFS_UPCALL) += dns_resolve.o cifs_dfs_ref.o
 
-cifs-$(CONFIG_CIFS_FSCACHE) += cache.o
+cifs-$(CONFIG_CIFS_FSCACHE) += fscache.o cache.o

Index: cifs-2.6/fs/cifs/cache.c
===================================================================

fs/cifs/cache.c +0 -0
@@ -51,3 +51,28 @@ void cifs_fscache_unregister(void)
 	fscache_unregister_netfs(&cifs_fscache_netfs);
 }
 
Quoted 15 lines

fs/cifs/cache.c void cifs_fscache_unregister(void) · line 62

Quoted 9 lines
fs/cifs/cache.c +9 -0
+/*
+ * Server object currently keyed by hostname
+ */
+static uint16_t cifs_server_get_key(const void *cookie_netfs_data,
+				   void *buffer, uint16_t maxbuf)
+{
+	const struct TCP_Server_Info *server = cookie_netfs_data;
+	uint16_t len = strnlen(server->hostname, sizeof(server->hostname));
+

Would a tuple of address/family/port be a better choice here? Imagine I mount "foo" and then later mount "foor.bar.baz". If they are the same address and only the UNC differs, then you won't get the benefit of the cache, right?

Good point. I'll fix it up when I do a respin.

Thanks,

Signature · 1 line
Suresh Jayaraman
#4 lore raw
In reply to Suresh Jayaraman
Quoted 7 lines · Suresh Jayaraman

Define server-level cache index objects (as managed by TCP_ServerInfo structs). Each server object is created in the CIFS top-level index object and is itself an index into which superblock-level objects are inserted.

Currently, the server objects are keyed by hostname.

Looks reasonable, apart from the index key. I agree with Jeff that you probably want {address,port,family} rather than a hostname.

David