Commit | Line | Data |
---|---|---|
b4d0d230 | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
8ec442ae DH |
2 | /* NFS filesystem cache interface definitions |
3 | * | |
4 | * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved. | |
5 | * Written by David Howells (dhowells@redhat.com) | |
8ec442ae DH |
6 | */ |
7 | ||
8 | #ifndef _NFS_FSCACHE_H | |
9 | #define _NFS_FSCACHE_H | |
10 | ||
d7bdba1c | 11 | #include <linux/swap.h> |
8ec442ae DH |
12 | #include <linux/nfs_fs.h> |
13 | #include <linux/nfs_mount.h> | |
14 | #include <linux/nfs4_mount.h> | |
15 | #include <linux/fscache.h> | |
a6b5a28e | 16 | #include <linux/iversion.h> |
8ec442ae DH |
17 | |
18 | #ifdef CONFIG_NFS_FSCACHE | |
19 | ||
402cb8dd DH |
20 | /* |
21 | * Definition of the auxiliary data attached to NFS inode storage objects | |
22 | * within the cache. | |
23 | * | |
24 | * The contents of this struct are recorded in the on-disk local cache in the | |
25 | * auxiliary data attached to the data storage object backing an inode. This | |
26 | * permits coherency to be managed when a new inode binds to an already extant | |
27 | * cache object. | |
28 | */ | |
29 | struct nfs_fscache_inode_auxdata { | |
6e31ded6 AB |
30 | s64 mtime_sec; |
31 | s64 mtime_nsec; | |
32 | s64 ctime_sec; | |
33 | s64 ctime_nsec; | |
34 | u64 change_attr; | |
402cb8dd DH |
35 | }; |
36 | ||
14727281 DH |
37 | /* |
38 | * fscache.c | |
39 | */ | |
a6b5a28e | 40 | extern int nfs_fscache_get_super_cookie(struct super_block *, const char *, int); |
08734048 DH |
41 | extern void nfs_fscache_release_super_cookie(struct super_block *); |
42 | ||
f1fe29b4 DH |
43 | extern void nfs_fscache_init_inode(struct inode *); |
44 | extern void nfs_fscache_clear_inode(struct inode *); | |
45 | extern void nfs_fscache_open_file(struct inode *, struct file *); | |
a6b5a28e | 46 | extern void nfs_fscache_release_file(struct inode *, struct file *); |
ef79c097 | 47 | |
fc1c5abf DW |
48 | extern int __nfs_fscache_read_page(struct inode *, struct page *); |
49 | extern void __nfs_fscache_write_page(struct inode *, struct page *); | |
9a9fc1c0 | 50 | |
a6b5a28e | 51 | static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp) |
545db45f | 52 | { |
a6b5a28e | 53 | if (PageFsCache(page)) { |
d7bdba1c | 54 | if (current_is_kswapd() || !(gfp & __GFP_FS)) |
a6b5a28e DW |
55 | return false; |
56 | wait_on_page_fscache(page); | |
57 | fscache_note_page_release(nfs_i_fscache(page->mapping->host)); | |
58 | nfs_inc_fscache_stats(page->mapping->host, | |
59 | NFSIOS_FSCACHE_PAGES_UNCACHED); | |
60 | } | |
61 | return true; | |
545db45f DH |
62 | } |
63 | ||
9a9fc1c0 DH |
64 | /* |
65 | * Retrieve a page from an inode data storage object. | |
66 | */ | |
fc1c5abf | 67 | static inline int nfs_fscache_read_page(struct inode *inode, struct page *page) |
9a9fc1c0 | 68 | { |
fc1c5abf DW |
69 | if (nfs_i_fscache(inode)) |
70 | return __nfs_fscache_read_page(inode, page); | |
9a9fc1c0 DH |
71 | return -ENOBUFS; |
72 | } | |
545db45f | 73 | |
7f8e05f6 DH |
74 | /* |
75 | * Store a page newly fetched from the server in an inode data storage object | |
76 | * in the cache. | |
77 | */ | |
fc1c5abf | 78 | static inline void nfs_fscache_write_page(struct inode *inode, |
16f2f4e6 | 79 | struct page *page) |
7f8e05f6 | 80 | { |
fc1c5abf DW |
81 | if (nfs_i_fscache(inode)) |
82 | __nfs_fscache_write_page(inode, page); | |
7f8e05f6 DH |
83 | } |
84 | ||
a6b5a28e | 85 | static inline void nfs_fscache_update_auxdata(struct nfs_fscache_inode_auxdata *auxdata, |
45f3a70b | 86 | struct inode *inode) |
de242c0b | 87 | { |
a6b5a28e | 88 | memset(auxdata, 0, sizeof(*auxdata)); |
45f3a70b DW |
89 | auxdata->mtime_sec = inode->i_mtime.tv_sec; |
90 | auxdata->mtime_nsec = inode->i_mtime.tv_nsec; | |
91 | auxdata->ctime_sec = inode->i_ctime.tv_sec; | |
92 | auxdata->ctime_nsec = inode->i_ctime.tv_nsec; | |
a6b5a28e | 93 | |
45f3a70b DW |
94 | if (NFS_SERVER(inode)->nfs_client->rpc_ops->version == 4) |
95 | auxdata->change_attr = inode_peek_iversion_raw(inode); | |
de242c0b DH |
96 | } |
97 | ||
98 | /* | |
a6b5a28e | 99 | * Invalidate the contents of fscache for this inode. This will not sleep. |
de242c0b | 100 | */ |
a6b5a28e | 101 | static inline void nfs_fscache_invalidate(struct inode *inode, int flags) |
de242c0b | 102 | { |
a6b5a28e DW |
103 | struct nfs_fscache_inode_auxdata auxdata; |
104 | struct nfs_inode *nfsi = NFS_I(inode); | |
105 | ||
106 | if (nfsi->fscache) { | |
45f3a70b | 107 | nfs_fscache_update_auxdata(&auxdata, inode); |
a6b5a28e | 108 | fscache_invalidate(nfsi->fscache, &auxdata, |
45f3a70b | 109 | i_size_read(inode), flags); |
a6b5a28e | 110 | } |
de242c0b DH |
111 | } |
112 | ||
5d1acff1 DH |
113 | /* |
114 | * indicate the client caching state as readable text | |
115 | */ | |
116 | static inline const char *nfs_server_fscache_state(struct nfs_server *server) | |
117 | { | |
dea1bb35 | 118 | if (server->fscache) |
5d1acff1 DH |
119 | return "yes"; |
120 | return "no "; | |
121 | } | |
122 | ||
8ec442ae | 123 | #else /* CONFIG_NFS_FSCACHE */ |
08734048 DH |
124 | static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {} |
125 | ||
f1fe29b4 DH |
126 | static inline void nfs_fscache_init_inode(struct inode *inode) {} |
127 | static inline void nfs_fscache_clear_inode(struct inode *inode) {} | |
128 | static inline void nfs_fscache_open_file(struct inode *inode, | |
129 | struct file *filp) {} | |
a6b5a28e | 130 | static inline void nfs_fscache_release_file(struct inode *inode, struct file *file) {} |
ef79c097 | 131 | |
545db45f DH |
132 | static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp) |
133 | { | |
134 | return 1; /* True: may release page */ | |
135 | } | |
fc1c5abf | 136 | static inline int nfs_fscache_read_page(struct inode *inode, struct page *page) |
9a9fc1c0 DH |
137 | { |
138 | return -ENOBUFS; | |
139 | } | |
fc1c5abf | 140 | static inline void nfs_fscache_write_page(struct inode *inode, struct page *page) {} |
a6b5a28e | 141 | static inline void nfs_fscache_invalidate(struct inode *inode, int flags) {} |
de242c0b | 142 | |
5d1acff1 DH |
143 | static inline const char *nfs_server_fscache_state(struct nfs_server *server) |
144 | { | |
145 | return "no "; | |
146 | } | |
147 | ||
8ec442ae DH |
148 | #endif /* CONFIG_NFS_FSCACHE */ |
149 | #endif /* _NFS_FSCACHE_H */ |