summaryrefslogtreecommitdiffstats
path: root/fs/ext4/inode.c
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2019-09-21 16:37:39 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2019-09-21 16:37:39 -0400
commit70cb0d02b58128db07fc39b5e87a2873e2c16bde (patch)
tree43c0a4eb00f192ceb306b9c52503b2d54bc59660 /fs/ext4/inode.c
parent104c0d6bc43e10ba84931c45b67e2c76c9c67f68 (diff)
parent040823b5372b445d1d9483811e85a24d71314d33 (diff)
Merge tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4
Pull ext4 updates from Ted Ts'o: "Added new ext4 debugging ioctls to allow userspace to get information about the state of the extent status cache. Dropped workaround for pre-1970 dates which were encoded incorrectly in pre-4.4 kernels. Since both the kernel correctly generates, and e2fsck detects and fixes this issue for the past four years, it'e time to drop the workaround. (Also, it's not like files with dates in the distant past were all that common in the first place.) A lot of miscellaneous bug fixes and cleanups, including some ext4 Documentation fixes. Also included are two minor bug fixes in fs/unicode" * tag 'ext4_for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/tytso/ext4: (21 commits) unicode: make array 'token' static const, makes object smaller unicode: Move static keyword to the front of declarations ext4: add missing bigalloc documentation. ext4: fix kernel oops caused by spurious casefold flag ext4: fix integer overflow when calculating commit interval ext4: use percpu_counters for extent_status cache hits/misses ext4: fix potential use after free after remounting with noblock_validity jbd2: add missing tracepoint for reserved handle ext4: fix punch hole for inline_data file systems ext4: rework reserved cluster accounting when invalidating pages ext4: documentation fixes ext4: treat buffers with write errors as containing valid data ext4: fix warning inside ext4_convert_unwritten_extents_endio ext4: set error return correctly when ext4_htree_store_dirent fails ext4: drop legacy pre-1970 encoding workaround ext4: add new ioctl EXT4_IOC_GET_ES_CACHE ext4: add a new ioctl EXT4_IOC_GETSTATE ext4: add a new ioctl EXT4_IOC_CLEAR_ES_CACHE jbd2: flush_descriptor(): Do not decrease buffer head's ref count ext4: remove unnecessary error check ...
Diffstat (limited to 'fs/ext4/inode.c')
-rw-r--r--fs/ext4/inode.c103
1 files changed, 27 insertions, 76 deletions
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index d0dc0e3463db..123e3dee7733 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -527,7 +527,7 @@ int ext4_map_blocks(handle_t *handle, struct inode *inode,
527 return -EFSCORRUPTED; 527 return -EFSCORRUPTED;
528 528
529 /* Lookup extent status tree firstly */ 529 /* Lookup extent status tree firstly */
530 if (ext4_es_lookup_extent(inode, map->m_lblk, &es)) { 530 if (ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) {
531 if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) { 531 if (ext4_es_is_written(&es) || ext4_es_is_unwritten(&es)) {
532 map->m_pblk = ext4_es_pblock(&es) + 532 map->m_pblk = ext4_es_pblock(&es) +
533 map->m_lblk - es.es_lblk; 533 map->m_lblk - es.es_lblk;
@@ -695,7 +695,7 @@ found:
695 * extent status tree. 695 * extent status tree.
696 */ 696 */
697 if ((flags & EXT4_GET_BLOCKS_PRE_IO) && 697 if ((flags & EXT4_GET_BLOCKS_PRE_IO) &&
698 ext4_es_lookup_extent(inode, map->m_lblk, &es)) { 698 ext4_es_lookup_extent(inode, map->m_lblk, NULL, &es)) {
699 if (ext4_es_is_written(&es)) 699 if (ext4_es_is_written(&es))
700 goto out_sem; 700 goto out_sem;
701 } 701 }
@@ -1024,7 +1024,7 @@ struct buffer_head *ext4_bread(handle_t *handle, struct inode *inode,
1024 bh = ext4_getblk(handle, inode, block, map_flags); 1024 bh = ext4_getblk(handle, inode, block, map_flags);
1025 if (IS_ERR(bh)) 1025 if (IS_ERR(bh))
1026 return bh; 1026 return bh;
1027 if (!bh || buffer_uptodate(bh)) 1027 if (!bh || ext4_buffer_uptodate(bh))
1028 return bh; 1028 return bh;
1029 ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1, &bh); 1029 ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1, &bh);
1030 wait_on_buffer(bh); 1030 wait_on_buffer(bh);
@@ -1051,7 +1051,7 @@ int ext4_bread_batch(struct inode *inode, ext4_lblk_t block, int bh_count,
1051 1051
1052 for (i = 0; i < bh_count; i++) 1052 for (i = 0; i < bh_count; i++)
1053 /* Note that NULL bhs[i] is valid because of holes. */ 1053 /* Note that NULL bhs[i] is valid because of holes. */
1054 if (bhs[i] && !buffer_uptodate(bhs[i])) 1054 if (bhs[i] && !ext4_buffer_uptodate(bhs[i]))
1055 ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1, 1055 ll_rw_block(REQ_OP_READ, REQ_META | REQ_PRIO, 1,
1056 &bhs[i]); 1056 &bhs[i]);
1057 1057
@@ -1656,49 +1656,6 @@ void ext4_da_release_space(struct inode *inode, int to_free)
1656 dquot_release_reservation_block(inode, EXT4_C2B(sbi, to_free)); 1656 dquot_release_reservation_block(inode, EXT4_C2B(sbi, to_free));
1657} 1657}
1658 1658
1659static void ext4_da_page_release_reservation(struct page *page,
1660 unsigned int offset,
1661 unsigned int length)
1662{
1663 int contiguous_blks = 0;
1664 struct buffer_head *head, *bh;
1665 unsigned int curr_off = 0;
1666 struct inode *inode = page->mapping->host;
1667 unsigned int stop = offset + length;
1668 ext4_fsblk_t lblk;
1669
1670 BUG_ON(stop > PAGE_SIZE || stop < length);
1671
1672 head = page_buffers(page);
1673 bh = head;
1674 do {
1675 unsigned int next_off = curr_off + bh->b_size;
1676
1677 if (next_off > stop)
1678 break;
1679
1680 if ((offset <= curr_off) && (buffer_delay(bh))) {
1681 contiguous_blks++;
1682 clear_buffer_delay(bh);
1683 } else if (contiguous_blks) {
1684 lblk = page->index <<
1685 (PAGE_SHIFT - inode->i_blkbits);
1686 lblk += (curr_off >> inode->i_blkbits) -
1687 contiguous_blks;
1688 ext4_es_remove_blks(inode, lblk, contiguous_blks);
1689 contiguous_blks = 0;
1690 }
1691 curr_off = next_off;
1692 } while ((bh = bh->b_this_page) != head);
1693
1694 if (contiguous_blks) {
1695 lblk = page->index << (PAGE_SHIFT - inode->i_blkbits);
1696 lblk += (curr_off >> inode->i_blkbits) - contiguous_blks;
1697 ext4_es_remove_blks(inode, lblk, contiguous_blks);
1698 }
1699
1700}
1701
1702/* 1659/*
1703 * Delayed allocation stuff 1660 * Delayed allocation stuff
1704 */ 1661 */
@@ -1878,7 +1835,7 @@ static int ext4_da_map_blocks(struct inode *inode, sector_t iblock,
1878 (unsigned long) map->m_lblk); 1835 (unsigned long) map->m_lblk);
1879 1836
1880 /* Lookup extent status tree firstly */ 1837 /* Lookup extent status tree firstly */
1881 if (ext4_es_lookup_extent(inode, iblock, &es)) { 1838 if (ext4_es_lookup_extent(inode, iblock, NULL, &es)) {
1882 if (ext4_es_is_hole(&es)) { 1839 if (ext4_es_is_hole(&es)) {
1883 retval = 0; 1840 retval = 0;
1884 down_read(&EXT4_I(inode)->i_data_sem); 1841 down_read(&EXT4_I(inode)->i_data_sem);
@@ -2800,15 +2757,6 @@ static int ext4_writepages(struct address_space *mapping,
2800 goto out_writepages; 2757 goto out_writepages;
2801 } 2758 }
2802 2759
2803 if (ext4_should_dioread_nolock(inode)) {
2804 /*
2805 * We may need to convert up to one extent per block in
2806 * the page and we may dirty the inode.
2807 */
2808 rsv_blocks = 1 + ext4_chunk_trans_blocks(inode,
2809 PAGE_SIZE >> inode->i_blkbits);
2810 }
2811
2812 /* 2760 /*
2813 * If we have inline data and arrive here, it means that 2761 * If we have inline data and arrive here, it means that
2814 * we will soon create the block for the 1st page, so 2762 * we will soon create the block for the 1st page, so
@@ -2827,6 +2775,15 @@ static int ext4_writepages(struct address_space *mapping,
2827 ext4_journal_stop(handle); 2775 ext4_journal_stop(handle);
2828 } 2776 }
2829 2777
2778 if (ext4_should_dioread_nolock(inode)) {
2779 /*
2780 * We may need to convert up to one extent per block in
2781 * the page and we may dirty the inode.
2782 */
2783 rsv_blocks = 1 + ext4_chunk_trans_blocks(inode,
2784 PAGE_SIZE >> inode->i_blkbits);
2785 }
2786
2830 if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) 2787 if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
2831 range_whole = 1; 2788 range_whole = 1;
2832 2789
@@ -3242,24 +3199,6 @@ static int ext4_da_write_end(struct file *file,
3242 return ret ? ret : copied; 3199 return ret ? ret : copied;
3243} 3200}
3244 3201
3245static void ext4_da_invalidatepage(struct page *page, unsigned int offset,
3246 unsigned int length)
3247{
3248 /*
3249 * Drop reserved blocks
3250 */
3251 BUG_ON(!PageLocked(page));
3252 if (!page_has_buffers(page))
3253 goto out;
3254
3255 ext4_da_page_release_reservation(page, offset, length);
3256
3257out:
3258 ext4_invalidatepage(page, offset, length);
3259
3260 return;
3261}
3262
3263/* 3202/*
3264 * Force all delayed allocation blocks to be allocated for a given inode. 3203 * Force all delayed allocation blocks to be allocated for a given inode.
3265 */ 3204 */
@@ -4002,7 +3941,7 @@ static const struct address_space_operations ext4_da_aops = {
4002 .write_end = ext4_da_write_end, 3941 .write_end = ext4_da_write_end,
4003 .set_page_dirty = ext4_set_page_dirty, 3942 .set_page_dirty = ext4_set_page_dirty,
4004 .bmap = ext4_bmap, 3943 .bmap = ext4_bmap,
4005 .invalidatepage = ext4_da_invalidatepage, 3944 .invalidatepage = ext4_invalidatepage,
4006 .releasepage = ext4_releasepage, 3945 .releasepage = ext4_releasepage,
4007 .direct_IO = ext4_direct_IO, 3946 .direct_IO = ext4_direct_IO,
4008 .migratepage = buffer_migrate_page, 3947 .migratepage = buffer_migrate_page,
@@ -4314,6 +4253,15 @@ int ext4_punch_hole(struct inode *inode, loff_t offset, loff_t length)
4314 4253
4315 trace_ext4_punch_hole(inode, offset, length, 0); 4254 trace_ext4_punch_hole(inode, offset, length, 0);
4316 4255
4256 ext4_clear_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
4257 if (ext4_has_inline_data(inode)) {
4258 down_write(&EXT4_I(inode)->i_mmap_sem);
4259 ret = ext4_convert_inline_data(inode);
4260 up_write(&EXT4_I(inode)->i_mmap_sem);
4261 if (ret)
4262 return ret;
4263 }
4264
4317 /* 4265 /*
4318 * Write out all dirty pages to avoid race conditions 4266 * Write out all dirty pages to avoid race conditions
4319 * Then release them. 4267 * Then release them.
@@ -5137,6 +5085,9 @@ struct inode *__ext4_iget(struct super_block *sb, unsigned long ino,
5137 "iget: bogus i_mode (%o)", inode->i_mode); 5085 "iget: bogus i_mode (%o)", inode->i_mode);
5138 goto bad_inode; 5086 goto bad_inode;
5139 } 5087 }
5088 if (IS_CASEFOLDED(inode) && !ext4_has_feature_casefold(inode->i_sb))
5089 ext4_error_inode(inode, function, line, 0,
5090 "casefold flag without casefold feature");
5140 brelse(iloc.bh); 5091 brelse(iloc.bh);
5141 5092
5142 unlock_new_inode(inode); 5093 unlock_new_inode(inode);