Skip to contentSkip to conversation

ocfs2: checkpoint appending truncate log transaction before flushing

PATCH New Changwei Ge 3 participants 8 messages Feb 14, 2019 – Sep 16, 2019 OCFS2

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ocfs2: checkpoint appending truncate log transaction before flushing

Appending truncate log(TA) and and flushing truncate log(TF) are two separated transactions. They can be both committed but not checkpointed. If crash occurs then, both two transaction will be replayed with several already released to global bitmap clusters. Then truncate log will be replayed resulting in cluster double free.

To reproduce this issue, just crash the host while punching hole to files.

---
 fs/ocfs2/alloc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
fs/ocfs2/alloc.c +15 -0
index d1cbb27..29bc777 100644
@@ -6007,6 +6007,7 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
 	struct buffer_head *data_alloc_bh = NULL;
 	struct ocfs2_dinode *di;
 	struct ocfs2_truncate_log *tl;
+	struct ocfs2_journal *journal = osb->journal;
 
 	BUG_ON(inode_trylock(tl_inode));
 
@@ -6027,6 +6028,20 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
 		goto out;
 	}
 
+	/* Appending truncate log(TA) and and flushing truncate log(TF) are
+	 * two separated transactions. They can be both committed but not
+	 * checkpointed. If crash occurs then, both two transaction will be
+	 * replayed with several already released to global bitmap clusters.
+	 * Then truncate log will be replayed resulting in cluster double free.
+	 */
+	jbd2_journal_lock_updates(journal->j_journal);
+	status = jbd2_journal_flush(journal->j_journal);
+	jbd2_journal_unlock_updates(journal->j_journal);
+	if (status < 0) {
+		mlog_errno(status);
+		goto out;
+	}
+
 	data_alloc_inode = ocfs2_get_system_file_inode(osb,
 						       GLOBAL_BITMAP_SYSTEM_INODE,
 						       OCFS2_INVALID_SLOT);
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/1 ocfs2: checkpoint appending truncate log transaction before flushing

Hi Changwei,

Quoted 4 lines · Changwei Ge

Appending truncate log(TA) and and flushing truncate log(TF) are two separated transactions. They can be both committed but not checkpointed. If crash occurs then, both two transaction will be replayed with several already released to global bitmap clusters.

Do you mean that both the two transactions will release cluster to global bitmap? But I think the TA won't give back clusters to global bitmap.

Quoted 1 line

Then truncate log will be replayed resulting in cluster double free.

Does this problem only cause some error log? As below:

ocfs2_replay_truncate_records
ocfs2_free_clusters
_ocfs2_free_clusters
_ocfs2_free_suballoc_bits
ocfs2_block_group_clear_bits
"Trying to clear %u bits at offset %u in group descriptor"

Thanks,
Jun

Quoted 42 lines

To reproduce this issue, just crash the host while punching hole to files.

---
 fs/ocfs2/alloc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
fs/ocfs2/alloc.c +15 -0
index d1cbb27..29bc777 100644
@@ -6007,6 +6007,7 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
 	struct buffer_head *data_alloc_bh = NULL;
 	struct ocfs2_dinode *di;
 	struct ocfs2_truncate_log *tl;
+	struct ocfs2_journal *journal = osb->journal;
 
 	BUG_ON(inode_trylock(tl_inode));
 
@@ -6027,6 +6028,20 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
 		goto out;
 	}
 
+	/* Appending truncate log(TA) and and flushing truncate log(TF) are
+	 * two separated transactions. They can be both committed but not
+	 * checkpointed. If crash occurs then, both two transaction will be
+	 * replayed with several already released to global bitmap clusters.
+	 * Then truncate log will be replayed resulting in cluster double free.
+	 */
+	jbd2_journal_lock_updates(journal->j_journal);
+	status = jbd2_journal_flush(journal->j_journal);
+	jbd2_journal_unlock_updates(journal->j_journal);
+	if (status < 0) {
+		mlog_errno(status);
+		goto out;
+	}
+
 	data_alloc_inode = ocfs2_get_system_file_inode(osb,
 						       GLOBAL_BITMAP_SYSTEM_INODE,
 						       OCFS2_INVALID_SLOT);
#2 lore raw

PATCH 1/1 ocfs2: checkpoint appending truncate log transaction before flushing

Hi Jun,

Thanks for looking into this :-)

Quoted 12 lines · piaojun

Hi Changwei,

Quoted 4 lines · Changwei Ge

Appending truncate log(TA) and and flushing truncate log(TF) are two separated transactions. They can be both committed but not checkpointed. If crash occurs then, both two transaction will be replayed with several already released to global bitmap clusters.

Do you mean that both the two transactions will release cluster to global bitmap? But I think the TA won't give back clusters to global bitmap.

No, I don't mean that both TA and TF are releasing clusters to global bitmap.

But consideration into clusters reclaim , clusters will first be recorded in truncate log and then be returned to global bitmap, which involves TA and TF jdb2/transactions.

TA's job is to append cluster records to truncate log, by which we can overcome a potential space leak problem. TF's job is to return clusters to global bitmap.

It's possible that TA and TF are both committed to JBD but sadly none of them is check-pointed. So journal replaying need to replay both TA and TF during next mount.
Then there is a record residing in truncate log representing the already released cluster which has been returned to global bitmap by replaying TF.

Now the double free shows up.

Quoted 11 lines
Quoted 1 line

Then truncate log will be replayed resulting in cluster double free.

Does this problem only cause some error log? As below:

ocfs2_replay_truncate_records
ocfs2_free_clusters
_ocfs2_free_clusters
_ocfs2_free_suballoc_bits
ocfs2_block_group_clear_bits
"Trying to clear %u bits at offset %u in group descriptor"

Exactly, when the issue occurs, it will be printed as above.

Thanks,
Changwei

Quoted 46 lines

Thanks,
Jun

Quoted 42 lines

To reproduce this issue, just crash the host while punching hole to files.

---
  fs/ocfs2/alloc.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
fs/ocfs2/alloc.c +15 -0
index d1cbb27..29bc777 100644
@@ -6007,6 +6007,7 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
  	struct buffer_head *data_alloc_bh = NULL;
  	struct ocfs2_dinode *di;
  	struct ocfs2_truncate_log *tl;
+	struct ocfs2_journal *journal = osb->journal;
 
  	BUG_ON(inode_trylock(tl_inode));
 
@@ -6027,6 +6028,20 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
  		goto out;
  	}
 
+	/* Appending truncate log(TA) and and flushing truncate log(TF) are
+	 * two separated transactions. They can be both committed but not
+	 * checkpointed. If crash occurs then, both two transaction will be
+	 * replayed with several already released to global bitmap clusters.
+	 * Then truncate log will be replayed resulting in cluster double free.
+	 */
+	jbd2_journal_lock_updates(journal->j_journal);
+	status = jbd2_journal_flush(journal->j_journal);
+	jbd2_journal_unlock_updates(journal->j_journal);
+	if (status < 0) {
+		mlog_errno(status);
+		goto out;
+	}
+
  	data_alloc_inode = ocfs2_get_system_file_inode(osb,
  						       GLOBAL_BITMAP_SYSTEM_INODE,
  						       OCFS2_INVALID_SLOT);
#3 lore raw

PATCH 1/1 ocfs2: checkpoint appending truncate log transaction before flushing

Hi Changwei,

Quoted 26 lines · Changwei Ge

Hi Jun,

Thanks for looking into this :-)

Quoted 12 lines · piaojun

Hi Changwei,

Quoted 4 lines · Changwei Ge

Appending truncate log(TA) and and flushing truncate log(TF) are two separated transactions. They can be both committed but not checkpointed. If crash occurs then, both two transaction will be replayed with several already released to global bitmap clusters.

Do you mean that both the two transactions will release cluster to global bitmap? But I think the TA won't give back clusters to global bitmap.

No, I don't mean that both TA and TF are releasing clusters to global bitmap.

But consideration into clusters reclaim , clusters will first be recorded in truncate log and then be returned to global bitmap, which involves TA and TF jdb2/transactions.

TA's job is to append cluster records to truncate log, by which we can overcome a potential space leak problem. TF's job is to return clusters to global bitmap.

Quoted 6 lines

It's possible that TA and TF are both committed to JBD but sadly none of them is check-pointed. So journal replaying need to replay both TA and TF during next mount.
Then there is a record residing in truncate log representing the already released cluster which has been returned to global bitmap by replaying TF.

Now the double free shows up.

Do you mean that when mount again, truncate log recovery will find record residing in truncate log which already released? But after the TF transaction replayed during mount, truncate log won't be recovered as tl->tl_used is less than tl->tl_count.

Thanks,
Jun

Quoted 67 lines
Quoted 4 lines
Quoted 3 lines

Then truncate log will be replayed resulting in cluster double free.

Quoted 9 lines

Does this problem only cause some error log? As below:

ocfs2_replay_truncate_records
ocfs2_free_clusters
_ocfs2_free_clusters
_ocfs2_free_suballoc_bits
ocfs2_block_group_clear_bits
"Trying to clear %u bits at offset %u in group descriptor"

Exactly, when the issue occurs, it will be printed as above.

Thanks,
Changwei

Quoted 37 lines

Thanks,
Jun

Quoted 34 lines

To reproduce this issue, just crash the host while punching hole to files.

---
  fs/ocfs2/alloc.c | 15 +++++++++++++++
  1 file changed, 15 insertions(+)
fs/ocfs2/alloc.c +11 -0
index d1cbb27..29bc777 100644
@@ -6007,6 +6007,7 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
  	struct buffer_head *data_alloc_bh = NULL;
  	struct ocfs2_dinode *di;
  	struct ocfs2_truncate_log *tl;
+	struct ocfs2_journal *journal = osb->journal;
 
  	BUG_ON(inode_trylock(tl_inode));
 
@@ -6027,6 +6028,20 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
  		goto out;
  	}
 
+	/* Appending truncate log(TA) and and flushing truncate log(TF) are
+	 * two separated transactions. They can be both committed but not
+	 * checkpointed. If crash occurs then, both two transaction will be
+	 * replayed with several already released to global bitmap clusters.
+	 * Then truncate log will be replayed resulting in cluster double free.
+	 */
+	jbd2_journal_lock_updates(journal->j_journal);
+	status = jbd2_journal_flush(journal->j_journal);
+	jbd2_journal_unlock_updates(journal->j_journal);
+	if (status < 0) {
Quoted 9 lines

fs/ocfs2/alloc.c int __ocfs2_flush_truncate_log(struct ocfs2_super *osb) · line 6047

Quoted 8 lines
fs/ocfs2/alloc.c +4 -0
+		mlog_errno(status);
+		goto out;
+	}
+
  	data_alloc_inode = ocfs2_get_system_file_inode(osb,
  						       GLOBAL_BITMAP_SYSTEM_INODE,
  						       OCFS2_INVALID_SLOT);

.

#4 lore raw

PATCH 1/1 ocfs2: checkpoint appending truncate log transaction before flushing

Quoted 34 lines · piaojun

Hi Changwei,

Quoted 31 lines · Changwei Ge

Hi Jun,

Thanks for looking into this :-)

Quoted 12 lines · piaojun

Hi Changwei,

Quoted 4 lines · Changwei Ge

Appending truncate log(TA) and and flushing truncate log(TF) are two separated transactions. They can be both committed but not checkpointed. If crash occurs then, both two transaction will be replayed with several already released to global bitmap clusters.

Do you mean that both the two transactions will release cluster to global bitmap? But I think the TA won't give back clusters to global bitmap.

No, I don't mean that both TA and TF are releasing clusters to global bitmap.

But consideration into clusters reclaim , clusters will first be recorded in truncate log and then be returned to global bitmap, which involves TA and TF jdb2/transactions.

TA's job is to append cluster records to truncate log, by which we can overcome a potential space leak problem. TF's job is to return clusters to global bitmap.

It's possible that TA and TF are both committed to JBD but sadly none of them is check-pointed. So journal replaying need to replay both TA and TF during next mount.
Then there is a record residing in truncate log representing the already released cluster which has been returned to global bitmap by replaying TF.

Quoted 6 lines
Quoted 1 line

Now the double free shows up.

Do you mean that when mount again, truncate log recovery will find record residing in truncate log which already released? But after the TF transaction replayed during mount, truncate log won't be recovered as tl->tl_used is less than tl->tl_count.

Um, not just truncate log relaying but also involves a jbd2 transaction recording its last append operation. That operation may meet the flush condition (ocfs2_truncate_log_needs_flush)

Thanks,
Changwei

Quoted 72 lines

Thanks,
Jun

Quoted 67 lines
Quoted 4 lines
Quoted 3 lines

Then truncate log will be replayed resulting in cluster double free.

Quoted 9 lines

Does this problem only cause some error log? As below:

ocfs2_replay_truncate_records
ocfs2_free_clusters
_ocfs2_free_clusters
_ocfs2_free_suballoc_bits
ocfs2_block_group_clear_bits
"Trying to clear %u bits at offset %u in group descriptor"

Exactly, when the issue occurs, it will be printed as above.

Thanks,
Changwei

Quoted 37 lines

Thanks,
Jun

Quoted 34 lines

To reproduce this issue, just crash the host while punching hole to files.

---
   fs/ocfs2/alloc.c | 15 +++++++++++++++
   1 file changed, 15 insertions(+)
fs/ocfs2/alloc.c +11 -0
index d1cbb27..29bc777 100644
@@ -6007,6 +6007,7 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
   	struct buffer_head *data_alloc_bh = NULL;
   	struct ocfs2_dinode *di;
   	struct ocfs2_truncate_log *tl;
+	struct ocfs2_journal *journal = osb->journal;
 
   	BUG_ON(inode_trylock(tl_inode));
 
@@ -6027,6 +6028,20 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
   		goto out;
   	}
 
+	/* Appending truncate log(TA) and and flushing truncate log(TF) are
+	 * two separated transactions. They can be both committed but not
+	 * checkpointed. If crash occurs then, both two transaction will be
+	 * replayed with several already released to global bitmap clusters.
+	 * Then truncate log will be replayed resulting in cluster double free.
+	 */
+	jbd2_journal_lock_updates(journal->j_journal);
+	status = jbd2_journal_flush(journal->j_journal);
+	jbd2_journal_unlock_updates(journal->j_journal);
+	if (status < 0) {
Quoted 9 lines

fs/ocfs2/alloc.c int __ocfs2_flush_truncate_log(struct ocfs2_super *osb) · line 6047

Quoted 8 lines
fs/ocfs2/alloc.c +4 -0
+		mlog_errno(status);
+		goto out;
+	}
+
   	data_alloc_inode = ocfs2_get_system_file_inode(osb,
   						       GLOBAL_BITMAP_SYSTEM_INODE,
   						       OCFS2_INVALID_SLOT);

.

#5 lore raw

PATCH 1/1 ocfs2: checkpoint appending truncate log transaction before flushing

Hi Jun,

Do you have any other question, advise or concern?
I am expecting an explicit feedback(ack/nack) if you already understand the problem and my way fixing it.

Thanks,
Changwei

Quoted 126 lines · Changwei Ge
Quoted 34 lines · piaojun

Hi Changwei,

Quoted 31 lines · Changwei Ge

Hi Jun,

Thanks for looking into this :-)

Quoted 12 lines · piaojun

Hi Changwei,

Quoted 4 lines · Changwei Ge

Appending truncate log(TA) and and flushing truncate log(TF) are two separated transactions. They can be both committed but not checkpointed. If crash occurs then, both two transaction will be replayed with several already released to global bitmap clusters.

Do you mean that both the two transactions will release cluster to global bitmap? But I think the TA won't give back clusters to global bitmap.

No, I don't mean that both TA and TF are releasing clusters to global bitmap.

But consideration into clusters reclaim , clusters will first be recorded in truncate log and then be returned to global bitmap, which involves TA and TF jdb2/transactions.

TA's job is to append cluster records to truncate log, by which we can overcome a potential space leak problem. TF's job is to return clusters to global bitmap.

It's possible that TA and TF are both committed to JBD but sadly none of them is check-pointed. So journal replaying need to replay both TA and TF during next mount.
Then there is a record residing in truncate log representing the already released cluster which has been returned to global bitmap by replaying TF.

Quoted 6 lines
Quoted 1 line

Now the double free shows up.

Do you mean that when mount again, truncate log recovery will find record residing in truncate log which already released? But after the TF transaction replayed during mount, truncate log won't be recovered as tl->tl_used is less than tl->tl_count.

Um, not just truncate log relaying but also involves a jbd2 transaction recording its last append operation. That operation may meet the flush condition (ocfs2_truncate_log_needs_flush)

Thanks,
Changwei

Quoted 72 lines

Thanks,
Jun

Quoted 67 lines
Quoted 4 lines
Quoted 3 lines

Then truncate log will be replayed resulting in cluster double free.

Quoted 9 lines

Does this problem only cause some error log? As below:

ocfs2_replay_truncate_records
ocfs2_free_clusters
_ocfs2_free_clusters
_ocfs2_free_suballoc_bits
ocfs2_block_group_clear_bits
"Trying to clear %u bits at offset %u in group descriptor"

Exactly, when the issue occurs, it will be printed as above.

Thanks,
Changwei

Quoted 37 lines

Thanks,
Jun

Quoted 34 lines

To reproduce this issue, just crash the host while punching hole to files.

---
    fs/ocfs2/alloc.c | 15 +++++++++++++++
    1 file changed, 15 insertions(+)
fs/ocfs2/alloc.c +11 -0
index d1cbb27..29bc777 100644
@@ -6007,6 +6007,7 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
    	struct buffer_head *data_alloc_bh = NULL;
    	struct ocfs2_dinode *di;
    	struct ocfs2_truncate_log *tl;
+	struct ocfs2_journal *journal = osb->journal;
 
    	BUG_ON(inode_trylock(tl_inode));
 
@@ -6027,6 +6028,20 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
    		goto out;
    	}
 
+	/* Appending truncate log(TA) and and flushing truncate log(TF) are
+	 * two separated transactions. They can be both committed but not
+	 * checkpointed. If crash occurs then, both two transaction will be
+	 * replayed with several already released to global bitmap clusters.
+	 * Then truncate log will be replayed resulting in cluster double free.
+	 */
+	jbd2_journal_lock_updates(journal->j_journal);
+	status = jbd2_journal_flush(journal->j_journal);
+	jbd2_journal_unlock_updates(journal->j_journal);
+	if (status < 0) {
Quoted 9 lines

fs/ocfs2/alloc.c int __ocfs2_flush_truncate_log(struct ocfs2_super *osb) · line 6047

Quoted 8 lines
fs/ocfs2/alloc.c +4 -0
+		mlog_errno(status);
+		goto out;
+	}
+
    	data_alloc_inode = ocfs2_get_system_file_inode(osb,
    						       GLOBAL_BITMAP_SYSTEM_INODE,
    						       OCFS2_INVALID_SLOT);

.

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

#6 lore raw

PATCH 1/1 ocfs2: checkpoint appending truncate log transaction before flushing

Hi Changwei,

I just need more time to review this.

Thanks,
Jun

Quoted 137 lines · Changwei Ge

Hi Jun,

Do you have any other question, advise or concern?
I am expecting an explicit feedback(ack/nack) if you already understand the problem and my way fixing it.

Thanks,
Changwei

Quoted 117 lines · Changwei Ge
Quoted 34 lines · piaojun

Hi Changwei,

Quoted 31 lines · Changwei Ge

Hi Jun,

Thanks for looking into this :-)

Quoted 12 lines · piaojun

Hi Changwei,

Quoted 4 lines · Changwei Ge

Appending truncate log(TA) and and flushing truncate log(TF) are two separated transactions. They can be both committed but not checkpointed. If crash occurs then, both two transaction will be replayed with several already released to global bitmap clusters.

Do you mean that both the two transactions will release cluster to global bitmap? But I think the TA won't give back clusters to global bitmap.

No, I don't mean that both TA and TF are releasing clusters to global bitmap.

But consideration into clusters reclaim , clusters will first be recorded in truncate log and then be returned to global bitmap, which involves TA and TF jdb2/transactions.

TA's job is to append cluster records to truncate log, by which we can overcome a potential space leak problem. TF's job is to return clusters to global bitmap.

It's possible that TA and TF are both committed to JBD but sadly none of them is check-pointed. So journal replaying need to replay both TA and TF during next mount.
Then there is a record residing in truncate log representing the already released cluster which has been returned to global bitmap by replaying TF.

Quoted 6 lines
Quoted 1 line

Now the double free shows up.

Do you mean that when mount again, truncate log recovery will find record residing in truncate log which already released? But after the TF transaction replayed during mount, truncate log won't be recovered as tl->tl_used is less than tl->tl_count.

Um, not just truncate log relaying but also involves a jbd2 transaction recording its last append operation. That operation may meet the flush condition (ocfs2_truncate_log_needs_flush)

Thanks,
Changwei

Quoted 69 lines

Thanks,
Jun

Quoted 65 lines
Quoted 4 lines
Quoted 3 lines

Then truncate log will be replayed resulting in cluster double free.

Quoted 9 lines

Does this problem only cause some error log? As below:

ocfs2_replay_truncate_records
ocfs2_free_clusters
_ocfs2_free_clusters
_ocfs2_free_suballoc_bits
ocfs2_block_group_clear_bits
"Trying to clear %u bits at offset %u in group descriptor"

Exactly, when the issue occurs, it will be printed as above.

Thanks,
Changwei

Quoted 46 lines

Thanks,
Jun

Quoted 42 lines

To reproduce this issue, just crash the host while punching hole to files.

---
    fs/ocfs2/alloc.c | 15 +++++++++++++++
    1 file changed, 15 insertions(+)
fs/ocfs2/alloc.c +15 -0
index d1cbb27..29bc777 100644
@@ -6007,6 +6007,7 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
    	struct buffer_head *data_alloc_bh = NULL;
    	struct ocfs2_dinode *di;
    	struct ocfs2_truncate_log *tl;
+	struct ocfs2_journal *journal = osb->journal;
 
    	BUG_ON(inode_trylock(tl_inode));
 
@@ -6027,6 +6028,20 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
    		goto out;
    	}
 
+	/* Appending truncate log(TA) and and flushing truncate log(TF) are
+	 * two separated transactions. They can be both committed but not
+	 * checkpointed. If crash occurs then, both two transaction will be
+	 * replayed with several already released to global bitmap clusters.
+	 * Then truncate log will be replayed resulting in cluster double free.
+	 */
+	jbd2_journal_lock_updates(journal->j_journal);
+	status = jbd2_journal_flush(journal->j_journal);
+	jbd2_journal_unlock_updates(journal->j_journal);
+	if (status < 0) {
+		mlog_errno(status);
+		goto out;
+	}
+
    	data_alloc_inode = ocfs2_get_system_file_inode(osb,
    						       GLOBAL_BITMAP_SYSTEM_INODE,
    						       OCFS2_INVALID_SLOT);
Quoted 9 lines
Quoted 3 lines
Quoted 2 lines

.

_______________________________________________
Ocfs2-devel mailing list
Ocfs2-devel at oss.oracle.com
https://oss.oracle.com/mailman/listinfo/ocfs2-devel

.

#7 lore raw

PATCH 1/1 ocfs2: checkpoint appending truncate log transaction before flushing

In reply to Changwei Ge
Quoted 9 lines · Changwei Ge

Appending truncate log(TA) and and flushing truncate log(TF) are two separated transactions. They can be both committed but not checkpointed. If crash occurs then, both two transaction will be replayed with several already released to global bitmap clusters. Then truncate log will be replayed resulting in cluster double free.

To reproduce this issue, just crash the host while punching hole to files.

Looks good to me.

Quoted 38 lines
---
 fs/ocfs2/alloc.c | 15 +++++++++++++++
 1 file changed, 15 insertions(+)
fs/ocfs2/alloc.c +15 -0
index d1cbb27..29bc777 100644
@@ -6007,6 +6007,7 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
 	struct buffer_head *data_alloc_bh = NULL;
 	struct ocfs2_dinode *di;
 	struct ocfs2_truncate_log *tl;
+	struct ocfs2_journal *journal = osb->journal;
 
 	BUG_ON(inode_trylock(tl_inode));
 
@@ -6027,6 +6028,20 @@ int __ocfs2_flush_truncate_log(struct ocfs2_super *osb)
 		goto out;
 	}
 
+	/* Appending truncate log(TA) and and flushing truncate log(TF) are
+	 * two separated transactions. They can be both committed but not
+	 * checkpointed. If crash occurs then, both two transaction will be
+	 * replayed with several already released to global bitmap clusters.
+	 * Then truncate log will be replayed resulting in cluster double free.
+	 */
+	jbd2_journal_lock_updates(journal->j_journal);
+	status = jbd2_journal_flush(journal->j_journal);
+	jbd2_journal_unlock_updates(journal->j_journal);
+	if (status < 0) {
+		mlog_errno(status);
+		goto out;
+	}
+
 	data_alloc_inode = ocfs2_get_system_file_inode(osb,
 						       GLOBAL_BITMAP_SYSTEM_INODE,
 						       OCFS2_INVALID_SLOT);