All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: zhanchengbin <zhanchengbin1@huawei.com>
Cc: Theodore Ts'o <tytso@mit.edu>,
	linux-ext4@vger.kernel.org, qiangxiaojun@huawei.com,
	hejie3@huawei.com
Subject: Re: [PATCH] debugfs/logdump.c: Add parameter t to dump sequence commit timestamps
Date: Mon, 30 Jun 2025 08:10:57 -0700	[thread overview]
Message-ID: <20250630151057.GA9987@frogsfrogsfrogs> (raw)
In-Reply-To: <50aeb0c1-9f14-ed04-c3b7-7a50f61c3341@huawei.com>

On Tue, Jun 17, 2025 at 07:31:35PM +0800, zhanchengbin wrote:
> When filesystem errors occur, inspect journal sequences with parameter t to
>  dump commit timestamps.
> 
> Signed-off-by: zhanchengbin <zhanchengbin@huawei.com>
> ---
>  debugfs/logdump.c | 63 ++++++++++++++++++++++++++++++++++++++++-------
>  1 file changed, 54 insertions(+), 9 deletions(-)
> 
> diff --git a/debugfs/logdump.c b/debugfs/logdump.c
> index 324ed42..bbe1384 100644
> --- a/debugfs/logdump.c
> +++ b/debugfs/logdump.c
> @@ -47,7 +47,7 @@ enum journal_location {JOURNAL_IS_INTERNAL,
> JOURNAL_IS_EXTERNAL};
> 
>  #define ANY_BLOCK ((blk64_t) -1)
> 
> -static int        dump_all, dump_super, dump_old, dump_contents,
> dump_descriptors;
> +static int        dump_all, dump_super, dump_old, dump_contents,
> dump_descriptors, dump_time;
>  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;
> @@ -67,6 +67,8 @@ static void dump_descriptor_block(FILE *, struct
> journal_source *,
>                    char *, journal_superblock_t *,
>                    unsigned int *, unsigned int, __u32, tid_t);
> 
> +static void dump_commit_time(FILE *out_file, char *buf);
> +
>  static void dump_revoke_block(FILE *, char *, journal_superblock_t *,
>                    unsigned int, unsigned int, tid_t);
> 
> @@ -118,10 +120,11 @@ void do_logdump(int argc, ss_argv_t argv, int sci_idx
> EXT2FS_ATTR((unused)),
>      inode_block_to_dump = ANY_BLOCK;
>      inode_to_dump = -1;
>      dump_counts = -1;
> +    dump_time = 0;

Globals are initialized to zero if not given an explicit value so this
isn't necessary.

>      wrapped_flag = false;
> 
>      reset_getopt();
> -    while ((c = getopt (argc, argv, "ab:ci:f:OsSn:")) != EOF) {
> +    while ((c = getopt (argc, argv, "ab:ci:f:OsSn:t")) != EOF) {
>          switch (c) {
>          case 'a':
>              dump_all++;
> @@ -162,6 +165,9 @@ void do_logdump(int argc, ss_argv_t argv, int sci_idx
> EXT2FS_ATTR((unused)),
>                  return;
>              }
>              break;
> +        case 't':
> +            dump_time++;
> +            break;
>          default:
>              goto print_usage;
>          }
> @@ -521,21 +527,33 @@ static void dump_journal(char *cmdname, FILE
> *out_file,
>                  break;
>          }
> 
> -        if (dump_descriptors) {
> -            fprintf (out_file, "Found expected sequence %u, "
> -                 "type %u (%s) at block %u\n",
> -                 sequence, blocktype,
> -                 type_to_name(blocktype), blocknr);
> -        }
> -
>          switch (blocktype) {
>          case JBD2_DESCRIPTOR_BLOCK:
> +            if (dump_descriptors) {
> +                fprintf (out_file, "Found expected sequence %u, "
> +                     "type %u (%s) at block %u\n",
> +                     sequence, blocktype,
> +                     type_to_name(blocktype), blocknr);
> +            }
> +
>              dump_descriptor_block(out_file, source, buf, jsb,
>                            &blocknr, blocksize, maxlen,
>                            transaction);
>              continue;
> 
>          case JBD2_COMMIT_BLOCK:
> +            if (dump_descriptors) {
> +                fprintf (out_file, "Found expected sequence %u, "
> +                     "type %u (%s) at block %u",
> +                     sequence, blocktype,
> +                     type_to_name(blocktype), blocknr);
> +            }

Why did the "Found expected sequence..." message get moved?

> +
> +            if (dump_time)
> +                dump_commit_time(out_file, buf);
> +
> +            fprintf(out_file, "\n");
> +
>              cur_counts++;
>              transaction++;
>              blocknr++;
> @@ -543,6 +561,13 @@ static void dump_journal(char *cmdname, FILE *out_file,
>              continue;
> 
>          case JBD2_REVOKE_BLOCK:
> +            if (dump_descriptors) {
> +                fprintf (out_file, "Found expected sequence %u, "
> +                     "type %u (%s) at block %u\n",
> +                     sequence, blocktype,
> +                     type_to_name(blocktype), blocknr);
> +            }
> +
>              dump_revoke_block(out_file, buf, jsb,
>                        blocknr, blocksize,
>                        transaction);
> @@ -742,6 +767,26 @@ static void dump_descriptor_block(FILE *out_file,
>      *blockp = blocknr;
>  }
> 
> +static void dump_commit_time(FILE *out_file, char *buf)
> +{
> +    struct commit_header    *header;
> +    __be64        commit_sec;
> +    time_t        timestamp;
> +    struct tm    timeinfo;
> +
> +    header = (struct commit_header*)buf;
> +    commit_sec = be64_to_cpu(header->h_commit_sec);
> +
> +    timestamp = commit_sec;
> +    gmtime_r(&timestamp, &timeinfo);
> +    fprintf(out_file, ", commit at UTC: %04d-%02d-%02d %02d:%02d:%02d",
> +        timeinfo.tm_year + 1900,
> +        timeinfo.tm_mon + 1,
> +        timeinfo.tm_mday,
> +        timeinfo.tm_hour,
> +        timeinfo.tm_min,
> +        timeinfo.tm_sec);

Use ctime_r() to get a locale-appropriate local timestamp string to
print out.  Or asctime_r() if you really need UTC.

--D

> +}
> 
>  static void dump_revoke_block(FILE *out_file, char *buf,
>                    journal_superblock_t *jsb EXT2FS_ATTR((unused)),
> -- 
> 2.33.0
> 

  reply	other threads:[~2025-06-30 15:10 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-06-17 11:31 [PATCH] debugfs/logdump.c: Add parameter t to dump sequence commit timestamps zhanchengbin
2025-06-30 15:10 ` Darrick J. Wong [this message]
2025-07-01  3:21   ` zhanchengbin
2025-07-01  9:31   ` zhanchengbin

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=20250630151057.GA9987@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=hejie3@huawei.com \
    --cc=linux-ext4@vger.kernel.org \
    --cc=qiangxiaojun@huawei.com \
    --cc=tytso@mit.edu \
    --cc=zhanchengbin1@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.