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>
This commit is contained in:
Simon Glass
2025-12-30 09:49:30 -07:00
parent 3235605698
commit dbf97406e9

View File

@@ -1938,6 +1938,24 @@ int jbd2_journal_stop(handle_t *handle)
*/
stop_this_handle(handle);
#ifdef __UBOOT__
/*
* U-Boot: Always commit synchronously for crash safety.
* In single-threaded mode, we commit immediately after each
* operation completes to ensure durability.
*/
if (IS_ENABLED(CONFIG_EXT4_WRITE) &&
journal->j_running_transaction &&
atomic_read(&journal->j_running_transaction->t_updates) == 0) {
jbd2_journal_commit_transaction(journal);
/*
* Check if journal was aborted during commit
* (e.g., due to I/O error) and propagate the error.
*/
if (is_journal_aborted(journal) && !err)
err = -EIO;
} else
#endif
if (wait_for_commit)
err = jbd2_log_wait_commit(journal, tid);