提交 854512ec 编写于 作者: M Miklos Szeredi 提交者: Linus Torvalds

fuse: clean up setting i_size in write

Extract common code for setting i_size in write functions into a common
helper.
Signed-off-by: NMiklos Szeredi <mszeredi@suse.cz>
Signed-off-by: NAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: NLinus Torvalds <torvalds@linux-foundation.org>
上级 3be5a52b
...@@ -610,13 +610,24 @@ static int fuse_write_begin(struct file *file, struct address_space *mapping, ...@@ -610,13 +610,24 @@ static int fuse_write_begin(struct file *file, struct address_space *mapping,
return 0; return 0;
} }
static void fuse_write_update_size(struct inode *inode, loff_t pos)
{
struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_inode *fi = get_fuse_inode(inode);
spin_lock(&fc->lock);
fi->attr_version = ++fc->attr_version;
if (pos > inode->i_size)
i_size_write(inode, pos);
spin_unlock(&fc->lock);
}
static int fuse_buffered_write(struct file *file, struct inode *inode, static int fuse_buffered_write(struct file *file, struct inode *inode,
loff_t pos, unsigned count, struct page *page) loff_t pos, unsigned count, struct page *page)
{ {
int err; int err;
size_t nres; size_t nres;
struct fuse_conn *fc = get_fuse_conn(inode); struct fuse_conn *fc = get_fuse_conn(inode);
struct fuse_inode *fi = get_fuse_inode(inode);
unsigned offset = pos & (PAGE_CACHE_SIZE - 1); unsigned offset = pos & (PAGE_CACHE_SIZE - 1);
struct fuse_req *req; struct fuse_req *req;
...@@ -643,12 +654,7 @@ static int fuse_buffered_write(struct file *file, struct inode *inode, ...@@ -643,12 +654,7 @@ static int fuse_buffered_write(struct file *file, struct inode *inode,
err = -EIO; err = -EIO;
if (!err) { if (!err) {
pos += nres; pos += nres;
spin_lock(&fc->lock); fuse_write_update_size(inode, pos);
fi->attr_version = ++fc->attr_version;
if (pos > inode->i_size)
i_size_write(inode, pos);
spin_unlock(&fc->lock);
if (count == PAGE_CACHE_SIZE) if (count == PAGE_CACHE_SIZE)
SetPageUptodate(page); SetPageUptodate(page);
} }
...@@ -766,12 +772,8 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf, ...@@ -766,12 +772,8 @@ static ssize_t fuse_direct_io(struct file *file, const char __user *buf,
} }
fuse_put_request(fc, req); fuse_put_request(fc, req);
if (res > 0) { if (res > 0) {
if (write) { if (write)
spin_lock(&fc->lock); fuse_write_update_size(inode, pos);
if (pos > inode->i_size)
i_size_write(inode, pos);
spin_unlock(&fc->lock);
}
*ppos = pos; *ppos = pos;
} }
fuse_invalidate_attr(inode); fuse_invalidate_attr(inode);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册