diff options
author | Brian Foster <bfoster@redhat.com> | 2012-07-16 15:23:49 -0400 |
---|---|---|
committer | Miklos Szeredi <mszeredi@suse.cz> | 2012-07-18 16:09:40 +0200 |
commit | eed2179efe1aac145bf6d54b925b750976380fa6 (patch) | |
tree | b266220b26632c699a858b66c3d7b9ebc5853289 /fs/fuse/inode.c | |
parent | 72d0d248ca8232dbd30d35b42d0d86e39b3e322b (diff) | |
download | linux-eed2179efe1aac145bf6d54b925b750976380fa6.tar.gz linux-eed2179efe1aac145bf6d54b925b750976380fa6.tar.bz2 linux-eed2179efe1aac145bf6d54b925b750976380fa6.zip |
fuse: invalidate inode mapping if mtime changes
We currently invalidate the inode address space mapping
if the file size changes unexpectedly. In the case of a
fuse network filesystem, a portion of a file could be
overwritten remotely without changing the file size.
Compare the old mtime as well to detect this condition
and invalidate the mapping if the file has been updated.
The original logic (to ignore changes in mtime) is
preserved unless the client specifies FUSE_AUTO_INVAL_DATA
on init.
Signed-off-by: Brian Foster <bfoster@redhat.com>
Signed-off-by: Miklos Szeredi <mszeredi@suse.cz>
Diffstat (limited to 'fs/fuse/inode.c')
-rw-r--r-- | fs/fuse/inode.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/fs/fuse/inode.c b/fs/fuse/inode.c index dd37ee291b8b..dd4401650b47 100644 --- a/fs/fuse/inode.c +++ b/fs/fuse/inode.c @@ -197,6 +197,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_inode *fi = get_fuse_inode(inode); loff_t oldsize; + struct timespec old_mtime; spin_lock(&fc->lock); if (attr_version != 0 && fi->attr_version > attr_version) { @@ -204,15 +205,35 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr, return; } + old_mtime = inode->i_mtime; fuse_change_attributes_common(inode, attr, attr_valid); oldsize = inode->i_size; i_size_write(inode, attr->size); spin_unlock(&fc->lock); - if (S_ISREG(inode->i_mode) && oldsize != attr->size) { - truncate_pagecache(inode, oldsize, attr->size); - invalidate_inode_pages2(inode->i_mapping); + if (S_ISREG(inode->i_mode)) { + bool inval = false; + + if (oldsize != attr->size) { + truncate_pagecache(inode, oldsize, attr->size); + inval = true; + } else if (fc->auto_inval_data) { + struct timespec new_mtime = { + .tv_sec = attr->mtime, + .tv_nsec = attr->mtimensec, + }; + + /* + * Auto inval mode also checks and invalidates if mtime + * has changed. + */ + if (!timespec_equal(&old_mtime, &new_mtime)) + inval = true; + } + + if (inval) + invalidate_inode_pages2(inode->i_mapping); } } |