[PATCH 08/26] xfs_logprint: refactor timestamp printing

Darrick J. Wong
2020-10-26T23:35:01Z

From: Darrick J. Wong <darrick.wong@oracle.com>

Introduce type-specific printing functions to xfs_logprint to print an
xfs_timestamp instead of open-coding the timestamp decoding. This is
needed to stay ahead of changes that we're going to make to
xfs_timestamp_t in the following patches.

Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
---
logprint/log_misc.c | 18 ++++++++++++++++--
logprint/log_print_all.c | 3 +--
logprint/logprint.h | 2 ++
3 files changed, 19 insertions(+), 4 deletions(-)

diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index af927cbfa792..a747cbd360af 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -435,6 +435,21 @@ xlog_print_trans_qoff(char **ptr, uint len)
}
} /* xlog_print_trans_qoff */

+void
+xlog_print_dinode_ts(
+ struct xfs_log_dinode *ldip,
+ bool compact)
+{
+ const char *fmt;
+
+ if (compact)
+ fmt = _("atime 0x%x mtime 0x%x ctime 0x%x\n");
+ else
+ fmt = _(" atime:%d mtime:%d ctime:%d\n");
+
+ printf(fmt, ldip->di_atime.t_sec, ldip->di_mtime.t_sec,
+ ldip->di_ctime.t_sec);
+}

static void
xlog_print_trans_inode_core(
@@ -446,8 +461,7 @@ xlog_print_trans_inode_core(
(int)ip->di_format);
printf(_("nlink %hd uid %d gid %d\n"),
ip->di_nlink, ip->di_uid, ip->di_gid);
- printf(_("atime 0x%x mtime 0x%x ctime 0x%x\n"),
- ip->di_atime.t_sec, ip->di_mtime.t_sec, ip->di_ctime.t_sec);
+ xlog_print_dinode_ts(ip, true);
printf(_("size 0x%llx nblocks 0x%llx extsize 0x%x nextents 0x%x\n"),
(unsigned long long)ip->di_size, (unsigned long long)ip->di_nblocks,
ip->di_extsize, ip->di_nextents);
diff --git a/logprint/log_print_all.c b/logprint/log_print_all.c
index 1924a0af70b6..fae531d3e030 100644
--- a/logprint/log_print_all.c
+++ b/logprint/log_print_all.c
@@ -249,8 +249,7 @@ xlog_recover_print_inode_core(
printf(_(" uid:%d gid:%d nlink:%d projid:0x%04x%04x\n"),
di->di_uid, di->di_gid, di->di_nlink,
di->di_projid_hi, di->di_projid_lo);
- printf(_(" atime:%d mtime:%d ctime:%d\n"),
- di->di_atime.t_sec, di->di_mtime.t_sec, di->di_ctime.t_sec);
+ xlog_print_dinode_ts(di, false);
printf(_(" flushiter:%d\n"), di->di_flushiter);
printf(_(" size:0x%llx nblks:0x%llx exsize:%d "
"nextents:%d anextents:%d\n"), (unsigned long long)
diff --git a/logprint/logprint.h b/logprint/logprint.h
index ee85bfe5f21f..6639e1cf5862 100644
--- a/logprint/logprint.h
+++ b/logprint/logprint.h
@@ -29,6 +29,8 @@ extern void print_xlog_record_line(void);
extern void print_xlog_op_line(void);
extern void print_stars(void);

+void xlog_print_dinode_ts(struct xfs_log_dinode *ldip, bool compact);
+
extern struct xfs_inode_log_format *
xfs_inode_item_format_convert(char *, uint, struct xfs_inode_log_format *);