1 ext4: call ext4_map_blocks() directly from read_page.c
3 Use ext4_map_blocks() directly instead of going through
4 ext4_get_block(). This allows us to drop out a lot of generic code
5 that was not needed for ext4.
7 Signed-off-by: Theodore Ts'o <tytso@mit.edu>
11 fs/ext4/readpage.c | 83 ++++++++++++++++++-----------------------------------------------------------------
12 1 file changed, 18 insertions(+), 65 deletions(-)
14 diff --git a/fs/ext4/readpage.c b/fs/ext4/readpage.c
15 index 3b29da1..ce3ecc1 100644
16 --- a/fs/ext4/readpage.c
17 +++ b/fs/ext4/readpage.c
18 @@ -85,49 +85,6 @@ mpage_alloc(struct block_device *bdev,
22 - * support function for mpage_readpages. The fs supplied get_block might
23 - * return an up to date buffer. This is used to map that buffer into
24 - * the page, which allows readpage to avoid triggering a duplicate call
27 - * The idea is to avoid adding buffers to pages that don't already have
28 - * them. So when the buffer is up to date and the page size == block size,
29 - * this marks the page up to date instead of adding new buffers.
32 -map_buffer_to_page(struct page *page, struct buffer_head *bh, int page_block)
34 - struct inode *inode = page->mapping->host;
35 - struct buffer_head *page_bh, *head;
38 - if (!page_has_buffers(page)) {
40 - * don't make any buffers if there is only one buffer on
41 - * the page and the page just needs to be set up to date
43 - if (inode->i_blkbits == PAGE_CACHE_SHIFT &&
44 - buffer_uptodate(bh)) {
45 - SetPageUptodate(page);
48 - create_empty_buffers(page, 1 << inode->i_blkbits, 0);
50 - head = page_buffers(page);
53 - if (block == page_block) {
54 - page_bh->b_state = bh->b_state;
55 - page_bh->b_bdev = bh->b_bdev;
56 - page_bh->b_blocknr = bh->b_blocknr;
59 - page_bh = page_bh->b_this_page;
61 - } while (page_bh != head);
65 * This is the worker routine which does all the work of mapping the disk
66 * blocks and constructs largest possible bios, submits them for IO if the
67 * blocks are not contiguous on the disk.
68 @@ -138,8 +95,8 @@ map_buffer_to_page(struct page *page, struct buffer_head *bh, int page_block)
71 do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
72 - sector_t *last_block_in_bio, struct buffer_head *map_bh,
73 - unsigned long *first_logical_block, get_block_t get_block)
74 + sector_t *last_block_in_bio, struct buffer_head *map_bh,
75 + unsigned long *first_logical_block)
77 struct inode *inode = page->mapping->host;
78 const unsigned blkbits = inode->i_blkbits;
79 @@ -151,7 +108,7 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
80 sector_t blocks[MAX_BUF_PER_PAGE];
82 unsigned first_hole = blocks_per_page;
83 - struct block_device *bdev = NULL;
84 + struct block_device *bdev = inode->i_sb->s_bdev;
88 @@ -188,7 +145,6 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
92 - bdev = map_bh->b_bdev;
96 @@ -200,9 +156,19 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
99 if (block_in_file < last_block) {
100 - map_bh->b_size = (last_block-block_in_file) << blkbits;
101 - if (get_block(inode, block_in_file, map_bh, 0))
102 + struct ext4_map_blocks map;
105 + map.m_lblk = block_in_file;
106 + map.m_len = last_block - block_in_file;
107 + ret = ext4_map_blocks(NULL, inode, &map, 0);
110 + map_bh->b_blocknr = map.m_pblk;
111 + map_bh->b_bdev = bdev;
112 + map_bh->b_size = inode->i_sb->s_blocksize * map.m_len;
113 + map_bh->b_state = map.m_flags;
115 *first_logical_block = block_in_file;
118 @@ -215,17 +181,6 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
122 - /* some filesystems will copy data into the page during
123 - * the get_block call, in which case we don't want to
124 - * read it again. map_buffer_to_page copies the data
125 - * we just collected from get_block into the page's buffers
126 - * so readpage doesn't have to repeat the get_block call
128 - if (buffer_uptodate(map_bh)) {
129 - map_buffer_to_page(page, map_bh, page_block);
133 if (first_hole != blocks_per_page)
134 goto confused; /* hole -> non-hole */
136 @@ -243,7 +198,6 @@ do_mpage_readpage(struct bio *bio, struct page *page, unsigned nr_pages,
140 - bdev = map_bh->b_bdev;
143 if (first_hole != blocks_per_page) {
144 @@ -303,7 +257,7 @@ confused:
146 bio = mpage_bio_submit(READ, bio);
147 if (!PageUptodate(page))
148 - block_read_full_page(page, get_block);
149 + block_read_full_page(page, ext4_get_block);
153 @@ -329,7 +283,7 @@ int ext4_readpage(struct file *file, struct page *page)
156 bio = do_mpage_readpage(bio, page, 1, &last_block_in_bio,
157 - &map_bh, &first_logical_block, ext4_get_block);
158 + &map_bh, &first_logical_block);
160 mpage_bio_submit(READ, bio);
162 @@ -361,8 +315,7 @@ int ext4_readpages(struct file *file, struct address_space *mapping,
163 bio = do_mpage_readpage(bio, page,
165 &last_block_in_bio, &map_bh,
166 - &first_logical_block,
168 + &first_logical_block);
170 page_cache_release(page);