[Concept,19/21] ext4l: Skip the journal flush in read-only builds

Message ID 20260108185149.1995917-20-sjg@u-boot.org
State New
Headers
Series ext4l: Add Kconfig options to reduce binary size (part P) |

Commit Message

Simon Glass Jan. 8, 2026, 6:51 p.m. UTC
  From: Simon Glass <simon.glass@canonical.com>

Add IS_ENABLED(CONFIG_EXT4_WRITE) guards to jbd2_journal_flush() and
__jbd2_log_wait_for_space() to skip these operations in read-only builds.

Journal flushing writes pending transactions to disk, which is not needed
when the filesystem is mounted read-only. Similarly, waiting for journal
space is only relevant when allocating space for new transactions.

This eliminates jbd2_log_do_checkpoint() and saves approximately 1K on
Thumb2 builds.

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

 fs/jbd2/checkpoint.c | 4 ++++
 fs/jbd2/journal.c    | 4 ++++
 2 files changed, 8 insertions(+)
  

Patch

diff --git a/fs/jbd2/checkpoint.c b/fs/jbd2/checkpoint.c
index 994e454bb5b..5b794df3384 100644
--- a/fs/jbd2/checkpoint.c
+++ b/fs/jbd2/checkpoint.c
@@ -48,6 +48,10 @@  __releases(&journal->j_state_lock)
 	int nblocks, space_left;
 	/* assert_spin_locked(&journal->j_state_lock); */
 
+	/* Only needed for write operations */
+	if (!IS_ENABLED(CONFIG_EXT4_WRITE))
+		return;
+
 	nblocks = journal->j_max_transaction_buffers;
 	while (jbd2_log_space_left(journal) < nblocks) {
 		write_unlock(&journal->j_state_lock);
diff --git a/fs/jbd2/journal.c b/fs/jbd2/journal.c
index 0d38f00e555..e5bc62ba337 100644
--- a/fs/jbd2/journal.c
+++ b/fs/jbd2/journal.c
@@ -2409,6 +2409,10 @@  int jbd2_journal_flush(journal_t *journal, unsigned int flags)
 	int err = 0;
 	transaction_t *transaction = NULL;
 
+	/* Nothing to flush in read-only builds */
+	if (!IS_ENABLED(CONFIG_EXT4_WRITE))
+		return 0;
+
 	write_lock(&journal->j_state_lock);
 
 	/* Force everything buffered to the log... */