[Concept,11/26] fs: jbd2: Add jbd2_journal_init_global() for ext4l

Message ID 20251222115639.700578-12-sjg@u-boot.org
State New
Headers
Series fs: ext4l: Add support for mounting ext4 filesystems (part G) |

Commit Message

Simon Glass Dec. 22, 2025, 11:56 a.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add jbd2_journal_init_global() which initializes the JBD2 journal
subsystem caches. This wraps the existing journal_init() with a
static guard to ensure it's only called once.

Call this from ext4l_probe() when CONFIG_EXT4_JOURNAL is enabled
to initialize the journal subsystem before any journal operations.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
---

 fs/ext4l/interface.c |  8 ++++++++
 fs/jbd2/journal.c    | 22 ++++++++++++++++++++++
 2 files changed, 30 insertions(+)
  

Patch

diff --git a/fs/ext4l/interface.c b/fs/ext4l/interface.c
index eb625e0b1a5..546017efd16 100644
--- a/fs/ext4l/interface.c
+++ b/fs/ext4l/interface.c
@@ -13,6 +13,7 @@ 
 #include <malloc.h>
 #include <asm/byteorder.h>
 #include <linux/errno.h>
+#include <linux/jbd2.h>
 #include <linux/types.h>
 
 #include "ext4_uboot.h"
@@ -33,6 +34,13 @@  int ext4l_probe(struct blk_desc *fs_dev_desc,
 	if (!fs_dev_desc)
 		return -EINVAL;
 
+	/* Initialise journal subsystem if enabled */
+	if (IS_ENABLED(CONFIG_EXT4_JOURNAL)) {
+		ret = jbd2_journal_init_global();
+		if (ret)
+			return ret;
+	}
+
 	buf = malloc(BLOCK_SIZE + 512);
 	if (!buf)
 		return -ENOMEM;
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 0b77fd0f34b..0cd95df8192 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -3118,6 +3118,28 @@  static int __init journal_init(void)
 	return ret;
 }
 
+/**
+ * jbd2_journal_init_global() - Initialize JBD2 global state
+ *
+ * This must be called before any journal operations. It initializes
+ * the journal caches and other global state.
+ *
+ * Return: 0 on success, negative error code on failure
+ */
+int jbd2_journal_init_global(void)
+{
+	static bool initialized;
+
+	if (initialized)
+		return 0;
+
+	if (journal_init())
+		return -ENOMEM;
+
+	initialized = true;
+	return 0;
+}
+
 static void __exit journal_exit(void)
 {
 #ifdef CONFIG_JBD2_DEBUG