Skip to content

Commit 362eca7

Browse files
committed
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
1 parent 2dca60d commit 362eca7

File tree

2 files changed

+18
-17
lines changed

2 files changed

+18
-17
lines changed

fs/ext4/inline.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,10 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
682682
goto convert;
683683
}
684684

685+
ret = ext4_journal_get_write_access(handle, iloc.bh);
686+
if (ret)
687+
goto out;
688+
685689
flags |= AOP_FLAG_NOFS;
686690

687691
page = grab_cache_page_write_begin(mapping, 0, flags);
@@ -710,7 +714,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
710714
out_up_read:
711715
up_read(&EXT4_I(inode)->xattr_sem);
712716
out:
713-
if (handle)
717+
if (handle && (ret != 1))
714718
ext4_journal_stop(handle);
715719
brelse(iloc.bh);
716720
return ret;
@@ -752,6 +756,7 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len,
752756

753757
ext4_write_unlock_xattr(inode, &no_expand);
754758
brelse(iloc.bh);
759+
mark_inode_dirty(inode);
755760
out:
756761
return copied;
757762
}
@@ -898,7 +903,6 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
898903
goto out;
899904
}
900905

901-
902906
page = grab_cache_page_write_begin(mapping, 0, flags);
903907
if (!page) {
904908
ret = -ENOMEM;
@@ -916,6 +920,9 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
916920
if (ret < 0)
917921
goto out_release_page;
918922
}
923+
ret = ext4_journal_get_write_access(handle, iloc.bh);
924+
if (ret)
925+
goto out_release_page;
919926

920927
up_read(&EXT4_I(inode)->xattr_sem);
921928
*pagep = page;
@@ -936,7 +943,6 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos,
936943
unsigned len, unsigned copied,
937944
struct page *page)
938945
{
939-
int i_size_changed = 0;
940946
int ret;
941947

942948
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,
954960
* But it's important to update i_size while still holding page lock:
955961
* page writeout could otherwise come in and zero beyond i_size.
956962
*/
957-
if (pos+copied > inode->i_size) {
963+
if (pos+copied > inode->i_size)
958964
i_size_write(inode, pos+copied);
959-
i_size_changed = 1;
960-
}
961965
unlock_page(page);
962966
put_page(page);
963967

@@ -967,8 +971,7 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos,
967971
* ordering of page lock and transaction start for journaling
968972
* filesystems.
969973
*/
970-
if (i_size_changed)
971-
mark_inode_dirty(inode);
974+
mark_inode_dirty(inode);
972975

973976
return copied;
974977
}

fs/ext4/inode.c

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1389,9 +1389,10 @@ static int ext4_write_end(struct file *file,
13891389
loff_t old_size = inode->i_size;
13901390
int ret = 0, ret2;
13911391
int i_size_changed = 0;
1392+
int inline_data = ext4_has_inline_data(inode);
13921393

13931394
trace_ext4_write_end(inode, pos, len, copied);
1394-
if (ext4_has_inline_data(inode)) {
1395+
if (inline_data) {
13951396
ret = ext4_write_inline_data_end(inode, pos, len,
13961397
copied, page);
13971398
if (ret < 0) {
@@ -1419,7 +1420,7 @@ static int ext4_write_end(struct file *file,
14191420
* ordering of page lock and transaction start for journaling
14201421
* filesystems.
14211422
*/
1422-
if (i_size_changed)
1423+
if (i_size_changed || inline_data)
14231424
ext4_mark_inode_dirty(handle, inode);
14241425

14251426
if (pos + len > inode->i_size && ext4_can_truncate(inode))
@@ -1493,14 +1494,15 @@ static int ext4_journalled_write_end(struct file *file,
14931494
int partial = 0;
14941495
unsigned from, to;
14951496
int size_changed = 0;
1497+
int inline_data = ext4_has_inline_data(inode);
14961498

14971499
trace_ext4_journalled_write_end(inode, pos, len, copied);
14981500
from = pos & (PAGE_SIZE - 1);
14991501
to = from + len;
15001502

15011503
BUG_ON(!ext4_handle_valid(handle));
15021504

1503-
if (ext4_has_inline_data(inode)) {
1505+
if (inline_data) {
15041506
ret = ext4_write_inline_data_end(inode, pos, len,
15051507
copied, page);
15061508
if (ret < 0) {
@@ -1531,7 +1533,7 @@ static int ext4_journalled_write_end(struct file *file,
15311533
if (old_size < pos)
15321534
pagecache_isize_extended(inode, old_size, pos);
15331535

1534-
if (size_changed) {
1536+
if (size_changed || inline_data) {
15351537
ret2 = ext4_mark_inode_dirty(handle, inode);
15361538
if (!ret)
15371539
ret = ret2;
@@ -2028,11 +2030,7 @@ static int __ext4_journalled_writepage(struct page *page,
20282030
}
20292031

20302032
if (inline_data) {
2031-
BUFFER_TRACE(inode_bh, "get write access");
2032-
ret = ext4_journal_get_write_access(handle, inode_bh);
2033-
2034-
err = ext4_handle_dirty_metadata(handle, inode, inode_bh);
2035-
2033+
ret = ext4_mark_inode_dirty(handle, inode);
20362034
} else {
20372035
ret = ext4_walk_page_buffers(handle, page_bufs, 0, len, NULL,
20382036
do_journal_get_write_access);

0 commit comments

Comments
 (0)