1 From: Suresh Jayaraman <sjayaraman-l3A5Bk7waGM@public.gmane.org>
2 Subject: [RFC][PATCH 05/10] cifs: define superblock-level cache index objects and register them
3 Date: Tue, 22 Jun 2010 20:53:26 +0530
5 Message-ID: <1277220206-3559-1-git-send-email-sjayaraman@suse.de>
7 Cc: 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>
9 To: Steve French <smfrench-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
10 X-From: linux-cifs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org Tue Jun 22 17:45:50 2010
11 Return-path: <linux-cifs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
12 Envelope-to: glkc-linux-cifs-1dZseelyfdZg9hUCZPvPmw@public.gmane.org
13 Received: 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>)
17 for glkc-linux-cifs-1dZseelyfdZg9hUCZPvPmw@public.gmane.org; Tue, 22 Jun 2010 17:45:50 +0200
18 Received: (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
21 Received: 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
26 Received: 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
28 X-Mailer: git-send-email 1.6.4.2
30 Sender: linux-cifs-owner-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
32 List-ID: <linux-cifs.vger.kernel.org>
33 X-Mailing-List: linux-cifs-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
34 Archived-At: <http://permalink.gmane.org/gmane.linux.kernel/1001766>
36 Define superblock-level cache index objects (managed by cifsTconInfo structs).
37 Each superblock object is created in a server-level index object and in itself
38 an index into which inode-level objects are inserted.
40 Currently, the superblock objects are keyed by sharename.
42 Signed-off-by: Suresh Jayaraman <sjayaraman-l3A5Bk7waGM@public.gmane.org>
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(+)
51 Index: 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,
60 +static char *extract_sharename(const char *treename)
66 + /* skip double chars at the beginning */
69 + /* share name is always preceded by '\\' now */
70 + delim = strchr(src, '\\');
72 + return ERR_PTR(-EINVAL);
74 + len = strlen(delim);
76 + /* caller has to free the memory */
77 + dst = kstrndup(delim, len, GFP_KERNEL);
79 + return ERR_PTR(-ENOMEM);
85 + * Superblock object currently keyed by share name
87 +static uint16_t cifs_super_get_key(const void *cookie_netfs_data, void *buffer,
90 + const struct cifsTconInfo *tcon = cookie_netfs_data;
94 + sharename = extract_sharename(tcon->treeName);
95 + if (IS_ERR(sharename)) {
96 + cFYI(1, "CIFS: couldn't extract sharename\n");
101 + len = strlen(sharename);
105 + memcpy(buffer, sharename, len);
113 + * Superblock object for FS-Cache
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,
121 Index: 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 */
132 /* BB add field for back pointer to sb struct(s)? */
135 Index: 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);
143 + cifs_fscache_release_super_cookie(tcon);
146 CIFSSMBTDis(xid, tcon);
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;
152 + cifs_fscache_get_super_cookie(tcon);
154 write_lock(&cifs_tcp_ses_lock);
155 list_add(&tcon->tcon_list, &ses->tcon_list);
156 write_unlock(&cifs_tcp_ses_lock);
157 Index: 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;
165 +void cifs_fscache_get_super_cookie(struct cifsTconInfo *tcon)
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);
174 +void cifs_fscache_release_super_cookie(struct cifsTconInfo *tcon)
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;
182 Index: 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
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;
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
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 *);
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) {}
206 cifs_fscache_get_client_cookie(struct TCP_Server_Info *server); {}
207 +static inline void cifs_fscache_get_super_cookie(struct cifsTconInfo *tcon) {}
209 +cifs_fscache_release_super_cookie(struct cifsTconInfo *tcon) {}
211 #endif /* CONFIG_CIFS_FSCACHE */