* [PATCH] ext4, jbd2: add an optimized bmap for the journal inode
@ 2023-03-08 4:16 Theodore Ts'o
2023-03-08 4:56 ` Eric Biggers
0 siblings, 1 reply; 2+ messages in thread
From: Theodore Ts'o @ 2023-03-08 4:16 UTC (permalink / raw)
To: Ext4 Developers List; +Cc: Theodore Ts'o
The generic bmap() function exported by the VFS takes locks and does
checks that are not necessary for the journal inode. So allow the
file system to set a journal-optimized bmap function in
journal->j_bmap.
The also has the benefit of avoiding some false positives by DEPT.
Signed-off-by: Theodore Ts'o <tytso@mit.edu>
---
fs/ext4/super.c | 23 +++++++++++++++++++++++
fs/jbd2/journal.c | 9 ++++++---
include/linux/jbd2.h | 8 ++++++++
3 files changed, 37 insertions(+), 3 deletions(-)
diff --git a/fs/ext4/super.c b/fs/ext4/super.c
index 2192b4111442..46b7345d2b6a 100644
--- a/fs/ext4/super.c
+++ b/fs/ext4/super.c
@@ -5742,6 +5742,28 @@ static struct inode *ext4_get_journal_inode(struct super_block *sb,
return journal_inode;
}
+static int ext4_journal_bmap(journal_t *journal, sector_t *block)
+{
+ struct ext4_map_blocks map;
+ int ret;
+
+ if (journal->j_inode == NULL)
+ return 0;
+
+ map.m_lblk = *block;
+ map.m_len = 1;
+ ret = ext4_map_blocks(NULL, journal->j_inode, &map, 0);
+ if (ret <= 0) {
+ ext4_msg(journal->j_inode->i_sb, KERN_CRIT,
+ "journal bmap failed: block %llu ret %d\n",
+ *block, ret);
+ jbd2_journal_abort(journal, ret ? ret : -EIO);
+ return ret;
+ }
+ *block = map.m_pblk;
+ return 0;
+}
+
static journal_t *ext4_get_journal(struct super_block *sb,
unsigned int journal_inum)
{
@@ -5762,6 +5784,7 @@ static journal_t *ext4_get_journal(struct super_block *sb,
return NULL;
}
journal->j_private = sb;
+ journal->j_bmap = ext4_journal_bmap;
ext4_init_journal_params(sb, journal);
return journal;
}
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 2696f43e7239..c84f588fdcd0 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -970,10 +970,13 @@ int jbd2_journal_bmap(journal_t *journal, unsigned long blocknr,
{
int err = 0;
unsigned long long ret;
- sector_t block = 0;
+ sector_t block = blocknr;
- if (journal->j_inode) {
- block = blocknr;
+ if (journal->j_bmap) {
+ err = journal->j_bmap(journal, &block);
+ if (err == 0)
+ *retp = block;
+ } else if (journal->j_inode) {
ret = bmap(journal->j_inode, &block);
if (ret || !block) {
diff --git a/include/linux/jbd2.h b/include/linux/jbd2.h
index 2170e0cc279d..6ffa34c51a11 100644
--- a/include/linux/jbd2.h
+++ b/include/linux/jbd2.h
@@ -1308,6 +1308,14 @@ struct journal_s
struct buffer_head *bh,
enum passtype pass, int off,
tid_t expected_commit_id);
+
+ /**
+ * @j_bmap:
+ *
+ * Bmap function that should be used instead of the generic
+ * VFS bmap function.
+ */
+ int (*j_bmap)(struct journal_s *journal, sector_t *block);
};
#define jbd2_might_wait_for_commit(j) \
--
2.31.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] ext4, jbd2: add an optimized bmap for the journal inode
2023-03-08 4:16 [PATCH] ext4, jbd2: add an optimized bmap for the journal inode Theodore Ts'o
@ 2023-03-08 4:56 ` Eric Biggers
0 siblings, 0 replies; 2+ messages in thread
From: Eric Biggers @ 2023-03-08 4:56 UTC (permalink / raw)
To: Theodore Ts'o; +Cc: Ext4 Developers List
On Tue, Mar 07, 2023 at 11:16:15PM -0500, Theodore Ts'o wrote:
> The generic bmap() function exported by the VFS takes locks and does
> checks that are not necessary for the journal inode. So allow the
> file system to set a journal-optimized bmap function in
> journal->j_bmap.
>
> The also has the benefit of avoiding some false positives by DEPT.
>
> Signed-off-by: Theodore Ts'o <tytso@mit.edu>
> ---
> fs/ext4/super.c | 23 +++++++++++++++++++++++
> fs/jbd2/journal.c | 9 ++++++---
> include/linux/jbd2.h | 8 ++++++++
> 3 files changed, 37 insertions(+), 3 deletions(-)
>
Should this also be marked as a fix for the syzbot report
https://syzkaller.appspot.com/bug?id=e4aaa78795e490421c79f76ec3679006c8ff4cf0 ?
- Eric
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2023-03-08 4:56 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-03-08 4:16 [PATCH] ext4, jbd2: add an optimized bmap for the journal inode Theodore Ts'o
2023-03-08 4:56 ` Eric Biggers
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).