Commit 5afdb453 authored by Theodore Ts'o's avatar Theodore Ts'o Committed by Greg Kroah-Hartman

ext4: fix inline data updates with checksums enabled

commit 362eca70 upstream.

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=200443Signed-off-by: default avatarTheodore Ts'o <tytso@mit.edu>
Cc: stable@vger.kernel.org
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent d0f02f70
...@@ -678,6 +678,10 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, ...@@ -678,6 +678,10 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
goto convert; goto convert;
} }
ret = ext4_journal_get_write_access(handle, iloc.bh);
if (ret)
goto out;
flags |= AOP_FLAG_NOFS; flags |= AOP_FLAG_NOFS;
page = grab_cache_page_write_begin(mapping, 0, flags); page = grab_cache_page_write_begin(mapping, 0, flags);
...@@ -706,7 +710,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping, ...@@ -706,7 +710,7 @@ int ext4_try_to_write_inline_data(struct address_space *mapping,
out_up_read: out_up_read:
up_read(&EXT4_I(inode)->xattr_sem); up_read(&EXT4_I(inode)->xattr_sem);
out: out:
if (handle) if (handle && (ret != 1))
ext4_journal_stop(handle); ext4_journal_stop(handle);
brelse(iloc.bh); brelse(iloc.bh);
return ret; return ret;
...@@ -748,6 +752,7 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len, ...@@ -748,6 +752,7 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len,
ext4_write_unlock_xattr(inode, &no_expand); ext4_write_unlock_xattr(inode, &no_expand);
brelse(iloc.bh); brelse(iloc.bh);
mark_inode_dirty(inode);
out: out:
return copied; return copied;
} }
...@@ -894,7 +899,6 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, ...@@ -894,7 +899,6 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
goto out; goto out;
} }
page = grab_cache_page_write_begin(mapping, 0, flags); page = grab_cache_page_write_begin(mapping, 0, flags);
if (!page) { if (!page) {
ret = -ENOMEM; ret = -ENOMEM;
...@@ -912,6 +916,9 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping, ...@@ -912,6 +916,9 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
if (ret < 0) if (ret < 0)
goto out_release_page; goto out_release_page;
} }
ret = ext4_journal_get_write_access(handle, iloc.bh);
if (ret)
goto out_release_page;
up_read(&EXT4_I(inode)->xattr_sem); up_read(&EXT4_I(inode)->xattr_sem);
*pagep = page; *pagep = page;
...@@ -932,7 +939,6 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos, ...@@ -932,7 +939,6 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos,
unsigned len, unsigned copied, unsigned len, unsigned copied,
struct page *page) struct page *page)
{ {
int i_size_changed = 0;
int ret; int ret;
ret = ext4_write_inline_data_end(inode, pos, len, copied, page); ret = ext4_write_inline_data_end(inode, pos, len, copied, page);
...@@ -950,10 +956,8 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos, ...@@ -950,10 +956,8 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos,
* But it's important to update i_size while still holding page lock: * But it's important to update i_size while still holding page lock:
* page writeout could otherwise come in and zero beyond i_size. * page writeout could otherwise come in and zero beyond i_size.
*/ */
if (pos+copied > inode->i_size) { if (pos+copied > inode->i_size)
i_size_write(inode, pos+copied); i_size_write(inode, pos+copied);
i_size_changed = 1;
}
unlock_page(page); unlock_page(page);
page_cache_release(page); page_cache_release(page);
...@@ -963,7 +967,6 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos, ...@@ -963,7 +967,6 @@ int ext4_da_write_inline_data_end(struct inode *inode, loff_t pos,
* ordering of page lock and transaction start for journaling * ordering of page lock and transaction start for journaling
* filesystems. * filesystems.
*/ */
if (i_size_changed)
mark_inode_dirty(inode); mark_inode_dirty(inode);
return copied; return copied;
......
...@@ -1164,9 +1164,10 @@ static int ext4_write_end(struct file *file, ...@@ -1164,9 +1164,10 @@ static int ext4_write_end(struct file *file,
loff_t old_size = inode->i_size; loff_t old_size = inode->i_size;
int ret = 0, ret2; int ret = 0, ret2;
int i_size_changed = 0; int i_size_changed = 0;
int inline_data = ext4_has_inline_data(inode);
trace_ext4_write_end(inode, pos, len, copied); trace_ext4_write_end(inode, pos, len, copied);
if (ext4_has_inline_data(inode)) { if (inline_data) {
ret = ext4_write_inline_data_end(inode, pos, len, ret = ext4_write_inline_data_end(inode, pos, len,
copied, page); copied, page);
if (ret < 0) { if (ret < 0) {
...@@ -1194,7 +1195,7 @@ static int ext4_write_end(struct file *file, ...@@ -1194,7 +1195,7 @@ static int ext4_write_end(struct file *file,
* ordering of page lock and transaction start for journaling * ordering of page lock and transaction start for journaling
* filesystems. * filesystems.
*/ */
if (i_size_changed) if (i_size_changed || inline_data)
ext4_mark_inode_dirty(handle, inode); ext4_mark_inode_dirty(handle, inode);
if (pos + len > inode->i_size && ext4_can_truncate(inode)) if (pos + len > inode->i_size && ext4_can_truncate(inode))
...@@ -1268,6 +1269,7 @@ static int ext4_journalled_write_end(struct file *file, ...@@ -1268,6 +1269,7 @@ static int ext4_journalled_write_end(struct file *file,
int partial = 0; int partial = 0;
unsigned from, to; unsigned from, to;
int size_changed = 0; int size_changed = 0;
int inline_data = ext4_has_inline_data(inode);
trace_ext4_journalled_write_end(inode, pos, len, copied); trace_ext4_journalled_write_end(inode, pos, len, copied);
from = pos & (PAGE_CACHE_SIZE - 1); from = pos & (PAGE_CACHE_SIZE - 1);
...@@ -1275,7 +1277,7 @@ static int ext4_journalled_write_end(struct file *file, ...@@ -1275,7 +1277,7 @@ static int ext4_journalled_write_end(struct file *file,
BUG_ON(!ext4_handle_valid(handle)); BUG_ON(!ext4_handle_valid(handle));
if (ext4_has_inline_data(inode)) { if (inline_data) {
ret = ext4_write_inline_data_end(inode, pos, len, ret = ext4_write_inline_data_end(inode, pos, len,
copied, page); copied, page);
if (ret < 0) { if (ret < 0) {
...@@ -1306,7 +1308,7 @@ static int ext4_journalled_write_end(struct file *file, ...@@ -1306,7 +1308,7 @@ static int ext4_journalled_write_end(struct file *file,
if (old_size < pos) if (old_size < pos)
pagecache_isize_extended(inode, old_size, pos); pagecache_isize_extended(inode, old_size, pos);
if (size_changed) { if (size_changed || inline_data) {
ret2 = ext4_mark_inode_dirty(handle, inode); ret2 = ext4_mark_inode_dirty(handle, inode);
if (!ret) if (!ret)
ret = ret2; ret = ret2;
...@@ -1804,11 +1806,7 @@ static int __ext4_journalled_writepage(struct page *page, ...@@ -1804,11 +1806,7 @@ static int __ext4_journalled_writepage(struct page *page,
} }
if (inline_data) { if (inline_data) {
BUFFER_TRACE(inode_bh, "get write access"); ret = ext4_mark_inode_dirty(handle, inode);
ret = ext4_journal_get_write_access(handle, inode_bh);
err = ext4_handle_dirty_metadata(handle, inode, inode_bh);
} else { } else {
ret = ext4_walk_page_buffers(handle, page_bufs, 0, len, NULL, ret = ext4_walk_page_buffers(handle, page_bufs, 0, len, NULL,
do_journal_get_write_access); do_journal_get_write_access);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment