[PATCH 17/37] CacheFiles: Add a hook to write a single page of data to an inode
Add an address space operation to write one single page of data to an inode at a page-aligned location (thus permitting the implementation to be highly optimised). The data source is a single page. This is used by CacheFiles to store the contents of netfs pages into their backing file pages. Supply a generic implementation for this that uses the write_begin() and write_end() address_space operations to bind a copy directly into the page cache. Hook the Ext2 and Ext3 operations to the generic implementation. Signed-off-by: David Howells <[EMAIL PROTECTED]> --- fs/ext2/inode.c|2 ++ fs/ext3/inode.c|3 +++ include/linux/fs.h |7 ++ mm/filemap.c | 61 4 files changed, 73 insertions(+), 0 deletions(-) diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index c620068..f483014 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -792,6 +792,7 @@ const struct address_space_operations ext2_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage= buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, }; const struct address_space_operations ext2_aops_xip = { @@ -810,6 +811,7 @@ const struct address_space_operations ext2_nobh_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage= buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, }; /* diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index c976123..0209f3b 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c @@ -1776,6 +1776,7 @@ static const struct address_space_operations ext3_ordered_aops = { .releasepage= ext3_releasepage, .direct_IO = ext3_direct_IO, .migratepage= buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, }; static const struct address_space_operations ext3_writeback_aops = { @@ -1790,6 +1791,7 @@ static const struct address_space_operations ext3_writeback_aops = { .releasepage= ext3_releasepage, .direct_IO = ext3_direct_IO, .migratepage= buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, }; static const struct address_space_operations ext3_journalled_aops = { @@ -1803,6 +1805,7 @@ static const struct address_space_operations ext3_journalled_aops = { .bmap = ext3_bmap, .invalidatepage = ext3_invalidatepage, .releasepage= ext3_releasepage, + .write_one_page = generic_file_buffered_write_one_page, }; void ext3_set_aops(struct inode *inode) diff --git a/include/linux/fs.h b/include/linux/fs.h index d218ef5..dd6c3d1 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -481,6 +481,11 @@ struct address_space_operations { int (*migratepage) (struct address_space *, struct page *, struct page *); int (*launder_page) (struct page *); + /* write the contents of the source page over the page at the specified +* index in the target address space (the source page does not need to +* be related to the target address space) */ + int (*write_one_page)(struct address_space *, pgoff_t, struct page *); + }; /* @@ -1811,6 +1816,8 @@ extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, unsigned long *, loff_t, loff_t *, size_t, size_t); extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *, unsigned long, loff_t, loff_t *, size_t, ssize_t); +extern int generic_file_buffered_write_one_page(struct address_space *, + pgoff_t, struct page *); extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); extern int generic_segment_checks(const struct iovec *iov, diff --git a/mm/filemap.c b/mm/filemap.c index df1e149..a583f44 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2359,6 +2359,67 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov, } EXPORT_SYMBOL(generic_file_buffered_write); +/** + * generic_file_buffered_write_one_page - Write a single page of data to an + * inode + * @mapping - The address space of the target inode + * @index - The target page in the target inode to fill + * @source - The data to write into the target page + * + * Write the data from the source page to the page in the nominated address + * space at the @index specified. Note that the file will not be extended if + * the page crosses the EOF marker, in which case only the first part of the + * page will be written. + * + * The @source page does not need to have any association with the fi
[PATCH 17/37] CacheFiles: Add a hook to write a single page of data to an inode
Add an address space operation to write one single page of data to an inode at a page-aligned location (thus permitting the implementation to be highly optimised). The data source is a single page. This is used by CacheFiles to store the contents of netfs pages into their backing file pages. Supply a generic implementation for this that uses the write_begin() and write_end() address_space operations to bind a copy directly into the page cache. Hook the Ext2 and Ext3 operations to the generic implementation. Signed-off-by: David Howells <[EMAIL PROTECTED]> --- fs/ext2/inode.c|2 ++ fs/ext3/inode.c|3 +++ include/linux/fs.h |7 ++ mm/filemap.c | 61 4 files changed, 73 insertions(+), 0 deletions(-) diff --git a/fs/ext2/inode.c b/fs/ext2/inode.c index c620068..f483014 100644 --- a/fs/ext2/inode.c +++ b/fs/ext2/inode.c @@ -792,6 +792,7 @@ const struct address_space_operations ext2_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage= buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, }; const struct address_space_operations ext2_aops_xip = { @@ -810,6 +811,7 @@ const struct address_space_operations ext2_nobh_aops = { .direct_IO = ext2_direct_IO, .writepages = ext2_writepages, .migratepage= buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, }; /* diff --git a/fs/ext3/inode.c b/fs/ext3/inode.c index c976123..0209f3b 100644 --- a/fs/ext3/inode.c +++ b/fs/ext3/inode.c @@ -1776,6 +1776,7 @@ static const struct address_space_operations ext3_ordered_aops = { .releasepage= ext3_releasepage, .direct_IO = ext3_direct_IO, .migratepage= buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, }; static const struct address_space_operations ext3_writeback_aops = { @@ -1790,6 +1791,7 @@ static const struct address_space_operations ext3_writeback_aops = { .releasepage= ext3_releasepage, .direct_IO = ext3_direct_IO, .migratepage= buffer_migrate_page, + .write_one_page = generic_file_buffered_write_one_page, }; static const struct address_space_operations ext3_journalled_aops = { @@ -1803,6 +1805,7 @@ static const struct address_space_operations ext3_journalled_aops = { .bmap = ext3_bmap, .invalidatepage = ext3_invalidatepage, .releasepage= ext3_releasepage, + .write_one_page = generic_file_buffered_write_one_page, }; void ext3_set_aops(struct inode *inode) diff --git a/include/linux/fs.h b/include/linux/fs.h index feea65d..35525c4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -481,6 +481,11 @@ struct address_space_operations { int (*migratepage) (struct address_space *, struct page *, struct page *); int (*launder_page) (struct page *); + /* write the contents of the source page over the page at the specified +* index in the target address space (the source page does not need to +* be related to the target address space) */ + int (*write_one_page)(struct address_space *, pgoff_t, struct page *); + }; /* @@ -1805,6 +1810,8 @@ extern ssize_t generic_file_direct_write(struct kiocb *, const struct iovec *, unsigned long *, loff_t, loff_t *, size_t, size_t); extern ssize_t generic_file_buffered_write(struct kiocb *, const struct iovec *, unsigned long, loff_t, loff_t *, size_t, ssize_t); +extern int generic_file_buffered_write_one_page(struct address_space *, + pgoff_t, struct page *); extern ssize_t do_sync_read(struct file *filp, char __user *buf, size_t len, loff_t *ppos); extern ssize_t do_sync_write(struct file *filp, const char __user *buf, size_t len, loff_t *ppos); extern void do_generic_mapping_read(struct address_space *mapping, diff --git a/mm/filemap.c b/mm/filemap.c index 89f5a5e..6c6cd76 100644 --- a/mm/filemap.c +++ b/mm/filemap.c @@ -2367,6 +2367,67 @@ generic_file_buffered_write(struct kiocb *iocb, const struct iovec *iov, } EXPORT_SYMBOL(generic_file_buffered_write); +/** + * generic_file_buffered_write_one_page - Write a single page of data to an + * inode + * @mapping - The address space of the target inode + * @index - The target page in the target inode to fill + * @source - The data to write into the target page + * + * Write the data from the source page to the page in the nominated address + * space at the @index specified. Note that the file will not be extended if + * the page crosses the EOF marker, in which case only the first part of the + * page will be written. + * + * The @source page does not need to have any association wit