ref: 253f1096402014f3ec8bbc721eac2d9a9bf2677a
parent: 053a3f4e32d8536287366f89a9ce23ded4d5e571
author: Kaho Ng <ngkaho1234@gmail.com>
date: Thu Aug 18 22:36:57 EDT 2016
ext4_journal: tune the logic of block zeroing in write_commit_block()
--- a/src/ext4_journal.c
+++ b/src/ext4_journal.c
@@ -1763,7 +1763,25 @@
struct jbd_journal *journal = trans->journal;
commit_iblock = jbd_journal_alloc_block(journal, trans);
- rc = jbd_block_get_noread(journal->jbd_fs, &block, commit_iblock);
+ orig_commit_iblock = commit_iblock;
+ commit_iblock++;
+ wrap(&journal->jbd_fs->sb, commit_iblock);
+
+ /* To prevent accidental reference to stale journalling metadata. */
+ if (orig_commit_iblock < commit_iblock) {
+ rc = jbd_block_get_noread(journal->jbd_fs, &block, commit_iblock);
+ if (rc != EOK)
+ return rc;
+
+ memset(block.data, 0, journal->block_size);
+ ext4_bcache_set_dirty(block.buf);
+ ext4_bcache_set_flag(block.buf, BC_TMP);
+ rc = jbd_block_set(journal->jbd_fs, &block);
+ if (rc != EOK)
+ return rc;
+ }
+
+ rc = jbd_block_get_noread(journal->jbd_fs, &block, orig_commit_iblock);
if (rc != EOK)
return rc;
@@ -1782,25 +1800,6 @@
ext4_bcache_set_dirty(block.buf);
ext4_bcache_set_flag(block.buf, BC_TMP);
rc = jbd_block_set(journal->jbd_fs, &block);
- if (rc != EOK)
- return rc;
-
- orig_commit_iblock = commit_iblock;
- commit_iblock++;
- wrap(&journal->jbd_fs->sb, commit_iblock);
-
- /* To prevent accidental reference to stale journalling metadata. */
- if (orig_commit_iblock < commit_iblock) {
- rc = jbd_block_get_noread(journal->jbd_fs, &block, commit_iblock);
- if (rc != EOK)
- return rc;
-
- memset(block.data, 0, journal->block_size);
- ext4_bcache_set_dirty(block.buf);
- ext4_bcache_set_flag(block.buf, BC_TMP);
- rc = jbd_block_set(journal->jbd_fs, &block);
- }
-
return rc;
}