jbd2: use a folio in jbd2_journal_write_metadata_buffer()

JIRA: https://issues.redhat.com/browse/RHEL-27743

This patch is a backport of the following upstream commit:
commit 8147c4c4546f9f05ef03bb839b741473b28bb560
Author: Matthew Wilcox (Oracle) <willy@infradead.org>
Date:   Thu Jul 13 04:55:11 2023 +0100

    jbd2: use a folio in jbd2_journal_write_metadata_buffer()

    The primary goal here is removing the use of set_bh_page().  Take the
    opportunity to switch from kmap_atomic() to kmap_local().  This simplifies
    the function as the offset is already added to the pointer.

    Link: https://lkml.kernel.org/r/20230713035512.4139457-7-willy@infradead.org
    Signed-off-by: Matthew Wilcox (Oracle) <willy@infradead.org>
    Reviewed-by: Jan Kara <jack@suse.cz>
    Cc: "Theodore Ts'o" <tytso@mit.edu>
    Cc: Alexander Viro <viro@zeniv.linux.org.uk>
    Cc: Christian Brauner <brauner@kernel.org>
    Cc: David Sterba <dsterba@suse.com>
    Cc: Konstantin Komarov <almaz.alexandrovich@paragon-software.com>
    Cc: Nathan Chancellor <nathan@kernel.org>
    Cc: Nick Desaulniers <ndesaulniers@google.com>
    Cc: Pankaj Raghav <p.raghav@samsung.com>
    Cc: Tom Rix <trix@redhat.com>
    Signed-off-by: Andrew Morton <akpm@linux-foundation.org>

Signed-off-by: Rafael Aquini <raquini@redhat.com>
This commit is contained in:
Rafael Aquini 2024-09-27 10:43:40 -04:00
parent 2751ffd905
commit d9687733e6
1 changed files with 16 additions and 19 deletions

View File

@ -333,7 +333,7 @@ int jbd2_journal_write_metadata_buffer(transaction_t *transaction,
int do_escape = 0;
char *mapped_data;
struct buffer_head *new_bh;
struct page *new_page;
struct folio *new_folio;
unsigned int new_offset;
struct buffer_head *bh_in = jh2bh(jh_in);
journal_t *journal = transaction->t_journal;
@ -362,14 +362,14 @@ repeat:
*/
if (jh_in->b_frozen_data) {
done_copy_out = 1;
new_page = virt_to_page(jh_in->b_frozen_data);
new_offset = offset_in_page(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);
} else {
new_page = jh2bh(jh_in)->b_page;
new_offset = offset_in_page(jh2bh(jh_in)->b_data);
new_folio = jh2bh(jh_in)->b_folio;
new_offset = offset_in_folio(new_folio, jh2bh(jh_in)->b_data);
}
mapped_data = kmap_atomic(new_page);
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
@ -377,18 +377,17 @@ repeat:
* data in the buffer.
*/
if (!done_copy_out)
jbd2_buffer_frozen_trigger(jh_in, mapped_data + new_offset,
jbd2_buffer_frozen_trigger(jh_in, mapped_data,
jh_in->b_triggers);
/*
* Check for escaping
*/
if (*((__be32 *)(mapped_data + new_offset)) ==
cpu_to_be32(JBD2_MAGIC_NUMBER)) {
if (*((__be32 *)mapped_data) == cpu_to_be32(JBD2_MAGIC_NUMBER)) {
need_copy_out = 1;
do_escape = 1;
}
kunmap_atomic(mapped_data);
kunmap_local(mapped_data);
/*
* Do we need to do a data copy?
@ -409,12 +408,10 @@ repeat:
}
jh_in->b_frozen_data = tmp;
mapped_data = kmap_atomic(new_page);
memcpy(tmp, mapped_data + new_offset, bh_in->b_size);
kunmap_atomic(mapped_data);
memcpy_from_folio(tmp, new_folio, new_offset, bh_in->b_size);
new_page = virt_to_page(tmp);
new_offset = offset_in_page(tmp);
new_folio = virt_to_folio(tmp);
new_offset = offset_in_folio(new_folio, tmp);
done_copy_out = 1;
/*
@ -430,12 +427,12 @@ repeat:
* copying, we can finally do so.
*/
if (do_escape) {
mapped_data = kmap_atomic(new_page);
*((unsigned int *)(mapped_data + new_offset)) = 0;
kunmap_atomic(mapped_data);
mapped_data = kmap_local_folio(new_folio, new_offset);
*((unsigned int *)mapped_data) = 0;
kunmap_local(mapped_data);
}
set_bh_page(new_bh, new_page, new_offset);
folio_set_bh(new_bh, new_folio, new_offset);
new_bh->b_size = bh_in->b_size;
new_bh->b_bdev = journal->j_dev;
new_bh->b_blocknr = blocknr;