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