2 * fs/cifs/cache.c - CIFS filesystem cache index structure definitions
4 * Copyright (c) 2010 Novell, Inc.
5 * Authors(s): Suresh Jayaraman (sjayaraman@suse.de>
7 * This library is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License as published
9 * by the Free Software Foundation; either version 2.1 of the License, or
10 * (at your option) any later version.
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
15 * the GNU Lesser General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with this library; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 #include "cifs_debug.h"
25 * CIFS filesystem definition for FS-Cache
27 struct fscache_netfs cifs_fscache_netfs
= {
33 * Register CIFS for caching with FS-Cache
35 int cifs_fscache_register(void)
37 return fscache_register_netfs(&cifs_fscache_netfs
);
41 * Unregister CIFS for caching
43 void cifs_fscache_unregister(void)
45 fscache_unregister_netfs(&cifs_fscache_netfs
);
49 * Server object for FS-Cache
51 const struct fscache_cookie_def cifs_fscache_server_index_def
= {
52 .name
= "CIFS.server",
53 .type
= FSCACHE_COOKIE_TYPE_INDEX
,
57 * Auxiliary data attached to CIFS superblock within the cache
59 struct cifs_fscache_super_auxdata
{
60 u64 resource_id
; /* unique server resource id */
63 char *extract_sharename(const char *treename
)
69 /* skip double chars at the beginning */
72 /* share name is always preceded by '\\' now */
73 delim
= strchr(src
, '\\');
75 return ERR_PTR(-EINVAL
);
79 /* caller has to free the memory */
80 dst
= kstrndup(delim
, len
, GFP_KERNEL
);
82 return ERR_PTR(-ENOMEM
);
88 fscache_checkaux
cifs_fscache_super_check_aux(void *cookie_netfs_data
,
93 struct cifs_fscache_super_auxdata auxdata
;
94 const struct cifs_tcon
*tcon
= cookie_netfs_data
;
96 if (datalen
!= sizeof(auxdata
))
97 return FSCACHE_CHECKAUX_OBSOLETE
;
99 memset(&auxdata
, 0, sizeof(auxdata
));
100 auxdata
.resource_id
= tcon
->resource_id
;
102 if (memcmp(data
, &auxdata
, datalen
) != 0)
103 return FSCACHE_CHECKAUX_OBSOLETE
;
105 return FSCACHE_CHECKAUX_OKAY
;
109 * Superblock object for FS-Cache
111 const struct fscache_cookie_def cifs_fscache_super_index_def
= {
112 .name
= "CIFS.super",
113 .type
= FSCACHE_COOKIE_TYPE_INDEX
,
114 .check_aux
= cifs_fscache_super_check_aux
,
118 fscache_checkaux
cifs_fscache_inode_check_aux(void *cookie_netfs_data
,
123 struct cifs_fscache_inode_auxdata auxdata
;
124 struct cifsInodeInfo
*cifsi
= cookie_netfs_data
;
126 if (datalen
!= sizeof(auxdata
))
127 return FSCACHE_CHECKAUX_OBSOLETE
;
129 memset(&auxdata
, 0, sizeof(auxdata
));
130 auxdata
.eof
= cifsi
->server_eof
;
131 auxdata
.last_write_time_sec
= cifsi
->vfs_inode
.i_mtime
.tv_sec
;
132 auxdata
.last_change_time_sec
= cifsi
->vfs_inode
.i_ctime
.tv_sec
;
133 auxdata
.last_write_time_nsec
= cifsi
->vfs_inode
.i_mtime
.tv_nsec
;
134 auxdata
.last_change_time_nsec
= cifsi
->vfs_inode
.i_ctime
.tv_nsec
;
136 if (memcmp(data
, &auxdata
, datalen
) != 0)
137 return FSCACHE_CHECKAUX_OBSOLETE
;
139 return FSCACHE_CHECKAUX_OKAY
;
142 const struct fscache_cookie_def cifs_fscache_inode_object_def
= {
143 .name
= "CIFS.uniqueid",
144 .type
= FSCACHE_COOKIE_TYPE_DATAFILE
,
145 .check_aux
= cifs_fscache_inode_check_aux
,