Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 39729
b: refs/heads/master
c: 9ffbb91
h: refs/heads/master
i:
  39727: c3ff6dd
v: v3
  • Loading branch information
Miklos Szeredi authored and Linus Torvalds committed Oct 17, 2006
1 parent 2cacc51 commit 93ead9e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 14 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: 48d1a7ea6373337985f27dc1c707649469df5827
refs/heads/master: 9ffbb9162312fd8113037cb3d94f787f06bbfa9a
30 changes: 21 additions & 9 deletions trunk/fs/fuse/dir.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,14 +935,30 @@ static void iattr_to_fattr(struct iattr *iattr, struct fuse_setattr_in *arg)
}
}

static void fuse_vmtruncate(struct inode *inode, loff_t offset)
{
struct fuse_conn *fc = get_fuse_conn(inode);
int need_trunc;

spin_lock(&fc->lock);
need_trunc = inode->i_size > offset;
i_size_write(inode, offset);
spin_unlock(&fc->lock);

if (need_trunc) {
struct address_space *mapping = inode->i_mapping;
unmap_mapping_range(mapping, offset + PAGE_SIZE - 1, 0, 1);
truncate_inode_pages(mapping, offset);
}
}

/*
* Set attributes, and at the same time refresh them.
*
* Truncation is slightly complicated, because the 'truncate' request
* may fail, in which case we don't want to touch the mapping.
* vmtruncate() doesn't allow for this case. So do the rlimit
* checking by hand and call vmtruncate() only after the file has
* actually been truncated.
* vmtruncate() doesn't allow for this case, so do the rlimit checking
* and the actual truncation by hand.
*/
static int fuse_setattr(struct dentry *entry, struct iattr *attr)
{
Expand Down Expand Up @@ -993,12 +1009,8 @@ static int fuse_setattr(struct dentry *entry, struct iattr *attr)
make_bad_inode(inode);
err = -EIO;
} else {
if (is_truncate) {
loff_t origsize = i_size_read(inode);
i_size_write(inode, outarg.attr.size);
if (origsize > outarg.attr.size)
vmtruncate(inode, outarg.attr.size);
}
if (is_truncate)
fuse_vmtruncate(inode, outarg.attr.size);
fuse_change_attributes(inode, &outarg.attr);
fi->i_time = time_to_jiffies(outarg.attr_valid,
outarg.attr_valid_nsec);
Expand Down
12 changes: 9 additions & 3 deletions trunk/fs/fuse/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,10 @@ static int fuse_commit_write(struct file *file, struct page *page,
err = -EIO;
if (!err) {
pos += count;
if (pos > i_size_read(inode))
spin_lock(&fc->lock);
if (pos > inode->i_size)
i_size_write(inode, pos);
spin_unlock(&fc->lock);

if (offset == 0 && to == PAGE_CACHE_SIZE) {
clear_page_dirty(page);
Expand Down Expand Up @@ -586,8 +588,12 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
}
fuse_put_request(fc, req);
if (res > 0) {
if (write && pos > i_size_read(inode))
i_size_write(inode, pos);
if (write) {
spin_lock(&fc->lock);
if (pos > inode->i_size)
i_size_write(inode, pos);
spin_unlock(&fc->lock);
}
*ppos = pos;
}
fuse_invalidate_attr(inode);
Expand Down
5 changes: 4 additions & 1 deletion trunk/fs/fuse/inode.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ static int fuse_remount_fs(struct super_block *sb, int *flags, char *data)

void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr)
{
struct fuse_conn *fc = get_fuse_conn(inode);
if (S_ISREG(inode->i_mode) && i_size_read(inode) != attr->size)
invalidate_inode_pages(inode->i_mapping);

Expand All @@ -117,7 +118,9 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr)
inode->i_nlink = attr->nlink;
inode->i_uid = attr->uid;
inode->i_gid = attr->gid;
spin_lock(&fc->lock);
i_size_write(inode, attr->size);
spin_unlock(&fc->lock);
inode->i_blocks = attr->blocks;
inode->i_atime.tv_sec = attr->atime;
inode->i_atime.tv_nsec = attr->atimensec;
Expand All @@ -130,7 +133,7 @@ void fuse_change_attributes(struct inode *inode, struct fuse_attr *attr)
static void fuse_init_inode(struct inode *inode, struct fuse_attr *attr)
{
inode->i_mode = attr->mode & S_IFMT;
i_size_write(inode, attr->size);
inode->i_size = attr->size;
if (S_ISREG(inode->i_mode)) {
fuse_init_common(inode);
fuse_init_file_inode(inode);
Expand Down

0 comments on commit 93ead9e

Please sign in to comment.