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_fscache_read_page(struct inode *, struct page *);
49 extern void __nfs_fscache_write_page(struct inode *, struct page *);
51 static inline bool nfs_fscache_release_folio(struct folio *folio, gfp_t gfp)
53 if (folio_test_fscache(folio)) {
54 if (current_is_kswapd() || !(gfp & __GFP_FS))
56 folio_wait_fscache(folio);
57 fscache_note_page_release(nfs_i_fscache(folio->mapping->host));
58 nfs_inc_fscache_stats(folio->mapping->host,
59 NFSIOS_FSCACHE_PAGES_UNCACHED);
65 * Retrieve a page from an inode data storage object.
67 static inline int nfs_fscache_read_page(struct inode *inode, struct page *page)
69 if (nfs_i_fscache(inode))
70 return __nfs_fscache_read_page(inode, page);
75 * Store a page newly fetched from the server in an inode data storage object
78 static inline void nfs_fscache_write_page(struct inode *inode,
81 if (nfs_i_fscache(inode))
82 __nfs_fscache_write_page(inode, page);
85 static inline void nfs_fscache_update_auxdata(struct nfs_fscache_inode_auxdata *auxdata,
88 memset(auxdata, 0, sizeof(*auxdata));
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;
94 if (NFS_SERVER(inode)->nfs_client->rpc_ops->version == 4)
95 auxdata->change_attr = inode_peek_iversion_raw(inode);
99 * Invalidate the contents of fscache for this inode. This will not sleep.
101 static inline void nfs_fscache_invalidate(struct inode *inode, int flags)
103 struct nfs_fscache_inode_auxdata auxdata;
104 struct nfs_inode *nfsi = NFS_I(inode);
107 nfs_fscache_update_auxdata(&auxdata, inode);
108 fscache_invalidate(nfsi->fscache, &auxdata,
109 i_size_read(inode), flags);
114 * indicate the client caching state as readable text
116 static inline const char *nfs_server_fscache_state(struct nfs_server *server)
123 #else /* CONFIG_NFS_FSCACHE */
124 static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {}
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) {}
130 static inline void nfs_fscache_release_file(struct inode *inode, struct file *file) {}
132 static inline bool nfs_fscache_release_folio(struct folio *folio, gfp_t gfp)
134 return true; /* may release folio */
136 static inline int nfs_fscache_read_page(struct inode *inode, struct page *page)
140 static inline void nfs_fscache_write_page(struct inode *inode, struct page *page) {}
141 static inline void nfs_fscache_invalidate(struct inode *inode, int flags) {}
143 static inline const char *nfs_server_fscache_state(struct nfs_server *server)
148 #endif /* CONFIG_NFS_FSCACHE */
149 #endif /* _NFS_FSCACHE_H */