* [PATCH 1/7] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit
2024-07-30 11:33 [PATCH 0/7] Fix and cleanups to jbd2 Kemeng Shi
@ 2024-07-30 11:33 ` Kemeng Shi
2024-07-30 13:21 ` Jan Kara
2024-07-31 3:24 ` Zhang Yi
2024-07-30 11:33 ` [PATCH 2/7] jbd2: remove dead check in journal_alloc_journal_head Kemeng Shi
` (5 subsequent siblings)
6 siblings, 2 replies; 24+ messages in thread
From: Kemeng Shi @ 2024-07-30 11:33 UTC (permalink / raw)
To: tytso, jack; +Cc: linux-ext4, linux-kernel
Use tid_geq to compare tids to work over sequence number wraps.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
fs/jbd2/journal.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 1ebf2393bfb7..da5a56d700f1 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -710,7 +710,7 @@ int jbd2_fc_begin_commit(journal_t *journal, tid_t tid)
return -EINVAL;
write_lock(&journal->j_state_lock);
- if (tid <= journal->j_commit_sequence) {
+ if (tid_geq(journal->j_commit_sequence, tid)) {
write_unlock(&journal->j_state_lock);
return -EALREADY;
}
--
2.30.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH 1/7] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit
2024-07-30 11:33 ` [PATCH 1/7] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit Kemeng Shi
@ 2024-07-30 13:21 ` Jan Kara
2024-07-30 14:55 ` Luis Henriques
2024-07-31 3:24 ` Zhang Yi
1 sibling, 1 reply; 24+ messages in thread
From: Jan Kara @ 2024-07-30 13:21 UTC (permalink / raw)
To: Kemeng Shi; +Cc: tytso, jack, linux-ext4, linux-kernel
On Tue 30-07-24 19:33:29, Kemeng Shi wrote:
> Use tid_geq to compare tids to work over sequence number wraps.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
> fs/jbd2/journal.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
Indeed, Luis seems to have missed this when fixing these bugs recently.
Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index 1ebf2393bfb7..da5a56d700f1 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -710,7 +710,7 @@ int jbd2_fc_begin_commit(journal_t *journal, tid_t tid)
> return -EINVAL;
>
> write_lock(&journal->j_state_lock);
> - if (tid <= journal->j_commit_sequence) {
> + if (tid_geq(journal->j_commit_sequence, tid)) {
> write_unlock(&journal->j_state_lock);
> return -EALREADY;
> }
> --
> 2.30.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH 1/7] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit
2024-07-30 13:21 ` Jan Kara
@ 2024-07-30 14:55 ` Luis Henriques
0 siblings, 0 replies; 24+ messages in thread
From: Luis Henriques @ 2024-07-30 14:55 UTC (permalink / raw)
To: Jan Kara; +Cc: Kemeng Shi, tytso, jack, linux-ext4, linux-kernel
On Tue, Jul 30 2024, Jan Kara wrote:
> On Tue 30-07-24 19:33:29, Kemeng Shi wrote:
>> Use tid_geq to compare tids to work over sequence number wraps.
>>
>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
>> ---
>> fs/jbd2/journal.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> Indeed, Luis seems to have missed this when fixing these bugs recently.
Ah! It looks like I did missed it. Thanks!
Cheers,
--
Luís
> Feel free to add:
>
> Reviewed-by: Jan Kara <jack@suse.cz>
>
> Honza
>
>>
>> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
>> index 1ebf2393bfb7..da5a56d700f1 100644
>> --- a/fs/jbd2/journal.c
>> +++ b/fs/jbd2/journal.c
>> @@ -710,7 +710,7 @@ int jbd2_fc_begin_commit(journal_t *journal, tid_t tid)
>> return -EINVAL;
>>
>> write_lock(&journal->j_state_lock);
>> - if (tid <= journal->j_commit_sequence) {
>> + if (tid_geq(journal->j_commit_sequence, tid)) {
>> write_unlock(&journal->j_state_lock);
>> return -EALREADY;
>> }
>> --
>> 2.30.0
>>
> --
> Jan Kara <jack@suse.com>
> SUSE Labs, CR
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 1/7] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit
2024-07-30 11:33 ` [PATCH 1/7] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit Kemeng Shi
2024-07-30 13:21 ` Jan Kara
@ 2024-07-31 3:24 ` Zhang Yi
1 sibling, 0 replies; 24+ messages in thread
From: Zhang Yi @ 2024-07-31 3:24 UTC (permalink / raw)
To: Kemeng Shi, tytso, jack; +Cc: linux-ext4, linux-kernel
On 2024/7/30 19:33, Kemeng Shi wrote:
> Use tid_geq to compare tids to work over sequence number wraps.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Looks good to me.
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
> ---
> fs/jbd2/journal.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index 1ebf2393bfb7..da5a56d700f1 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -710,7 +710,7 @@ int jbd2_fc_begin_commit(journal_t *journal, tid_t tid)
> return -EINVAL;
>
> write_lock(&journal->j_state_lock);
> - if (tid <= journal->j_commit_sequence) {
> + if (tid_geq(journal->j_commit_sequence, tid)) {
> write_unlock(&journal->j_state_lock);
> return -EALREADY;
> }
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 2/7] jbd2: remove dead check in journal_alloc_journal_head
2024-07-30 11:33 [PATCH 0/7] Fix and cleanups to jbd2 Kemeng Shi
2024-07-30 11:33 ` [PATCH 1/7] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit Kemeng Shi
@ 2024-07-30 11:33 ` Kemeng Shi
2024-07-30 13:23 ` Jan Kara
2024-07-31 3:30 ` Zhang Yi
2024-07-30 11:33 ` [PATCH 3/7] jbd2: remove unused return value of jbd2_fc_release_bufs Kemeng Shi
` (4 subsequent siblings)
6 siblings, 2 replies; 24+ messages in thread
From: Kemeng Shi @ 2024-07-30 11:33 UTC (permalink / raw)
To: tytso, jack; +Cc: linux-ext4, linux-kernel
We will alloc journal_head with __GFP_NOFAIL anyway, test for failure
is pointless.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
fs/jbd2/journal.c | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index da5a56d700f1..b5d02de1ffff 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -2866,8 +2866,7 @@ static struct journal_head *journal_alloc_journal_head(void)
ret = kmem_cache_zalloc(jbd2_journal_head_cache,
GFP_NOFS | __GFP_NOFAIL);
}
- if (ret)
- spin_lock_init(&ret->b_state_lock);
+ spin_lock_init(&ret->b_state_lock);
return ret;
}
--
2.30.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH 2/7] jbd2: remove dead check in journal_alloc_journal_head
2024-07-30 11:33 ` [PATCH 2/7] jbd2: remove dead check in journal_alloc_journal_head Kemeng Shi
@ 2024-07-30 13:23 ` Jan Kara
2024-07-31 3:30 ` Zhang Yi
1 sibling, 0 replies; 24+ messages in thread
From: Jan Kara @ 2024-07-30 13:23 UTC (permalink / raw)
To: Kemeng Shi; +Cc: tytso, jack, linux-ext4, linux-kernel
On Tue 30-07-24 19:33:30, Kemeng Shi wrote:
> We will alloc journal_head with __GFP_NOFAIL anyway, test for failure
> is pointless.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Why not. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/jbd2/journal.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index da5a56d700f1..b5d02de1ffff 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -2866,8 +2866,7 @@ static struct journal_head *journal_alloc_journal_head(void)
> ret = kmem_cache_zalloc(jbd2_journal_head_cache,
> GFP_NOFS | __GFP_NOFAIL);
> }
> - if (ret)
> - spin_lock_init(&ret->b_state_lock);
> + spin_lock_init(&ret->b_state_lock);
> return ret;
> }
>
> --
> 2.30.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 2/7] jbd2: remove dead check in journal_alloc_journal_head
2024-07-30 11:33 ` [PATCH 2/7] jbd2: remove dead check in journal_alloc_journal_head Kemeng Shi
2024-07-30 13:23 ` Jan Kara
@ 2024-07-31 3:30 ` Zhang Yi
1 sibling, 0 replies; 24+ messages in thread
From: Zhang Yi @ 2024-07-31 3:30 UTC (permalink / raw)
To: Kemeng Shi, tytso, jack; +Cc: linux-ext4, linux-kernel
On 2024/7/30 19:33, Kemeng Shi wrote:
> We will alloc journal_head with __GFP_NOFAIL anyway, test for failure
> is pointless.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
A nice cleanup.
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
> ---
> fs/jbd2/journal.c | 3 +--
> 1 file changed, 1 insertion(+), 2 deletions(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index da5a56d700f1..b5d02de1ffff 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -2866,8 +2866,7 @@ static struct journal_head *journal_alloc_journal_head(void)
> ret = kmem_cache_zalloc(jbd2_journal_head_cache,
> GFP_NOFS | __GFP_NOFAIL);
> }
> - if (ret)
> - spin_lock_init(&ret->b_state_lock);
> + spin_lock_init(&ret->b_state_lock);
> return ret;
> }
>
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 3/7] jbd2: remove unused return value of jbd2_fc_release_bufs
2024-07-30 11:33 [PATCH 0/7] Fix and cleanups to jbd2 Kemeng Shi
2024-07-30 11:33 ` [PATCH 1/7] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit Kemeng Shi
2024-07-30 11:33 ` [PATCH 2/7] jbd2: remove dead check in journal_alloc_journal_head Kemeng Shi
@ 2024-07-30 11:33 ` Kemeng Shi
2024-07-30 13:24 ` Jan Kara
2024-07-31 3:32 ` Zhang Yi
2024-07-30 11:33 ` [PATCH 4/7] jbd2: remove unneeded kmap for jh_in->b_frozen_data in jbd2_journal_write_metadata_buffer Kemeng Shi
` (3 subsequent siblings)
6 siblings, 2 replies; 24+ messages in thread
From: Kemeng Shi @ 2024-07-30 11:33 UTC (permalink / raw)
To: tytso, jack; +Cc: linux-ext4, linux-kernel
Remove unused return value of jbd2_fc_release_bufs.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
fs/jbd2/journal.c | 4 +---
include/linux/jbd2.h | 2 +-
2 files changed, 2 insertions(+), 4 deletions(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index b5d02de1ffff..312c7575b54f 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -903,7 +903,7 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks)
}
EXPORT_SYMBOL(jbd2_fc_wait_bufs);
-int jbd2_fc_release_bufs(journal_t *journal)
+void jbd2_fc_release_bufs(journal_t *journal)
{
struct buffer_head *bh;
int i, j_fc_off;
@@ -917,8 +917,6 @@ int jbd2_fc_release_bufs(journal_t *journal)
put_bh(bh);
journal->j_fc_wbuf[i] = NULL;
}
-
- return 0;
}
EXPORT_SYMBOL(jbd2_fc_release_bufs);
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index b900c642210c..735229e8ad17 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -1665,7 +1665,7 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out);
int jbd2_submit_inode_data(journal_t *journal, struct jbd2_inode *jinode);
int jbd2_wait_inode_data(journal_t *journal, struct jbd2_inode *jinode);
int jbd2_fc_wait_bufs(journal_t *journal, int num_blks);
-int jbd2_fc_release_bufs(journal_t *journal);
+void jbd2_fc_release_bufs(journal_t *journal);
/*
* is_journal_abort
--
2.30.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH 3/7] jbd2: remove unused return value of jbd2_fc_release_bufs
2024-07-30 11:33 ` [PATCH 3/7] jbd2: remove unused return value of jbd2_fc_release_bufs Kemeng Shi
@ 2024-07-30 13:24 ` Jan Kara
2024-07-31 3:32 ` Zhang Yi
1 sibling, 0 replies; 24+ messages in thread
From: Jan Kara @ 2024-07-30 13:24 UTC (permalink / raw)
To: Kemeng Shi; +Cc: tytso, jack, linux-ext4, linux-kernel
On Tue 30-07-24 19:33:31, Kemeng Shi wrote:
> Remove unused return value of jbd2_fc_release_bufs.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/jbd2/journal.c | 4 +---
> include/linux/jbd2.h | 2 +-
> 2 files changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index b5d02de1ffff..312c7575b54f 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -903,7 +903,7 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks)
> }
> EXPORT_SYMBOL(jbd2_fc_wait_bufs);
>
> -int jbd2_fc_release_bufs(journal_t *journal)
> +void jbd2_fc_release_bufs(journal_t *journal)
> {
> struct buffer_head *bh;
> int i, j_fc_off;
> @@ -917,8 +917,6 @@ int jbd2_fc_release_bufs(journal_t *journal)
> put_bh(bh);
> journal->j_fc_wbuf[i] = NULL;
> }
> -
> - return 0;
> }
> EXPORT_SYMBOL(jbd2_fc_release_bufs);
>
> diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
> index b900c642210c..735229e8ad17 100644
> --- a/include/linux/jbd2.h
> +++ b/include/linux/jbd2.h
> @@ -1665,7 +1665,7 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out);
> int jbd2_submit_inode_data(journal_t *journal, struct jbd2_inode *jinode);
> int jbd2_wait_inode_data(journal_t *journal, struct jbd2_inode *jinode);
> int jbd2_fc_wait_bufs(journal_t *journal, int num_blks);
> -int jbd2_fc_release_bufs(journal_t *journal);
> +void jbd2_fc_release_bufs(journal_t *journal);
>
> /*
> * is_journal_abort
> --
> 2.30.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH 3/7] jbd2: remove unused return value of jbd2_fc_release_bufs
2024-07-30 11:33 ` [PATCH 3/7] jbd2: remove unused return value of jbd2_fc_release_bufs Kemeng Shi
2024-07-30 13:24 ` Jan Kara
@ 2024-07-31 3:32 ` Zhang Yi
1 sibling, 0 replies; 24+ messages in thread
From: Zhang Yi @ 2024-07-31 3:32 UTC (permalink / raw)
To: Kemeng Shi; +Cc: linux-ext4, linux-kernel, tytso, jack
On 2024/7/30 19:33, Kemeng Shi wrote:
> Remove unused return value of jbd2_fc_release_bufs.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Looks good to me.
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
> ---
> fs/jbd2/journal.c | 4 +---
> include/linux/jbd2.h | 2 +-
> 2 files changed, 2 insertions(+), 4 deletions(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index b5d02de1ffff..312c7575b54f 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -903,7 +903,7 @@ int jbd2_fc_wait_bufs(journal_t *journal, int num_blks)
> }
> EXPORT_SYMBOL(jbd2_fc_wait_bufs);
>
> -int jbd2_fc_release_bufs(journal_t *journal)
> +void jbd2_fc_release_bufs(journal_t *journal)
> {
> struct buffer_head *bh;
> int i, j_fc_off;
> @@ -917,8 +917,6 @@ int jbd2_fc_release_bufs(journal_t *journal)
> put_bh(bh);
> journal->j_fc_wbuf[i] = NULL;
> }
> -
> - return 0;
> }
> EXPORT_SYMBOL(jbd2_fc_release_bufs);
>
> diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
> index b900c642210c..735229e8ad17 100644
> --- a/include/linux/jbd2.h
> +++ b/include/linux/jbd2.h
> @@ -1665,7 +1665,7 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out);
> int jbd2_submit_inode_data(journal_t *journal, struct jbd2_inode *jinode);
> int jbd2_wait_inode_data(journal_t *journal, struct jbd2_inode *jinode);
> int jbd2_fc_wait_bufs(journal_t *journal, int num_blks);
> -int jbd2_fc_release_bufs(journal_t *journal);
> +void jbd2_fc_release_bufs(journal_t *journal);
>
> /*
> * is_journal_abort
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 4/7] jbd2: remove unneeded kmap for jh_in->b_frozen_data in jbd2_journal_write_metadata_buffer
2024-07-30 11:33 [PATCH 0/7] Fix and cleanups to jbd2 Kemeng Shi
` (2 preceding siblings ...)
2024-07-30 11:33 ` [PATCH 3/7] jbd2: remove unused return value of jbd2_fc_release_bufs Kemeng Shi
@ 2024-07-30 11:33 ` Kemeng Shi
2024-07-30 13:32 ` Jan Kara
2024-07-30 11:33 ` [PATCH 5/7] jbd2: remove unneeded done_copy_out variable " Kemeng Shi
` (2 subsequent siblings)
6 siblings, 1 reply; 24+ messages in thread
From: Kemeng Shi @ 2024-07-30 11:33 UTC (permalink / raw)
To: tytso, jack; +Cc: linux-ext4, linux-kernel
Remove kmap for page of b_frozen_data from jbd2_alloc() which always
provides an address from the direct kernel mapping.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
fs/jbd2/journal.c | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 312c7575b54f..9c1ffb0dc740 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -352,12 +352,13 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
done_copy_out = 1;
new_folio = virt_to_folio(jh_in->b_frozen_data);
new_offset = offset_in_folio(new_folio, jh_in->b_frozen_data);
+ mapped_data = jh_in->b_frozen_data;
} else {
new_folio = bh_in->b_folio;
new_offset = offset_in_folio(new_folio, bh_in->b_data);
+ mapped_data = kmap_local_folio(new_folio, new_offset);
}
- mapped_data = kmap_local_folio(new_folio, new_offset);
/*
* Fire data frozen trigger if data already wasn't frozen. Do this
* before checking for escaping, as the trigger may modify the magic
@@ -373,7 +374,8 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
*/
if (*((__be32 *)mapped_data) == cpu_to_be32(JBD2_MAGIC_NUMBER))
do_escape = 1;
- kunmap_local(mapped_data);
+ if (!jh_in->b_frozen_data)
+ kunmap_local(mapped_data);
/*
* Do we need to do a data copy?
--
2.30.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH 4/7] jbd2: remove unneeded kmap for jh_in->b_frozen_data in jbd2_journal_write_metadata_buffer
2024-07-30 11:33 ` [PATCH 4/7] jbd2: remove unneeded kmap for jh_in->b_frozen_data in jbd2_journal_write_metadata_buffer Kemeng Shi
@ 2024-07-30 13:32 ` Jan Kara
2024-07-30 13:41 ` Jan Kara
0 siblings, 1 reply; 24+ messages in thread
From: Jan Kara @ 2024-07-30 13:32 UTC (permalink / raw)
To: Kemeng Shi; +Cc: tytso, jack, linux-ext4, linux-kernel
On Tue 30-07-24 19:33:32, Kemeng Shi wrote:
> Remove kmap for page of b_frozen_data from jbd2_alloc() which always
> provides an address from the direct kernel mapping.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
I don't think this is really a win. On majority of installations kmap is a
noop anyway and for the remainder kmap_local() is cheap. And the
readability of the code is just worse with this.
Honza
> ---
> fs/jbd2/journal.c | 6 ++++--
> 1 file changed, 4 insertions(+), 2 deletions(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index 312c7575b54f..9c1ffb0dc740 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -352,12 +352,13 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
> done_copy_out = 1;
> new_folio = virt_to_folio(jh_in->b_frozen_data);
> new_offset = offset_in_folio(new_folio, jh_in->b_frozen_data);
> + mapped_data = jh_in->b_frozen_data;
> } else {
> new_folio = bh_in->b_folio;
> new_offset = offset_in_folio(new_folio, bh_in->b_data);
> + mapped_data = kmap_local_folio(new_folio, new_offset);
> }
>
> - mapped_data = kmap_local_folio(new_folio, new_offset);
> /*
> * Fire data frozen trigger if data already wasn't frozen. Do this
> * before checking for escaping, as the trigger may modify the magic
> @@ -373,7 +374,8 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
> */
> if (*((__be32 *)mapped_data) == cpu_to_be32(JBD2_MAGIC_NUMBER))
> do_escape = 1;
> - kunmap_local(mapped_data);
> + if (!jh_in->b_frozen_data)
> + kunmap_local(mapped_data);
>
> /*
> * Do we need to do a data copy?
> --
> 2.30.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH 4/7] jbd2: remove unneeded kmap for jh_in->b_frozen_data in jbd2_journal_write_metadata_buffer
2024-07-30 13:32 ` Jan Kara
@ 2024-07-30 13:41 ` Jan Kara
0 siblings, 0 replies; 24+ messages in thread
From: Jan Kara @ 2024-07-30 13:41 UTC (permalink / raw)
To: Kemeng Shi; +Cc: tytso, jack, linux-ext4, linux-kernel
On Tue 30-07-24 15:32:48, Jan Kara wrote:
> On Tue 30-07-24 19:33:32, Kemeng Shi wrote:
> > Remove kmap for page of b_frozen_data from jbd2_alloc() which always
> > provides an address from the direct kernel mapping.
> >
> > Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
>
> I don't think this is really a win. On majority of installations kmap is a
> noop anyway and for the remainder kmap_local() is cheap. And the
> readability of the code is just worse with this.
Ah, the following patch actually improves the code flow so the end result
looks fine. OK, feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Maybe mention in the changelog that following patch will further improve
the function.
Honza
> > diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> > index 312c7575b54f..9c1ffb0dc740 100644
> > --- a/fs/jbd2/journal.c
> > +++ b/fs/jbd2/journal.c
> > @@ -352,12 +352,13 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
> > done_copy_out = 1;
> > new_folio = virt_to_folio(jh_in->b_frozen_data);
> > new_offset = offset_in_folio(new_folio, jh_in->b_frozen_data);
> > + mapped_data = jh_in->b_frozen_data;
> > } else {
> > new_folio = bh_in->b_folio;
> > new_offset = offset_in_folio(new_folio, bh_in->b_data);
> > + mapped_data = kmap_local_folio(new_folio, new_offset);
> > }
> >
> > - mapped_data = kmap_local_folio(new_folio, new_offset);
> > /*
> > * Fire data frozen trigger if data already wasn't frozen. Do this
> > * before checking for escaping, as the trigger may modify the magic
> > @@ -373,7 +374,8 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
> > */
> > if (*((__be32 *)mapped_data) == cpu_to_be32(JBD2_MAGIC_NUMBER))
> > do_escape = 1;
> > - kunmap_local(mapped_data);
> > + if (!jh_in->b_frozen_data)
> > + kunmap_local(mapped_data);
> >
> > /*
> > * Do we need to do a data copy?
> > --
> > 2.30.0
> >
> --
> Jan Kara <jack@suse.com>
> SUSE Labs, CR
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 5/7] jbd2: remove unneeded done_copy_out variable in jbd2_journal_write_metadata_buffer
2024-07-30 11:33 [PATCH 0/7] Fix and cleanups to jbd2 Kemeng Shi
` (3 preceding siblings ...)
2024-07-30 11:33 ` [PATCH 4/7] jbd2: remove unneeded kmap for jh_in->b_frozen_data in jbd2_journal_write_metadata_buffer Kemeng Shi
@ 2024-07-30 11:33 ` Kemeng Shi
2024-07-30 13:49 ` Jan Kara
2024-07-30 11:33 ` [PATCH 6/7] jbd2: correct comment jbd2_mark_journal_empty Kemeng Shi
2024-07-30 11:33 ` [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf Kemeng Shi
6 siblings, 1 reply; 24+ messages in thread
From: Kemeng Shi @ 2024-07-30 11:33 UTC (permalink / raw)
To: tytso, jack; +Cc: linux-ext4, linux-kernel
It's more intuitive to use jh_in->b_frozen_data directly instead of
done_copy_out variable. Simply remove unneeded done_copy_out variable
and use b_frozen_data instead.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
fs/jbd2/journal.c | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 9c1ffb0dc740..f17d05bc61df 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -318,7 +318,6 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
struct buffer_head **bh_out,
sector_t blocknr)
{
- int done_copy_out = 0;
int do_escape = 0;
char *mapped_data;
struct buffer_head *new_bh;
@@ -349,7 +348,6 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
* we use that version of the data for the commit.
*/
if (jh_in->b_frozen_data) {
- done_copy_out = 1;
new_folio = virt_to_folio(jh_in->b_frozen_data);
new_offset = offset_in_folio(new_folio, jh_in->b_frozen_data);
mapped_data = jh_in->b_frozen_data;
@@ -357,17 +355,15 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
new_folio = bh_in->b_folio;
new_offset = offset_in_folio(new_folio, bh_in->b_data);
mapped_data = kmap_local_folio(new_folio, new_offset);
- }
-
- /*
- * Fire data frozen trigger if data already wasn't frozen. Do this
- * before checking for escaping, as the trigger may modify the magic
- * offset. If a copy-out happens afterwards, it will have the correct
- * data in the buffer.
- */
- if (!done_copy_out)
+ /*
+ * Fire data frozen trigger if data already wasn't frozen. Do
+ * this before checking for escaping, as the trigger may modify
+ * the magic offset. If a copy-out happens afterwards, it will
+ * have the correct data in the buffer.
+ */
jbd2_buffer_frozen_trigger(jh_in, mapped_data,
jh_in->b_triggers);
+ }
/*
* Check for escaping
@@ -380,7 +376,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
/*
* Do we need to do a data copy?
*/
- if (do_escape && !done_copy_out) {
+ if (do_escape && !jh_in->b_frozen_data) {
char *tmp;
spin_unlock(&jh_in->b_state_lock);
@@ -408,7 +404,6 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
copy_done:
new_folio = virt_to_folio(jh_in->b_frozen_data);
new_offset = offset_in_folio(new_folio, jh_in->b_frozen_data);
- done_copy_out = 1;
}
/*
--
2.30.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH 5/7] jbd2: remove unneeded done_copy_out variable in jbd2_journal_write_metadata_buffer
2024-07-30 11:33 ` [PATCH 5/7] jbd2: remove unneeded done_copy_out variable " Kemeng Shi
@ 2024-07-30 13:49 ` Jan Kara
2024-07-31 1:34 ` Kemeng Shi
0 siblings, 1 reply; 24+ messages in thread
From: Jan Kara @ 2024-07-30 13:49 UTC (permalink / raw)
To: Kemeng Shi; +Cc: tytso, jack, linux-ext4, linux-kernel
On Tue 30-07-24 19:33:33, Kemeng Shi wrote:
> It's more intuitive to use jh_in->b_frozen_data directly instead of
> done_copy_out variable. Simply remove unneeded done_copy_out variable
> and use b_frozen_data instead.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> @@ -357,17 +355,15 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
> new_folio = bh_in->b_folio;
> new_offset = offset_in_folio(new_folio, bh_in->b_data);
> mapped_data = kmap_local_folio(new_folio, new_offset);
> - }
> -
> - /*
> - * Fire data frozen trigger if data already wasn't frozen. Do this
> - * before checking for escaping, as the trigger may modify the magic
> - * offset. If a copy-out happens afterwards, it will have the correct
> - * data in the buffer.
> - */
> - if (!done_copy_out)
> + /*
> + * Fire data frozen trigger if data already wasn't frozen. Do
> + * this before checking for escaping, as the trigger may modify
> + * the magic offset. If a copy-out happens afterwards, it will
> + * have the correct data in the buffer.
> + */
> jbd2_buffer_frozen_trigger(jh_in, mapped_data,
> jh_in->b_triggers);
> + }
I like how you've got rid of the conditional. But I'd go further and also
move the escaping check and thus unmap & possible frozen buffer creation
into the branch. Like:
do_escape = jbd2_data_needs_escaping(mapped_data);
- create this trivial helper
kunmap_local(mapped_data);
if (do_escape) {
handle b_frozen_data creation
}
Honza
>
> /*
> * Check for escaping
> @@ -380,7 +376,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
> /*
> * Do we need to do a data copy?
> */
> - if (do_escape && !done_copy_out) {
> + if (do_escape && !jh_in->b_frozen_data) {
> char *tmp;
>
> spin_unlock(&jh_in->b_state_lock);
> @@ -408,7 +404,6 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
> copy_done:
> new_folio = virt_to_folio(jh_in->b_frozen_data);
> new_offset = offset_in_folio(new_folio, jh_in->b_frozen_data);
> - done_copy_out = 1;
> }
>
> /*
> --
> 2.30.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH 5/7] jbd2: remove unneeded done_copy_out variable in jbd2_journal_write_metadata_buffer
2024-07-30 13:49 ` Jan Kara
@ 2024-07-31 1:34 ` Kemeng Shi
0 siblings, 0 replies; 24+ messages in thread
From: Kemeng Shi @ 2024-07-31 1:34 UTC (permalink / raw)
To: Jan Kara; +Cc: tytso, jack, linux-ext4, linux-kernel
on 7/30/2024 9:49 PM, Jan Kara wrote:
> On Tue 30-07-24 19:33:33, Kemeng Shi wrote:
>> It's more intuitive to use jh_in->b_frozen_data directly instead of
>> done_copy_out variable. Simply remove unneeded done_copy_out variable
>> and use b_frozen_data instead.
>>
>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
>
>> @@ -357,17 +355,15 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
>> new_folio = bh_in->b_folio;
>> new_offset = offset_in_folio(new_folio, bh_in->b_data);
>> mapped_data = kmap_local_folio(new_folio, new_offset);
>> - }
>> -
>> - /*
>> - * Fire data frozen trigger if data already wasn't frozen. Do this
>> - * before checking for escaping, as the trigger may modify the magic
>> - * offset. If a copy-out happens afterwards, it will have the correct
>> - * data in the buffer.
>> - */
>> - if (!done_copy_out)
>> + /*
>> + * Fire data frozen trigger if data already wasn't frozen. Do
>> + * this before checking for escaping, as the trigger may modify
>> + * the magic offset. If a copy-out happens afterwards, it will
>> + * have the correct data in the buffer.
>> + */
>> jbd2_buffer_frozen_trigger(jh_in, mapped_data,
>> jh_in->b_triggers);
>> + }
>
> I like how you've got rid of the conditional. But I'd go further and also
> move the escaping check and thus unmap & possible frozen buffer creation
> into the branch. Like:
>
> do_escape = jbd2_data_needs_escaping(mapped_data);
> - create this trivial helper
> kunmap_local(mapped_data);
> if (do_escape) {
> handle b_frozen_data creation
> }
Thanks Jan. It does look better this way, I will do it in next version.
Kemeng.
>
> Honza
>
>>
>> /*
>> * Check for escaping
>> @@ -380,7 +376,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
>> /*
>> * Do we need to do a data copy?
>> */
>> - if (do_escape && !done_copy_out) {
>> + if (do_escape && !jh_in->b_frozen_data) {
>> char *tmp;
>>
>> spin_unlock(&jh_in->b_state_lock);
>> @@ -408,7 +404,6 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
>> copy_done:
>> new_folio = virt_to_folio(jh_in->b_frozen_data);
>> new_offset = offset_in_folio(new_folio, jh_in->b_frozen_data);
>> - done_copy_out = 1;
>> }
>>
>> /*
>> --
>> 2.30.0
>>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 6/7] jbd2: correct comment jbd2_mark_journal_empty
2024-07-30 11:33 [PATCH 0/7] Fix and cleanups to jbd2 Kemeng Shi
` (4 preceding siblings ...)
2024-07-30 11:33 ` [PATCH 5/7] jbd2: remove unneeded done_copy_out variable " Kemeng Shi
@ 2024-07-30 11:33 ` Kemeng Shi
2024-07-30 13:37 ` Jan Kara
2024-07-31 3:53 ` Zhang Yi
2024-07-30 11:33 ` [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf Kemeng Shi
6 siblings, 2 replies; 24+ messages in thread
From: Kemeng Shi @ 2024-07-30 11:33 UTC (permalink / raw)
To: tytso, jack; +Cc: linux-ext4, linux-kernel
After jbd2_mark_journal_empty, journal log is supposed to be empty.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
fs/jbd2/journal.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index f17d05bc61df..dc18b9f7c999 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1939,7 +1939,7 @@ static void jbd2_mark_journal_empty(journal_t *journal, blk_opf_t write_flags)
if (had_fast_commit)
jbd2_set_feature_fast_commit(journal);
- /* Log is no longer empty */
+ /* Log is empty */
write_lock(&journal->j_state_lock);
journal->j_flags |= JBD2_FLUSHED;
write_unlock(&journal->j_state_lock);
--
2.30.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH 6/7] jbd2: correct comment jbd2_mark_journal_empty
2024-07-30 11:33 ` [PATCH 6/7] jbd2: correct comment jbd2_mark_journal_empty Kemeng Shi
@ 2024-07-30 13:37 ` Jan Kara
2024-07-31 3:53 ` Zhang Yi
1 sibling, 0 replies; 24+ messages in thread
From: Jan Kara @ 2024-07-30 13:37 UTC (permalink / raw)
To: Kemeng Shi; +Cc: tytso, jack, linux-ext4, linux-kernel
On Tue 30-07-24 19:33:34, Kemeng Shi wrote:
> After jbd2_mark_journal_empty, journal log is supposed to be empty.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/jbd2/journal.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index f17d05bc61df..dc18b9f7c999 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -1939,7 +1939,7 @@ static void jbd2_mark_journal_empty(journal_t *journal, blk_opf_t write_flags)
> if (had_fast_commit)
> jbd2_set_feature_fast_commit(journal);
>
> - /* Log is no longer empty */
> + /* Log is empty */
> write_lock(&journal->j_state_lock);
> journal->j_flags |= JBD2_FLUSHED;
> write_unlock(&journal->j_state_lock);
> --
> 2.30.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 24+ messages in thread
* Re: [PATCH 6/7] jbd2: correct comment jbd2_mark_journal_empty
2024-07-30 11:33 ` [PATCH 6/7] jbd2: correct comment jbd2_mark_journal_empty Kemeng Shi
2024-07-30 13:37 ` Jan Kara
@ 2024-07-31 3:53 ` Zhang Yi
1 sibling, 0 replies; 24+ messages in thread
From: Zhang Yi @ 2024-07-31 3:53 UTC (permalink / raw)
To: Kemeng Shi, tytso, jack; +Cc: linux-ext4, linux-kernel
On 2024/7/30 19:33, Kemeng Shi wrote:
> After jbd2_mark_journal_empty, journal log is supposed to be empty.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Looks good to me.
Reviewed-by: Zhang Yi <yi.zhang@huawei.com>
> ---
> fs/jbd2/journal.c | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index f17d05bc61df..dc18b9f7c999 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -1939,7 +1939,7 @@ static void jbd2_mark_journal_empty(journal_t *journal, blk_opf_t write_flags)
> if (had_fast_commit)
> jbd2_set_feature_fast_commit(journal);
>
> - /* Log is no longer empty */
> + /* Log is empty */
> write_lock(&journal->j_state_lock);
> journal->j_flags |= JBD2_FLUSHED;
> write_unlock(&journal->j_state_lock);
>
^ permalink raw reply [flat|nested] 24+ messages in thread
* [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf
2024-07-30 11:33 [PATCH 0/7] Fix and cleanups to jbd2 Kemeng Shi
` (5 preceding siblings ...)
2024-07-30 11:33 ` [PATCH 6/7] jbd2: correct comment jbd2_mark_journal_empty Kemeng Shi
@ 2024-07-30 11:33 ` Kemeng Shi
2024-07-30 13:38 ` Jan Kara
2024-07-31 6:17 ` Zhang Yi
6 siblings, 2 replies; 24+ messages in thread
From: Kemeng Shi @ 2024-07-30 11:33 UTC (permalink / raw)
To: tytso, jack; +Cc: linux-ext4, linux-kernel
Simply return -EINVAL if j_fc_off is invalid to avoid repeated check of
ret.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
---
fs/jbd2/journal.c | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index dc18b9f7c999..6f90f7b8e9e5 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -842,12 +842,8 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
fc_off = journal->j_fc_off;
blocknr = journal->j_fc_first + fc_off;
journal->j_fc_off++;
- } else {
- ret = -EINVAL;
- }
-
- if (ret)
- return ret;
+ } else
+ return -EINVAL;
ret = jbd2_journal_bmap(journal, blocknr, &pblock);
if (ret)
--
2.30.0
^ permalink raw reply related [flat|nested] 24+ messages in thread* Re: [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf
2024-07-30 11:33 ` [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf Kemeng Shi
@ 2024-07-30 13:38 ` Jan Kara
2024-07-31 6:17 ` Zhang Yi
1 sibling, 0 replies; 24+ messages in thread
From: Jan Kara @ 2024-07-30 13:38 UTC (permalink / raw)
To: Kemeng Shi; +Cc: tytso, jack, linux-ext4, linux-kernel
On Tue 30-07-24 19:33:35, Kemeng Shi wrote:
> Simply return -EINVAL if j_fc_off is invalid to avoid repeated check of
> ret.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/jbd2/journal.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index dc18b9f7c999..6f90f7b8e9e5 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -842,12 +842,8 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
> fc_off = journal->j_fc_off;
> blocknr = journal->j_fc_first + fc_off;
> journal->j_fc_off++;
> - } else {
> - ret = -EINVAL;
> - }
> -
> - if (ret)
> - return ret;
> + } else
> + return -EINVAL;
>
> ret = jbd2_journal_bmap(journal, blocknr, &pblock);
> if (ret)
> --
> 2.30.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf
2024-07-30 11:33 ` [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf Kemeng Shi
2024-07-30 13:38 ` Jan Kara
@ 2024-07-31 6:17 ` Zhang Yi
2024-07-31 8:37 ` Kemeng Shi
1 sibling, 1 reply; 24+ messages in thread
From: Zhang Yi @ 2024-07-31 6:17 UTC (permalink / raw)
To: Kemeng Shi; +Cc: linux-ext4, linux-kernel, tytso, jack
On 2024/7/30 19:33, Kemeng Shi wrote:
> Simply return -EINVAL if j_fc_off is invalid to avoid repeated check of
> ret.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> ---
> fs/jbd2/journal.c | 8 ++------
> 1 file changed, 2 insertions(+), 6 deletions(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index dc18b9f7c999..6f90f7b8e9e5 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -842,12 +842,8 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
> fc_off = journal->j_fc_off;
> blocknr = journal->j_fc_first + fc_off;
> journal->j_fc_off++;
> - } else {
> - ret = -EINVAL;
> - }
> -
> - if (ret)
> - return ret;
> + } else
> + return -EINVAL;
>
I'd like this style, just a suggestion.
if (journal->j_fc_off + journal->j_fc_first >= journal->j_fc_last)
return -EINVAL;
fc_off = journal->j_fc_off;
blocknr = journal->j_fc_first + fc_off;
journal->j_fc_off++;
...
Thanks,
Yi.
> ret = jbd2_journal_bmap(journal, blocknr, &pblock);
> if (ret)
>
^ permalink raw reply [flat|nested] 24+ messages in thread* Re: [PATCH 7/7] jbd2: remove unneeded check of ret in jbd2_fc_get_buf
2024-07-31 6:17 ` Zhang Yi
@ 2024-07-31 8:37 ` Kemeng Shi
0 siblings, 0 replies; 24+ messages in thread
From: Kemeng Shi @ 2024-07-31 8:37 UTC (permalink / raw)
To: Zhang Yi; +Cc: linux-ext4, linux-kernel, tytso, jack
on 7/31/2024 2:17 PM, Zhang Yi wrote:
> On 2024/7/30 19:33, Kemeng Shi wrote:
>> Simply return -EINVAL if j_fc_off is invalid to avoid repeated check of
>> ret.
>>
>> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
>> ---
>> fs/jbd2/journal.c | 8 ++------
>> 1 file changed, 2 insertions(+), 6 deletions(-)
>>
>> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
>> index dc18b9f7c999..6f90f7b8e9e5 100644
>> --- a/fs/jbd2/journal.c
>> +++ b/fs/jbd2/journal.c
>> @@ -842,12 +842,8 @@ int jbd2_fc_get_buf(journal_t *journal, struct buffer_head **bh_out)
>> fc_off = journal->j_fc_off;
>> blocknr = journal->j_fc_first + fc_off;
>> journal->j_fc_off++;
>> - } else {
>> - ret = -EINVAL;
>> - }
>> -
>> - if (ret)
>> - return ret;
>> + } else
>> + return -EINVAL;
>>
>
> I'd like this style, just a suggestion.
>
> if (journal->j_fc_off + journal->j_fc_first >= journal->j_fc_last)
> return -EINVAL;
>
> fc_off = journal->j_fc_off;
> blocknr = journal->j_fc_first + fc_off;
> journal->j_fc_off++;
>
> ...
>
Sorry, I miss this. I also think code looks better in this way. I will do
it in next version. Thanks.
> Thanks,
> Yi.
>
>
>> ret = jbd2_journal_bmap(journal, blocknr, &pblock);
>> if (ret)
>>
>
^ permalink raw reply [flat|nested] 24+ messages in thread