Commit b767e78a authored by Aneesh Kumar K.V's avatar Aneesh Kumar K.V Committed by Theodore Ts'o

ext4: Don't look at buffer_heads outside i_size.

Buffer heads outside i_size will be unmapped. So when we
are doing "walk_page_buffers" limit ourself to i_size.
Signed-off-by: default avatarAneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Reviewed-by: default avatarJosef Bacik <jbacik@redhat.com>
Acked-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatar"Theodore Ts'o" <tytso@mit.edu>
----
parent e6462869
...@@ -2578,7 +2578,7 @@ static int ext4_da_writepage(struct page *page, ...@@ -2578,7 +2578,7 @@ static int ext4_da_writepage(struct page *page,
* all are mapped and non delay. We don't want to * all are mapped and non delay. We don't want to
* do block allocation here. * do block allocation here.
*/ */
ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, ret = block_prepare_write(page, 0, len,
noalloc_get_block_write); noalloc_get_block_write);
if (!ret) { if (!ret) {
page_bufs = page_buffers(page); page_bufs = page_buffers(page);
...@@ -2600,7 +2600,7 @@ static int ext4_da_writepage(struct page *page, ...@@ -2600,7 +2600,7 @@ static int ext4_da_writepage(struct page *page,
return 0; return 0;
} }
/* now mark the buffer_heads as dirty and uptodate */ /* now mark the buffer_heads as dirty and uptodate */
block_commit_write(page, 0, PAGE_CACHE_SIZE); block_commit_write(page, 0, len);
} }
if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode)) if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode))
...@@ -3246,6 +3246,8 @@ static int ext4_normal_writepage(struct page *page, ...@@ -3246,6 +3246,8 @@ static int ext4_normal_writepage(struct page *page,
static int __ext4_journalled_writepage(struct page *page, static int __ext4_journalled_writepage(struct page *page,
struct writeback_control *wbc) struct writeback_control *wbc)
{ {
loff_t size;
unsigned int len;
struct address_space *mapping = page->mapping; struct address_space *mapping = page->mapping;
struct inode *inode = mapping->host; struct inode *inode = mapping->host;
struct buffer_head *page_bufs; struct buffer_head *page_bufs;
...@@ -3253,14 +3255,17 @@ static int __ext4_journalled_writepage(struct page *page, ...@@ -3253,14 +3255,17 @@ static int __ext4_journalled_writepage(struct page *page,
int ret = 0; int ret = 0;
int err; int err;
ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, size = i_size_read(inode);
noalloc_get_block_write); if (page->index == size >> PAGE_CACHE_SHIFT)
len = size & ~PAGE_CACHE_MASK;
else
len = PAGE_CACHE_SIZE;
ret = block_prepare_write(page, 0, len, noalloc_get_block_write);
if (ret != 0) if (ret != 0)
goto out_unlock; goto out_unlock;
page_bufs = page_buffers(page); page_bufs = page_buffers(page);
walk_page_buffers(handle, page_bufs, 0, PAGE_CACHE_SIZE, NULL, walk_page_buffers(handle, page_bufs, 0, len, NULL, bget_one);
bget_one);
/* As soon as we unlock the page, it can go away, but we have /* As soon as we unlock the page, it can go away, but we have
* references to buffers so we are safe */ * references to buffers so we are safe */
unlock_page(page); unlock_page(page);
...@@ -3271,19 +3276,18 @@ static int __ext4_journalled_writepage(struct page *page, ...@@ -3271,19 +3276,18 @@ static int __ext4_journalled_writepage(struct page *page,
goto out; goto out;
} }
ret = walk_page_buffers(handle, page_bufs, 0, ret = walk_page_buffers(handle, page_bufs, 0, len, NULL,
PAGE_CACHE_SIZE, NULL, do_journal_get_write_access); do_journal_get_write_access);
err = walk_page_buffers(handle, page_bufs, 0, err = walk_page_buffers(handle, page_bufs, 0, len, NULL,
PAGE_CACHE_SIZE, NULL, write_end_fn); write_end_fn);
if (ret == 0) if (ret == 0)
ret = err; ret = err;
err = ext4_journal_stop(handle); err = ext4_journal_stop(handle);
if (!ret) if (!ret)
ret = err; ret = err;
walk_page_buffers(handle, page_bufs, 0, walk_page_buffers(handle, page_bufs, 0, len, NULL, bput_one);
PAGE_CACHE_SIZE, NULL, bput_one);
EXT4_I(inode)->i_state |= EXT4_STATE_JDATA; EXT4_I(inode)->i_state |= EXT4_STATE_JDATA;
goto out; goto out;
......
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