1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 /* NFS filesystem cache interface definitions
4 * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
5 * Written by David Howells (dhowells@redhat.com)
11 #include <linux/swap.h>
12 #include <linux/nfs_fs.h>
13 #include <linux/nfs_mount.h>
14 #include <linux/nfs4_mount.h>
15 #include <linux/fscache.h>
16 #include <linux/iversion.h>
18 #ifdef CONFIG_NFS_FSCACHE
21 * Definition of the auxiliary data attached to NFS inode storage objects
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
29 struct nfs_fscache_inode_auxdata {
40 extern int nfs_fscache_get_super_cookie(struct super_block *, const char *, int);
41 extern void nfs_fscache_release_super_cookie(struct super_block *);
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 *);
46 extern void nfs_fscache_release_file(struct inode *, struct file *);
48 extern int __nfs_readpage_from_fscache(struct inode *, struct page *);
49 extern void __nfs_read_completion_to_fscache(struct nfs_pgio_header *hdr,
51 extern void __nfs_readpage_to_fscache(struct inode *, struct page *);
53 static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp)
55 if (PageFsCache(page)) {
56 if (current_is_kswapd() || !(gfp & __GFP_FS))
58 wait_on_page_fscache(page);
59 fscache_note_page_release(nfs_i_fscache(page->mapping->host));
60 nfs_inc_fscache_stats(page->mapping->host,
61 NFSIOS_FSCACHE_PAGES_UNCACHED);
67 * Retrieve a page from an inode data storage object.
69 static inline int nfs_readpage_from_fscache(struct inode *inode,
72 if (NFS_I(inode)->fscache)
73 return __nfs_readpage_from_fscache(inode, page);
78 * Store a page newly fetched from the server in an inode data storage object
81 static inline void nfs_readpage_to_fscache(struct inode *inode,
84 if (NFS_I(inode)->fscache)
85 __nfs_readpage_to_fscache(inode, page);
88 static inline void nfs_fscache_update_auxdata(struct nfs_fscache_inode_auxdata *auxdata,
89 struct nfs_inode *nfsi)
91 memset(auxdata, 0, sizeof(*auxdata));
92 auxdata->mtime_sec = nfsi->vfs_inode.i_mtime.tv_sec;
93 auxdata->mtime_nsec = nfsi->vfs_inode.i_mtime.tv_nsec;
94 auxdata->ctime_sec = nfsi->vfs_inode.i_ctime.tv_sec;
95 auxdata->ctime_nsec = nfsi->vfs_inode.i_ctime.tv_nsec;
97 if (NFS_SERVER(&nfsi->vfs_inode)->nfs_client->rpc_ops->version == 4)
98 auxdata->change_attr = inode_peek_iversion_raw(&nfsi->vfs_inode);
102 * Invalidate the contents of fscache for this inode. This will not sleep.
104 static inline void nfs_fscache_invalidate(struct inode *inode, int flags)
106 struct nfs_fscache_inode_auxdata auxdata;
107 struct nfs_inode *nfsi = NFS_I(inode);
110 nfs_fscache_update_auxdata(&auxdata, nfsi);
111 fscache_invalidate(nfsi->fscache, &auxdata,
112 i_size_read(&nfsi->vfs_inode), flags);
117 * indicate the client caching state as readable text
119 static inline const char *nfs_server_fscache_state(struct nfs_server *server)
126 #else /* CONFIG_NFS_FSCACHE */
127 static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {}
129 static inline void nfs_fscache_init_inode(struct inode *inode) {}
130 static inline void nfs_fscache_clear_inode(struct inode *inode) {}
131 static inline void nfs_fscache_open_file(struct inode *inode,
132 struct file *filp) {}
133 static inline void nfs_fscache_release_file(struct inode *inode, struct file *file) {}
135 static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp)
137 return 1; /* True: may release page */
139 static inline int nfs_readpage_from_fscache(struct inode *inode,
144 static inline void nfs_readpage_to_fscache(struct inode *inode,
145 struct page *page) {}
148 static inline void nfs_fscache_invalidate(struct inode *inode, int flags) {}
150 static inline const char *nfs_server_fscache_state(struct nfs_server *server)
155 #endif /* CONFIG_NFS_FSCACHE */
156 #endif /* _NFS_FSCACHE_H */