aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNick Piggin <npiggin@suse.de>2007-10-16 04:25:17 -0400
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2007-10-16 12:42:57 -0400
commitae361ff46ba93b2644675d9de19e885185f0d0c1 (patch)
treeb5af5dd9b66382e5681ae9195147c38cc8f1f3b4
parent5e6f58a1d7ce2fd5ef099f9aec5b3e3f7ba176b4 (diff)
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: Nick Piggin <npiggin@suse.de> Cc: Jeff Dike <jdike@addtoit.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
-rw-r--r--fs/hostfs/hostfs_kern.c68
1 files changed, 27 insertions, 41 deletions
diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
index c77862032e84..8a21289d774d 100644
--- a/fs/hostfs/hostfs_kern.c
+++ b/fs/hostfs/hostfs_kern.c
@@ -466,56 +466,42 @@ int hostfs_readpage(struct file *file, struct page *page)
466 return err; 466 return err;
467} 467}
468 468
469int hostfs_prepare_write(struct file *file, struct page *page, 469int hostfs_write_begin(struct file *file, struct address_space *mapping,
470 unsigned int from, unsigned int to) 470 loff_t pos, unsigned len, unsigned flags,
471 struct page **pagep, void **fsdata)
471{ 472{
472 char *buffer; 473 pgoff_t index = pos >> PAGE_CACHE_SHIFT;
473 long long start, tmp;
474 int err;
475 474
476 start = (long long) page->index << PAGE_CACHE_SHIFT; 475 *pagep = __grab_cache_page(mapping, index);
477 buffer = kmap(page); 476 if (!*pagep)
478 if(from != 0){ 477 return -ENOMEM;
479 tmp = start; 478 return 0;
480 err = read_file(FILE_HOSTFS_I(file)->fd, &tmp, buffer,
481 from);
482 if(err < 0) goto out;
483 }
484 if(to != PAGE_CACHE_SIZE){
485 start += to;
486 err = read_file(FILE_HOSTFS_I(file)->fd, &start, buffer + to,
487 PAGE_CACHE_SIZE - to);
488 if(err < 0) goto out;
489 }
490 err = 0;
491 out:
492 kunmap(page);
493 return err;
494} 479}
495 480
496int hostfs_commit_write(struct file *file, struct page *page, unsigned from, 481int hostfs_write_end(struct file *file, struct address_space *mapping,
497 unsigned to) 482 loff_t pos, unsigned len, unsigned copied,
483 struct page *page, void *fsdata)
498{ 484{
499 struct address_space *mapping = page->mapping;
500 struct inode *inode = mapping->host; 485 struct inode *inode = mapping->host;
501 char *buffer; 486 void *buffer;
502 long long start; 487 unsigned from = pos & (PAGE_CACHE_SIZE - 1);
503 int err = 0; 488 int err;
504 489
505 start = (((long long) page->index) << PAGE_CACHE_SHIFT) + from;
506 buffer = kmap(page); 490 buffer = kmap(page);
507 err = write_file(FILE_HOSTFS_I(file)->fd, &start, buffer + from, 491 err = write_file(FILE_HOSTFS_I(file)->fd, &pos, buffer + from, copied);
508 to - from); 492 kunmap(page);
509 if(err > 0) err = 0;
510 493
511 /* Actually, if !err, write_file has added to-from to start, so, despite 494 if (!PageUptodate(page) && err == PAGE_CACHE_SIZE)
512 * the appearance, we are comparing i_size against the _last_ written 495 SetPageUptodate(page);
513 * location, as we should. */
514 496
515 if(!err && (start > inode->i_size)) 497 /* If err > 0, write_file has added err to pos, so we are comparing
516 inode->i_size = start; 498 * i_size against the last byte written.
499 */
500 if (err > 0 && (pos > inode->i_size))
501 inode->i_size = pos;
502 unlock_page(page);
503 page_cache_release(page);
517 504
518 kunmap(page);
519 return err; 505 return err;
520} 506}
521 507
@@ -523,8 +509,8 @@ static const struct address_space_operations hostfs_aops = {
523 .writepage = hostfs_writepage, 509 .writepage = hostfs_writepage,
524 .readpage = hostfs_readpage, 510 .readpage = hostfs_readpage,
525 .set_page_dirty = __set_page_dirty_nobuffers, 511 .set_page_dirty = __set_page_dirty_nobuffers,
526 .prepare_write = hostfs_prepare_write, 512 .write_begin = hostfs_write_begin,
527 .commit_write = hostfs_commit_write 513 .write_end = hostfs_write_end,
528}; 514};
529 515
530static int init_inode(struct inode *inode, struct dentry *dentry) 516static int init_inode(struct inode *inode, struct dentry *dentry)