2022-01-18 02:23:09

by Ritesh Harjani

[permalink] [raw]
Subject: [PATCHv2 0/5] ext4/jbd2: inline_data fixes and minor cleanups

Hello,

Please find v2 of the inline_data fixes and some minor cleanups found during
code review.

I have dropped patch-6 in v2 which was removing use of t_handle_lock (spinlock)
from within jbd2_journal_wait_updates(). Based on Jan comments, I feel we can
push that as killing of t_handle_lock into a separate series (which will be on
top of this).

v1 -> v2
========
1. Added Jan's Reviewed-by tag & addressed one of his comment on no need to make
jbd2_journal_wait_updates() function inline.
2. Dropped patch-6 as described above.

Description
============
Patch[1]: fixes BUG_ON with inline_data which was reported [1] with generic/475.

Patch[2]: is mostly cleanup found during code review of inline_data code.

Patch[3]: is a possible memory corruption fix in case of krealloc failure.

Patch[4-5]: Cleanups.

[v1]: https://lore.kernel.org/linux-ext4/[email protected]/T/

Ritesh Harjani (5):
ext4: Fix error handling in ext4_restore_inline_data()
ext4: Remove redundant max inline_size check in ext4_da_write_inline_data_begin()
ext4: Fix error handling in ext4_fc_record_modified_inode()
jbd2: Cleanup unused functions declarations from jbd2.h
jbd2: Refactor wait logic for transaction updates into a common function

fs/ext4/fast_commit.c | 64 ++++++++++++++++++++-----------------------
fs/ext4/inline.c | 23 +++++++++-------
fs/jbd2/commit.c | 19 ++-----------
fs/jbd2/transaction.c | 53 +++++++++++++++++++++--------------
include/linux/jbd2.h | 11 ++------
5 files changed, 80 insertions(+), 90 deletions(-)

--
2.31.1


2022-01-18 02:23:09

by Ritesh Harjani

[permalink] [raw]
Subject: [PATCHv2 1/5] ext4: Fix error handling in ext4_restore_inline_data()

While running "./check -I 200 generic/475" it sometimes gives below
kernel BUG(). Ideally we should not call ext4_write_inline_data() if
ext4_create_inline_data() has failed.

<log snip>
[73131.453234] kernel BUG at fs/ext4/inline.c:223!

<code snip>
212 static void ext4_write_inline_data(struct inode *inode, struct ext4_iloc *iloc,
213 void *buffer, loff_t pos, unsigned int len)
214 {
<...>
223 BUG_ON(!EXT4_I(inode)->i_inline_off);
224 BUG_ON(pos + len > EXT4_I(inode)->i_inline_size);

This patch handles the error and prints out a emergency msg saying potential
data loss for the given inode (since we couldn't restore the original
inline_data due to some previous error).

[ 9571.070313] EXT4-fs (dm-0): error restoring inline_data for inode -- potential data loss! (inode 1703982, error -30)

Reported-by: Eric Whitney <[email protected]>
Signed-off-by: Ritesh Harjani <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
---
fs/ext4/inline.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index 39a1ab129fdc..d091133a4b46 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -1133,7 +1133,15 @@ static void ext4_restore_inline_data(handle_t *handle, struct inode *inode,
struct ext4_iloc *iloc,
void *buf, int inline_size)
{
- ext4_create_inline_data(handle, inode, inline_size);
+ int ret;
+
+ ret = ext4_create_inline_data(handle, inode, inline_size);
+ if (ret) {
+ ext4_msg(inode->i_sb, KERN_EMERG,
+ "error restoring inline_data for inode -- potential data loss! (inode %lu, error %d)",
+ inode->i_ino, ret);
+ return;
+ }
ext4_write_inline_data(inode, iloc, buf, 0, inline_size);
ext4_set_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA);
}
--
2.31.1

2022-01-18 02:23:10

by Ritesh Harjani

[permalink] [raw]
Subject: [PATCHv2 2/5] ext4: Remove redundant max inline_size check in ext4_da_write_inline_data_begin()

ext4_prepare_inline_data() already checks for ext4_get_max_inline_size()
and returns -ENOSPC. So there is no need to check it twice within
ext4_da_write_inline_data_begin(). This patch removes the extra check.

It also makes it more clean.

No functionality change in this patch.

Signed-off-by: Ritesh Harjani <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
---
fs/ext4/inline.c | 13 ++++---------
1 file changed, 4 insertions(+), 9 deletions(-)

diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index d091133a4b46..cbdd84e49f2c 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -911,7 +911,7 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
struct page **pagep,
void **fsdata)
{
- int ret, inline_size;
+ int ret;
handle_t *handle;
struct page *page;
struct ext4_iloc iloc;
@@ -928,14 +928,9 @@ int ext4_da_write_inline_data_begin(struct address_space *mapping,
goto out;
}

- inline_size = ext4_get_max_inline_size(inode);
-
- ret = -ENOSPC;
- if (inline_size >= pos + len) {
- ret = ext4_prepare_inline_data(handle, inode, pos + len);
- if (ret && ret != -ENOSPC)
- goto out_journal;
- }
+ ret = ext4_prepare_inline_data(handle, inode, pos + len);
+ if (ret && ret != -ENOSPC)
+ goto out_journal;

/*
* We cannot recurse into the filesystem as the transaction
--
2.31.1

2022-01-21 22:22:58

by Theodore Ts'o

[permalink] [raw]
Subject: Re: [PATCHv2 0/5] ext4/jbd2: inline_data fixes and minor cleanups

On Mon, 17 Jan 2022 17:41:46 +0530, Ritesh Harjani wrote:
> Please find v2 of the inline_data fixes and some minor cleanups found during
> code review.
>
> I have dropped patch-6 in v2 which was removing use of t_handle_lock (spinlock)
> from within jbd2_journal_wait_updates(). Based on Jan comments, I feel we can
> push that as killing of t_handle_lock into a separate series (which will be on
> top of this).
>
> [...]

Applied, thanks!

[1/5] ext4: Fix error handling in ext4_restore_inline_data()
commit: 2fdd85005f708691a64270ecb67d98191d668c4c
[2/5] ext4: Remove redundant max inline_size check in ext4_da_write_inline_data_begin()
commit: c7fc77e512a432bba754f969c4eb72b33cda3431
[3/5] ext4: Fix error handling in ext4_fc_record_modified_inode()
commit: 6dcee78ea266fb736a3357c2e04d81ee7ec7b6e4
[4/5] jbd2: Cleanup unused functions declarations from jbd2.h
commit: 16263b9820b0d40c778c8ee867f853d3fe638f37
[5/5] jbd2: Refactor wait logic for transaction updates into a common function
commit: b0544c1f23ddeabd89480d842867ca1c6894e021

Best regards,
--
Theodore Ts'o <[email protected]>