shithub: lwext4

Download patch

ref: e970afced259e8a524cef8cd1d74120e3c70eb1a
parent: 9cc36f15cc9a72a2b53470533704e31f7616f846
author: ngkaho1234 <ngkaho1234@gmail.com>
date: Mon Dec 14 11:10:58 EST 2015

ext4_journal: some changes below.

  - check whether buffer going to be added is dirty.
  - skip checkpoint on transactions having no data block.

--- a/lwext4/ext4_journal.c
+++ b/lwext4/ext4_journal.c
@@ -831,7 +831,13 @@
 int jbd_trans_add_block(struct jbd_trans *trans,
 			struct ext4_block *block)
 {
-	struct jbd_buf *buf = calloc(1, sizeof(struct jbd_buf));
+	struct jbd_buf *buf;
+	/* We do not need to add those unmodified buffer to
+	 * a transaction. */
+	if (!ext4_bcache_test_flag(block->buf, BC_DIRTY))
+		return EOK;
+
+	buf = calloc(1, sizeof(struct jbd_buf));
 	if (!buf)
 		return ENOMEM;
 
@@ -946,6 +952,10 @@
 			uuid_exist = true;
 			tag_tbl_size = journal->block_size -
 				sizeof(struct jbd_bhdr);
+
+			if (!trans->start_iblock)
+				trans->start_iblock = desc_iblock;
+
 		}
 		tag_info.block = jbd_buf->block.lb_id;
 		tag_info.uuid_exist = uuid_exist;
@@ -1032,6 +1042,10 @@
 			blocks_entry = (char *)(header + 1);
 			tag_tbl_size = journal->block_size -
 				sizeof(struct jbd_revoke_header);
+
+			if (!trans->start_iblock)
+				trans->start_iblock = desc_iblock;
+
 		}
 
 		if (tag_tbl_size < record_len) {
@@ -1097,8 +1111,9 @@
 	trans->written_cnt++;
 	if (trans->written_cnt == trans->data_cnt) {
 		TAILQ_REMOVE(&journal->cp_queue, trans, trans_node);
-		journal->start += trans->alloc_blocks;
-		journal->trans_id = ++trans->trans_id;
+		journal->start = trans->start_iblock +
+				 trans->alloc_blocks;
+		journal->trans_id = trans->trans_id + 1;
 		jbd_journal_write_sb(journal);
 		jbd_write_sb(journal->jbd_fs);
 		jbd_journal_free_trans(journal, trans, false);
@@ -1134,11 +1149,14 @@
 			goto Finish;
 
 		journal->alloc_trans_id++;
-		TAILQ_INSERT_TAIL(&journal->cp_queue, trans,
-			  trans_node);
-		if (trans == TAILQ_FIRST(&journal->cp_queue)) {
-			jbd_journal_cp_trans(journal, trans);
-		}
+		if (trans->data_cnt) {
+			TAILQ_INSERT_TAIL(&journal->cp_queue, trans,
+					trans_node);
+			if (trans == TAILQ_FIRST(&journal->cp_queue)) {
+				jbd_journal_cp_trans(journal, trans);
+			}
+		} else
+			jbd_journal_free_trans(journal, trans, false);
 	}
 Finish:
 	if (rc != EOK) {
--- a/lwext4/ext4_types.h
+++ b/lwext4/ext4_types.h
@@ -1107,6 +1107,7 @@
 struct jbd_trans {
 	uint32_t trans_id;
 
+	uint32_t start_iblock;
 	int alloc_blocks;
 	int data_cnt;
 	int written_cnt;