1From: Suresh Jayaraman <sjayaraman-l3A5Bk7waGM@public.gmane.org>
2Subject: [RFC][PATCH 05/10] cifs: define superblock-level cache index objects and register them
3Date: Tue, 22 Jun 2010 20:53:26 +0530
4Lines: 177
5Message-ID: <1277220206-3559-1-git-send-email-sjayaraman@suse.de>
6References: <yes>
7Cc: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, linux-fsdevel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
8	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org, David Howells <dhowells-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
9To: Steve French <smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
10X-From: linux-cifs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Tue Jun 22 17:45:50 2010
11Return-path: <linux-cifs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
12Envelope-to: glkc-linux-cifs-1dZseelyfdZg9hUCZPvPmw@public.gmane.org
13Received: from vger.kernel.org ([209.132.180.67])
14	by lo.gmane.org with esmtp (Exim 4.69)
15	(envelope-from <linux-cifs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>)
16	id 1OR5fZ-0000Vj-Mj
17	for glkc-linux-cifs-1dZseelyfdZg9hUCZPvPmw@public.gmane.org; Tue, 22 Jun 2010 17:45:50 +0200
18Received: (majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org) by vger.kernel.org via listexpand
19	id S1752511Ab0FVPpJ (ORCPT <rfc822;glkc-linux-cifs@m.gmane.org>);
20	Tue, 22 Jun 2010 11:45:09 -0400
21Received: from victor.provo.novell.com ([137.65.250.26]:56189 "EHLO
22	victor.provo.novell.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org
23	with ESMTP id S1752441Ab0FVPoA (ORCPT
24	<rfc822;groupwise-SJayaraman-Et1tbQHTxzrQT0dZR+AlfA@public.gmane.org:0:0>);
25	Tue, 22 Jun 2010 11:44:00 -0400
26Received: from localhost (prv-ext-foundry1int.gns.novell.com [137.65.251.240])
27	by victor.provo.novell.com with ESMTP; Tue, 22 Jun 2010 09:23:29 -0600
28X-Mailer: git-send-email 1.6.4.2
29In-Reply-To: <yes>
30Sender: linux-cifs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
31Precedence: bulk
32List-ID: <linux-cifs.vger.kernel.org>
33X-Mailing-List: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
34Archived-At: <http://permalink.gmane.org/gmane.linux.kernel/1001766>
35
36Define superblock-level cache index objects (managed by cifsTconInfo structs).
37Each superblock object is created in a server-level index object and in itself
38an index into which inode-level objects are inserted.
39
40Currently, the superblock objects are keyed by sharename.
41
42Signed-off-by: Suresh Jayaraman <sjayaraman-l3A5Bk7waGM@public.gmane.org>
43---
44 fs/cifs/cache.c    |   62 +++++++++++++++++++++++++++++++++++++++++++++++++++++
45 fs/cifs/cifsglob.h |    3 ++
46 fs/cifs/connect.c  |    4 +++
47 fs/cifs/fscache.c  |   17 ++++++++++++++
48 fs/cifs/fscache.h  |    6 +++++
49 5 files changed, 92 insertions(+)
50
51Index: cifs-2.6/fs/cifs/cache.c
52===================================================================
53--- cifs-2.6.orig/fs/cifs/cache.c
54+++ cifs-2.6/fs/cifs/cache.c
55@@ -76,3 +76,65 @@ const struct fscache_cookie_def cifs_fsc
56 	.type = FSCACHE_COOKIE_TYPE_INDEX,
57 	.get_key = cifs_server_get_key,
58 };
59+
60+static char *extract_sharename(const char *treename)
61+{
62+	const char *src;
63+	char *delim, *dst;
64+	int len;
65+
66+	/* skip double chars at the beginning */
67+	src = treename + 2;
68+
69+	/* share name is always preceded by '\\' now */
70+	delim = strchr(src, '\\');
71+	if (!delim)
72+		return ERR_PTR(-EINVAL);
73+	delim++;
74+	len = strlen(delim);
75+
76+	/* caller has to free the memory */
77+	dst = kstrndup(delim, len, GFP_KERNEL);
78+	if (!dst)
79+		return ERR_PTR(-ENOMEM);
80+
81+	return dst;
82+}
83+
84+/*
85+ * Superblock object currently keyed by share name
86+ */
87+static uint16_t cifs_super_get_key(const void *cookie_netfs_data, void *buffer,
88+				   uint16_t maxbuf)
89+{
90+	const struct cifsTconInfo *tcon = cookie_netfs_data;
91+	char *sharename;
92+	uint16_t len;
93+
94+	sharename = extract_sharename(tcon->treeName);
95+	if (IS_ERR(sharename)) {
96+		cFYI(1, "CIFS: couldn't extract sharename\n");
97+		sharename = NULL;
98+		return 0;
99+	}
100+
101+	len = strlen(sharename);
102+	if (len > maxbuf)
103+		return 0;
104+
105+	memcpy(buffer, sharename, len);
106+
107+	kfree(sharename);
108+
109+	return len;
110+}
111+
112+/*
113+ * Superblock object for FS-Cache
114+ */
115+const struct fscache_cookie_def cifs_fscache_super_index_def = {
116+	.name = "CIFS.super",
117+	.type = FSCACHE_COOKIE_TYPE_INDEX,
118+	.get_key = cifs_super_get_key,
119+};
120+
121Index: cifs-2.6/fs/cifs/cifsglob.h
122===================================================================
123--- cifs-2.6.orig/fs/cifs/cifsglob.h
124+++ cifs-2.6/fs/cifs/cifsglob.h
125@@ -317,6 +317,9 @@ struct cifsTconInfo {
126 	bool local_lease:1; /* check leases (only) on local system not remote */
127 	bool broken_posix_open; /* e.g. Samba server versions < 3.3.2, 3.2.9 */
128 	bool need_reconnect:1; /* connection reset, tid now invalid */
129+#ifdef CONFIG_CIFS_FSCACHE
130+	struct fscache_cookie *fscache; /* cookie for share */
131+#endif
132 	/* BB add field for back pointer to sb struct(s)? */
133 };
134
135Index: cifs-2.6/fs/cifs/connect.c
136===================================================================
137--- cifs-2.6.orig/fs/cifs/connect.c
138+++ cifs-2.6/fs/cifs/connect.c
139@@ -1773,6 +1773,8 @@ cifs_put_tcon(struct cifsTconInfo *tcon)
140 	list_del_init(&tcon->tcon_list);
141 	write_unlock(&cifs_tcp_ses_lock);
142
143+	cifs_fscache_release_super_cookie(tcon);
144+
145 	xid = GetXid();
146 	CIFSSMBTDis(xid, tcon);
147 	_FreeXid(xid);
148@@ -1843,6 +1845,8 @@ cifs_get_tcon(struct cifsSesInfo *ses, s
149 	tcon->nocase = volume_info->nocase;
150 	tcon->local_lease = volume_info->local_lease;
151
152+	cifs_fscache_get_super_cookie(tcon);
153+
154 	write_lock(&cifs_tcp_ses_lock);
155 	list_add(&tcon->tcon_list, &ses->tcon_list);
156 	write_unlock(&cifs_tcp_ses_lock);
157Index: cifs-2.6/fs/cifs/fscache.c
158===================================================================
159--- cifs-2.6.orig/fs/cifs/fscache.c
160+++ cifs-2.6/fs/cifs/fscache.c
161@@ -45,3 +45,20 @@ void cifs_fscache_release_client_cookie(
162 	server->fscache = NULL;
163 }
164
165+void cifs_fscache_get_super_cookie(struct cifsTconInfo *tcon)
166+{
167+	tcon->fscache =
168+		fscache_acquire_cookie(tcon->ses->server->fscache,
169+				&cifs_fscache_super_index_def, tcon);
170+	cFYI(1, "CIFS: get superblock cookie (0x%p/0x%p)\n",
171+				tcon, tcon->fscache);
172+}
173+
174+void cifs_fscache_release_super_cookie(struct cifsTconInfo *tcon)
175+{
176+	cFYI(1, "CIFS: releasing superblock cookie (0x%p/0x%p)\n",
177+			tcon, tcon->fscache);
178+	fscache_relinquish_cookie(tcon->fscache, 0);
179+	tcon->fscache = NULL;
180+}
181+
182Index: cifs-2.6/fs/cifs/fscache.h
183===================================================================
184--- cifs-2.6.orig/fs/cifs/fscache.h
185+++ cifs-2.6/fs/cifs/fscache.h
186@@ -28,6 +28,7 @@
187
188 extern struct fscache_netfs cifs_fscache_netfs;
189 extern const struct fscache_cookie_def cifs_fscache_server_index_def;
190+extern const struct fscache_cookie_def cifs_fscache_super_index_def;
191
192 extern int cifs_fscache_register(void);
193 extern void cifs_fscache_unregister(void);
194@@ -37,6 +38,8 @@ extern void cifs_fscache_unregister(void
195  */
196 extern void cifs_fscache_get_client_cookie(struct TCP_Server_Info *);
197 extern void cifs_fscache_release_client_cookie(struct TCP_Server_Info *);
198+extern void cifs_fscache_get_super_cookie(struct cifsTconInfo *);
199+extern void cifs_fscache_release_super_cookie(struct cifsTconInfo *);
200
201 #else /* CONFIG_CIFS_FSCACHE */
202 static inline int cifs_fscache_register(void) { return 0; }
203@@ -46,6 +49,9 @@ static inline void
204 cifs_fscache_get_client_cookie(struct TCP_Server_Info *server) {}
205 static inline void
206 cifs_fscache_get_client_cookie(struct TCP_Server_Info *server); {}
207+static inline void cifs_fscache_get_super_cookie(struct cifsTconInfo *tcon) {}
208+static inline void
209+cifs_fscache_release_super_cookie(struct cifsTconInfo *tcon) {}
210
211 #endif /* CONFIG_CIFS_FSCACHE */
212
213
214
215