Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-or-later */
0002 /* NFS filesystem cache interface definitions
0003  *
0004  * Copyright (C) 2008 Red Hat, Inc. All Rights Reserved.
0005  * Written by David Howells (dhowells@redhat.com)
0006  */
0007 
0008 #ifndef _NFS_FSCACHE_H
0009 #define _NFS_FSCACHE_H
0010 
0011 #include <linux/swap.h>
0012 #include <linux/nfs_fs.h>
0013 #include <linux/nfs_mount.h>
0014 #include <linux/nfs4_mount.h>
0015 #include <linux/fscache.h>
0016 #include <linux/iversion.h>
0017 
0018 #ifdef CONFIG_NFS_FSCACHE
0019 
0020 /*
0021  * Definition of the auxiliary data attached to NFS inode storage objects
0022  * within the cache.
0023  *
0024  * The contents of this struct are recorded in the on-disk local cache in the
0025  * auxiliary data attached to the data storage object backing an inode.  This
0026  * permits coherency to be managed when a new inode binds to an already extant
0027  * cache object.
0028  */
0029 struct nfs_fscache_inode_auxdata {
0030     s64 mtime_sec;
0031     s64 mtime_nsec;
0032     s64 ctime_sec;
0033     s64 ctime_nsec;
0034     u64 change_attr;
0035 };
0036 
0037 /*
0038  * fscache.c
0039  */
0040 extern int nfs_fscache_get_super_cookie(struct super_block *, const char *, int);
0041 extern void nfs_fscache_release_super_cookie(struct super_block *);
0042 
0043 extern void nfs_fscache_init_inode(struct inode *);
0044 extern void nfs_fscache_clear_inode(struct inode *);
0045 extern void nfs_fscache_open_file(struct inode *, struct file *);
0046 extern void nfs_fscache_release_file(struct inode *, struct file *);
0047 
0048 extern int __nfs_fscache_read_page(struct inode *, struct page *);
0049 extern void __nfs_fscache_write_page(struct inode *, struct page *);
0050 
0051 static inline bool nfs_fscache_release_folio(struct folio *folio, gfp_t gfp)
0052 {
0053     if (folio_test_fscache(folio)) {
0054         if (current_is_kswapd() || !(gfp & __GFP_FS))
0055             return false;
0056         folio_wait_fscache(folio);
0057         fscache_note_page_release(nfs_i_fscache(folio->mapping->host));
0058         nfs_inc_fscache_stats(folio->mapping->host,
0059                       NFSIOS_FSCACHE_PAGES_UNCACHED);
0060     }
0061     return true;
0062 }
0063 
0064 /*
0065  * Retrieve a page from an inode data storage object.
0066  */
0067 static inline int nfs_fscache_read_page(struct inode *inode, struct page *page)
0068 {
0069     if (nfs_i_fscache(inode))
0070         return __nfs_fscache_read_page(inode, page);
0071     return -ENOBUFS;
0072 }
0073 
0074 /*
0075  * Store a page newly fetched from the server in an inode data storage object
0076  * in the cache.
0077  */
0078 static inline void nfs_fscache_write_page(struct inode *inode,
0079                        struct page *page)
0080 {
0081     if (nfs_i_fscache(inode))
0082         __nfs_fscache_write_page(inode, page);
0083 }
0084 
0085 static inline void nfs_fscache_update_auxdata(struct nfs_fscache_inode_auxdata *auxdata,
0086                           struct inode *inode)
0087 {
0088     memset(auxdata, 0, sizeof(*auxdata));
0089     auxdata->mtime_sec  = inode->i_mtime.tv_sec;
0090     auxdata->mtime_nsec = inode->i_mtime.tv_nsec;
0091     auxdata->ctime_sec  = inode->i_ctime.tv_sec;
0092     auxdata->ctime_nsec = inode->i_ctime.tv_nsec;
0093 
0094     if (NFS_SERVER(inode)->nfs_client->rpc_ops->version == 4)
0095         auxdata->change_attr = inode_peek_iversion_raw(inode);
0096 }
0097 
0098 /*
0099  * Invalidate the contents of fscache for this inode.  This will not sleep.
0100  */
0101 static inline void nfs_fscache_invalidate(struct inode *inode, int flags)
0102 {
0103     struct nfs_fscache_inode_auxdata auxdata;
0104     struct nfs_inode *nfsi = NFS_I(inode);
0105 
0106     if (nfsi->fscache) {
0107         nfs_fscache_update_auxdata(&auxdata, inode);
0108         fscache_invalidate(nfsi->fscache, &auxdata,
0109                    i_size_read(inode), flags);
0110     }
0111 }
0112 
0113 /*
0114  * indicate the client caching state as readable text
0115  */
0116 static inline const char *nfs_server_fscache_state(struct nfs_server *server)
0117 {
0118     if (server->fscache)
0119         return "yes";
0120     return "no ";
0121 }
0122 
0123 #else /* CONFIG_NFS_FSCACHE */
0124 static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {}
0125 
0126 static inline void nfs_fscache_init_inode(struct inode *inode) {}
0127 static inline void nfs_fscache_clear_inode(struct inode *inode) {}
0128 static inline void nfs_fscache_open_file(struct inode *inode,
0129                      struct file *filp) {}
0130 static inline void nfs_fscache_release_file(struct inode *inode, struct file *file) {}
0131 
0132 static inline bool nfs_fscache_release_folio(struct folio *folio, gfp_t gfp)
0133 {
0134     return true; /* may release folio */
0135 }
0136 static inline int nfs_fscache_read_page(struct inode *inode, struct page *page)
0137 {
0138     return -ENOBUFS;
0139 }
0140 static inline void nfs_fscache_write_page(struct inode *inode, struct page *page) {}
0141 static inline void nfs_fscache_invalidate(struct inode *inode, int flags) {}
0142 
0143 static inline const char *nfs_server_fscache_state(struct nfs_server *server)
0144 {
0145     return "no ";
0146 }
0147 
0148 #endif /* CONFIG_NFS_FSCACHE */
0149 #endif /* _NFS_FSCACHE_H */