Commit Graph

13 Commits

Author SHA1 Message Date
Simon Glass
5761cf33ab linux: jbd2: Add jbd2_journal_exit_global for clean shutdown
In U-Boot, filesystems may be mounted and unmounted multiple times in a
single session. The JBD2 global state (caches) was only initialized once
and never cleaned up, preventing proper reinitialization.

Add jbd2_journal_exit_global() to properly destroy caches and reset the
initialization flag. This allows the JBD2 subsystem to be cleanly
reinitialized on subsequent mounts.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-30 13:36:38 -07:00
Simon Glass
ae723b8385 linux: jbd2: Add validation in jbd2_journal_write_metadata_buffer
When debugging journal corruption issues, invalid journal_head or
buffer_head pointers can cause crashes that are difficult to diagnose.

Add explicit validation of jh_in and its associated buffer_head at the
start of jbd2_journal_write_metadata_buffer() to catch corruption early
and provide useful debug output rather than crashing with a SIGSEGV.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-30 13:36:38 -07:00
Simon Glass
dbf97406e9 linux: jbd2: Add synchronous commit on transaction stop
U-Boot operates in a single-threaded environment without a journal
daemon. Commit transactions synchronously when jbd2_journal_stop()
is called and there are no active handles (t_updates == 0).

This ensures crash-safety by writing journal entries to disk immediately
after each file-operation completes.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-30 13:25:04 -07:00
Simon Glass
19de128635 fs: jbd2: Add jbd2_journal_init_global() for ext4l
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>
2025-12-22 05:07:02 -07:00
Simon Glass
5c428be137 jbd2: Add transaction.c to the build
Add transaction.c to the jbd2 Makefile and update includes to use the
ext4l compatibility layer.

Add stubs for various functions needed by transaction.c including
atomic_add_return, prepare_to_wait_exclusive, rwsem_acquire_read,
hrtimer functions, and JBD2 trace stubs.

Remove JBD2 transaction function stubs that are now provided by
transaction.c.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-21 14:15:36 -07:00
Simon Glass
81d8264b76 jbd2: Add revoke.c to the build
Add revoke.c to the jbd2 Makefile and update its includes to use the
compatibility layer.

Add stubs for hash_64 and __find_get_block_nonatomic()

Remove JBD2 revoke function stubs that are now provided by revoke.c.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-21 14:15:36 -07:00
Simon Glass
87f7e16bfa jbd2: Add recovery.c to the build
Add recovery.c to the jbd2 Makefile and update includes to use the ext4l
compatibility layer.

Add stubs for revoke.c functions that recovery.c depends on and tweak a
few so things build.

Fix sync_blockdev to return int instead of void.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-21 14:15:36 -07:00
Simon Glass
525cff9f6c jbd2: Add journal.c to the build
Add journal.c to the jbd2 Makefile and update includes to use the
ext4l compatibility layer.

Add stubs for functions from recovery.c, revoke.c, and transaction.c
that journal.c depends on.

Remove JBD2 function stubs from stub.c that are now provided by
journal.c.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
2025-12-21 14:15:36 -07:00
Simon Glass
c113b81eab jbd2: Add checkpoint.c to the build
Update checkpoint.c includes to use ext4_uboot.h compatibility layer.
Add jbd2/Makefile and include jbd2 in the build via fs/Makefile

Add necessary stubs and definitions:
- JBD2 trace stubs (trace_jbd2_checkpoint, etc.)
- mutex_lock_io, write_dirty_buffer, spin_needbreak stubs
- bd_dev field to struct block_device
- Temporary JBD2 function stubs until other jbd2 files are added

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-21 14:15:36 -07:00
Simon Glass
33ba48ad14 jbd2: Add journal.c from Linux
Add the JBD2 journaling layer core journal management from the
Linux 6.18 kernel ext4 filesystem driver.

journal.c handles:
- Journal initialisation and destruction
- Superblock management
- Journal thread (kjournald2) operations
- Block-mapping for journal storage
- Feature flag management
- Journal format versioning
- Fast-commit support infrastructure

This file provides the main journal_t structure management and
is the entry point for creating and destroying journals.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-21 14:15:36 -07:00
Simon Glass
d2feaa01d8 jbd2: Add transaction.c from Linux
Add the JBD2 journaling layer transaction management from the
Linux 6.18 kernel ext4 filesystem driver.

transaction.c handles:
- Transaction lifecycle (start, stop, restart)
- Handle management for filesystem operations
- Buffer attachment to transactions
- Transaction state machine
- Credit reservation and accounting
- Metadata and data buffer journaling

This is the core transaction API that ext4 uses to ensure
atomic updates to filesystem metadata.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-21 14:15:36 -07:00
Simon Glass
c5bf8fcdf2 jbd2: Add recovery.c and commit.c from Linux
Add the JBD2 journaling layer recovery and commit functionality
from the Linux 6.18 kernel ext4 filesystem driver.

recovery.c handles:
- Journal recovery after unclean shutdown
- Transaction replay and verification
- Descriptor block parsing
- Revoke block processing

commit.c handles:
- Transaction commit processing
- Descriptor block writing
- Data and metadata buffer submission
- Checksum calculation for journal blocks

These files are needed for journal integrity and crash recovery in the
ext4 filesystem.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-21 14:15:36 -07:00
Simon Glass
83206febed jbd2: Add checkpoint.c and revoke.c from Linux
Add the JBD2 journaling layer checkpoint and revoke functionality
from the Linux 6.18 kernel ext4 filesystem driver.

checkpoint.c handles:
- Log space management and checkpointing
- Buffer flushing and cleanup
- Transaction checkpoint processing

revoke.c handles:
- Block revocation for journal recovery
- Revoke record management
- Hash table for revoked blocks

These files are part of the JBD2 (Journaling Block Device 2) layer
that provides transaction support for ext4.

Co-developed-by: Claude Opus 4.5 <noreply@anthropic.com>
Signed-off-by: Simon Glass <simon.glass@canonical.com>
2025-12-21 14:15:36 -07:00