diff options
Diffstat (limited to 'fs/fuse/dir.c')
-rw-r--r-- | fs/fuse/dir.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c index 8605155db171..a8f65c11aa2c 100644 --- a/fs/fuse/dir.c +++ b/fs/fuse/dir.c | |||
@@ -935,14 +935,30 @@ static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg) | |||
935 | } | 935 | } |
936 | } | 936 | } |
937 | 937 | ||
938 | static void fuse_vmtruncate(struct inode *inode, loff_t offset) | ||
939 | { | ||
940 | struct fuse_conn *fc = get_fuse_conn(inode); | ||
941 | int need_trunc; | ||
942 | |||
943 | spin_lock(&fc->lock); | ||
944 | need_trunc = inode->i_size > offset; | ||
945 | i_size_write(inode, offset); | ||
946 | spin_unlock(&fc->lock); | ||
947 | |||
948 | if (need_trunc) { | ||
949 | struct address_space *mapping = inode->i_mapping; | ||
950 | unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1); | ||
951 | truncate_inode_pages(mapping, offset); | ||
952 | } | ||
953 | } | ||
954 | |||
938 | /* | 955 | /* |
939 | * Set attributes, and at the same time refresh them. | 956 | * Set attributes, and at the same time refresh them. |
940 | * | 957 | * |
941 | * Truncation is slightly complicated, because the 'truncate' request | 958 | * Truncation is slightly complicated, because the 'truncate' request |
942 | * may fail, in which case we don't want to touch the mapping. | 959 | * may fail, in which case we don't want to touch the mapping. |
943 | * vmtruncate() doesn't allow for this case. So do the rlimit | 960 | * vmtruncate() doesn't allow for this case, so do the rlimit checking |
944 | * checking by hand and call vmtruncate() only after the file has | 961 | * and the actual truncation by hand. |
945 | * actually been truncated. | ||
946 | */ | 962 | */ |
947 | static int fuse_setattr(struct dentry *entry, struct iattr *attr) | 963 | static int fuse_setattr(struct dentry *entry, struct iattr *attr) |
948 | { | 964 | { |
@@ -993,12 +1009,8 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr) | |||
993 | make_bad_inode(inode); | 1009 | make_bad_inode(inode); |
994 | err = -EIO; | 1010 | err = -EIO; |
995 | } else { | 1011 | } else { |
996 | if (is_truncate) { | 1012 | if (is_truncate) |
997 | loff_t origsize = i_size_read(inode); | 1013 | fuse_vmtruncate(inode, outarg.attr.size); |
998 | i_size_write(inode, outarg.attr.size); | ||
999 | if (origsize > outarg.attr.size) | ||
1000 | vmtruncate(inode, outarg.attr.size); | ||
1001 | } | ||
1002 | fuse_change_attributes(inode, &outarg.attr); | 1014 | fuse_change_attributes(inode, &outarg.attr); |
1003 | fi->i_time = time_to_jiffies(outarg.attr_valid, | 1015 | fi->i_time = time_to_jiffies(outarg.attr_valid, |
1004 | outarg.attr_valid_nsec); | 1016 | outarg.attr_valid_nsec); |