Commit ae361ff4 authored by Nick Piggin's avatar Nick Piggin Committed by Linus Torvalds

hostfs: convert to new aops

This also gets rid of a lot of useless read_file stuff. And also
optimises the full page write case by marking a !uptodate page uptodate.
Signed-off-by: default avatarNick Piggin <npiggin@suse.de>
Cc: Jeff Dike <jdike@addtoit.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent 5e6f58a1
...@@ -466,56 +466,42 @@ int hostfs_readpage(struct file *file, struct page *page) ...@@ -466,56 +466,42 @@ int hostfs_readpage(struct file *file, struct page *page)
return err; return err;
} }
int hostfs_prepare_write(struct file *file, struct page *page, int hostfs_write_begin(struct file *file, struct address_space *mapping,
unsigned int from, unsigned int to) loff_t pos, unsigned len, unsigned flags,
struct page **pagep, void **fsdata)
{ {
char *buffer; pgoff_t index = pos >> PAGE_CACHE_SHIFT;
long long start, tmp;
int err;
start = (long long) page->index << PAGE_CACHE_SHIFT; *pagep = __grab_cache_page(mapping, index);
buffer = kmap(page); if (!*pagep)
if(from != 0){ return -ENOMEM;
tmp = start; return 0;
err = read_file(FILE_HOSTFS_I(file)->fd, &tmp, buffer,
from);
if(err < 0) goto out;
}
if(to != PAGE_CACHE_SIZE){
start += to;
err = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer + to,
PAGE_CACHE_SIZE - to);
if(err < 0) goto out;
}
err = 0;
out:
kunmap(page);
return err;
} }
int hostfs_commit_write(struct file *file, struct page *page, unsigned from, int hostfs_write_end(struct file *file, struct address_space *mapping,
unsigned to) loff_t pos, unsigned len, unsigned copied,
struct page *page, void *fsdata)
{ {
struct address_space *mapping = page->mapping;
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
char *buffer; void *buffer;
long long start; unsigned from = pos & (PAGE_CACHE_SIZE - 1);
int err = 0; int err;
start = (((long long) page->index) << PAGE_CACHE_SHIFT) + from;
buffer = kmap(page); buffer = kmap(page);
err = write_file(FILE_HOSTFS_I(file)->fd, &start, buffer + from, err = write_file(FILE_HOSTFS_I(file)->fd, &pos, buffer + from, copied);
to - from); kunmap(page);
if(err > 0) err = 0;
/* Actually, if !err, write_file has added to-from to start, so, despite if (!PageUptodate(page) && err == PAGE_CACHE_SIZE)
* the appearance, we are comparing i_size against the _last_ written SetPageUptodate(page);
* location, as we should. */
if(!err && (start > inode->i_size)) /* If err > 0, write_file has added err to pos, so we are comparing
inode->i_size = start; * i_size against the last byte written.
*/
if (err > 0 && (pos > inode->i_size))
inode->i_size = pos;
unlock_page(page);
page_cache_release(page);
kunmap(page);
return err; return err;
} }
...@@ -523,8 +509,8 @@ static const struct address_space_operations hostfs_aops = { ...@@ -523,8 +509,8 @@ static const struct address_space_operations hostfs_aops = {
.writepage = hostfs_writepage, .writepage = hostfs_writepage,
.readpage = hostfs_readpage, .readpage = hostfs_readpage,
.set_page_dirty = __set_page_dirty_nobuffers, .set_page_dirty = __set_page_dirty_nobuffers,
.prepare_write = hostfs_prepare_write, .write_begin = hostfs_write_begin,
.commit_write = hostfs_commit_write .write_end = hostfs_write_end,
}; };
static int init_inode(struct inode *inode, struct dentry *dentry) static int init_inode(struct inode *inode, struct dentry *dentry)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment