* [PATCH v2 0/8] Fix and cleanups to jbd2
@ 2024-07-31 6:22 Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 1/8] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit Kemeng Shi
` (7 more replies)
0 siblings, 8 replies; 11+ messages in thread
From: Kemeng Shi @ 2024-07-31 6:22 UTC (permalink / raw)
To: tytso, jack; +Cc: linux-ext4, linux-kernel
v1->v2:
-Move escape handle to futher improve
jbd2_journal_write_metadata_buffer.
This series contains a fix and some random cleanups to jbd2. More
details can be found in respective patches. Thanks!
Kemeng Shi (8):
jbd2: correctly compare tids with tid_geq function in
jbd2_fc_begin_commit
jbd2: remove dead check in journal_alloc_journal_head
jbd2: remove unused return value of jbd2_fc_release_bufs
jbd2: remove unneeded kmap for jh_in->b_frozen_data in
jbd2_journal_write_metadata_buffer
jbd2: remove unneeded done_copy_out variable in
jbd2_journal_write_metadata_buffer
ext4: move escape handle to futher improve
jbd2_journal_write_metadata_buffer
jbd2: correct comment jbd2_mark_journal_empty
jbd2: remove unneeded check of ret in jbd2_fc_get_buf
fs/jbd2/journal.c | 87 +++++++++++++++++++-------------------------
include/linux/jbd2.h | 2 +-
2 files changed, 39 insertions(+), 50 deletions(-)
--
2.30.0
^ permalink raw reply [flat|nested] 11+ messages in thread
* [PATCH v2 1/8] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit
2024-07-31 6:22 [PATCH v2 0/8] Fix and cleanups to jbd2 Kemeng Shi
@ 2024-07-31 6:22 ` Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 2/8] jbd2: remove dead check in journal_alloc_journal_head Kemeng Shi
` (6 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Kemeng Shi @ 2024-07-31 6:22 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>
Reviewed-by: Jan Kara <jack@suse.cz>
---
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] 11+ messages in thread
* [PATCH v2 2/8] jbd2: remove dead check in journal_alloc_journal_head
2024-07-31 6:22 [PATCH v2 0/8] Fix and cleanups to jbd2 Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 1/8] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit Kemeng Shi
@ 2024-07-31 6:22 ` Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 3/8] jbd2: remove unused return value of jbd2_fc_release_bufs Kemeng Shi
` (5 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Kemeng Shi @ 2024-07-31 6:22 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>
Reviewed-by: Jan Kara <jack@suse.cz>
---
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] 11+ messages in thread
* [PATCH v2 3/8] jbd2: remove unused return value of jbd2_fc_release_bufs
2024-07-31 6:22 [PATCH v2 0/8] Fix and cleanups to jbd2 Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 1/8] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 2/8] jbd2: remove dead check in journal_alloc_journal_head Kemeng Shi
@ 2024-07-31 6:22 ` Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 4/8] jbd2: remove unneeded kmap for jh_in->b_frozen_data in jbd2_journal_write_metadata_buffer Kemeng Shi
` (4 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Kemeng Shi @ 2024-07-31 6:22 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>
Reviewed-by: Jan Kara <jack@suse.cz>
---
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] 11+ messages in thread
* [PATCH v2 4/8] jbd2: remove unneeded kmap for jh_in->b_frozen_data in jbd2_journal_write_metadata_buffer
2024-07-31 6:22 [PATCH v2 0/8] Fix and cleanups to jbd2 Kemeng Shi
` (2 preceding siblings ...)
2024-07-31 6:22 ` [PATCH v2 3/8] jbd2: remove unused return value of jbd2_fc_release_bufs Kemeng Shi
@ 2024-07-31 6:22 ` Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 5/8] jbd2: remove unneeded done_copy_out variable " Kemeng Shi
` (3 subsequent siblings)
7 siblings, 0 replies; 11+ messages in thread
From: Kemeng Shi @ 2024-07-31 6:22 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>
Reviewed-by: Jan Kara <jack@suse.cz>
---
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] 11+ messages in thread
* [PATCH v2 5/8] jbd2: remove unneeded done_copy_out variable in jbd2_journal_write_metadata_buffer
2024-07-31 6:22 [PATCH v2 0/8] Fix and cleanups to jbd2 Kemeng Shi
` (3 preceding siblings ...)
2024-07-31 6:22 ` [PATCH v2 4/8] jbd2: remove unneeded kmap for jh_in->b_frozen_data in jbd2_journal_write_metadata_buffer Kemeng Shi
@ 2024-07-31 6:22 ` Kemeng Shi
2024-07-31 12:00 ` Jan Kara
2024-07-31 6:22 ` [PATCH v2 6/8] ext4: move escape handle to futher improve jbd2_journal_write_metadata_buffer Kemeng Shi
` (2 subsequent siblings)
7 siblings, 1 reply; 11+ messages in thread
From: Kemeng Shi @ 2024-07-31 6:22 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] 11+ messages in thread
* [PATCH v2 6/8] ext4: move escape handle to futher improve jbd2_journal_write_metadata_buffer
2024-07-31 6:22 [PATCH v2 0/8] Fix and cleanups to jbd2 Kemeng Shi
` (4 preceding siblings ...)
2024-07-31 6:22 ` [PATCH v2 5/8] jbd2: remove unneeded done_copy_out variable " Kemeng Shi
@ 2024-07-31 6:22 ` Kemeng Shi
2024-07-31 12:00 ` Jan Kara
2024-07-31 6:22 ` [PATCH v2 7/8] jbd2: correct comment jbd2_mark_journal_empty Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 8/8] jbd2: remove unneeded check of ret in jbd2_fc_get_buf Kemeng Shi
7 siblings, 1 reply; 11+ messages in thread
From: Kemeng Shi @ 2024-07-31 6:22 UTC (permalink / raw)
To: tytso, jack; +Cc: linux-ext4, linux-kernel
Move escape handle to futher improve code readability and remove some
repeat check.
Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
Suggested-by: Jan Kara <jack@suse.cz>
---
fs/jbd2/journal.c | 49 +++++++++++++++++++++++------------------------
1 file changed, 24 insertions(+), 25 deletions(-)
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index f17d05bc61df..85273fb1accb 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -281,6 +281,16 @@ static void journal_kill_thread(journal_t *journal)
write_unlock(&journal->j_state_lock);
}
+static inline bool jbd2_data_needs_escaping(char *data)
+{
+ return *((__be32 *)data) == cpu_to_be32(JBD2_MAGIC_NUMBER);
+}
+
+static inline void jbd2_data_do_escape(char *data)
+{
+ *((unsigned int *)data) = 0;
+}
+
/*
* jbd2_journal_write_metadata_buffer: write a metadata buffer to the journal.
*
@@ -319,7 +329,6 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
sector_t blocknr)
{
int do_escape = 0;
- char *mapped_data;
struct buffer_head *new_bh;
struct folio *new_folio;
unsigned int new_offset;
@@ -350,8 +359,13 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
if (jh_in->b_frozen_data) {
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;
+ do_escape = jbd2_data_needs_escaping(jh_in->b_frozen_data);
+ if (do_escape)
+ jbd2_data_do_escape(jh_in->b_frozen_data);
} else {
+ char *tmp;
+ char *mapped_data;
+
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);
@@ -363,21 +377,13 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
*/
jbd2_buffer_frozen_trigger(jh_in, mapped_data,
jh_in->b_triggers);
- }
-
- /*
- * Check for escaping
- */
- if (*((__be32 *)mapped_data) == cpu_to_be32(JBD2_MAGIC_NUMBER))
- do_escape = 1;
- if (!jh_in->b_frozen_data)
+ do_escape = jbd2_data_needs_escaping(mapped_data);
kunmap_local(mapped_data);
-
- /*
- * Do we need to do a data copy?
- */
- if (do_escape && !jh_in->b_frozen_data) {
- char *tmp;
+ /*
+ * Do we need to do a data copy?
+ */
+ if (!do_escape)
+ goto escape_done;
spin_unlock(&jh_in->b_state_lock);
tmp = jbd2_alloc(bh_in->b_size, GFP_NOFS);
@@ -404,17 +410,10 @@ 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);
+ jbd2_data_do_escape(jh_in->b_frozen_data);
}
- /*
- * Did we need to do an escaping? Now we've done all the
- * copying, we can finally do so.
- * b_frozen_data is from jbd2_alloc() which always provides an
- * address from the direct kernels mapping.
- */
- if (do_escape)
- *((unsigned int *)jh_in->b_frozen_data) = 0;
-
+escape_done:
folio_set_bh(new_bh, new_folio, new_offset);
new_bh->b_size = bh_in->b_size;
new_bh->b_bdev = journal->j_dev;
--
2.30.0
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH v2 7/8] jbd2: correct comment jbd2_mark_journal_empty
2024-07-31 6:22 [PATCH v2 0/8] Fix and cleanups to jbd2 Kemeng Shi
` (5 preceding siblings ...)
2024-07-31 6:22 ` [PATCH v2 6/8] ext4: move escape handle to futher improve jbd2_journal_write_metadata_buffer Kemeng Shi
@ 2024-07-31 6:22 ` Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 8/8] jbd2: remove unneeded check of ret in jbd2_fc_get_buf Kemeng Shi
7 siblings, 0 replies; 11+ messages in thread
From: Kemeng Shi @ 2024-07-31 6:22 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>
Reviewed-by: Jan Kara <jack@suse.cz>
---
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 85273fb1accb..e89d777ded34 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -1938,7 +1938,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] 11+ messages in thread
* [PATCH v2 8/8] jbd2: remove unneeded check of ret in jbd2_fc_get_buf
2024-07-31 6:22 [PATCH v2 0/8] Fix and cleanups to jbd2 Kemeng Shi
` (6 preceding siblings ...)
2024-07-31 6:22 ` [PATCH v2 7/8] jbd2: correct comment jbd2_mark_journal_empty Kemeng Shi
@ 2024-07-31 6:22 ` Kemeng Shi
7 siblings, 0 replies; 11+ messages in thread
From: Kemeng Shi @ 2024-07-31 6:22 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>
Reviewed-by: Jan Kara <jack@suse.cz>
---
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 e89d777ded34..9d0f6735f8e6 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -841,12 +841,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] 11+ messages in thread
* Re: [PATCH v2 6/8] ext4: move escape handle to futher improve jbd2_journal_write_metadata_buffer
2024-07-31 6:22 ` [PATCH v2 6/8] ext4: move escape handle to futher improve jbd2_journal_write_metadata_buffer Kemeng Shi
@ 2024-07-31 12:00 ` Jan Kara
0 siblings, 0 replies; 11+ messages in thread
From: Jan Kara @ 2024-07-31 12:00 UTC (permalink / raw)
To: Kemeng Shi; +Cc: tytso, jack, linux-ext4, linux-kernel
On Wed 31-07-24 14:22:45, Kemeng Shi wrote:
> Move escape handle to futher improve code readability and remove some
> repeat check.
>
> Signed-off-by: Kemeng Shi <shikemeng@huaweicloud.com>
> Suggested-by: Jan Kara <jack@suse.cz>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> fs/jbd2/journal.c | 49 +++++++++++++++++++++++------------------------
> 1 file changed, 24 insertions(+), 25 deletions(-)
>
> diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
> index f17d05bc61df..85273fb1accb 100644
> --- a/fs/jbd2/journal.c
> +++ b/fs/jbd2/journal.c
> @@ -281,6 +281,16 @@ static void journal_kill_thread(journal_t *journal)
> write_unlock(&journal->j_state_lock);
> }
>
> +static inline bool jbd2_data_needs_escaping(char *data)
> +{
> + return *((__be32 *)data) == cpu_to_be32(JBD2_MAGIC_NUMBER);
> +}
> +
> +static inline void jbd2_data_do_escape(char *data)
> +{
> + *((unsigned int *)data) = 0;
> +}
> +
> /*
> * jbd2_journal_write_metadata_buffer: write a metadata buffer to the journal.
> *
> @@ -319,7 +329,6 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
> sector_t blocknr)
> {
> int do_escape = 0;
> - char *mapped_data;
> struct buffer_head *new_bh;
> struct folio *new_folio;
> unsigned int new_offset;
> @@ -350,8 +359,13 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
> if (jh_in->b_frozen_data) {
> 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;
> + do_escape = jbd2_data_needs_escaping(jh_in->b_frozen_data);
> + if (do_escape)
> + jbd2_data_do_escape(jh_in->b_frozen_data);
> } else {
> + char *tmp;
> + char *mapped_data;
> +
> 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);
> @@ -363,21 +377,13 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
> */
> jbd2_buffer_frozen_trigger(jh_in, mapped_data,
> jh_in->b_triggers);
> - }
> -
> - /*
> - * Check for escaping
> - */
> - if (*((__be32 *)mapped_data) == cpu_to_be32(JBD2_MAGIC_NUMBER))
> - do_escape = 1;
> - if (!jh_in->b_frozen_data)
> + do_escape = jbd2_data_needs_escaping(mapped_data);
> kunmap_local(mapped_data);
> -
> - /*
> - * Do we need to do a data copy?
> - */
> - if (do_escape && !jh_in->b_frozen_data) {
> - char *tmp;
> + /*
> + * Do we need to do a data copy?
> + */
> + if (!do_escape)
> + goto escape_done;
>
> spin_unlock(&jh_in->b_state_lock);
> tmp = jbd2_alloc(bh_in->b_size, GFP_NOFS);
> @@ -404,17 +410,10 @@ 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);
> + jbd2_data_do_escape(jh_in->b_frozen_data);
> }
>
> - /*
> - * Did we need to do an escaping? Now we've done all the
> - * copying, we can finally do so.
> - * b_frozen_data is from jbd2_alloc() which always provides an
> - * address from the direct kernels mapping.
> - */
> - if (do_escape)
> - *((unsigned int *)jh_in->b_frozen_data) = 0;
> -
> +escape_done:
> folio_set_bh(new_bh, new_folio, new_offset);
> new_bh->b_size = bh_in->b_size;
> new_bh->b_bdev = journal->j_dev;
> --
> 2.30.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH v2 5/8] jbd2: remove unneeded done_copy_out variable in jbd2_journal_write_metadata_buffer
2024-07-31 6:22 ` [PATCH v2 5/8] jbd2: remove unneeded done_copy_out variable " Kemeng Shi
@ 2024-07-31 12:00 ` Jan Kara
0 siblings, 0 replies; 11+ messages in thread
From: Jan Kara @ 2024-07-31 12:00 UTC (permalink / raw)
To: Kemeng Shi; +Cc: tytso, jack, linux-ext4, linux-kernel
On Wed 31-07-24 14:22:44, 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>
Looks good. Feel free to add:
Reviewed-by: Jan Kara <jack@suse.cz>
Honza
> ---
> 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
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2024-07-31 12:00 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-31 6:22 [PATCH v2 0/8] Fix and cleanups to jbd2 Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 1/8] jbd2: correctly compare tids with tid_geq function in jbd2_fc_begin_commit Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 2/8] jbd2: remove dead check in journal_alloc_journal_head Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 3/8] jbd2: remove unused return value of jbd2_fc_release_bufs Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 4/8] jbd2: remove unneeded kmap for jh_in->b_frozen_data in jbd2_journal_write_metadata_buffer Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 5/8] jbd2: remove unneeded done_copy_out variable " Kemeng Shi
2024-07-31 12:00 ` Jan Kara
2024-07-31 6:22 ` [PATCH v2 6/8] ext4: move escape handle to futher improve jbd2_journal_write_metadata_buffer Kemeng Shi
2024-07-31 12:00 ` Jan Kara
2024-07-31 6:22 ` [PATCH v2 7/8] jbd2: correct comment jbd2_mark_journal_empty Kemeng Shi
2024-07-31 6:22 ` [PATCH v2 8/8] jbd2: remove unneeded check of ret in jbd2_fc_get_buf Kemeng Shi
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox