All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] debugfs: check first journal block type when a tail-to-head reversal occurs in logdump
@ 2023-02-02 14:20 Baokun Li
  0 siblings, 0 replies; only message in thread
From: Baokun Li @ 2023-02-02 14:20 UTC (permalink / raw)
  To: linux-ext4
  Cc: tytso, adilger.kernel, jack, yi.zhang, yangerkun, yukuai3, libaokun1

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 --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;
 }
 
-- 
2.31.1


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2023-02-02 13:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-02 14:20 [PATCH] debugfs: check first journal block type when a tail-to-head reversal occurs in logdump Baokun Li

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.