Thomas Gleixner | b4d0d23 | 2019-05-20 19:08:01 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
David Howells | 8ec442a | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 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) |
David Howells | 8ec442a | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #ifndef _NFS_FSCACHE_H |
| 9 | #define _NFS_FSCACHE_H |
| 10 | |
David Howells | d7bdba1 | 2021-12-22 17:21:04 +0000 | [diff] [blame] | 11 | #include <linux/swap.h> |
David Howells | 8ec442a | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 12 | #include <linux/nfs_fs.h> |
| 13 | #include <linux/nfs_mount.h> |
| 14 | #include <linux/nfs4_mount.h> |
| 15 | #include <linux/fscache.h> |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 16 | #include <linux/iversion.h> |
David Howells | 8ec442a | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 17 | |
| 18 | #ifdef CONFIG_NFS_FSCACHE |
| 19 | |
| 20 | /* |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 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 { |
Arnd Bergmann | 6e31ded | 2019-10-28 11:41:42 +0100 | [diff] [blame] | 30 | s64 mtime_sec; |
| 31 | s64 mtime_nsec; |
| 32 | s64 ctime_sec; |
| 33 | s64 ctime_nsec; |
| 34 | u64 change_attr; |
David Howells | 402cb8d | 2018-04-04 13:41:28 +0100 | [diff] [blame] | 35 | }; |
| 36 | |
| 37 | /* |
David Howells | 1472728 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 38 | * fscache.c |
| 39 | */ |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 40 | extern int nfs_fscache_get_super_cookie(struct super_block *, const char *, int); |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 41 | extern void nfs_fscache_release_super_cookie(struct super_block *); |
| 42 | |
David Howells | f1fe29b | 2013-09-27 11:20:03 +0100 | [diff] [blame] | 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 *); |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 46 | extern void nfs_fscache_release_file(struct inode *, struct file *); |
David Howells | ef79c09 | 2009-04-03 16:42:43 +0100 | [diff] [blame] | 47 | |
David Howells | 16f2f4e | 2021-08-27 15:19:34 +0100 | [diff] [blame] | 48 | extern int __nfs_readpage_from_fscache(struct inode *, struct page *); |
| 49 | extern void __nfs_read_completion_to_fscache(struct nfs_pgio_header *hdr, |
| 50 | unsigned long bytes); |
| 51 | extern void __nfs_readpage_to_fscache(struct inode *, struct page *); |
David Howells | 9a9fc1c | 2009-04-03 16:42:44 +0100 | [diff] [blame] | 52 | |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 53 | static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp) |
David Howells | 545db45 | 2009-04-03 16:42:44 +0100 | [diff] [blame] | 54 | { |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 55 | if (PageFsCache(page)) { |
David Howells | d7bdba1 | 2021-12-22 17:21:04 +0000 | [diff] [blame] | 56 | if (current_is_kswapd() || !(gfp & __GFP_FS)) |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 57 | return false; |
| 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); |
| 62 | } |
| 63 | return true; |
David Howells | 545db45 | 2009-04-03 16:42:44 +0100 | [diff] [blame] | 64 | } |
| 65 | |
David Howells | 9a9fc1c | 2009-04-03 16:42:44 +0100 | [diff] [blame] | 66 | /* |
| 67 | * Retrieve a page from an inode data storage object. |
| 68 | */ |
David Howells | 16f2f4e | 2021-08-27 15:19:34 +0100 | [diff] [blame] | 69 | static inline int nfs_readpage_from_fscache(struct inode *inode, |
David Howells | 9a9fc1c | 2009-04-03 16:42:44 +0100 | [diff] [blame] | 70 | struct page *page) |
| 71 | { |
| 72 | if (NFS_I(inode)->fscache) |
David Howells | 16f2f4e | 2021-08-27 15:19:34 +0100 | [diff] [blame] | 73 | return __nfs_readpage_from_fscache(inode, page); |
David Howells | 9a9fc1c | 2009-04-03 16:42:44 +0100 | [diff] [blame] | 74 | return -ENOBUFS; |
| 75 | } |
David Howells | 545db45 | 2009-04-03 16:42:44 +0100 | [diff] [blame] | 76 | |
David Howells | 7f8e05f | 2009-04-03 16:42:45 +0100 | [diff] [blame] | 77 | /* |
| 78 | * Store a page newly fetched from the server in an inode data storage object |
| 79 | * in the cache. |
| 80 | */ |
| 81 | static inline void nfs_readpage_to_fscache(struct inode *inode, |
David Howells | 16f2f4e | 2021-08-27 15:19:34 +0100 | [diff] [blame] | 82 | struct page *page) |
David Howells | 7f8e05f | 2009-04-03 16:42:45 +0100 | [diff] [blame] | 83 | { |
David Howells | 16f2f4e | 2021-08-27 15:19:34 +0100 | [diff] [blame] | 84 | if (NFS_I(inode)->fscache) |
| 85 | __nfs_readpage_to_fscache(inode, page); |
David Howells | 7f8e05f | 2009-04-03 16:42:45 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 88 | static inline void nfs_fscache_update_auxdata(struct nfs_fscache_inode_auxdata *auxdata, |
| 89 | struct nfs_inode *nfsi) |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 90 | { |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 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; |
| 96 | |
| 97 | if (NFS_SERVER(&nfsi->vfs_inode)->nfs_client->rpc_ops->version == 4) |
| 98 | auxdata->change_attr = inode_peek_iversion_raw(&nfsi->vfs_inode); |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 99 | } |
| 100 | |
| 101 | /* |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 102 | * Invalidate the contents of fscache for this inode. This will not sleep. |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 103 | */ |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 104 | static inline void nfs_fscache_invalidate(struct inode *inode, int flags) |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 105 | { |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 106 | struct nfs_fscache_inode_auxdata auxdata; |
| 107 | struct nfs_inode *nfsi = NFS_I(inode); |
| 108 | |
| 109 | if (nfsi->fscache) { |
| 110 | nfs_fscache_update_auxdata(&auxdata, nfsi); |
| 111 | fscache_invalidate(nfsi->fscache, &auxdata, |
| 112 | i_size_read(&nfsi->vfs_inode), flags); |
| 113 | } |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | /* |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 117 | * indicate the client caching state as readable text |
| 118 | */ |
| 119 | static inline const char *nfs_server_fscache_state(struct nfs_server *server) |
| 120 | { |
Trond Myklebust | dea1bb3 | 2019-08-03 13:39:24 -0400 | [diff] [blame] | 121 | if (server->fscache) |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 122 | return "yes"; |
| 123 | return "no "; |
| 124 | } |
| 125 | |
David Howells | 8ec442a | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 126 | #else /* CONFIG_NFS_FSCACHE */ |
David Howells | 0873404 | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 127 | static inline void nfs_fscache_release_super_cookie(struct super_block *sb) {} |
| 128 | |
David Howells | f1fe29b | 2013-09-27 11:20:03 +0100 | [diff] [blame] | 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) {} |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 133 | static inline void nfs_fscache_release_file(struct inode *inode, struct file *file) {} |
David Howells | ef79c09 | 2009-04-03 16:42:43 +0100 | [diff] [blame] | 134 | |
David Howells | 545db45 | 2009-04-03 16:42:44 +0100 | [diff] [blame] | 135 | static inline int nfs_fscache_release_page(struct page *page, gfp_t gfp) |
| 136 | { |
| 137 | return 1; /* True: may release page */ |
| 138 | } |
David Howells | 16f2f4e | 2021-08-27 15:19:34 +0100 | [diff] [blame] | 139 | static inline int nfs_readpage_from_fscache(struct inode *inode, |
David Howells | 9a9fc1c | 2009-04-03 16:42:44 +0100 | [diff] [blame] | 140 | struct page *page) |
| 141 | { |
| 142 | return -ENOBUFS; |
| 143 | } |
David Howells | 7f8e05f | 2009-04-03 16:42:45 +0100 | [diff] [blame] | 144 | static inline void nfs_readpage_to_fscache(struct inode *inode, |
David Howells | 16f2f4e | 2021-08-27 15:19:34 +0100 | [diff] [blame] | 145 | struct page *page) {} |
David Howells | 9a9fc1c | 2009-04-03 16:42:44 +0100 | [diff] [blame] | 146 | |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 147 | |
Dave Wysochanski | a6b5a28 | 2020-11-14 13:43:54 -0500 | [diff] [blame] | 148 | static inline void nfs_fscache_invalidate(struct inode *inode, int flags) {} |
David Howells | de242c0 | 2012-12-20 21:52:38 +0000 | [diff] [blame] | 149 | |
David Howells | 5d1acff | 2009-04-03 16:42:47 +0100 | [diff] [blame] | 150 | static inline const char *nfs_server_fscache_state(struct nfs_server *server) |
| 151 | { |
| 152 | return "no "; |
| 153 | } |
| 154 | |
David Howells | 8ec442a | 2009-04-03 16:42:42 +0100 | [diff] [blame] | 155 | #endif /* CONFIG_NFS_FSCACHE */ |
| 156 | #endif /* _NFS_FSCACHE_H */ |