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: Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
Reviewed-by: Josef Bacik <jbacik@redhat.com>
Acked-by: Jan Kara <jack@suse.cz>
Signed-off-by: "Theodore Ts'o" <tytso@mit.edu>
----

authored by Aneesh Kumar K.V and committed by Theodore Ts'o b767e78a e6462869

+16 -12
+16 -12
fs/ext4/inode.c
··· 2578 * all are mapped and non delay. We don't want to 2579 * do block allocation here. 2580 */ 2581 - ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, 2582 noalloc_get_block_write); 2583 if (!ret) { 2584 page_bufs = page_buffers(page); ··· 2600 return 0; 2601 } 2602 /* now mark the buffer_heads as dirty and uptodate */ 2603 - block_commit_write(page, 0, PAGE_CACHE_SIZE); 2604 } 2605 2606 if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode)) ··· 3246 static int __ext4_journalled_writepage(struct page *page, 3247 struct writeback_control *wbc) 3248 { 3249 struct address_space *mapping = page->mapping; 3250 struct inode *inode = mapping->host; 3251 struct buffer_head *page_bufs; ··· 3255 int ret = 0; 3256 int err; 3257 3258 - ret = block_prepare_write(page, 0, PAGE_CACHE_SIZE, 3259 - noalloc_get_block_write); 3260 if (ret != 0) 3261 goto out_unlock; 3262 3263 page_bufs = page_buffers(page); 3264 - walk_page_buffers(handle, page_bufs, 0, PAGE_CACHE_SIZE, NULL, 3265 - bget_one); 3266 /* As soon as we unlock the page, it can go away, but we have 3267 * references to buffers so we are safe */ 3268 unlock_page(page); ··· 3276 goto out; 3277 } 3278 3279 - ret = walk_page_buffers(handle, page_bufs, 0, 3280 - PAGE_CACHE_SIZE, NULL, do_journal_get_write_access); 3281 3282 - err = walk_page_buffers(handle, page_bufs, 0, 3283 - PAGE_CACHE_SIZE, NULL, write_end_fn); 3284 if (ret == 0) 3285 ret = err; 3286 err = ext4_journal_stop(handle); 3287 if (!ret) 3288 ret = err; 3289 3290 - walk_page_buffers(handle, page_bufs, 0, 3291 - PAGE_CACHE_SIZE, NULL, bput_one); 3292 EXT4_I(inode)->i_state |= EXT4_STATE_JDATA; 3293 goto out; 3294
··· 2578 * all are mapped and non delay. We don't want to 2579 * do block allocation here. 2580 */ 2581 + ret = block_prepare_write(page, 0, len, 2582 noalloc_get_block_write); 2583 if (!ret) { 2584 page_bufs = page_buffers(page); ··· 2600 return 0; 2601 } 2602 /* now mark the buffer_heads as dirty and uptodate */ 2603 + block_commit_write(page, 0, len); 2604 } 2605 2606 if (test_opt(inode->i_sb, NOBH) && ext4_should_writeback_data(inode)) ··· 3246 static int __ext4_journalled_writepage(struct page *page, 3247 struct writeback_control *wbc) 3248 { 3249 + loff_t size; 3250 + unsigned int len; 3251 struct address_space *mapping = page->mapping; 3252 struct inode *inode = mapping->host; 3253 struct buffer_head *page_bufs; ··· 3253 int ret = 0; 3254 int err; 3255 3256 + size = i_size_read(inode); 3257 + if (page->index == size >> PAGE_CACHE_SHIFT) 3258 + len = size & ~PAGE_CACHE_MASK; 3259 + else 3260 + len = PAGE_CACHE_SIZE; 3261 + ret = block_prepare_write(page, 0, len, noalloc_get_block_write); 3262 if (ret != 0) 3263 goto out_unlock; 3264 3265 page_bufs = page_buffers(page); 3266 + walk_page_buffers(handle, page_bufs, 0, len, NULL, bget_one); 3267 /* As soon as we unlock the page, it can go away, but we have 3268 * references to buffers so we are safe */ 3269 unlock_page(page); ··· 3271 goto out; 3272 } 3273 3274 + ret = walk_page_buffers(handle, page_bufs, 0, len, NULL, 3275 + do_journal_get_write_access); 3276 3277 + err = walk_page_buffers(handle, page_bufs, 0, len, NULL, 3278 + write_end_fn); 3279 if (ret == 0) 3280 ret = err; 3281 err = ext4_journal_stop(handle); 3282 if (!ret) 3283 ret = err; 3284 3285 + walk_page_buffers(handle, page_bufs, 0, len, NULL, bput_one); 3286 EXT4_I(inode)->i_state |= EXT4_STATE_JDATA; 3287 goto out; 3288