[Concept,02/14] linux: jbd2: Add synchronous commit on transaction stop
Commit Message
From: Simon Glass <simon.glass@canonical.com>
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>
---
fs/jbd2/transaction.c | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
@@ -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);