[Concept,11/26] fs: jbd2: Add jbd2_journal_init_global() for ext4l
Commit Message
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(+)
@@ -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;
@@ -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