All of lore.kernel.org
 help / color / mirror / Atom feed
From: Baokun Li <libaokun1@huawei.com>
To: <linux-ext4@vger.kernel.org>
Cc: <tytso@mit.edu>, <adilger.kernel@dilger.ca>, <jack@suse.cz>,
	<yi.zhang@huawei.com>, <yangerkun@huawei.com>,
	<yukuai3@huawei.com>, <libaokun1@huawei.com>
Subject: [PATCH] debugfs: check first journal block type when a tail-to-head reversal occurs in logdump
Date: Thu, 2 Feb 2023 22:20:55 +0800	[thread overview]
Message-ID: <20230202142055.2482087-1-libaokun1@huawei.com> (raw)

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


                 reply	other threads:[~2023-02-02 13:57 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230202142055.2482087-1-libaokun1@huawei.com \
    --to=libaokun1@huawei.com \
    --cc=adilger.kernel@dilger.ca \
    --cc=jack@suse.cz \
    --cc=linux-ext4@vger.kernel.org \
    --cc=tytso@mit.edu \
    --cc=yangerkun@huawei.com \
    --cc=yi.zhang@huawei.com \
    --cc=yukuai3@huawei.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.