diff mbox series

debugfs: check first journal block type when a tail-to-head reversal occurs in logdump

Message ID 20230202142055.2482087-1-libaokun1@huawei.com
State New
Headers show
Series debugfs: check first journal block type when a tail-to-head reversal occurs in logdump | expand

Commit Message

Baokun Li Feb. 2, 2023, 2:20 p.m. UTC
When logs are dumped, if the last description block in the journal area
contains the first journal block as the data block, logs may be repeatedly
printed or not completely printed. After the journal replay, we always
restart logging from the first journal block. In this case, there are the
following two cases:

1) If start == first, the first block is always skipped due to reversal.
Therefore, the condition (blocknr == first_transaction_blocknr) for
determining repeated printing does not take effect. As a result, logs are
repeatedly printed.

2) If start != first, we will traverse backwards from the first non-data
block after the last journal data block in the last description block, and
the logs from the first journal block to this block will not be printed.
That is, the dump log is incomplete.

To solve this problem, we only need to check the type of the first log
block when reversal occurs. If it is a non-log data block, we should
continue to dump directly from the first block.

Signed-off-by: Baokun Li <libaokun1@huawei.com>
---
 debugfs/logdump.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/debugfs/logdump.c b/debugfs/logdump.c
index b103cf1e..0019b6cf 100644
--- a/debugfs/logdump.c
+++ b/debugfs/logdump.c
@@ -740,6 +740,18 @@  static void dump_descriptor_block(FILE *out_file,
 
 	} while (!(tag_flags & JBD2_FLAG_LAST_TAG));
 
+	/* When a tail-to-head reversal occurs, we need to check whether
+	 * there is a log that starts from the beginning again.
+	 */
+	if (*blockp > blocknr) {
+		journal_header_t first_header = {0};
+
+		read_journal_block("logdump", source, blocksize,
+				   (char *)&first_header, sizeof(journal_header_t));
+		if ((be32_to_cpu(first_header.h_magic) == JBD2_MAGIC_NUMBER) &&
+		    (be32_to_cpu(first_header.h_blocktype) == JBD2_DESCRIPTOR_BLOCK))
+			blocknr = 1;
+	}
 	*blockp = blocknr;
 }