shithub: lwext4

Download patch

ref: cb473bbcead90b2541817f81f7a030d6e8215185
parent: 1366373d0c66281935e9e0fc71f52f5919a3a085
author: ngkaho1234 <[email protected]>
date: Fri Dec 25 07:07:01 EST 2015

ext4_journal: set buffer dirty if it does not belong to any transaction.

When calling jbd_trans_set_block_dirty, if a buffer does not belong to
any other transaction, it will be set dirty.

--- a/lwext4/ext4_journal.c
+++ b/lwext4/ext4_journal.c
@@ -1123,23 +1123,26 @@
 {
 	struct jbd_buf *buf;
 
-	buf = calloc(1, sizeof(struct jbd_buf));
-	if (!buf)
-		return ENOMEM;
+	if (!ext4_bcache_test_flag(block->buf, BC_DIRTY) &&
+	    block->buf->end_write != jbd_trans_end_write) {
+		buf = calloc(1, sizeof(struct jbd_buf));
+		if (!buf)
+			return ENOMEM;
 
-	buf->trans = trans;
-	buf->block = *block;
-	ext4_bcache_inc_ref(block->buf);
+		buf->trans = trans;
+		buf->block = *block;
+		ext4_bcache_inc_ref(block->buf);
 
-	/* If the content reach the disk, notify us
-	 * so that we may do a checkpoint. */
-	block->buf->end_write = jbd_trans_end_write;
-	block->buf->end_write_arg = buf;
+		/* If the content reach the disk, notify us
+		 * so that we may do a checkpoint. */
+		block->buf->end_write = jbd_trans_end_write;
+		block->buf->end_write_arg = buf;
 
-	trans->data_cnt++;
-	LIST_INSERT_HEAD(&trans->buf_list, buf, buf_node);
+		trans->data_cnt++;
+		LIST_INSERT_HEAD(&trans->buf_list, buf, buf_node);
 
-	ext4_bcache_set_dirty(block->buf);
+		ext4_bcache_set_dirty(block->buf);
+	}
 	return EOK;
 }