diff options
author | Trond Myklebust <trond.myklebust@primarydata.com> | 2016-12-08 18:18:38 -0500 |
---|---|---|
committer | Trond Myklebust <trond.myklebust@primarydata.com> | 2016-12-19 17:29:35 -0500 |
commit | 61540bf6bb40ddfa3e766de91cedca2e1afd24eb (patch) | |
tree | 36d2a5f7ad7086cb0cdde12bdd6907676db080f0 | |
parent | 58ff41842c7b8b8a79752e3d040188ebddb95194 (diff) |
NFS: Clean up cache validity checking
Consolidate the open-coded checking of NFS_I(inode)->cache_validity
into a couple of helper functions.
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
-rw-r--r-- | fs/nfs/file.c | 12 | ||||
-rw-r--r-- | fs/nfs/inode.c | 43 | ||||
-rw-r--r-- | fs/nfs/internal.h | 1 |
3 files changed, 34 insertions, 22 deletions
diff --git a/fs/nfs/file.c b/fs/nfs/file.c index 64c11f399b3d..599a602cb2fd 100644 --- a/fs/nfs/file.c +++ b/fs/nfs/file.c | |||
@@ -101,21 +101,11 @@ EXPORT_SYMBOL_GPL(nfs_file_release); | |||
101 | static int nfs_revalidate_file_size(struct inode *inode, struct file *filp) | 101 | static int nfs_revalidate_file_size(struct inode *inode, struct file *filp) |
102 | { | 102 | { |
103 | struct nfs_server *server = NFS_SERVER(inode); | 103 | struct nfs_server *server = NFS_SERVER(inode); |
104 | struct nfs_inode *nfsi = NFS_I(inode); | ||
105 | const unsigned long force_reval = NFS_INO_REVAL_PAGECACHE|NFS_INO_REVAL_FORCED; | ||
106 | unsigned long cache_validity = nfsi->cache_validity; | ||
107 | |||
108 | if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ) && | ||
109 | (cache_validity & force_reval) != force_reval) | ||
110 | goto out_noreval; | ||
111 | 104 | ||
112 | if (filp->f_flags & O_DIRECT) | 105 | if (filp->f_flags & O_DIRECT) |
113 | goto force_reval; | 106 | goto force_reval; |
114 | if (nfsi->cache_validity & NFS_INO_REVAL_PAGECACHE) | 107 | if (nfs_check_cache_invalid(inode, NFS_INO_REVAL_PAGECACHE)) |
115 | goto force_reval; | ||
116 | if (nfs_attribute_timeout(inode)) | ||
117 | goto force_reval; | 108 | goto force_reval; |
118 | out_noreval: | ||
119 | return 0; | 109 | return 0; |
120 | force_reval: | 110 | force_reval: |
121 | return __nfs_revalidate_inode(server, inode); | 111 | return __nfs_revalidate_inode(server, inode); |
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index 2fc237cd338e..e3194aa797f7 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -160,6 +160,36 @@ int nfs_sync_mapping(struct address_space *mapping) | |||
160 | return ret; | 160 | return ret; |
161 | } | 161 | } |
162 | 162 | ||
163 | static bool nfs_check_cache_invalid_delegated(struct inode *inode, unsigned long flags) | ||
164 | { | ||
165 | unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); | ||
166 | |||
167 | /* Special case for the pagecache or access cache */ | ||
168 | if (flags == NFS_INO_REVAL_PAGECACHE && | ||
169 | !(cache_validity & NFS_INO_REVAL_FORCED)) | ||
170 | return false; | ||
171 | return (cache_validity & flags) != 0; | ||
172 | } | ||
173 | |||
174 | static bool nfs_check_cache_invalid_not_delegated(struct inode *inode, unsigned long flags) | ||
175 | { | ||
176 | unsigned long cache_validity = READ_ONCE(NFS_I(inode)->cache_validity); | ||
177 | |||
178 | if ((cache_validity & flags) != 0) | ||
179 | return true; | ||
180 | if (nfs_attribute_timeout(inode)) | ||
181 | return true; | ||
182 | return false; | ||
183 | } | ||
184 | |||
185 | bool nfs_check_cache_invalid(struct inode *inode, unsigned long flags) | ||
186 | { | ||
187 | if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) | ||
188 | return nfs_check_cache_invalid_delegated(inode, flags); | ||
189 | |||
190 | return nfs_check_cache_invalid_not_delegated(inode, flags); | ||
191 | } | ||
192 | |||
163 | static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags) | 193 | static void nfs_set_cache_invalid(struct inode *inode, unsigned long flags) |
164 | { | 194 | { |
165 | struct nfs_inode *nfsi = NFS_I(inode); | 195 | struct nfs_inode *nfsi = NFS_I(inode); |
@@ -1116,17 +1146,8 @@ static int nfs_invalidate_mapping(struct inode *inode, struct address_space *map | |||
1116 | 1146 | ||
1117 | bool nfs_mapping_need_revalidate_inode(struct inode *inode) | 1147 | bool nfs_mapping_need_revalidate_inode(struct inode *inode) |
1118 | { | 1148 | { |
1119 | unsigned long cache_validity = NFS_I(inode)->cache_validity; | 1149 | return nfs_check_cache_invalid(inode, NFS_INO_REVAL_PAGECACHE) || |
1120 | 1150 | NFS_STALE(inode); | |
1121 | if (NFS_PROTO(inode)->have_delegation(inode, FMODE_READ)) { | ||
1122 | const unsigned long force_reval = | ||
1123 | NFS_INO_REVAL_PAGECACHE|NFS_INO_REVAL_FORCED; | ||
1124 | return (cache_validity & force_reval) == force_reval; | ||
1125 | } | ||
1126 | |||
1127 | return (cache_validity & NFS_INO_REVAL_PAGECACHE) | ||
1128 | || nfs_attribute_timeout(inode) | ||
1129 | || NFS_STALE(inode); | ||
1130 | } | 1151 | } |
1131 | 1152 | ||
1132 | int nfs_revalidate_mapping_rcu(struct inode *inode) | 1153 | int nfs_revalidate_mapping_rcu(struct inode *inode) |
diff --git a/fs/nfs/internal.h b/fs/nfs/internal.h index 6b79c2ca9b9a..09ca5095c04e 100644 --- a/fs/nfs/internal.h +++ b/fs/nfs/internal.h | |||
@@ -381,6 +381,7 @@ extern int nfs_drop_inode(struct inode *); | |||
381 | extern void nfs_clear_inode(struct inode *); | 381 | extern void nfs_clear_inode(struct inode *); |
382 | extern void nfs_evict_inode(struct inode *); | 382 | extern void nfs_evict_inode(struct inode *); |
383 | void nfs_zap_acl_cache(struct inode *inode); | 383 | void nfs_zap_acl_cache(struct inode *inode); |
384 | extern bool nfs_check_cache_invalid(struct inode *, unsigned long); | ||
384 | extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode); | 385 | extern int nfs_wait_bit_killable(struct wait_bit_key *key, int mode); |
385 | extern int nfs_wait_atomic_killable(atomic_t *p); | 386 | extern int nfs_wait_atomic_killable(atomic_t *p); |
386 | 387 | ||