aboutsummaryrefslogtreecommitdiffstats
path: root/fs/ext4/inode.c
diff options
context:
space:
mode:
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r--fs/ext4/inode.c176
1 files changed, 87 insertions, 89 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index dab84a2530ff..981a1fc30eaa 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -763,39 +763,47 @@ int ext4_get_block_unwritten(struct inode *inode, sector_t iblock,
763/* Maximum number of blocks we map for direct IO at once. */ 763/* Maximum number of blocks we map for direct IO at once. */
764#define DIO_MAX_BLOCKS 4096 764#define DIO_MAX_BLOCKS 4096
765 765
766static handle_t *start_dio_trans(struct inode *inode, 766/*
767 struct buffer_head *bh_result) 767 * Get blocks function for the cases that need to start a transaction -
768 * generally difference cases of direct IO and DAX IO. It also handles retries
769 * in case of ENOSPC.
770 */
771static int ext4_get_block_trans(struct inode *inode, sector_t iblock,
772 struct buffer_head *bh_result, int flags)
768{ 773{
769 int dio_credits; 774 int dio_credits;
775 handle_t *handle;
776 int retries = 0;
777 int ret;
770 778
771 /* Trim mapping request to maximum we can map at once for DIO */ 779 /* Trim mapping request to maximum we can map at once for DIO */
772 if (bh_result->b_size >> inode->i_blkbits > DIO_MAX_BLOCKS) 780 if (bh_result->b_size >> inode->i_blkbits > DIO_MAX_BLOCKS)
773 bh_result->b_size = DIO_MAX_BLOCKS << inode->i_blkbits; 781 bh_result->b_size = DIO_MAX_BLOCKS << inode->i_blkbits;
774 dio_credits = ext4_chunk_trans_blocks(inode, 782 dio_credits = ext4_chunk_trans_blocks(inode,
775 bh_result->b_size >> inode->i_blkbits); 783 bh_result->b_size >> inode->i_blkbits);
776 return ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, dio_credits); 784retry:
785 handle = ext4_journal_start(inode, EXT4_HT_MAP_BLOCKS, dio_credits);
786 if (IS_ERR(handle))
787 return PTR_ERR(handle);
788
789 ret = _ext4_get_block(inode, iblock, bh_result, flags);
790 ext4_journal_stop(handle);
791
792 if (ret == -ENOSPC && ext4_should_retry_alloc(inode->i_sb, &retries))
793 goto retry;
794 return ret;
777} 795}
778 796
779/* Get block function for DIO reads and writes to inodes without extents */ 797/* Get block function for DIO reads and writes to inodes without extents */
780int ext4_dio_get_block(struct inode *inode, sector_t iblock, 798int ext4_dio_get_block(struct inode *inode, sector_t iblock,
781 struct buffer_head *bh, int create) 799 struct buffer_head *bh, int create)
782{ 800{
783 handle_t *handle;
784 int ret;
785
786 /* We don't expect handle for direct IO */ 801 /* We don't expect handle for direct IO */
787 WARN_ON_ONCE(ext4_journal_current_handle()); 802 WARN_ON_ONCE(ext4_journal_current_handle());
788 803
789 if (create) { 804 if (!create)
790 handle = start_dio_trans(inode, bh); 805 return _ext4_get_block(inode, iblock, bh, 0);
791 if (IS_ERR(handle)) 806 return ext4_get_block_trans(inode, iblock, bh, EXT4_GET_BLOCKS_CREATE);
792 return PTR_ERR(handle);
793 }
794 ret = _ext4_get_block(inode, iblock, bh,
795 create ? EXT4_GET_BLOCKS_CREATE : 0);
796 if (create)
797 ext4_journal_stop(handle);
798 return ret;
799} 807}
800 808
801/* 809/*
@@ -806,18 +814,13 @@ int ext4_dio_get_block(struct inode *inode, sector_t iblock,
806static int ext4_dio_get_block_unwritten_async(struct inode *inode, 814static int ext4_dio_get_block_unwritten_async(struct inode *inode,
807 sector_t iblock, struct buffer_head *bh_result, int create) 815 sector_t iblock, struct buffer_head *bh_result, int create)
808{ 816{
809 handle_t *handle;
810 int ret; 817 int ret;
811 818
812 /* We don't expect handle for direct IO */ 819 /* We don't expect handle for direct IO */
813 WARN_ON_ONCE(ext4_journal_current_handle()); 820 WARN_ON_ONCE(ext4_journal_current_handle());
814 821
815 handle = start_dio_trans(inode, bh_result); 822 ret = ext4_get_block_trans(inode, iblock, bh_result,
816 if (IS_ERR(handle)) 823 EXT4_GET_BLOCKS_IO_CREATE_EXT);
817 return PTR_ERR(handle);
818 ret = _ext4_get_block(inode, iblock, bh_result,
819 EXT4_GET_BLOCKS_IO_CREATE_EXT);
820 ext4_journal_stop(handle);
821 824
822 /* 825 /*
823 * When doing DIO using unwritten extents, we need io_end to convert 826 * When doing DIO using unwritten extents, we need io_end to convert
@@ -850,18 +853,13 @@ static int ext4_dio_get_block_unwritten_async(struct inode *inode,
850static int ext4_dio_get_block_unwritten_sync(struct inode *inode, 853static int ext4_dio_get_block_unwritten_sync(struct inode *inode,
851 sector_t iblock, struct buffer_head *bh_result, int create) 854 sector_t iblock, struct buffer_head *bh_result, int create)
852{ 855{
853 handle_t *handle;
854 int ret; 856 int ret;
855 857
856 /* We don't expect handle for direct IO */ 858 /* We don't expect handle for direct IO */
857 WARN_ON_ONCE(ext4_journal_current_handle()); 859 WARN_ON_ONCE(ext4_journal_current_handle());
858 860
859 handle = start_dio_trans(inode, bh_result); 861 ret = ext4_get_block_trans(inode, iblock, bh_result,
860 if (IS_ERR(handle)) 862 EXT4_GET_BLOCKS_IO_CREATE_EXT);
861 return PTR_ERR(handle);
862 ret = _ext4_get_block(inode, iblock, bh_result,
863 EXT4_GET_BLOCKS_IO_CREATE_EXT);
864 ext4_journal_stop(handle);
865 863
866 /* 864 /*
867 * Mark inode as having pending DIO writes to unwritten extents. 865 * Mark inode as having pending DIO writes to unwritten extents.
@@ -1057,7 +1055,7 @@ int do_journal_get_write_access(handle_t *handle,
1057static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len, 1055static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
1058 get_block_t *get_block) 1056 get_block_t *get_block)
1059{ 1057{
1060 unsigned from = pos & (PAGE_CACHE_SIZE - 1); 1058 unsigned from = pos & (PAGE_SIZE - 1);
1061 unsigned to = from + len; 1059 unsigned to = from + len;
1062 struct inode *inode = page->mapping->host; 1060 struct inode *inode = page->mapping->host;
1063 unsigned block_start, block_end; 1061 unsigned block_start, block_end;
@@ -1069,15 +1067,15 @@ static int ext4_block_write_begin(struct page *page, loff_t pos, unsigned len,
1069 bool decrypt = false; 1067 bool decrypt = false;
1070 1068
1071 BUG_ON(!PageLocked(page)); 1069 BUG_ON(!PageLocked(page));
1072 BUG_ON(from > PAGE_CACHE_SIZE); 1070 BUG_ON(from > PAGE_SIZE);
1073 BUG_ON(to > PAGE_CACHE_SIZE); 1071 BUG_ON(to > PAGE_SIZE);
1074 BUG_ON(from > to); 1072 BUG_ON(from > to);
1075 1073
1076 if (!page_has_buffers(page)) 1074 if (!page_has_buffers(page))
1077 create_empty_buffers(page, blocksize, 0); 1075 create_empty_buffers(page, blocksize, 0);
1078 head = page_buffers(page); 1076 head = page_buffers(page);
1079 bbits = ilog2(blocksize); 1077 bbits = ilog2(blocksize);
1080 block = (sector_t)page->index << (PAGE_CACHE_SHIFT - bbits); 1078 block = (sector_t)page->index << (PAGE_SHIFT - bbits);
1081 1079
1082 for (bh = head, block_start = 0; bh != head || !block_start; 1080 for (bh = head, block_start = 0; bh != head || !block_start;
1083 block++, block_start = block_end, bh = bh->b_this_page) { 1081 block++, block_start = block_end, bh = bh->b_this_page) {
@@ -1159,8 +1157,8 @@ static int ext4_write_begin(struct file *file, struct address_space *mapping,
1159 * we allocate blocks but write fails for some reason 1157 * we allocate blocks but write fails for some reason
1160 */ 1158 */
1161 needed_blocks = ext4_writepage_trans_blocks(inode) + 1; 1159 needed_blocks = ext4_writepage_trans_blocks(inode) + 1;
1162 index = pos >> PAGE_CACHE_SHIFT; 1160 index = pos >> PAGE_SHIFT;
1163 from = pos & (PAGE_CACHE_SIZE - 1); 1161 from = pos & (PAGE_SIZE - 1);
1164 to = from + len; 1162 to = from + len;
1165 1163
1166 if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) { 1164 if (ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
@@ -1188,7 +1186,7 @@ retry_grab:
1188retry_journal: 1186retry_journal:
1189 handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks); 1187 handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, needed_blocks);
1190 if (IS_ERR(handle)) { 1188 if (IS_ERR(handle)) {
1191 page_cache_release(page); 1189 put_page(page);
1192 return PTR_ERR(handle); 1190 return PTR_ERR(handle);
1193 } 1191 }
1194 1192
@@ -1196,7 +1194,7 @@ retry_journal:
1196 if (page->mapping != mapping) { 1194 if (page->mapping != mapping) {
1197 /* The page got truncated from under us */ 1195 /* The page got truncated from under us */
1198 unlock_page(page); 1196 unlock_page(page);
1199 page_cache_release(page); 1197 put_page(page);
1200 ext4_journal_stop(handle); 1198 ext4_journal_stop(handle);
1201 goto retry_grab; 1199 goto retry_grab;
1202 } 1200 }
@@ -1252,7 +1250,7 @@ retry_journal:
1252 if (ret == -ENOSPC && 1250 if (ret == -ENOSPC &&
1253 ext4_should_retry_alloc(inode->i_sb, &retries)) 1251 ext4_should_retry_alloc(inode->i_sb, &retries))
1254 goto retry_journal; 1252 goto retry_journal;
1255 page_cache_release(page); 1253 put_page(page);
1256 return ret; 1254 return ret;
1257 } 1255 }
1258 *pagep = page; 1256 *pagep = page;
@@ -1295,7 +1293,7 @@ static int ext4_write_end(struct file *file,
1295 ret = ext4_jbd2_file_inode(handle, inode); 1293 ret = ext4_jbd2_file_inode(handle, inode);
1296 if (ret) { 1294 if (ret) {
1297 unlock_page(page); 1295 unlock_page(page);
1298 page_cache_release(page); 1296 put_page(page);
1299 goto errout; 1297 goto errout;
1300 } 1298 }
1301 } 1299 }
@@ -1315,7 +1313,7 @@ static int ext4_write_end(struct file *file,
1315 */ 1313 */
1316 i_size_changed = ext4_update_inode_size(inode, pos + copied); 1314 i_size_changed = ext4_update_inode_size(inode, pos + copied);
1317 unlock_page(page); 1315 unlock_page(page);
1318 page_cache_release(page); 1316 put_page(page);
1319 1317
1320 if (old_size < pos) 1318 if (old_size < pos)
1321 pagecache_isize_extended(inode, old_size, pos); 1319 pagecache_isize_extended(inode, old_size, pos);
@@ -1399,7 +1397,7 @@ static int ext4_journalled_write_end(struct file *file,
1399 int size_changed = 0; 1397 int size_changed = 0;
1400 1398
1401 trace_ext4_journalled_write_end(inode, pos, len, copied); 1399 trace_ext4_journalled_write_end(inode, pos, len, copied);
1402 from = pos & (PAGE_CACHE_SIZE - 1); 1400 from = pos & (PAGE_SIZE - 1);
1403 to = from + len; 1401 to = from + len;
1404 1402
1405 BUG_ON(!ext4_handle_valid(handle)); 1403 BUG_ON(!ext4_handle_valid(handle));
@@ -1423,7 +1421,7 @@ static int ext4_journalled_write_end(struct file *file,
1423 ext4_set_inode_state(inode, EXT4_STATE_JDATA); 1421 ext4_set_inode_state(inode, EXT4_STATE_JDATA);
1424 EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid; 1422 EXT4_I(inode)->i_datasync_tid = handle->h_transaction->t_tid;
1425 unlock_page(page); 1423 unlock_page(page);
1426 page_cache_release(page); 1424 put_page(page);
1427 1425
1428 if (old_size < pos) 1426 if (old_size < pos)
1429 pagecache_isize_extended(inode, old_size, pos); 1427 pagecache_isize_extended(inode, old_size, pos);
@@ -1537,7 +1535,7 @@ static void ext4_da_page_release_reservation(struct page *page,
1537 int num_clusters; 1535 int num_clusters;
1538 ext4_fsblk_t lblk; 1536 ext4_fsblk_t lblk;
1539 1537
1540 BUG_ON(stop > PAGE_CACHE_SIZE || stop < length); 1538 BUG_ON(stop > PAGE_SIZE || stop < length);
1541 1539
1542 head = page_buffers(page); 1540 head = page_buffers(page);
1543 bh = head; 1541 bh = head;
@@ -1553,7 +1551,7 @@ static void ext4_da_page_release_reservation(struct page *page,
1553 clear_buffer_delay(bh); 1551 clear_buffer_delay(bh);
1554 } else if (contiguous_blks) { 1552 } else if (contiguous_blks) {
1555 lblk = page->index << 1553 lblk = page->index <<
1556 (PAGE_CACHE_SHIFT - inode->i_blkbits); 1554 (PAGE_SHIFT - inode->i_blkbits);
1557 lblk += (curr_off >> inode->i_blkbits) - 1555 lblk += (curr_off >> inode->i_blkbits) -
1558 contiguous_blks; 1556 contiguous_blks;
1559 ext4_es_remove_extent(inode, lblk, contiguous_blks); 1557 ext4_es_remove_extent(inode, lblk, contiguous_blks);
@@ -1563,7 +1561,7 @@ static void ext4_da_page_release_reservation(struct page *page,
1563 } while ((bh = bh->b_this_page) != head); 1561 } while ((bh = bh->b_this_page) != head);
1564 1562
1565 if (contiguous_blks) { 1563 if (contiguous_blks) {
1566 lblk = page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits); 1564 lblk = page->index << (PAGE_SHIFT - inode->i_blkbits);
1567 lblk += (curr_off >> inode->i_blkbits) - contiguous_blks; 1565 lblk += (curr_off >> inode->i_blkbits) - contiguous_blks;
1568 ext4_es_remove_extent(inode, lblk, contiguous_blks); 1566 ext4_es_remove_extent(inode, lblk, contiguous_blks);
1569 } 1567 }
@@ -1572,7 +1570,7 @@ static void ext4_da_page_release_reservation(struct page *page,
1572 * need to release the reserved space for that cluster. */ 1570 * need to release the reserved space for that cluster. */
1573 num_clusters = EXT4_NUM_B2C(sbi, to_release); 1571 num_clusters = EXT4_NUM_B2C(sbi, to_release);
1574 while (num_clusters > 0) { 1572 while (num_clusters > 0) {
1575 lblk = (page->index << (PAGE_CACHE_SHIFT - inode->i_blkbits)) + 1573 lblk = (page->index << (PAGE_SHIFT - inode->i_blkbits)) +
1576 ((num_clusters - 1) << sbi->s_cluster_bits); 1574 ((num_clusters - 1) << sbi->s_cluster_bits);
1577 if (sbi->s_cluster_ratio == 1 || 1575 if (sbi->s_cluster_ratio == 1 ||
1578 !ext4_find_delalloc_cluster(inode, lblk)) 1576 !ext4_find_delalloc_cluster(inode, lblk))
@@ -1619,8 +1617,8 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,
1619 end = mpd->next_page - 1; 1617 end = mpd->next_page - 1;
1620 if (invalidate) { 1618 if (invalidate) {
1621 ext4_lblk_t start, last; 1619 ext4_lblk_t start, last;
1622 start = index << (PAGE_CACHE_SHIFT - inode->i_blkbits); 1620 start = index << (PAGE_SHIFT - inode->i_blkbits);
1623 last = end << (PAGE_CACHE_SHIFT - inode->i_blkbits); 1621 last = end << (PAGE_SHIFT - inode->i_blkbits);
1624 ext4_es_remove_extent(inode, start, last - start + 1); 1622 ext4_es_remove_extent(inode, start, last - start + 1);
1625 } 1623 }
1626 1624
@@ -1636,7 +1634,7 @@ static void mpage_release_unused_pages(struct mpage_da_data *mpd,
1636 BUG_ON(!PageLocked(page)); 1634 BUG_ON(!PageLocked(page));
1637 BUG_ON(PageWriteback(page)); 1635 BUG_ON(PageWriteback(page));
1638 if (invalidate) { 1636 if (invalidate) {
1639 block_invalidatepage(page, 0, PAGE_CACHE_SIZE); 1637 block_invalidatepage(page, 0, PAGE_SIZE);
1640 ClearPageUptodate(page); 1638 ClearPageUptodate(page);
1641 } 1639 }
1642 unlock_page(page); 1640 unlock_page(page);
@@ -2007,10 +2005,10 @@ static int ext4_writepage(struct page *page,
2007 2005
2008 trace_ext4_writepage(page); 2006 trace_ext4_writepage(page);
2009 size = i_size_read(inode); 2007 size = i_size_read(inode);
2010 if (page->index == size >> PAGE_CACHE_SHIFT) 2008 if (page->index == size >> PAGE_SHIFT)
2011 len = size & ~PAGE_CACHE_MASK; 2009 len = size & ~PAGE_MASK;
2012 else 2010 else
2013 len = PAGE_CACHE_SIZE; 2011 len = PAGE_SIZE;
2014 2012
2015 page_bufs = page_buffers(page); 2013 page_bufs = page_buffers(page);
2016 /* 2014 /*
@@ -2034,7 +2032,7 @@ static int ext4_writepage(struct page *page,
2034 ext4_bh_delay_or_unwritten)) { 2032 ext4_bh_delay_or_unwritten)) {
2035 redirty_page_for_writepage(wbc, page); 2033 redirty_page_for_writepage(wbc, page);
2036 if ((current->flags & PF_MEMALLOC) || 2034 if ((current->flags & PF_MEMALLOC) ||
2037 (inode->i_sb->s_blocksize == PAGE_CACHE_SIZE)) { 2035 (inode->i_sb->s_blocksize == PAGE_SIZE)) {
2038 /* 2036 /*
2039 * For memory cleaning there's no point in writing only 2037 * For memory cleaning there's no point in writing only
2040 * some buffers. So just bail out. Warn if we came here 2038 * some buffers. So just bail out. Warn if we came here
@@ -2076,10 +2074,10 @@ static int mpage_submit_page(struct mpage_da_data *mpd, struct page *page)
2076 int err; 2074 int err;
2077 2075
2078 BUG_ON(page->index != mpd->first_page); 2076 BUG_ON(page->index != mpd->first_page);
2079 if (page->index == size >> PAGE_CACHE_SHIFT) 2077 if (page->index == size >> PAGE_SHIFT)
2080 len = size & ~PAGE_CACHE_MASK; 2078 len = size & ~PAGE_MASK;
2081 else 2079 else
2082 len = PAGE_CACHE_SIZE; 2080 len = PAGE_SIZE;
2083 clear_page_dirty_for_io(page); 2081 clear_page_dirty_for_io(page);
2084 err = ext4_bio_write_page(&mpd->io_submit, page, len, mpd->wbc, false); 2082 err = ext4_bio_write_page(&mpd->io_submit, page, len, mpd->wbc, false);
2085 if (!err) 2083 if (!err)
@@ -2213,7 +2211,7 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)
2213 int nr_pages, i; 2211 int nr_pages, i;
2214 struct inode *inode = mpd->inode; 2212 struct inode *inode = mpd->inode;
2215 struct buffer_head *head, *bh; 2213 struct buffer_head *head, *bh;
2216 int bpp_bits = PAGE_CACHE_SHIFT - inode->i_blkbits; 2214 int bpp_bits = PAGE_SHIFT - inode->i_blkbits;
2217 pgoff_t start, end; 2215 pgoff_t start, end;
2218 ext4_lblk_t lblk; 2216 ext4_lblk_t lblk;
2219 sector_t pblock; 2217 sector_t pblock;
@@ -2274,7 +2272,7 @@ static int mpage_map_and_submit_buffers(struct mpage_da_data *mpd)
2274 * supports blocksize < pagesize as we will try to 2272 * supports blocksize < pagesize as we will try to
2275 * convert potentially unmapped parts of inode. 2273 * convert potentially unmapped parts of inode.
2276 */ 2274 */
2277 mpd->io_submit.io_end->size += PAGE_CACHE_SIZE; 2275 mpd->io_submit.io_end->size += PAGE_SIZE;
2278 /* Page fully mapped - let IO run! */ 2276 /* Page fully mapped - let IO run! */
2279 err = mpage_submit_page(mpd, page); 2277 err = mpage_submit_page(mpd, page);
2280 if (err < 0) { 2278 if (err < 0) {
@@ -2426,7 +2424,7 @@ update_disksize:
2426 * Update on-disk size after IO is submitted. Races with 2424 * Update on-disk size after IO is submitted. Races with
2427 * truncate are avoided by checking i_size under i_data_sem. 2425 * truncate are avoided by checking i_size under i_data_sem.
2428 */ 2426 */
2429 disksize = ((loff_t)mpd->first_page) << PAGE_CACHE_SHIFT; 2427 disksize = ((loff_t)mpd->first_page) << PAGE_SHIFT;
2430 if (disksize > EXT4_I(inode)->i_disksize) { 2428 if (disksize > EXT4_I(inode)->i_disksize) {
2431 int err2; 2429 int err2;
2432 loff_t i_size; 2430 loff_t i_size;
@@ -2562,7 +2560,7 @@ static int mpage_prepare_extent_to_map(struct mpage_da_data *mpd)
2562 mpd->next_page = page->index + 1; 2560 mpd->next_page = page->index + 1;
2563 /* Add all dirty buffers to mpd */ 2561 /* Add all dirty buffers to mpd */
2564 lblk = ((ext4_lblk_t)page->index) << 2562 lblk = ((ext4_lblk_t)page->index) <<
2565 (PAGE_CACHE_SHIFT - blkbits); 2563 (PAGE_SHIFT - blkbits);
2566 head = page_buffers(page); 2564 head = page_buffers(page);
2567 err = mpage_process_page_bufs(mpd, head, head, lblk); 2565 err = mpage_process_page_bufs(mpd, head, head, lblk);
2568 if (err <= 0) 2566 if (err <= 0)
@@ -2647,7 +2645,7 @@ static int ext4_writepages(struct address_space *mapping,
2647 * We may need to convert up to one extent per block in 2645 * We may need to convert up to one extent per block in
2648 * the page and we may dirty the inode. 2646 * the page and we may dirty the inode.
2649 */ 2647 */
2650 rsv_blocks = 1 + (PAGE_CACHE_SIZE >> inode->i_blkbits); 2648 rsv_blocks = 1 + (PAGE_SIZE >> inode->i_blkbits);
2651 } 2649 }
2652 2650
2653 /* 2651 /*
@@ -2678,8 +2676,8 @@ static int ext4_writepages(struct address_space *mapping,
2678 mpd.first_page = writeback_index; 2676 mpd.first_page = writeback_index;
2679 mpd.last_page = -1; 2677 mpd.last_page = -1;
2680 } else { 2678 } else {
2681 mpd.first_page = wbc->range_start >> PAGE_CACHE_SHIFT; 2679 mpd.first_page = wbc->range_start >> PAGE_SHIFT;
2682 mpd.last_page = wbc->range_end >> PAGE_CACHE_SHIFT; 2680 mpd.last_page = wbc->range_end >> PAGE_SHIFT;
2683 } 2681 }
2684 2682
2685 mpd.inode = inode; 2683 mpd.inode = inode;
@@ -2838,7 +2836,7 @@ static int ext4_da_write_begin(struct file *file, struct address_space *mapping,
2838 struct inode *inode = mapping->host; 2836 struct inode *inode = mapping->host;
2839 handle_t *handle; 2837 handle_t *handle;
2840 2838
2841 index = pos >> PAGE_CACHE_SHIFT; 2839 index = pos >> PAGE_SHIFT;
2842 2840
2843 if (ext4_nonda_switch(inode->i_sb)) { 2841 if (ext4_nonda_switch(inode->i_sb)) {
2844 *fsdata = (void *)FALL_BACK_TO_NONDELALLOC; 2842 *fsdata = (void *)FALL_BACK_TO_NONDELALLOC;
@@ -2881,7 +2879,7 @@ retry_journal:
2881 handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE, 2879 handle = ext4_journal_start(inode, EXT4_HT_WRITE_PAGE,
2882 ext4_da_write_credits(inode, pos, len)); 2880 ext4_da_write_credits(inode, pos, len));
2883 if (IS_ERR(handle)) { 2881 if (IS_ERR(handle)) {
2884 page_cache_release(page); 2882 put_page(page);
2885 return PTR_ERR(handle); 2883 return PTR_ERR(handle);
2886 } 2884 }
2887 2885
@@ -2889,7 +2887,7 @@ retry_journal:
2889 if (page->mapping != mapping) { 2887 if (page->mapping != mapping) {
2890 /* The page got truncated from under us */ 2888 /* The page got truncated from under us */
2891 unlock_page(page); 2889 unlock_page(page);
2892 page_cache_release(page); 2890 put_page(page);
2893 ext4_journal_stop(handle); 2891 ext4_journal_stop(handle);
2894 goto retry_grab; 2892 goto retry_grab;
2895 } 2893 }
@@ -2917,7 +2915,7 @@ retry_journal:
2917 ext4_should_retry_alloc(inode->i_sb, &retries)) 2915 ext4_should_retry_alloc(inode->i_sb, &retries))
2918 goto retry_journal; 2916 goto retry_journal;
2919 2917
2920 page_cache_release(page); 2918 put_page(page);
2921 return ret; 2919 return ret;
2922 } 2920 }
2923 2921
@@ -2965,7 +2963,7 @@ static int ext4_da_write_end(struct file *file,
2965 len, copied, page, fsdata); 2963 len, copied, page, fsdata);
2966 2964
2967 trace_ext4_da_write_end(inode, pos, len, copied); 2965 trace_ext4_da_write_end(inode, pos, len, copied);
2968 start = pos & (PAGE_CACHE_SIZE - 1); 2966 start = pos & (PAGE_SIZE - 1);
2969 end = start + copied - 1; 2967 end = start + copied - 1;
2970 2968
2971 /* 2969 /*
@@ -3187,7 +3185,7 @@ static int __ext4_journalled_invalidatepage(struct page *page,
3187 /* 3185 /*
3188 * If it's a full truncate we just forget about the pending dirtying 3186 * If it's a full truncate we just forget about the pending dirtying
3189 */ 3187 */
3190 if (offset == 0 && length == PAGE_CACHE_SIZE) 3188 if (offset == 0 && length == PAGE_SIZE)
3191 ClearPageChecked(page); 3189 ClearPageChecked(page);
3192 3190
3193 return jbd2_journal_invalidatepage(journal, page, offset, length); 3191 return jbd2_journal_invalidatepage(journal, page, offset, length);
@@ -3556,8 +3554,8 @@ void ext4_set_aops(struct inode *inode)
3556static int __ext4_block_zero_page_range(handle_t *handle, 3554static int __ext4_block_zero_page_range(handle_t *handle,
3557 struct address_space *mapping, loff_t from, loff_t length) 3555 struct address_space *mapping, loff_t from, loff_t length)
3558{ 3556{
3559 ext4_fsblk_t index = from >> PAGE_CACHE_SHIFT; 3557 ext4_fsblk_t index = from >> PAGE_SHIFT;
3560 unsigned offset = from & (PAGE_CACHE_SIZE-1); 3558 unsigned offset = from & (PAGE_SIZE-1);
3561 unsigned blocksize, pos; 3559 unsigned blocksize, pos;
3562 ext4_lblk_t iblock; 3560 ext4_lblk_t iblock;
3563 struct inode *inode = mapping->host; 3561 struct inode *inode = mapping->host;
@@ -3565,14 +3563,14 @@ static int __ext4_block_zero_page_range(handle_t *handle,
3565 struct page *page; 3563 struct page *page;
3566 int err = 0; 3564 int err = 0;
3567 3565
3568 page = find_or_create_page(mapping, from >> PAGE_CACHE_SHIFT, 3566 page = find_or_create_page(mapping, from >> PAGE_SHIFT,
3569 mapping_gfp_constraint(mapping, ~__GFP_FS)); 3567 mapping_gfp_constraint(mapping, ~__GFP_FS));
3570 if (!page) 3568 if (!page)
3571 return -ENOMEM; 3569 return -ENOMEM;
3572 3570
3573 blocksize = inode->i_sb->s_blocksize; 3571 blocksize = inode->i_sb->s_blocksize;
3574 3572
3575 iblock = index << (PAGE_CACHE_SHIFT - inode->i_sb->s_blocksize_bits); 3573 iblock = index << (PAGE_SHIFT - inode->i_sb->s_blocksize_bits);
3576 3574
3577 if (!page_has_buffers(page)) 3575 if (!page_has_buffers(page))
3578 create_empty_buffers(page, blocksize, 0); 3576 create_empty_buffers(page, blocksize, 0);
@@ -3614,7 +3612,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
3614 ext4_encrypted_inode(inode)) { 3612 ext4_encrypted_inode(inode)) {
3615 /* We expect the key to be set. */ 3613 /* We expect the key to be set. */
3616 BUG_ON(!ext4_has_encryption_key(inode)); 3614 BUG_ON(!ext4_has_encryption_key(inode));
3617 BUG_ON(blocksize != PAGE_CACHE_SIZE); 3615 BUG_ON(blocksize != PAGE_SIZE);
3618 WARN_ON_ONCE(ext4_decrypt(page)); 3616 WARN_ON_ONCE(ext4_decrypt(page));
3619 } 3617 }
3620 } 3618 }
@@ -3638,7 +3636,7 @@ static int __ext4_block_zero_page_range(handle_t *handle,
3638 3636
3639unlock: 3637unlock:
3640 unlock_page(page); 3638 unlock_page(page);
3641 page_cache_release(page); 3639 put_page(page);
3642 return err; 3640 return err;
3643} 3641}
3644 3642
@@ -3653,7 +3651,7 @@ static int ext4_block_zero_page_range(handle_t *handle,
3653 struct address_space *mapping, loff_t from, loff_t length) 3651 struct address_space *mapping, loff_t from, loff_t length)
3654{ 3652{
3655 struct inode *inode = mapping->host; 3653 struct inode *inode = mapping->host;
3656 unsigned offset = from & (PAGE_CACHE_SIZE-1); 3654 unsigned offset = from & (PAGE_SIZE-1);
3657 unsigned blocksize = inode->i_sb->s_blocksize; 3655 unsigned blocksize = inode->i_sb->s_blocksize;
3658 unsigned max = blocksize - (offset & (blocksize - 1)); 3656 unsigned max = blocksize - (offset & (blocksize - 1));
3659 3657
@@ -3678,7 +3676,7 @@ static int ext4_block_zero_page_range(handle_t *handle,
3678static int ext4_block_truncate_page(handle_t *handle, 3676static int ext4_block_truncate_page(handle_t *handle,
3679 struct address_space *mapping, loff_t from) 3677 struct address_space *mapping, loff_t from)
3680{ 3678{
3681 unsigned offset = from & (PAGE_CACHE_SIZE-1); 3679 unsigned offset = from & (PAGE_SIZE-1);
3682 unsigned length; 3680 unsigned length;
3683 unsigned blocksize; 3681 unsigned blocksize;
3684 struct inode *inode = mapping->host; 3682 struct inode *inode = mapping->host;
@@ -3816,7 +3814,7 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
3816 */ 3814 */
3817 if (offset + length > inode->i_size) { 3815 if (offset + length > inode->i_size) {
3818 length = inode->i_size + 3816 length = inode->i_size +
3819 PAGE_CACHE_SIZE - (inode->i_size & (PAGE_CACHE_SIZE - 1)) - 3817 PAGE_SIZE - (inode->i_size & (PAGE_SIZE - 1)) -
3820 offset; 3818 offset;
3821 } 3819 }
3822 3820
@@ -4891,23 +4889,23 @@ static void ext4_wait_for_tail_page_commit(struct inode *inode)
4891 tid_t commit_tid = 0; 4889 tid_t commit_tid = 0;
4892 int ret; 4890 int ret;
4893 4891
4894 offset = inode->i_size & (PAGE_CACHE_SIZE - 1); 4892 offset = inode->i_size & (PAGE_SIZE - 1);
4895 /* 4893 /*
4896 * All buffers in the last page remain valid? Then there's nothing to 4894 * All buffers in the last page remain valid? Then there's nothing to
4897 * do. We do the check mainly to optimize the common PAGE_CACHE_SIZE == 4895 * do. We do the check mainly to optimize the common PAGE_SIZE ==
4898 * blocksize case 4896 * blocksize case
4899 */ 4897 */
4900 if (offset > PAGE_CACHE_SIZE - (1 << inode->i_blkbits)) 4898 if (offset > PAGE_SIZE - (1 << inode->i_blkbits))
4901 return; 4899 return;
4902 while (1) { 4900 while (1) {
4903 page = find_lock_page(inode->i_mapping, 4901 page = find_lock_page(inode->i_mapping,
4904 inode->i_size >> PAGE_CACHE_SHIFT); 4902 inode->i_size >> PAGE_SHIFT);
4905 if (!page) 4903 if (!page)
4906 return; 4904 return;
4907 ret = __ext4_journalled_invalidatepage(page, offset, 4905 ret = __ext4_journalled_invalidatepage(page, offset,
4908 PAGE_CACHE_SIZE - offset); 4906 PAGE_SIZE - offset);
4909 unlock_page(page); 4907 unlock_page(page);
4910 page_cache_release(page); 4908 put_page(page);
4911 if (ret != -EBUSY) 4909 if (ret != -EBUSY)
4912 return; 4910 return;
4913 commit_tid = 0; 4911 commit_tid = 0;
@@ -5546,10 +5544,10 @@ int ext4_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf)
5546 goto out; 5544 goto out;
5547 } 5545 }
5548 5546
5549 if (page->index == size >> PAGE_CACHE_SHIFT) 5547 if (page->index == size >> PAGE_SHIFT)
5550 len = size & ~PAGE_CACHE_MASK; 5548 len = size & ~PAGE_MASK;
5551 else 5549 else
5552 len = PAGE_CACHE_SIZE; 5550 len = PAGE_SIZE;
5553 /* 5551 /*
5554 * Return if we have all the buffers mapped. This avoids the need to do 5552 * Return if we have all the buffers mapped. This avoids the need to do
5555 * journal_start/journal_stop which can block and take a long time 5553 * journal_start/journal_stop which can block and take a long time
@@ -5580,7 +5578,7 @@ retry_alloc:
5580 ret = block_page_mkwrite(vma, vmf, get_block); 5578 ret = block_page_mkwrite(vma, vmf, get_block);
5581 if (!ret && ext4_should_journal_data(inode)) { 5579 if (!ret && ext4_should_journal_data(inode)) {
5582 if (ext4_walk_page_buffers(handle, page_buffers(page), 0, 5580 if (ext4_walk_page_buffers(handle, page_buffers(page), 0,
5583 PAGE_CACHE_SIZE, NULL, do_journal_get_write_access)) { 5581 PAGE_SIZE, NULL, do_journal_get_write_access)) {
5584 unlock_page(page); 5582 unlock_page(page);
5585 ret = VM_FAULT_SIGBUS; 5583 ret = VM_FAULT_SIGBUS;
5586 ext4_journal_stop(handle); 5584 ext4_journal_stop(handle);