diff options
author | Theodore Ts'o <tytso@mit.edu> | 2018-07-10 01:07:43 -0400 |
---|---|---|
committer | Theodore Ts'o <tytso@mit.edu> | 2018-07-10 01:07:43 -0400 |
commit | 362eca70b53389bddf3143fe20f53dcce2cfdf61 (patch) | |
tree | 6a8114ace853e46e790b2d3354601710045720e7 | |
parent | 2dca60d98e241bea686004168f85208f215fc697 (diff) |
ext4: fix inline data updates with checksums enabled
The inline data code was updating the raw inode directly; this is
problematic since if metadata checksums are enabled,
ext4_mark_inode_dirty() must be called to update the inode's checksum.
In addition, the jbd2 layer requires that get_write_access() be called
before the metadata buffer is modified. Fix both of these problems.
https://bugzilla.kernel.org/show_bug.cgi?id=200443
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
-rw-r--r-- | fs/ext4/inline.c | 19 | ||||
-rw-r--r-- | fs/ext4/inode.c | 16 |
2 files changed, 18 insertions, 17 deletions
diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c index e55a8bc870bd..3543fe80a3c4 100644 --- a/fs/ext4/inline.c +++ b/fs/ext4/inline.c | |||
@@ -682,6 +682,10 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, | |||
682 | goto convert; | 682 | goto convert; |
683 | } | 683 | } |
684 | 684 | ||
685 | ret = ext4_journal_get_write_access(handle, iloc.bh); | ||
686 | if (ret) | ||
687 | goto out; | ||
688 | |||
685 | flags |= AOP_FLAG_NOFS; | 689 | flags |= AOP_FLAG_NOFS; |
686 | 690 | ||
687 | page = grab_cache_page_write_begin(mapping, 0, flags); | 691 | page = grab_cache_page_write_begin(mapping, 0, flags); |
@@ -710,7 +714,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, | |||
710 | out_up_read: | 714 | out_up_read: |
711 | up_read(&EXT4_I(inode)->xattr_sem); | 715 | up_read(&EXT4_I(inode)->xattr_sem); |
712 | out: | 716 | out: |
713 | if (handle) | 717 | if (handle && (ret != 1)) |
714 | ext4_journal_stop(handle); | 718 | ext4_journal_stop(handle); |
715 | brelse(iloc.bh); | 719 | brelse(iloc.bh); |
716 | return ret; | 720 | return ret; |
@@ -752,6 +756,7 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, | |||
752 | 756 | ||
753 | ext4_write_unlock_xattr(inode, &no_expand); | 757 | ext4_write_unlock_xattr(inode, &no_expand); |
754 | brelse(iloc.bh); | 758 | brelse(iloc.bh); |
759 | mark_inode_dirty(inode); | ||
755 | out: | 760 | out: |
756 | return copied; | 761 | return copied; |
757 | } | 762 | } |
@@ -898,7 +903,6 @@ retry_journal: | |||
898 | goto out; | 903 | goto out; |
899 | } | 904 | } |
900 | 905 | ||
901 | |||
902 | page = grab_cache_page_write_begin(mapping, 0, flags); | 906 | page = grab_cache_page_write_begin(mapping, 0, flags); |
903 | if (!page) { | 907 | if (!page) { |
904 | ret = -ENOMEM; | 908 | ret = -ENOMEM; |
@@ -916,6 +920,9 @@ retry_journal: | |||
916 | if (ret < 0) | 920 | if (ret < 0) |
917 | goto out_release_page; | 921 | goto out_release_page; |
918 | } | 922 | } |
923 | ret = ext4_journal_get_write_access(handle, iloc.bh); | ||
924 | if (ret) | ||
925 | goto out_release_page; | ||
919 | 926 | ||
920 | up_read(&EXT4_I(inode)->xattr_sem); | 927 | up_read(&EXT4_I(inode)->xattr_sem); |
921 | *pagep = page; | 928 | *pagep = page; |
@@ -936,7 +943,6 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos, | |||
936 | unsigned len, unsigned copied, | 943 | unsigned len, unsigned copied, |
937 | struct page *page) | 944 | struct page *page) |
938 | { | 945 | { |
939 | int i_size_changed = 0; | ||
940 | int ret; | 946 | int ret; |
941 | 947 | ||
942 | ret = ext4_write_inline_data_end(inode, pos, len, copied, page); | 948 | ret = ext4_write_inline_data_end(inode, pos, len, copied, page); |
@@ -954,10 +960,8 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos, | |||
954 | * But it's important to update i_size while still holding page lock: | 960 | * But it's important to update i_size while still holding page lock: |
955 | * page writeout could otherwise come in and zero beyond i_size. | 961 | * page writeout could otherwise come in and zero beyond i_size. |
956 | */ | 962 | */ |
957 | if (pos+copied > inode->i_size) { | 963 | if (pos+copied > inode->i_size) |
958 | i_size_write(inode, pos+copied); | 964 | i_size_write(inode, pos+copied); |
959 | i_size_changed = 1; | ||
960 | } | ||
961 | unlock_page(page); | 965 | unlock_page(page); |
962 | put_page(page); | 966 | put_page(page); |
963 | 967 | ||
@@ -967,8 +971,7 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos, | |||
967 | * ordering of page lock and transaction start for journaling | 971 | * ordering of page lock and transaction start for journaling |
968 | * filesystems. | 972 | * filesystems. |
969 | */ | 973 | */ |
970 | if (i_size_changed) | 974 | mark_inode_dirty(inode); |
971 | mark_inode_dirty(inode); | ||
972 | 975 | ||
973 | return copied; | 976 | return copied; |
974 | } | 977 | } |
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c index 7d6c10017bdf..4efe77286ecd 100644 --- a/fs/ext4/inode.c +++ b/fs/ext4/inode.c | |||
@@ -1389,9 +1389,10 @@ static int ext4_write_end(struct file *file, | |||
1389 | loff_t old_size = inode->i_size; | 1389 | loff_t old_size = inode->i_size; |
1390 | int ret = 0, ret2; | 1390 | int ret = 0, ret2; |
1391 | int i_size_changed = 0; | 1391 | int i_size_changed = 0; |
1392 | int inline_data = ext4_has_inline_data(inode); | ||
1392 | 1393 | ||
1393 | trace_ext4_write_end(inode, pos, len, copied); | 1394 | trace_ext4_write_end(inode, pos, len, copied); |
1394 | if (ext4_has_inline_data(inode)) { | 1395 | if (inline_data) { |
1395 | ret = ext4_write_inline_data_end(inode, pos, len, | 1396 | ret = ext4_write_inline_data_end(inode, pos, len, |
1396 | copied, page); | 1397 | copied, page); |
1397 | if (ret < 0) { | 1398 | if (ret < 0) { |
@@ -1419,7 +1420,7 @@ static int ext4_write_end(struct file *file, | |||
1419 | * ordering of page lock and transaction start for journaling | 1420 | * ordering of page lock and transaction start for journaling |
1420 | * filesystems. | 1421 | * filesystems. |
1421 | */ | 1422 | */ |
1422 | if (i_size_changed) | 1423 | if (i_size_changed || inline_data) |
1423 | ext4_mark_inode_dirty(handle, inode); | 1424 | ext4_mark_inode_dirty(handle, inode); |
1424 | 1425 | ||
1425 | if (pos + len > inode->i_size && ext4_can_truncate(inode)) | 1426 | if (pos + len > inode->i_size && ext4_can_truncate(inode)) |
@@ -1493,6 +1494,7 @@ static int ext4_journalled_write_end(struct file *file, | |||
1493 | int partial = 0; | 1494 | int partial = 0; |
1494 | unsigned from, to; | 1495 | unsigned from, to; |
1495 | int size_changed = 0; | 1496 | int size_changed = 0; |
1497 | int inline_data = ext4_has_inline_data(inode); | ||
1496 | 1498 | ||
1497 | trace_ext4_journalled_write_end(inode, pos, len, copied); | 1499 | trace_ext4_journalled_write_end(inode, pos, len, copied); |
1498 | from = pos & (PAGE_SIZE - 1); | 1500 | from = pos & (PAGE_SIZE - 1); |
@@ -1500,7 +1502,7 @@ static int ext4_journalled_write_end(struct file *file, | |||
1500 | 1502 | ||
1501 | BUG_ON(!ext4_handle_valid(handle)); | 1503 | BUG_ON(!ext4_handle_valid(handle)); |
1502 | 1504 | ||
1503 | if (ext4_has_inline_data(inode)) { | 1505 | if (inline_data) { |
1504 | ret = ext4_write_inline_data_end(inode, pos, len, | 1506 | ret = ext4_write_inline_data_end(inode, pos, len, |
1505 | copied, page); | 1507 | copied, page); |
1506 | if (ret < 0) { | 1508 | if (ret < 0) { |
@@ -1531,7 +1533,7 @@ static int ext4_journalled_write_end(struct file *file, | |||
1531 | if (old_size < pos) | 1533 | if (old_size < pos) |
1532 | pagecache_isize_extended(inode, old_size, pos); | 1534 | pagecache_isize_extended(inode, old_size, pos); |
1533 | 1535 | ||
1534 | if (size_changed) { | 1536 | if (size_changed || inline_data) { |
1535 | ret2 = ext4_mark_inode_dirty(handle, inode); | 1537 | ret2 = ext4_mark_inode_dirty(handle, inode); |
1536 | if (!ret) | 1538 | if (!ret) |
1537 | ret = ret2; | 1539 | ret = ret2; |
@@ -2028,11 +2030,7 @@ static int __ext4_journalled_writepage(struct page *page, | |||
2028 | } | 2030 | } |
2029 | 2031 | ||
2030 | if (inline_data) { | 2032 | if (inline_data) { |
2031 | BUFFER_TRACE(inode_bh, "get write access"); | 2033 | ret = ext4_mark_inode_dirty(handle, inode); |
2032 | ret = ext4_journal_get_write_access(handle, inode_bh); | ||
2033 | |||
2034 | err = ext4_handle_dirty_metadata(handle, inode, inode_bh); | ||
2035 | |||
2036 | } else { | 2034 | } else { |
2037 | ret = ext4_walk_page_buffers(handle, page_bufs, 0, len, NULL, | 2035 | ret = ext4_walk_page_buffers(handle, page_bufs, 0, len, NULL, |
2038 | do_journal_get_write_access); | 2036 | do_journal_get_write_access); |