From: Pekka Enberg Add read_mapping_page() which is used for callers that pass mapping->a_ops->readpage as the filler for read_cache_page. This removes some duplication from filesystem code. Signed-off-by: Pekka Enberg Signed-off-by: Andrew Morton --- fs/afs/dir.c | 4 +--- fs/afs/mntpt.c | 11 ++--------- fs/cramfs/inode.c | 4 +--- fs/ext2/dir.c | 3 +-- fs/freevxfs/vxfs_subr.c | 3 +-- fs/hfs/bnode.c | 2 +- fs/hfs/btree.c | 2 +- fs/hfsplus/bitmap.c | 15 +++++++-------- fs/hfsplus/bnode.c | 2 +- fs/hfsplus/btree.c | 2 +- fs/jfs/jfs_metapage.c | 5 ++--- fs/minix/dir.c | 3 +-- fs/namei.c | 3 +-- fs/ntfs/aops.h | 3 +-- fs/ntfs/attrib.c | 6 ++---- fs/ntfs/file.c | 3 +-- fs/ocfs2/symlink.c | 3 +-- fs/partitions/check.c | 4 ++-- fs/reiserfs/xattr.c | 3 +-- fs/sysv/dir.c | 3 +-- include/linux/pagemap.h | 7 +++++++ mm/swapfile.c | 3 +-- 22 files changed, 38 insertions(+), 56 deletions(-) diff -puN fs/afs/dir.c~read_mapping_page-for-address-space fs/afs/dir.c --- devel/fs/afs/dir.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/afs/dir.c 2006-04-22 01:39:36.000000000 -0700 @@ -185,9 +185,7 @@ static struct page *afs_dir_get_page(str _enter("{%lu},%lu", dir->i_ino, index); - page = read_cache_page(dir->i_mapping,index, - (filler_t *) dir->i_mapping->a_ops->readpage, - NULL); + page = read_mapping_page(dir->i_mapping, index, NULL); if (!IS_ERR(page)) { wait_on_page_locked(page); kmap(page); diff -puN fs/afs/mntpt.c~read_mapping_page-for-address-space fs/afs/mntpt.c --- devel/fs/afs/mntpt.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/afs/mntpt.c 2006-04-22 01:39:36.000000000 -0700 @@ -63,7 +63,6 @@ unsigned long afs_mntpt_expiry_timeout = int afs_mntpt_check_symlink(struct afs_vnode *vnode) { struct page *page; - filler_t *filler; size_t size; char *buf; int ret; @@ -71,10 +70,7 @@ int afs_mntpt_check_symlink(struct afs_v _enter("{%u,%u}", vnode->fid.vnode, vnode->fid.unique); /* read the contents of the symlink into the pagecache */ - filler = (filler_t *) AFS_VNODE_TO_I(vnode)->i_mapping->a_ops->readpage; - - page = read_cache_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, - filler, NULL); + page = read_mapping_page(AFS_VNODE_TO_I(vnode)->i_mapping, 0, NULL); if (IS_ERR(page)) { ret = PTR_ERR(page); goto out; @@ -160,7 +156,6 @@ static struct vfsmount *afs_mntpt_do_aut struct page *page = NULL; size_t size; char *buf, *devname = NULL, *options = NULL; - filler_t *filler; int ret; kenter("{%s}", mntpt->d_name.name); @@ -182,9 +177,7 @@ static struct vfsmount *afs_mntpt_do_aut goto error; /* read the contents of the AFS special symlink */ - filler = (filler_t *)mntpt->d_inode->i_mapping->a_ops->readpage; - - page = read_cache_page(mntpt->d_inode->i_mapping, 0, filler, NULL); + page = read_mapping_page(mntpt->d_inode->i_mapping, 0, NULL); if (IS_ERR(page)) { ret = PTR_ERR(page); goto error; diff -puN fs/cramfs/inode.c~read_mapping_page-for-address-space fs/cramfs/inode.c --- devel/fs/cramfs/inode.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/cramfs/inode.c 2006-04-22 01:39:36.000000000 -0700 @@ -181,9 +181,7 @@ static void *cramfs_read(struct super_bl struct page *page = NULL; if (blocknr + i < devsize) { - page = read_cache_page(mapping, blocknr + i, - (filler_t *)mapping->a_ops->readpage, - NULL); + page = read_mapping_page(mapping, blocknr + i, NULL); /* synchronous error? */ if (IS_ERR(page)) page = NULL; diff -puN fs/ext2/dir.c~read_mapping_page-for-address-space fs/ext2/dir.c --- devel/fs/ext2/dir.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/ext2/dir.c 2006-04-22 01:39:36.000000000 -0700 @@ -159,8 +159,7 @@ fail: static struct page * ext2_get_page(struct inode *dir, unsigned long n) { struct address_space *mapping = dir->i_mapping; - struct page *page = read_cache_page(mapping, n, - (filler_t*)mapping->a_ops->readpage, NULL); + struct page *page = read_mapping_page(mapping, n, NULL); if (!IS_ERR(page)) { wait_on_page_locked(page); kmap(page); diff -puN fs/freevxfs/vxfs_subr.c~read_mapping_page-for-address-space fs/freevxfs/vxfs_subr.c --- devel/fs/freevxfs/vxfs_subr.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/freevxfs/vxfs_subr.c 2006-04-22 01:39:36.000000000 -0700 @@ -71,8 +71,7 @@ vxfs_get_page(struct address_space *mapp { struct page * pp; - pp = read_cache_page(mapping, n, - (filler_t*)mapping->a_ops->readpage, NULL); + pp = read_mapping_page(mapping, n, NULL); if (!IS_ERR(pp)) { wait_on_page_locked(pp); diff -puN fs/hfs/bnode.c~read_mapping_page-for-address-space fs/hfs/bnode.c --- devel/fs/hfs/bnode.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/hfs/bnode.c 2006-04-22 01:39:36.000000000 -0700 @@ -280,7 +280,7 @@ static struct hfs_bnode *__hfs_bnode_cre block = off >> PAGE_CACHE_SHIFT; node->page_offset = off & ~PAGE_CACHE_MASK; for (i = 0; i < tree->pages_per_bnode; i++) { - page = read_cache_page(mapping, block++, (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, block++, NULL); if (IS_ERR(page)) goto fail; if (PageError(page)) { diff -puN fs/hfs/btree.c~read_mapping_page-for-address-space fs/hfs/btree.c --- devel/fs/hfs/btree.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/hfs/btree.c 2006-04-22 01:39:36.000000000 -0700 @@ -59,7 +59,7 @@ struct hfs_btree *hfs_btree_open(struct unlock_new_inode(tree->inode); mapping = tree->inode->i_mapping; - page = read_cache_page(mapping, 0, (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, 0, NULL); if (IS_ERR(page)) goto free_tree; diff -puN fs/hfsplus/bitmap.c~read_mapping_page-for-address-space fs/hfsplus/bitmap.c --- devel/fs/hfsplus/bitmap.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/hfsplus/bitmap.c 2006-04-22 01:39:36.000000000 -0700 @@ -31,8 +31,7 @@ int hfsplus_block_allocate(struct super_ dprint(DBG_BITMAP, "block_allocate: %u,%u,%u\n", size, offset, len); mutex_lock(&HFSPLUS_SB(sb).alloc_file->i_mutex); mapping = HFSPLUS_SB(sb).alloc_file->i_mapping; - page = read_cache_page(mapping, offset / PAGE_CACHE_BITS, - (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS, NULL); pptr = kmap(page); curr = pptr + (offset & (PAGE_CACHE_BITS - 1)) / 32; i = offset % 32; @@ -72,8 +71,8 @@ int hfsplus_block_allocate(struct super_ offset += PAGE_CACHE_BITS; if (offset >= size) break; - page = read_cache_page(mapping, offset / PAGE_CACHE_BITS, - (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS, + NULL); curr = pptr = kmap(page); if ((size ^ offset) / PAGE_CACHE_BITS) end = pptr + PAGE_CACHE_BITS / 32; @@ -119,8 +118,8 @@ found: set_page_dirty(page); kunmap(page); offset += PAGE_CACHE_BITS; - page = read_cache_page(mapping, offset / PAGE_CACHE_BITS, - (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, offset / PAGE_CACHE_BITS, + NULL); pptr = kmap(page); curr = pptr; end = pptr + PAGE_CACHE_BITS / 32; @@ -167,7 +166,7 @@ int hfsplus_block_free(struct super_bloc mutex_lock(&HFSPLUS_SB(sb).alloc_file->i_mutex); mapping = HFSPLUS_SB(sb).alloc_file->i_mapping; pnr = offset / PAGE_CACHE_BITS; - page = read_cache_page(mapping, pnr, (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, pnr, NULL); pptr = kmap(page); curr = pptr + (offset & (PAGE_CACHE_BITS - 1)) / 32; end = pptr + PAGE_CACHE_BITS / 32; @@ -199,7 +198,7 @@ int hfsplus_block_free(struct super_bloc break; set_page_dirty(page); kunmap(page); - page = read_cache_page(mapping, ++pnr, (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, ++pnr, NULL); pptr = kmap(page); curr = pptr; end = pptr + PAGE_CACHE_BITS / 32; diff -puN fs/hfsplus/bnode.c~read_mapping_page-for-address-space fs/hfsplus/bnode.c --- devel/fs/hfsplus/bnode.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/hfsplus/bnode.c 2006-04-22 01:39:36.000000000 -0700 @@ -440,7 +440,7 @@ static struct hfs_bnode *__hfs_bnode_cre block = off >> PAGE_CACHE_SHIFT; node->page_offset = off & ~PAGE_CACHE_MASK; for (i = 0; i < tree->pages_per_bnode; block++, i++) { - page = read_cache_page(mapping, block, (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, block, NULL); if (IS_ERR(page)) goto fail; if (PageError(page)) { diff -puN fs/hfsplus/btree.c~read_mapping_page-for-address-space fs/hfsplus/btree.c --- devel/fs/hfsplus/btree.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/hfsplus/btree.c 2006-04-22 01:39:36.000000000 -0700 @@ -38,7 +38,7 @@ struct hfs_btree *hfs_btree_open(struct goto free_tree; mapping = tree->inode->i_mapping; - page = read_cache_page(mapping, 0, (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, 0, NULL); if (IS_ERR(page)) goto free_tree; diff -puN fs/jfs/jfs_metapage.c~read_mapping_page-for-address-space fs/jfs/jfs_metapage.c --- devel/fs/jfs/jfs_metapage.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/jfs/jfs_metapage.c 2006-04-22 01:39:36.000000000 -0700 @@ -642,10 +642,9 @@ struct metapage *__get_metapage(struct i } SetPageUptodate(page); } else { - page = read_cache_page(mapping, page_index, - (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, page_index, NULL); if (IS_ERR(page) || !PageUptodate(page)) { - jfs_err("read_cache_page failed!"); + jfs_err("read_mapping_page failed!"); return NULL; } lock_page(page); diff -puN fs/minix/dir.c~read_mapping_page-for-address-space fs/minix/dir.c --- devel/fs/minix/dir.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/minix/dir.c 2006-04-22 01:39:36.000000000 -0700 @@ -60,8 +60,7 @@ static int dir_commit_chunk(struct page static struct page * dir_get_page(struct inode *dir, unsigned long n) { struct address_space *mapping = dir->i_mapping; - struct page *page = read_cache_page(mapping, n, - (filler_t*)mapping->a_ops->readpage, NULL); + struct page *page = read_mapping_page(mapping, n, NULL); if (!IS_ERR(page)) { wait_on_page_locked(page); kmap(page); diff -puN fs/namei.c~read_mapping_page-for-address-space fs/namei.c --- devel/fs/namei.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/namei.c 2006-04-22 01:39:36.000000000 -0700 @@ -2576,8 +2576,7 @@ static char *page_getlink(struct dentry { struct page * page; struct address_space *mapping = dentry->d_inode->i_mapping; - page = read_cache_page(mapping, 0, (filler_t *)mapping->a_ops->readpage, - NULL); + page = read_mapping_page(mapping, 0, NULL); if (IS_ERR(page)) goto sync_fail; wait_on_page_locked(page); diff -puN fs/ntfs/aops.h~read_mapping_page-for-address-space fs/ntfs/aops.h --- devel/fs/ntfs/aops.h~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/ntfs/aops.h 2006-04-22 01:39:36.000000000 -0700 @@ -86,8 +86,7 @@ static inline void ntfs_unmap_page(struc static inline struct page *ntfs_map_page(struct address_space *mapping, unsigned long index) { - struct page *page = read_cache_page(mapping, index, - (filler_t*)mapping->a_ops->readpage, NULL); + struct page *page = read_mapping_page(mapping, index, NULL); if (!IS_ERR(page)) { wait_on_page_locked(page); diff -puN fs/ntfs/attrib.c~read_mapping_page-for-address-space fs/ntfs/attrib.c --- devel/fs/ntfs/attrib.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/ntfs/attrib.c 2006-04-22 01:39:36.000000000 -0700 @@ -2529,8 +2529,7 @@ int ntfs_attr_set(ntfs_inode *ni, const end >>= PAGE_CACHE_SHIFT; /* If there is a first partial page, need to do it the slow way. */ if (start_ofs) { - page = read_cache_page(mapping, idx, - (filler_t*)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, idx, NULL); if (IS_ERR(page)) { ntfs_error(vol->sb, "Failed to read first partial " "page (sync error, index 0x%lx).", idx); @@ -2600,8 +2599,7 @@ int ntfs_attr_set(ntfs_inode *ni, const } /* If there is a last partial page, need to do it the slow way. */ if (end_ofs) { - page = read_cache_page(mapping, idx, - (filler_t*)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, idx, NULL); if (IS_ERR(page)) { ntfs_error(vol->sb, "Failed to read last partial page " "(sync error, index 0x%lx).", idx); diff -puN fs/ntfs/file.c~read_mapping_page-for-address-space fs/ntfs/file.c --- devel/fs/ntfs/file.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/ntfs/file.c 2006-04-22 01:39:36.000000000 -0700 @@ -231,8 +231,7 @@ do_non_resident_extend: * Read the page. If the page is not present, this will zero * the uninitialized regions for us. */ - page = read_cache_page(mapping, index, - (filler_t*)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, index, NULL); if (IS_ERR(page)) { err = PTR_ERR(page); goto init_err_out; diff -puN fs/ocfs2/symlink.c~read_mapping_page-for-address-space fs/ocfs2/symlink.c --- devel/fs/ocfs2/symlink.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/ocfs2/symlink.c 2006-04-22 01:39:36.000000000 -0700 @@ -64,8 +64,7 @@ static char *ocfs2_page_getlink(struct d { struct page * page; struct address_space *mapping = dentry->d_inode->i_mapping; - page = read_cache_page(mapping, 0, - (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, 0, NULL); if (IS_ERR(page)) goto sync_fail; wait_on_page_locked(page); diff -puN fs/partitions/check.c~read_mapping_page-for-address-space fs/partitions/check.c --- devel/fs/partitions/check.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/partitions/check.c 2006-04-22 01:39:36.000000000 -0700 @@ -496,8 +496,8 @@ unsigned char *read_dev_sector(struct bl struct address_space *mapping = bdev->bd_inode->i_mapping; struct page *page; - page = read_cache_page(mapping, (pgoff_t)(n >> (PAGE_CACHE_SHIFT-9)), - (filler_t *)mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, (pgoff_t)(n >> (PAGE_CACHE_SHIFT-9)), + NULL); if (!IS_ERR(page)) { wait_on_page_locked(page); if (!PageUptodate(page)) diff -puN fs/reiserfs/xattr.c~read_mapping_page-for-address-space fs/reiserfs/xattr.c --- devel/fs/reiserfs/xattr.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/reiserfs/xattr.c 2006-04-22 01:39:36.000000000 -0700 @@ -452,8 +452,7 @@ static struct page *reiserfs_get_page(st /* We can deadlock if we try to free dentries, and an unlink/rmdir has just occured - GFP_NOFS avoids this */ mapping_set_gfp_mask(mapping, GFP_NOFS); - page = read_cache_page(mapping, n, - (filler_t *) mapping->a_ops->readpage, NULL); + page = read_mapping_page(mapping, n, NULL); if (!IS_ERR(page)) { wait_on_page_locked(page); kmap(page); diff -puN fs/sysv/dir.c~read_mapping_page-for-address-space fs/sysv/dir.c --- devel/fs/sysv/dir.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/fs/sysv/dir.c 2006-04-22 01:39:36.000000000 -0700 @@ -53,8 +53,7 @@ static int dir_commit_chunk(struct page static struct page * dir_get_page(struct inode *dir, unsigned long n) { struct address_space *mapping = dir->i_mapping; - struct page *page = read_cache_page(mapping, n, - (filler_t*)mapping->a_ops->readpage, NULL); + struct page *page = read_mapping_page(mapping, n, NULL); if (!IS_ERR(page)) { wait_on_page_locked(page); kmap(page); diff -puN include/linux/pagemap.h~read_mapping_page-for-address-space include/linux/pagemap.h --- devel/include/linux/pagemap.h~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/include/linux/pagemap.h 2006-04-22 01:39:36.000000000 -0700 @@ -97,6 +97,13 @@ extern struct page * read_cache_page(str extern int read_cache_pages(struct address_space *mapping, struct list_head *pages, filler_t *filler, void *data); +static inline struct page *read_mapping_page(struct address_space *mapping, + unsigned long index, void *data) +{ + filler_t *filler = (filler_t *)mapping->a_ops->readpage; + return read_cache_page(mapping, index, filler, data); +} + int add_to_page_cache(struct page *page, struct address_space *mapping, unsigned long index, gfp_t gfp_mask); int add_to_page_cache_lru(struct page *page, struct address_space *mapping, diff -puN mm/swapfile.c~read_mapping_page-for-address-space mm/swapfile.c --- devel/mm/swapfile.c~read_mapping_page-for-address-space 2006-04-22 01:39:36.000000000 -0700 +++ devel-akpm/mm/swapfile.c 2006-04-22 01:39:36.000000000 -0700 @@ -1491,8 +1491,7 @@ asmlinkage long sys_swapon(const char __ error = -EINVAL; goto bad_swap; } - page = read_cache_page(mapping, 0, - (filler_t *)mapping->a_ops->readpage, swap_file); + page = read_mapping_page(mapping, 0, swap_file); if (IS_ERR(page)) { error = PTR_ERR(page); goto bad_swap; _