1 /* NFS FS-Cache index structure definition
3 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
12 #include <linux/init.h>
13 #include <linux/kernel.h>
14 #include <linux/sched.h>
16 #include <linux/nfs_fs.h>
17 #include <linux/nfs_fs_sb.h>
18 #include <linux/in6.h>
19 #include <linux/iversion.h>
24 #define NFSDBG_FACILITY NFSDBG_FSCACHE
27 * Define the NFS filesystem for FS-Cache. Upon registration FS-Cache sticks
28 * the cookie for the top-level index object for NFS into here. The top-level
29 * index can than have other cache objects inserted into it.
31 struct fscache_netfs nfs_fscache_netfs
= {
37 * Register NFS for caching
39 int nfs_fscache_register(void)
41 return fscache_register_netfs(&nfs_fscache_netfs
);
45 * Unregister NFS for caching
47 void nfs_fscache_unregister(void)
49 fscache_unregister_netfs(&nfs_fscache_netfs
);
53 * Define the server object for FS-Cache. This is used to describe a server
54 * object to fscache_acquire_cookie(). It is keyed by the NFS protocol and
55 * server address parameters.
57 const struct fscache_cookie_def nfs_fscache_server_index_def
= {
59 .type
= FSCACHE_COOKIE_TYPE_INDEX
,
63 * Define the superblock object for FS-Cache. This is used to describe a
64 * superblock object to fscache_acquire_cookie(). It is keyed by all the NFS
65 * parameters that might cause a separate superblock.
67 const struct fscache_cookie_def nfs_fscache_super_index_def
= {
69 .type
= FSCACHE_COOKIE_TYPE_INDEX
,
73 * Consult the netfs about the state of an object
74 * - This function can be absent if the index carries no state data
75 * - The netfs data from the cookie being used as the target is
76 * presented, as is the auxiliary data
79 enum fscache_checkaux
nfs_fscache_inode_check_aux(void *cookie_netfs_data
,
84 struct nfs_fscache_inode_auxdata auxdata
;
85 struct nfs_inode
*nfsi
= cookie_netfs_data
;
87 if (datalen
!= sizeof(auxdata
))
88 return FSCACHE_CHECKAUX_OBSOLETE
;
90 memset(&auxdata
, 0, sizeof(auxdata
));
91 auxdata
.mtime_sec
= nfsi
->vfs_inode
.i_mtime
.tv_sec
;
92 auxdata
.mtime_nsec
= nfsi
->vfs_inode
.i_mtime
.tv_nsec
;
93 auxdata
.ctime_sec
= nfsi
->vfs_inode
.i_ctime
.tv_sec
;
94 auxdata
.ctime_nsec
= nfsi
->vfs_inode
.i_ctime
.tv_nsec
;
96 if (NFS_SERVER(&nfsi
->vfs_inode
)->nfs_client
->rpc_ops
->version
== 4)
97 auxdata
.change_attr
= inode_peek_iversion_raw(&nfsi
->vfs_inode
);
99 if (memcmp(data
, &auxdata
, datalen
) != 0)
100 return FSCACHE_CHECKAUX_OBSOLETE
;
102 return FSCACHE_CHECKAUX_OKAY
;
106 * Get an extra reference on a read context.
107 * - This function can be absent if the completion function doesn't require a
109 * - The read context is passed back to NFS in the event that a data read on the
110 * cache fails with EIO - in which case the server must be contacted to
111 * retrieve the data, which requires the read context for security.
113 static void nfs_fh_get_context(void *cookie_netfs_data
, void *context
)
115 get_nfs_open_context(context
);
119 * Release an extra reference on a read context.
120 * - This function can be absent if the completion function doesn't require a
123 static void nfs_fh_put_context(void *cookie_netfs_data
, void *context
)
126 put_nfs_open_context(context
);
130 * Define the inode object for FS-Cache. This is used to describe an inode
131 * object to fscache_acquire_cookie(). It is keyed by the NFS file handle for
134 * Coherency is managed by comparing the copies of i_size, i_mtime and i_ctime
135 * held in the cache auxiliary data for the data storage object with those in
136 * the inode struct in memory.
138 const struct fscache_cookie_def nfs_fscache_inode_object_def
= {
140 .type
= FSCACHE_COOKIE_TYPE_DATAFILE
,
141 .check_aux
= nfs_fscache_inode_check_aux
,
142 .get_context
= nfs_fh_get_context
,
143 .put_context
= nfs_fh_put_context
,