From: Wenchao Hao <haowenchao2@huawei.com>
To: Theodore Ts'o <tytso@mit.edu>,
Andreas Dilger <adilger.kernel@dilger.ca>,
<linux-ext4@vger.kernel.org>
Cc: <louhongxiang@huawei.com>, Wenchao Hao <haowenchao2@huawei.com>
Subject: [RESEND PATCH] e2fsprogs: debugfs: Fix infinite loop when dump log
Date: Mon, 26 Feb 2024 16:14:51 +0800 [thread overview]
Message-ID: <20240226081451.3224276-1-haowenchao2@huawei.com> (raw)
There are 2 scenarios which would trigger infinite loop:
1. None log is recorded, then dumplog with "-n", for example:
debugfs -R "logdump -O -n 10" /dev/xxx
while /dev/xxx has no valid log recorded.
2. The log area is full and cycle write is triggered, then dumplog with
debugfs -R "logdump -aOS" /dev/xxx
This patch add a new flag "reverse_flag" to mark if logdump has reached
to tail of logarea, it is default false, and set in macro WRAP().
If reverse_flag is true, and we comes to first_transaction_blocknr
again, just break the logdump loop.
Signed-off-by: Wenchao Hao <haowenchao2@huawei.com>
---
debugfs/logdump.c | 11 +++++++----
1 file changed, 7 insertions(+), 4 deletions(-)
diff --git a/debugfs/logdump.c b/debugfs/logdump.c
index b600228e..05ea839a 100644
--- a/debugfs/logdump.c
+++ b/debugfs/logdump.c
@@ -52,6 +52,7 @@ static int64_t dump_counts;
static blk64_t block_to_dump, bitmap_to_dump, inode_block_to_dump;
static unsigned int group_to_dump, inode_offset_to_dump;
static ext2_ino_t inode_to_dump;
+static bool reverse_flag;
struct journal_source
{
@@ -80,8 +81,10 @@ static void dump_fc_block(FILE *out_file, char *buf, int blocksize,
static void do_hexdump (FILE *, char *, int);
#define WRAP(jsb, blocknr, maxlen) \
- if (blocknr >= (maxlen)) \
- blocknr -= (maxlen - be32_to_cpu((jsb)->s_first));
+ if (blocknr >= (maxlen)) { \
+ blocknr -= (maxlen - be32_to_cpu((jsb)->s_first)); \
+ reverse_flag = true; \
+ }
void do_logdump(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
void *infop EXT2FS_ATTR((unused)))
@@ -115,6 +118,7 @@ void do_logdump(int argc, char **argv, int sci_idx EXT2FS_ATTR((unused)),
inode_block_to_dump = ANY_BLOCK;
inode_to_dump = -1;
dump_counts = -1;
+ reverse_flag = false;
reset_getopt();
while ((c = getopt (argc, argv, "ab:ci:f:OsSn:")) != EOF) {
@@ -477,8 +481,7 @@ static void dump_journal(char *cmdname, FILE *out_file,
if (dump_old && (dump_counts != -1) && (cur_counts >= dump_counts))
break;
- if ((blocknr == first_transaction_blocknr) &&
- (cur_counts != 0) && dump_old && (dump_counts != -1)) {
+ if ((blocknr == first_transaction_blocknr) && dump_old && reverse_flag) {
fprintf(out_file, "Dump all %lld journal records.\n",
(long long) cur_counts);
break;
--
2.32.0
next reply other threads:[~2024-02-26 8:17 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-26 8:14 Wenchao Hao [this message]
2024-03-18 9:32 ` [RESEND PATCH] e2fsprogs: debugfs: Fix infinite loop when dump log Wenchao Hao
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=20240226081451.3224276-1-haowenchao2@huawei.com \
--to=haowenchao2@huawei.com \
--cc=adilger.kernel@dilger.ca \
--cc=linux-ext4@vger.kernel.org \
--cc=louhongxiang@huawei.com \
--cc=tytso@mit.edu \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).