1
2
3
4
5
6
7
8
9
10
11
12#include <linux/init.h>
13#include <linux/kernel.h>
14#include <linux/sched.h>
15#include <linux/mm.h>
16#include <linux/nfs_fs.h>
17#include <linux/nfs_fs_sb.h>
18#include <linux/in6.h>
19#include <linux/iversion.h>
20
21#include "internal.h"
22#include "fscache.h"
23
24#define NFSDBG_FACILITY NFSDBG_FSCACHE
25
26
27
28
29
30
31struct fscache_netfs nfs_fscache_netfs = {
32 .name = "nfs",
33 .version = 0,
34};
35
36
37
38
39int nfs_fscache_register(void)
40{
41 return fscache_register_netfs(&nfs_fscache_netfs);
42}
43
44
45
46
47void nfs_fscache_unregister(void)
48{
49 fscache_unregister_netfs(&nfs_fscache_netfs);
50}
51
52
53
54
55
56
57const struct fscache_cookie_def nfs_fscache_server_index_def = {
58 .name = "NFS.server",
59 .type = FSCACHE_COOKIE_TYPE_INDEX,
60};
61
62
63
64
65
66
67const struct fscache_cookie_def nfs_fscache_super_index_def = {
68 .name = "NFS.super",
69 .type = FSCACHE_COOKIE_TYPE_INDEX,
70};
71
72
73
74
75
76
77
78static
79enum fscache_checkaux nfs_fscache_inode_check_aux(void *cookie_netfs_data,
80 const void *data,
81 uint16_t datalen,
82 loff_t object_size)
83{
84 struct nfs_fscache_inode_auxdata auxdata;
85 struct nfs_inode *nfsi = cookie_netfs_data;
86
87 if (datalen != sizeof(auxdata))
88 return FSCACHE_CHECKAUX_OBSOLETE;
89
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;
95
96 if (NFS_SERVER(&nfsi->vfs_inode)->nfs_client->rpc_ops->version == 4)
97 auxdata.change_attr = inode_peek_iversion_raw(&nfsi->vfs_inode);
98
99 if (memcmp(data, &auxdata, datalen) != 0)
100 return FSCACHE_CHECKAUX_OBSOLETE;
101
102 return FSCACHE_CHECKAUX_OKAY;
103}
104
105
106
107
108
109
110
111
112
113static void nfs_fh_get_context(void *cookie_netfs_data, void *context)
114{
115 get_nfs_open_context(context);
116}
117
118
119
120
121
122
123static void nfs_fh_put_context(void *cookie_netfs_data, void *context)
124{
125 if (context)
126 put_nfs_open_context(context);
127}
128
129
130
131
132
133
134
135
136
137
138const struct fscache_cookie_def nfs_fscache_inode_object_def = {
139 .name = "NFS.fh",
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,
144};
145