diff options
author | Jeff Layton <jlayton@redhat.com> | 2014-01-28 13:47:46 -0500 |
---|---|---|
committer | Trond Myklebust <trond.myklebust@primarydata.com> | 2014-01-28 14:48:18 -0500 |
commit | 4db72b40fdbc706f8957e9773ae73b1574b8c694 (patch) | |
tree | 7ccf6324c0643b0b35c1ccc0895292f51000685e | |
parent | 17dfeb9113397a6119091a491ef7182649f0c5a9 (diff) |
nfs: add memory barriers around NFS_INO_INVALID_DATA and NFS_INO_INVALIDATING
If the setting of NFS_INO_INVALIDATING gets reordered to before the
clearing of NFS_INO_INVALID_DATA, then another task may hit a race
window where both appear to be clear, even though the inode's pages are
still in need of invalidation. Fix this by adding the appropriate memory
barriers.
Signed-off-by: Jeff Layton <jlayton@redhat.com>
Signed-off-by: Trond Myklebust <trond.myklebust@primarydata.com>
-rw-r--r-- | fs/nfs/dir.c | 14 | ||||
-rw-r--r-- | fs/nfs/inode.c | 1 | ||||
-rw-r--r-- | fs/nfs/write.c | 1 |
3 files changed, 13 insertions, 3 deletions
diff --git a/fs/nfs/dir.c b/fs/nfs/dir.c index b39a0468829b..be38b573495a 100644 --- a/fs/nfs/dir.c +++ b/fs/nfs/dir.c | |||
@@ -274,6 +274,15 @@ out_eof: | |||
274 | return -EBADCOOKIE; | 274 | return -EBADCOOKIE; |
275 | } | 275 | } |
276 | 276 | ||
277 | static bool | ||
278 | nfs_readdir_inode_mapping_valid(struct nfs_inode *nfsi) | ||
279 | { | ||
280 | if (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA)) | ||
281 | return false; | ||
282 | smp_rmb(); | ||
283 | return !test_bit(NFS_INO_INVALIDATING, &nfsi->flags); | ||
284 | } | ||
285 | |||
277 | static | 286 | static |
278 | int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_descriptor_t *desc) | 287 | int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_descriptor_t *desc) |
279 | { | 288 | { |
@@ -287,9 +296,8 @@ int nfs_readdir_search_for_cookie(struct nfs_cache_array *array, nfs_readdir_des | |||
287 | struct nfs_open_dir_context *ctx = desc->file->private_data; | 296 | struct nfs_open_dir_context *ctx = desc->file->private_data; |
288 | 297 | ||
289 | new_pos = desc->current_index + i; | 298 | new_pos = desc->current_index + i; |
290 | if (ctx->attr_gencount != nfsi->attr_gencount | 299 | if (ctx->attr_gencount != nfsi->attr_gencount || |
291 | || (nfsi->cache_validity & (NFS_INO_INVALID_ATTR|NFS_INO_INVALID_DATA)) | 300 | !nfs_readdir_inode_mapping_valid(nfsi)) { |
292 | || test_bit(NFS_INO_INVALIDATING, &nfsi->flags)) { | ||
293 | ctx->duped = 0; | 301 | ctx->duped = 0; |
294 | ctx->attr_gencount = nfsi->attr_gencount; | 302 | ctx->attr_gencount = nfsi->attr_gencount; |
295 | } else if (new_pos < desc->ctx->pos) { | 303 | } else if (new_pos < desc->ctx->pos) { |
diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c index e5070aa5f175..02e185168602 100644 --- a/fs/nfs/inode.c +++ b/fs/nfs/inode.c | |||
@@ -1050,6 +1050,7 @@ int nfs_revalidate_mapping(struct inode *inode, struct address_space *mapping) | |||
1050 | } | 1050 | } |
1051 | 1051 | ||
1052 | set_bit(NFS_INO_INVALIDATING, bitlock); | 1052 | set_bit(NFS_INO_INVALIDATING, bitlock); |
1053 | smp_wmb(); | ||
1053 | nfsi->cache_validity &= ~NFS_INO_INVALID_DATA; | 1054 | nfsi->cache_validity &= ~NFS_INO_INVALID_DATA; |
1054 | spin_unlock(&inode->i_lock); | 1055 | spin_unlock(&inode->i_lock); |
1055 | trace_nfs_invalidate_mapping_enter(inode); | 1056 | trace_nfs_invalidate_mapping_enter(inode); |
diff --git a/fs/nfs/write.c b/fs/nfs/write.c index 5511a4247190..9a3b6a4cd6b9 100644 --- a/fs/nfs/write.c +++ b/fs/nfs/write.c | |||
@@ -915,6 +915,7 @@ static bool nfs_write_pageuptodate(struct page *page, struct inode *inode) | |||
915 | goto out; | 915 | goto out; |
916 | if (nfsi->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE)) | 916 | if (nfsi->cache_validity & (NFS_INO_INVALID_DATA|NFS_INO_REVAL_PAGECACHE)) |
917 | return false; | 917 | return false; |
918 | smp_rmb(); | ||
918 | if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags)) | 919 | if (test_bit(NFS_INO_INVALIDATING, &nfsi->flags)) |
919 | return false; | 920 | return false; |
920 | out: | 921 | out: |