* [PATCH 01/25] include: remove struct xfs_qoff_logitem
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 02/25] logprint: remove xlog_print_dir2_sf Christoph Hellwig
` (24 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Not used anywhere, so remove it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
include/xfs_trans.h | 6 ------
1 file changed, 6 deletions(-)
diff --git a/include/xfs_trans.h b/include/xfs_trans.h
index 4f4bfff350a4..d7d390411964 100644
--- a/include/xfs_trans.h
+++ b/include/xfs_trans.h
@@ -59,12 +59,6 @@ typedef struct xfs_buf_log_item {
#define XFS_BLI_INODE_ALLOC_BUF (1<<3)
#define XFS_BLI_ORDERED (1<<4)
-typedef struct xfs_qoff_logitem {
- xfs_log_item_t qql_item; /* common portion */
- struct xfs_qoff_logitem *qql_start_lip; /* qoff-start logitem, if any */
- xfs_qoff_logformat_t qql_format; /* logged structure */
-} xfs_qoff_logitem_t;
-
typedef struct xfs_trans {
unsigned int t_log_res; /* amt of log space resvd */
unsigned int t_log_count; /* count for perm log res */
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 02/25] logprint: remove xlog_print_dir2_sf
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
2025-11-28 6:29 ` [PATCH 01/25] include: remove struct xfs_qoff_logitem Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 03/25] logprint: re-indent printing helpers Christoph Hellwig
` (23 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
The code has been stubbed out since the initial creation of the
xfsprogs repository. Open code the single-line printf in the
data fork caller (attr forks can't contain directories) and remove
the dead code.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 40 +---------------------------------------
1 file changed, 1 insertion(+), 39 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 88679e9ee1dc..bde7e2a5f1db 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -504,42 +504,6 @@ xlog_print_trans_inode_core(
}
}
-static void
-xlog_print_dir2_sf(
- struct xlog *log,
- xfs_dir2_sf_hdr_t *sfp,
- int size)
-{
- __be64 pino; /* parent inode nr */
- xfs_ino_t ino;
- int count;
- int i;
- char namebuf[257];
- xfs_dir2_sf_entry_t *sfep;
-
- printf(_("SHORTFORM DIRECTORY size %d\n"),
- size);
- /* bail out for now */
-
- return;
-
- printf(_("SHORTFORM DIRECTORY size %d count %d\n"),
- size, sfp->count);
- memmove(&pino, &(sfp->parent), sizeof(pino));
- printf(_(".. ino 0x%llx\n"), (unsigned long long) be64_to_cpu(pino));
-
- count = sfp->count;
- sfep = xfs_dir2_sf_firstentry(sfp);
- for (i = 0; i < count; i++) {
- ino = libxfs_dir2_sf_get_ino(log->l_mp, sfp, sfep);
- memmove(namebuf, (sfep->name), sfep->namelen);
- namebuf[sfep->namelen] = '\0';
- printf(_("%s ino 0x%llx namelen %d\n"),
- namebuf, (unsigned long long)ino, sfep->namelen);
- sfep = libxfs_dir2_sf_nextentry(log->l_mp, sfp, sfep);
- }
-}
-
static int
xlog_print_trans_inode(
struct xlog *log,
@@ -643,7 +607,7 @@ xlog_print_trans_inode(
case XFS_ILOG_DDATA:
printf(_("LOCAL inode data\n"));
if (mode == S_IFDIR)
- xlog_print_dir2_sf(log, (xfs_dir2_sf_hdr_t *)*ptr, size);
+ printf(_("SHORTFORM DIRECTORY size %d\n"), size);
break;
default:
ASSERT((f->ilf_fields & XFS_ILOG_DFORK) == 0);
@@ -672,8 +636,6 @@ xlog_print_trans_inode(
break;
case XFS_ILOG_ADATA:
printf(_("LOCAL attr data\n"));
- if (mode == S_IFDIR)
- xlog_print_dir2_sf(log, (xfs_dir2_sf_hdr_t *)*ptr, size);
break;
default:
ASSERT((f->ilf_fields & XFS_ILOG_AFORK) == 0);
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 03/25] logprint: re-indent printing helpers
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
2025-11-28 6:29 ` [PATCH 01/25] include: remove struct xfs_qoff_logitem Christoph Hellwig
2025-11-28 6:29 ` [PATCH 02/25] logprint: remove xlog_print_dir2_sf Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 04/25] logprint: cleanup xlog_print_op_header Christoph Hellwig
` (22 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 33 ++++++++++++++++++---------------
1 file changed, 18 insertions(+), 15 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index bde7e2a5f1db..505b6f0fa150 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -29,33 +29,34 @@ static xlog_split_item_t *split_list = NULL;
void
print_xlog_op_line(void)
{
- printf("--------------------------------------"
- "--------------------------------------\n");
-} /* print_xlog_op_line */
+ printf("--------------------------------------"
+ "--------------------------------------\n");
+}
static void
print_xlog_xhdr_line(void)
{
- printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
- "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
-} /* print_xlog_xhdr_line */
+ printf("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
+ "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n");
+}
void
print_xlog_record_line(void)
{
- printf("======================================"
- "======================================\n");
-} /* print_xlog_record_line */
+ printf("======================================"
+ "======================================\n");
+}
void
print_stars(void)
{
- printf("***********************************"
- "***********************************\n");
-} /* print_stars */
+ printf("***********************************"
+ "***********************************\n");
+}
void
-print_hex_dump(char *ptr, int len) {
+print_hex_dump(char *ptr, int len)
+{
int i = 0;
for (i = 0; i < len; i++) {
@@ -73,7 +74,8 @@ print_hex_dump(char *ptr, int len) {
}
bool
-is_printable(char *ptr, int len) {
+is_printable(char *ptr, int len)
+{
int i = 0;
for (i = 0; i < len; i++)
@@ -83,7 +85,8 @@ is_printable(char *ptr, int len) {
}
void
-print_or_dump(char *ptr, int len) {
+print_or_dump(char *ptr, int len)
+{
if (is_printable(ptr, len))
printf("%.*s\n", len, ptr);
else
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 04/25] logprint: cleanup xlog_print_op_header
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (2 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 03/25] logprint: re-indent printing helpers Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 05/25] logprint: cleanup struct xlog_split_item handling Christoph Hellwig
` (21 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent and drop typedef use.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 75 +++++++++++++++++++++++----------------------
1 file changed, 38 insertions(+), 37 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 505b6f0fa150..5d44c2b1eb67 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -98,44 +98,45 @@ print_or_dump(char *ptr, int len)
* a log operation header.
*/
void
-xlog_print_op_header(xlog_op_header_t *op_head,
- int i,
- char **ptr)
+xlog_print_op_header(
+ struct xlog_op_header *ophdr,
+ int i,
+ char **ptr)
{
- xlog_op_header_t hbuf;
-
- /*
- * memmove because on 64/n32, partial reads can cause the op_head
- * pointer to come in pointing to an odd-numbered byte
- */
- memmove(&hbuf, op_head, sizeof(xlog_op_header_t));
- op_head = &hbuf;
- *ptr += sizeof(xlog_op_header_t);
- printf(_("Oper (%d): tid: %x len: %d clientid: %s "), i,
- be32_to_cpu(op_head->oh_tid),
- be32_to_cpu(op_head->oh_len),
- (op_head->oh_clientid == XFS_TRANSACTION ? "TRANS" :
- (op_head->oh_clientid == XFS_LOG ? "LOG" : "ERROR")));
- printf(_("flags: "));
- if (op_head->oh_flags) {
- if (op_head->oh_flags & XLOG_START_TRANS)
- printf("START ");
- if (op_head->oh_flags & XLOG_COMMIT_TRANS)
- printf("COMMIT ");
- if (op_head->oh_flags & XLOG_WAS_CONT_TRANS)
- printf("WAS_CONT ");
- if (op_head->oh_flags & XLOG_UNMOUNT_TRANS)
- printf("UNMOUNT ");
- if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
- printf("CONTINUE ");
- if (op_head->oh_flags & XLOG_END_TRANS)
- printf("END ");
- } else {
- printf(_("none"));
- }
- printf("\n");
-} /* xlog_print_op_header */
-
+ struct xlog_op_header hbuf;
+
+ /*
+ * memmove because on 64/n32, partial reads can cause the op_head
+ * pointer to come in pointing to an odd-numbered byte
+ */
+ memmove(&hbuf, ophdr, sizeof(hbuf));
+ ophdr = &hbuf;
+ *ptr += sizeof(hbuf);
+
+ printf(_("Oper (%d): tid: %x len: %d clientid: %s "), i,
+ be32_to_cpu(ophdr->oh_tid),
+ be32_to_cpu(ophdr->oh_len),
+ (ophdr->oh_clientid == XFS_TRANSACTION ? "TRANS" :
+ (ophdr->oh_clientid == XFS_LOG ? "LOG" : "ERROR")));
+ printf(_("flags: "));
+ if (ophdr->oh_flags) {
+ if (ophdr->oh_flags & XLOG_START_TRANS)
+ printf("START ");
+ if (ophdr->oh_flags & XLOG_COMMIT_TRANS)
+ printf("COMMIT ");
+ if (ophdr->oh_flags & XLOG_WAS_CONT_TRANS)
+ printf("WAS_CONT ");
+ if (ophdr->oh_flags & XLOG_UNMOUNT_TRANS)
+ printf("UNMOUNT ");
+ if (ophdr->oh_flags & XLOG_CONTINUE_TRANS)
+ printf("CONTINUE ");
+ if (ophdr->oh_flags & XLOG_END_TRANS)
+ printf("END ");
+ } else {
+ printf(_("none"));
+ }
+ printf("\n");
+}
static void
xlog_print_add_to_trans(xlog_tid_t tid,
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 05/25] logprint: cleanup struct xlog_split_item handling
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (3 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 04/25] logprint: cleanup xlog_print_op_header Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 06/25] logprint: cleanup xlog_print_trans_header Christoph Hellwig
` (20 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Drop the typedef and re-indent the helpers for it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 94 +++++++++++++++++++++++----------------------
1 file changed, 48 insertions(+), 46 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 5d44c2b1eb67..a4fba0333a60 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -17,14 +17,14 @@
static int logBBsize;
-typedef struct xlog_split_item {
+struct xlog_split_item {
struct xlog_split_item *si_next;
struct xlog_split_item *si_prev;
xlog_tid_t si_xtid;
int si_skip;
-} xlog_split_item_t;
+};
-static xlog_split_item_t *split_list = NULL;
+static struct xlog_split_item *split_list;
void
print_xlog_op_line(void)
@@ -139,55 +139,57 @@ xlog_print_op_header(
}
static void
-xlog_print_add_to_trans(xlog_tid_t tid,
- int skip)
+xlog_print_add_to_trans(
+ xlog_tid_t tid,
+ int skip)
{
- xlog_split_item_t *item;
-
- item = (xlog_split_item_t *)calloc(1, sizeof(xlog_split_item_t));
- item->si_xtid = tid;
- item->si_skip = skip;
- item->si_next = split_list;
- item->si_prev = NULL;
- if (split_list)
- split_list->si_prev = item;
- split_list = item;
-} /* xlog_print_add_to_trans */
-
+ struct xlog_split_item *item;
+
+ item = calloc(1, sizeof(*item));
+ item->si_xtid = tid;
+ item->si_skip = skip;
+ item->si_next = split_list;
+ if (split_list)
+ split_list->si_prev = item;
+ split_list = item;
+}
static int
-xlog_print_find_tid(xlog_tid_t tid, uint was_cont)
+xlog_print_find_tid(
+ xlog_tid_t tid,
+ uint was_cont)
{
- xlog_split_item_t *listp = split_list;
+ struct xlog_split_item *listp = split_list;
- if (!split_list) {
- if (was_cont != 0) /* Not first time we have used this tid */
- return 1;
- else
- return 0;
- }
- while (listp) {
- if (listp->si_xtid == tid)
- break;
- listp = listp->si_next;
- }
- if (!listp) {
- return 0;
- }
- if (--listp->si_skip == 0) {
- if (listp == split_list) { /* delete at head */
- split_list = listp->si_next;
- if (split_list)
- split_list->si_prev = NULL;
- } else {
- if (listp->si_next)
- listp->si_next->si_prev = listp->si_prev;
- listp->si_prev->si_next = listp->si_next;
+ if (!split_list) {
+ if (was_cont) /* Not first time we have used this tid */
+ return 1;
+ return 0;
}
- free(listp);
- }
- return 1;
-} /* xlog_print_find_tid */
+
+ while (listp) {
+ if (listp->si_xtid == tid)
+ break;
+ listp = listp->si_next;
+ }
+ if (!listp)
+ return 0;
+
+ if (--listp->si_skip == 0) {
+ if (listp == split_list) { /* delete at head */
+ split_list = listp->si_next;
+ if (split_list)
+ split_list->si_prev = NULL;
+ } else {
+ if (listp->si_next)
+ listp->si_next->si_prev = listp->si_prev;
+ listp->si_prev->si_next = listp->si_next;
+ }
+ free(listp);
+ }
+
+ return 1;
+}
static int
xlog_print_trans_header(char **ptr, int len)
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 06/25] logprint: cleanup xlog_print_trans_header
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (4 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 05/25] logprint: cleanup struct xlog_split_item handling Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 07/25] logprint: split per-type helpers out of xlog_print_trans_buffer Christoph Hellwig
` (19 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent and drop typedef use.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 49 ++++++++++++++++++++++-----------------------
1 file changed, 24 insertions(+), 25 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index a4fba0333a60..48611c746bea 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -192,36 +192,35 @@ xlog_print_find_tid(
}
static int
-xlog_print_trans_header(char **ptr, int len)
+xlog_print_trans_header(
+ char **ptr,
+ int len)
{
- xfs_trans_header_t *h;
- char *cptr = *ptr;
- uint32_t magic;
- char *magic_c = (char *)&magic;
-
- *ptr += len;
-
- magic = *(uint32_t *)cptr; /* XXX be32_to_cpu soon */
+ struct xfs_trans_header *h;
+ char *cptr = *ptr;
+ uint32_t magic;
+ char *magic_c = (char *)&magic;
- if (len >= 4) {
+ *ptr += len;
+ magic = *(uint32_t *)cptr; /* XXX be32_to_cpu soon */
+ if (len >= 4) {
#if __BYTE_ORDER == __LITTLE_ENDIAN
- printf("%c%c%c%c:",
- magic_c[3], magic_c[2], magic_c[1], magic_c[0]);
+ printf("%c%c%c%c:",
+ magic_c[3], magic_c[2], magic_c[1], magic_c[0]);
#else
- printf("%c%c%c%c:",
- magic_c[0], magic_c[1], magic_c[2], magic_c[3]);
+ printf("%c%c%c%c:",
+ magic_c[0], magic_c[1], magic_c[2], magic_c[3]);
#endif
- }
- if (len != sizeof(xfs_trans_header_t)) {
- printf(_(" Not enough data to decode further\n"));
- return 1;
- }
- h = (xfs_trans_header_t *)cptr;
- printf(_(" tid: %x num_items: %d\n"),
- h->th_tid, h->th_num_items);
- return 0;
-} /* xlog_print_trans_header */
-
+ }
+ if (len != sizeof(struct xfs_trans_header)) {
+ printf(_(" Not enough data to decode further\n"));
+ return 1;
+ }
+ h = (struct xfs_trans_header *)cptr;
+ printf(_(" tid: %x num_items: %d\n"),
+ h->th_tid, h->th_num_items);
+ return 0;
+}
static int
xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 07/25] logprint: split per-type helpers out of xlog_print_trans_buffer
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (5 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 06/25] logprint: cleanup xlog_print_trans_header Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 08/25] logprint: cleanup xlog_print_trans_buffer Christoph Hellwig
` (18 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Add a new helper for each special cased buffer type.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 360 +++++++++++++++++++++++++-------------------
1 file changed, 205 insertions(+), 155 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 48611c746bea..a47b955c4204 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -222,6 +222,205 @@ xlog_print_trans_header(
return 0;
}
+static void
+xlog_print_sb_buf(
+ struct xlog_op_header *ophdr,
+ void *ptr)
+{
+ struct xfs_dsb *dsb = ptr;
+
+ printf(_("SUPER BLOCK Buffer: "));
+ if (be32_to_cpu(ophdr->oh_len) < 4 * 8) {
+ printf(_("Out of space\n"));
+ return;
+ }
+
+ printf("\n");
+ printf(_("icount: %llu ifree: %llu "),
+ (unsigned long long)get_unaligned_be64(&dsb->sb_icount),
+ (unsigned long long)get_unaligned_be64(&dsb->sb_ifree));
+ printf(_("fdblks: %llu frext: %llu\n"),
+ (unsigned long long)get_unaligned_be64(&dsb->sb_fdblocks),
+ (unsigned long long)get_unaligned_be64(&dsb->sb_frextents));
+}
+
+static bool
+xlog_print_agi_buf(
+ struct xlog_op_header *ophdr,
+ void *ptr)
+{
+ int bucket, col, buckets;
+ struct xfs_agi agi;
+
+ /* memmove because ptr may not be 8-byte aligned */
+ memmove(&agi, ptr, sizeof(agi));
+
+ printf(_("AGI Buffer: XAGI "));
+
+ /*
+ * v4 filesystems only contain the fields before the uuid.
+ *
+ * Even v5 filesystems don't log any field beneath it. That means that
+ * the size that is logged is almost always going to be smaller than the
+ * structure itself. Hence we need to make sure that the buffer
+ * contains all the data we want to print rather than just check against
+ * the structure size.
+ */
+ if (be32_to_cpu(ophdr->oh_len) <
+ offsetof(xfs_agi_t, agi_uuid) -
+ XFS_AGI_UNLINKED_BUCKETS * sizeof(xfs_agino_t)) {
+ printf(_("out of space\n"));
+ return true;
+ }
+
+ printf("\n");
+ printf(_("ver: %d "),
+ be32_to_cpu(agi.agi_versionnum));
+ printf(_("seq#: %d len: %d cnt: %d root: %d\n"),
+ be32_to_cpu(agi.agi_seqno),
+ be32_to_cpu(agi.agi_length),
+ be32_to_cpu(agi.agi_count),
+ be32_to_cpu(agi.agi_root));
+ printf(_("level: %d free#: 0x%x newino: 0x%x\n"),
+ be32_to_cpu(agi.agi_level),
+ be32_to_cpu(agi.agi_freecount),
+ be32_to_cpu(agi.agi_newino));
+ if (be32_to_cpu(ophdr->oh_len) == 128) {
+ buckets = 17;
+ } else if (be32_to_cpu(ophdr->oh_len) == 256) {
+ buckets = 32 + 17;
+ } else {
+ if (ophdr->oh_flags & XLOG_CONTINUE_TRANS) {
+ printf(_("AGI unlinked data skipped "));
+ printf(_("(CONTINUE set, no space)\n"));
+ return false;
+ }
+ buckets = XFS_AGI_UNLINKED_BUCKETS;
+ }
+
+ for (bucket = 0; bucket < buckets;) {
+ printf(_("bucket[%d - %d]: "), bucket, bucket + 3);
+ for (col = 0; col < 4; col++, bucket++) {
+ if (bucket < buckets) {
+ printf("0x%x ",
+ be32_to_cpu(agi.agi_unlinked[bucket]));
+ }
+ }
+ printf("\n");
+ }
+
+ return true;
+}
+
+static void
+xlog_print_agf_buf(
+ struct xlog_op_header *ophdr,
+ void *ptr)
+{
+ struct xfs_agf agf;
+
+ /* memmove because ptr may not be 8-byte aligned */
+ memmove(&agf, ptr, sizeof(agf));
+
+ printf(_("AGF Buffer: XAGF "));
+
+ /*
+ * v4 filesystems only contain the fields before the uuid.
+ *
+ * Even v5 filesystems don't log any field beneath it. That means that
+ * the size that is logged is almost always going to be smaller than the
+ * structure itself. Hence we need to make sure that the buffer
+ * contains all the data we want to print rather than just check against
+ * the structure size.
+ */
+ if (be32_to_cpu(ophdr->oh_len) < offsetof(xfs_agf_t, agf_uuid)) {
+ printf(_("Out of space\n"));
+ return;
+ }
+
+ printf("\n");
+ printf(_("ver: %d seq#: %d len: %d \n"),
+ be32_to_cpu(agf.agf_versionnum),
+ be32_to_cpu(agf.agf_seqno),
+ be32_to_cpu(agf.agf_length));
+ printf(_("root BNO: %d CNT: %d\n"),
+ be32_to_cpu(agf.agf_bno_root),
+ be32_to_cpu(agf.agf_cnt_root));
+ printf(_("level BNO: %d CNT: %d\n"),
+ be32_to_cpu(agf.agf_bno_level),
+ be32_to_cpu(agf.agf_cnt_level));
+ printf(_("1st: %d last: %d cnt: %d freeblks: %d longest: %d\n"),
+ be32_to_cpu(agf.agf_flfirst),
+ be32_to_cpu(agf.agf_fllast),
+ be32_to_cpu(agf.agf_flcount),
+ be32_to_cpu(agf.agf_freeblks),
+ be32_to_cpu(agf.agf_longest));
+}
+
+static void
+xlog_print_dquot_buf(
+ struct xlog_op_header *ophdr,
+ void *ptr)
+{
+ struct xfs_disk_dquot dq;
+
+ /* memmove because ptr may not be 8-byte aligned */
+ memmove(&dq, ptr, sizeof(dq));
+
+ printf(_("DQUOT Buffer: DQ "));
+ if (be32_to_cpu(ophdr->oh_len) < sizeof(struct xfs_disk_dquot)) {
+ printf(_("Out of space\n"));
+ return;
+ }
+
+ printf("\n");
+ printf(_("ver: %d flags: 0x%x id: %d \n"),
+ dq.d_version,
+ dq.d_type,
+ be32_to_cpu(dq.d_id));
+ printf(_("blk limits hard: %llu soft: %llu\n"),
+ (unsigned long long)be64_to_cpu(dq.d_blk_hardlimit),
+ (unsigned long long)be64_to_cpu(dq.d_blk_softlimit));
+ printf(_("blk count: %llu warns: %d timer: %d\n"),
+ (unsigned long long) be64_to_cpu(dq.d_bcount),
+ (int) be16_to_cpu(dq.d_bwarns),
+ be32_to_cpu(dq.d_btimer));
+ printf(_("ino limits hard: %llu soft: %llu\n"),
+ (unsigned long long)be64_to_cpu(dq.d_ino_hardlimit),
+ (unsigned long long)be64_to_cpu(dq.d_ino_softlimit));
+ printf(_("ino count: %llu warns: %d timer: %d\n"),
+ (unsigned long long)be64_to_cpu(dq.d_icount),
+ (int) be16_to_cpu(dq.d_iwarns),
+ be32_to_cpu(dq.d_itimer));
+}
+
+static void
+xlog_print_buf_data(
+ struct xlog_op_header *ophdr,
+ void *ptr)
+{
+
+ uint *dp = ptr;
+ int nums = be32_to_cpu(ophdr->oh_len) >> 2;
+ int byte = 0;
+
+ printf(_("BUF DATA\n"));
+
+ if (!print_data)
+ return;
+
+ while (byte < nums) {
+ if ((byte % 8) == 0)
+ printf("%2x ", byte);
+ printf("%8x ", *dp);
+ dp++;
+ byte++;
+ if ((byte % 8) == 0)
+ printf("\n");
+ }
+ printf("\n");
+}
+
static int
xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
{
@@ -229,7 +428,6 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
xlog_op_header_t *head = NULL;
int num, skip;
int super_block = 0;
- int bucket, col, buckets;
int64_t blkno;
xfs_buf_log_format_t lbuf;
int size, blen, map_size, struct_size;
@@ -283,165 +481,17 @@ xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
head = (xlog_op_header_t *)*ptr;
xlog_print_op_header(head, *i, ptr);
if (super_block) {
- printf(_("SUPER BLOCK Buffer: "));
- if (be32_to_cpu(head->oh_len) < 4*8) {
- printf(_("Out of space\n"));
- } else {
- struct xfs_dsb *dsb = (struct xfs_dsb *) *ptr;
-
- printf("\n");
- printf(_("icount: %llu ifree: %llu "),
- (unsigned long long) get_unaligned_be64(&dsb->sb_icount),
- (unsigned long long) get_unaligned_be64(&dsb->sb_ifree));
- printf(_("fdblks: %llu frext: %llu\n"),
- (unsigned long long) get_unaligned_be64(&dsb->sb_fdblocks),
- (unsigned long long) get_unaligned_be64(&dsb->sb_frextents));
- }
+ xlog_print_sb_buf(head, *ptr);
super_block = 0;
} else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGI_MAGIC) {
- struct xfs_agi *agi, agi_s;
-
- /* memmove because *ptr may not be 8-byte aligned */
- agi = &agi_s;
- memmove(agi, *ptr, sizeof(struct xfs_agi));
- printf(_("AGI Buffer: XAGI "));
- /*
- * v4 filesystems only contain the fields before the uuid.
- * Even v5 filesystems don't log any field beneath it. That
- * means that the size that is logged is almost always going to
- * be smaller than the structure itself. Hence we need to make
- * sure that the buffer contains all the data we want to print
- * rather than just check against the structure size.
- */
- if (be32_to_cpu(head->oh_len) < offsetof(xfs_agi_t, agi_uuid) -
- XFS_AGI_UNLINKED_BUCKETS*sizeof(xfs_agino_t)) {
- printf(_("out of space\n"));
- } else {
- printf("\n");
- printf(_("ver: %d "),
- be32_to_cpu(agi->agi_versionnum));
- printf(_("seq#: %d len: %d cnt: %d root: %d\n"),
- be32_to_cpu(agi->agi_seqno),
- be32_to_cpu(agi->agi_length),
- be32_to_cpu(agi->agi_count),
- be32_to_cpu(agi->agi_root));
- printf(_("level: %d free#: 0x%x newino: 0x%x\n"),
- be32_to_cpu(agi->agi_level),
- be32_to_cpu(agi->agi_freecount),
- be32_to_cpu(agi->agi_newino));
- if (be32_to_cpu(head->oh_len) == 128) {
- buckets = 17;
- } else if (be32_to_cpu(head->oh_len) == 256) {
- buckets = 32 + 17;
- } else {
- if (head->oh_flags & XLOG_CONTINUE_TRANS) {
- printf(_("AGI unlinked data skipped "));
- printf(_("(CONTINUE set, no space)\n"));
- continue;
- }
- buckets = XFS_AGI_UNLINKED_BUCKETS;
- }
- for (bucket = 0; bucket < buckets;) {
- printf(_("bucket[%d - %d]: "), bucket, bucket+3);
- for (col = 0; col < 4; col++, bucket++) {
- if (bucket < buckets) {
- printf("0x%x ",
- be32_to_cpu(agi->agi_unlinked[bucket]));
- }
- }
- printf("\n");
- }
- }
+ if (!xlog_print_agi_buf(head, *ptr))
+ continue;
} else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGF_MAGIC) {
- struct xfs_agf *agf, agf_s;
-
- /* memmove because *ptr may not be 8-byte aligned */
- agf = &agf_s;
- memmove(agf, *ptr, sizeof(struct xfs_agf));
- printf(_("AGF Buffer: XAGF "));
- /*
- * v4 filesystems only contain the fields before the uuid.
- * Even v5 filesystems don't log any field beneath it. That
- * means that the size that is logged is almost always going to
- * be smaller than the structure itself. Hence we need to make
- * sure that the buffer contains all the data we want to print
- * rather than just check against the structure size.
- */
- if (be32_to_cpu(head->oh_len) < offsetof(xfs_agf_t, agf_uuid)) {
- printf(_("Out of space\n"));
- } else {
- printf("\n");
- printf(_("ver: %d seq#: %d len: %d \n"),
- be32_to_cpu(agf->agf_versionnum),
- be32_to_cpu(agf->agf_seqno),
- be32_to_cpu(agf->agf_length));
- printf(_("root BNO: %d CNT: %d\n"),
- be32_to_cpu(agf->agf_bno_root),
- be32_to_cpu(agf->agf_cnt_root));
- printf(_("level BNO: %d CNT: %d\n"),
- be32_to_cpu(agf->agf_bno_level),
- be32_to_cpu(agf->agf_cnt_level));
- printf(_("1st: %d last: %d cnt: %d "
- "freeblks: %d longest: %d\n"),
- be32_to_cpu(agf->agf_flfirst),
- be32_to_cpu(agf->agf_fllast),
- be32_to_cpu(agf->agf_flcount),
- be32_to_cpu(agf->agf_freeblks),
- be32_to_cpu(agf->agf_longest));
- }
+ xlog_print_agf_buf(head, *ptr);
} else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_DQUOT_MAGIC) {
- struct xfs_disk_dquot *dq, dq_s;
-
- /* memmove because *ptr may not be 8-byte aligned */
- dq = &dq_s;
- memmove(dq, *ptr, sizeof(struct xfs_disk_dquot));
- printf(_("DQUOT Buffer: DQ "));
- if (be32_to_cpu(head->oh_len) <
- sizeof(struct xfs_disk_dquot)) {
- printf(_("Out of space\n"));
- }
- else {
- printf("\n");
- printf(_("ver: %d flags: 0x%x id: %d \n"),
- dq->d_version, dq->d_type,
- be32_to_cpu(dq->d_id));
- printf(_("blk limits hard: %llu soft: %llu\n"),
- (unsigned long long)
- be64_to_cpu(dq->d_blk_hardlimit),
- (unsigned long long)
- be64_to_cpu(dq->d_blk_softlimit));
- printf(_("blk count: %llu warns: %d timer: %d\n"),
- (unsigned long long) be64_to_cpu(dq->d_bcount),
- (int) be16_to_cpu(dq->d_bwarns),
- be32_to_cpu(dq->d_btimer));
- printf(_("ino limits hard: %llu soft: %llu\n"),
- (unsigned long long)
- be64_to_cpu(dq->d_ino_hardlimit),
- (unsigned long long)
- be64_to_cpu(dq->d_ino_softlimit));
- printf(_("ino count: %llu warns: %d timer: %d\n"),
- (unsigned long long) be64_to_cpu(dq->d_icount),
- (int) be16_to_cpu(dq->d_iwarns),
- be32_to_cpu(dq->d_itimer));
- }
+ xlog_print_dquot_buf(head, *ptr);
} else {
- printf(_("BUF DATA\n"));
- if (print_data) {
- uint *dp = (uint *)*ptr;
- int nums = be32_to_cpu(head->oh_len) >> 2;
- int byte = 0;
-
- while (byte < nums) {
- if ((byte % 8) == 0)
- printf("%2x ", byte);
- printf("%8x ", *dp);
- dp++;
- byte++;
- if ((byte % 8) == 0)
- printf("\n");
- }
- printf("\n");
- }
+ xlog_print_buf_data(head, *ptr);
}
*ptr += be32_to_cpu(head->oh_len);
}
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 08/25] logprint: cleanup xlog_print_trans_buffer
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (6 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 07/25] logprint: split per-type helpers out of xlog_print_trans_buffer Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 09/25] logprint: cleanup xlog_print_trans_qoff Christoph Hellwig
` (17 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent, drop typedefs and invert a conditional to allow for an early
return.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 142 +++++++++++++++++++++++---------------------
1 file changed, 75 insertions(+), 67 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index a47b955c4204..533f57bdfc36 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -422,84 +422,92 @@ xlog_print_buf_data(
}
static int
-xlog_print_trans_buffer(char **ptr, int len, int *i, int num_ops)
+xlog_print_trans_buffer(
+ char **ptr,
+ int len,
+ int *i,
+ int num_ops)
{
- xfs_buf_log_format_t *f;
- xlog_op_header_t *head = NULL;
- int num, skip;
- int super_block = 0;
- int64_t blkno;
- xfs_buf_log_format_t lbuf;
- int size, blen, map_size, struct_size;
- unsigned short flags;
+ struct xfs_buf_log_format blf;
+ struct xlog_op_header *ophdr = NULL;
+ int num, skip;
+ int super_block = 0;
+ int64_t blkno;
+ int size, blen, map_size, struct_size;
+ unsigned short flags;
- /*
- * memmove to ensure 8-byte alignment for the long longs in
- * buf_log_format_t structure
- */
- memmove(&lbuf, *ptr, min(sizeof(xfs_buf_log_format_t), len));
- f = &lbuf;
- *ptr += len;
-
- ASSERT(f->blf_type == XFS_LI_BUF);
- printf("BUF: ");
- blkno = f->blf_blkno;
- size = f->blf_size;
- blen = f->blf_len;
- map_size = f->blf_map_size;
- flags = f->blf_flags;
+ /*
+ * memmove to ensure 8-byte alignment for the long longs in
+ * struct xfs_buf_log_format.
+ */
+ memmove(&blf, *ptr, min(sizeof(blf), len));
+ *ptr += len;
- /*
- * size of the format header is dependent on the size of the bitmap, not
- * the size of the in-memory structure. Hence the slightly obtuse
- * calculation.
- */
- struct_size = offsetof(struct xfs_buf_log_format, blf_map_size) + map_size;
+ ASSERT(blf.blf_type == XFS_LI_BUF);
+ printf("BUF: ");
+ blkno = blf.blf_blkno;
+ size = blf.blf_size;
+ blen = blf.blf_len;
+ map_size = blf.blf_map_size;
+ flags = blf.blf_flags;
- if (len >= struct_size) {
+ /*
+ * size of the format header is dependent on the size of the bitmap, not
+ * the size of the in-memory structure. Hence the slightly obtuse
+ * calculation.
+ */
+ struct_size = offsetof(struct xfs_buf_log_format, blf_map_size) +
+ map_size;
+ if (len < struct_size) {
+ ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
+ printf(_("#regs: %d Not printing rest of data\n"), blf.blf_size);
+ return size;
+ }
ASSERT((len - sizeof(struct_size)) % sizeof(int) == 0);
printf(_("#regs: %d start blkno: %lld (0x%llx) len: %d bmap size: %d flags: 0x%x\n"),
- size, (long long)blkno, (unsigned long long)blkno, blen, map_size, flags);
+ size,
+ (long long)blkno,
+ (unsigned long long)blkno,
+ blen,
+ map_size,
+ flags);
+
if (blkno == 0)
- super_block = 1;
- } else {
- ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
- printf(_("#regs: %d Not printing rest of data\n"), f->blf_size);
- return size;
- }
- num = size-1;
+ super_block = 1;
- /* Check if all regions in this log item were in the given LR ptr */
- if (*i+num > num_ops-1) {
- skip = num - (num_ops-1-*i);
- num = num_ops-1-*i;
- } else {
- skip = 0;
- }
- while (num-- > 0) {
- (*i)++;
- head = (xlog_op_header_t *)*ptr;
- xlog_print_op_header(head, *i, ptr);
- if (super_block) {
- xlog_print_sb_buf(head, *ptr);
- super_block = 0;
- } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGI_MAGIC) {
- if (!xlog_print_agi_buf(head, *ptr))
- continue;
- } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGF_MAGIC) {
- xlog_print_agf_buf(head, *ptr);
- } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_DQUOT_MAGIC) {
- xlog_print_dquot_buf(head, *ptr);
+ /* Check if all regions in this log item were in the given LR ptr */
+ num = size-1;
+ if (*i + num > num_ops - 1) {
+ skip = num - (num_ops - 1 - *i);
+ num = num_ops - 1 - *i;
} else {
- xlog_print_buf_data(head, *ptr);
+ skip = 0;
}
- *ptr += be32_to_cpu(head->oh_len);
- }
- if (head && head->oh_flags & XLOG_CONTINUE_TRANS)
- skip++;
- return skip;
-} /* xlog_print_trans_buffer */
+ while (num-- > 0) {
+ (*i)++;
+ ophdr = (struct xlog_op_header *)*ptr;
+ xlog_print_op_header(ophdr, *i, ptr);
+ if (super_block) {
+ xlog_print_sb_buf(ophdr, *ptr);
+ super_block = 0;
+ } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGI_MAGIC) {
+ if (!xlog_print_agi_buf(ophdr, *ptr))
+ continue;
+ } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_AGF_MAGIC) {
+ xlog_print_agf_buf(ophdr, *ptr);
+ } else if (be32_to_cpu(*(__be32 *)(*ptr)) == XFS_DQUOT_MAGIC) {
+ xlog_print_dquot_buf(ophdr, *ptr);
+ } else {
+ xlog_print_buf_data(ophdr, *ptr);
+ }
+ *ptr += be32_to_cpu(ophdr->oh_len);
+ }
+
+ if (ophdr && ophdr->oh_flags & XLOG_CONTINUE_TRANS)
+ skip++;
+ return skip;
+}
static int
xlog_print_trans_qoff(char **ptr, uint len)
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 09/25] logprint: cleanup xlog_print_trans_qoff
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (7 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 08/25] logprint: cleanup xlog_print_trans_buffer Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 10/25] logprint: cleanup xlog_print_trans_inode_core Christoph Hellwig
` (16 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent, drop typedefs and invert a conditional to allow for an early
return.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 533f57bdfc36..227a0c84644f 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -510,23 +510,22 @@ xlog_print_trans_buffer(
}
static int
-xlog_print_trans_qoff(char **ptr, uint len)
+xlog_print_trans_qoff(
+ char **ptr,
+ uint len)
{
- xfs_qoff_logformat_t *f;
- xfs_qoff_logformat_t lbuf;
+ struct xfs_qoff_logformat qlf;
- memmove(&lbuf, *ptr, min(sizeof(xfs_qoff_logformat_t), len));
- f = &lbuf;
- *ptr += len;
- if (len >= sizeof(xfs_qoff_logformat_t)) {
- printf(_("QOFF: #regs: %d flags: 0x%x\n"), f->qf_size, f->qf_flags);
+ memmove(&qlf, *ptr, min(sizeof(qlf), len));
+ *ptr += len;
+ if (len < sizeof(qlf)) {
+ printf(_("QOFF: Not enough data to decode further\n"));
+ return 1;
+ }
+ printf(_("QOFF: #regs: %d flags: 0x%x\n"),
+ qlf.qf_size, qlf.qf_flags);
return 0;
- } else {
- printf(_("QOFF: Not enough data to decode further\n"));
- return 1;
- }
-} /* xlog_print_trans_qoff */
-
+}
static void
xlog_print_trans_inode_core(
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 10/25] logprint: cleanup xlog_print_trans_inode_core
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (8 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 09/25] logprint: cleanup xlog_print_trans_qoff Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-12-01 18:23 ` Andrey Albershteyn
2025-11-28 6:29 ` [PATCH 11/25] logprint: move xfs_inode_item_format_convert up Christoph Hellwig
` (15 subsequent siblings)
25 siblings, 1 reply; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent and drop typedefs.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 69 +++++++++++++++++++++++++++------------------
1 file changed, 41 insertions(+), 28 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 227a0c84644f..a3aa4a323193 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -531,39 +531,52 @@ static void
xlog_print_trans_inode_core(
struct xfs_log_dinode *ip)
{
- xfs_extnum_t nextents;
-
- printf(_("INODE CORE\n"));
- printf(_("magic 0x%hx mode 0%ho version %d format %d\n"),
- ip->di_magic, ip->di_mode, (int)ip->di_version,
- (int)ip->di_format);
- printf(_("nlink %" PRIu32 " uid %d gid %d\n"),
- ip->di_nlink, ip->di_uid, ip->di_gid);
- printf(_("atime 0x%llx mtime 0x%llx ctime 0x%llx\n"),
+ xfs_extnum_t nextents;
+
+ printf(_("INODE CORE\n"));
+ printf(_("magic 0x%hx mode 0%ho version %d format %d\n"),
+ ip->di_magic,
+ ip->di_mode,
+ (int)ip->di_version,
+ (int)ip->di_format);
+ printf(_("nlink %" PRIu32 " uid %d gid %d\n"),
+ ip->di_nlink,
+ ip->di_uid,
+ ip->di_gid);
+ printf(_("atime 0x%llx mtime 0x%llx ctime 0x%llx\n"),
xlog_extract_dinode_ts(ip->di_atime),
xlog_extract_dinode_ts(ip->di_mtime),
xlog_extract_dinode_ts(ip->di_ctime));
- if (ip->di_flags2 & XFS_DIFLAG2_NREXT64)
- nextents = ip->di_big_nextents;
- else
- nextents = ip->di_nextents;
- printf(_("size 0x%llx nblocks 0x%llx extsize 0x%x nextents 0x%llx\n"),
- (unsigned long long)ip->di_size, (unsigned long long)ip->di_nblocks,
- ip->di_extsize, (unsigned long long)nextents);
+ if (ip->di_flags2 & XFS_DIFLAG2_NREXT64)
+ nextents = ip->di_big_nextents;
+ else
+ nextents = ip->di_nextents;
+ printf(_("size 0x%llx nblocks 0x%llx extsize 0x%x nextents 0x%llx\n"),
+ (unsigned long long)ip->di_size,
+ (unsigned long long)ip->di_nblocks,
+ ip->di_extsize,
+ (unsigned long long)nextents);
+
+ if (ip->di_flags2 & XFS_DIFLAG2_NREXT64)
+ nextents = ip->di_big_anextents;
+ else
+ nextents = ip->di_anextents;
+ printf(_("naextents 0x%llx forkoff %d dmevmask 0x%x dmstate 0x%hx\n"),
+ (unsigned long long)nextents,
+ (int)ip->di_forkoff,
+ ip->di_dmevmask,
+ ip->di_dmstate);
+ printf(_("flags 0x%x gen 0x%x\n"),
+ ip->di_flags,
+ ip->di_gen);
+
+ if (ip->di_version < 3)
+ return;
- if (ip->di_flags2 & XFS_DIFLAG2_NREXT64)
- nextents = ip->di_big_anextents;
- else
- nextents = ip->di_anextents;
- printf(_("naextents 0x%llx forkoff %d dmevmask 0x%x dmstate 0x%hx\n"),
- (unsigned long long)nextents, (int)ip->di_forkoff, ip->di_dmevmask, ip->di_dmstate);
- printf(_("flags 0x%x gen 0x%x\n"),
- ip->di_flags, ip->di_gen);
- if (ip->di_version == 3) {
- printf(_("flags2 0x%llx cowextsize 0x%x\n"),
- (unsigned long long)ip->di_flags2, ip->di_cowextsize);
- }
+ printf(_("flags2 0x%llx cowextsize 0x%x\n"),
+ (unsigned long long)ip->di_flags2,
+ ip->di_cowextsize);
}
static int
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* Re: [PATCH 10/25] logprint: cleanup xlog_print_trans_inode_core
2025-11-28 6:29 ` [PATCH 10/25] logprint: cleanup xlog_print_trans_inode_core Christoph Hellwig
@ 2025-12-01 18:23 ` Andrey Albershteyn
2025-12-02 7:27 ` Christoph Hellwig
0 siblings, 1 reply; 34+ messages in thread
From: Andrey Albershteyn @ 2025-12-01 18:23 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Andrey Albershteyn, linux-xfs
On 2025-11-28 07:29:47, Christoph Hellwig wrote:
> Re-indent and drop typedefs.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> logprint/log_misc.c | 69 +++++++++++++++++++++++++++------------------
> 1 file changed, 41 insertions(+), 28 deletions(-)
>
> diff --git a/logprint/log_misc.c b/logprint/log_misc.c
> index 227a0c84644f..a3aa4a323193 100644
> --- a/logprint/log_misc.c
> +++ b/logprint/log_misc.c
> @@ -531,39 +531,52 @@ static void
> xlog_print_trans_inode_core(
> struct xfs_log_dinode *ip)
> {
> - xfs_extnum_t nextents;
> -
> - printf(_("INODE CORE\n"));
> - printf(_("magic 0x%hx mode 0%ho version %d format %d\n"),
> - ip->di_magic, ip->di_mode, (int)ip->di_version,
> - (int)ip->di_format);
> - printf(_("nlink %" PRIu32 " uid %d gid %d\n"),
> - ip->di_nlink, ip->di_uid, ip->di_gid);
> - printf(_("atime 0x%llx mtime 0x%llx ctime 0x%llx\n"),
> + xfs_extnum_t nextents;
Still here? I don't see any other typedefs
> +
> + printf(_("INODE CORE\n"));
> + printf(_("magic 0x%hx mode 0%ho version %d format %d\n"),
> + ip->di_magic,
> + ip->di_mode,
> + (int)ip->di_version,
> + (int)ip->di_format);
> + printf(_("nlink %" PRIu32 " uid %d gid %d\n"),
> + ip->di_nlink,
> + ip->di_uid,
> + ip->di_gid);
> + printf(_("atime 0x%llx mtime 0x%llx ctime 0x%llx\n"),
> xlog_extract_dinode_ts(ip->di_atime),
> xlog_extract_dinode_ts(ip->di_mtime),
> xlog_extract_dinode_ts(ip->di_ctime));
>
> - if (ip->di_flags2 & XFS_DIFLAG2_NREXT64)
> - nextents = ip->di_big_nextents;
> - else
> - nextents = ip->di_nextents;
> - printf(_("size 0x%llx nblocks 0x%llx extsize 0x%x nextents 0x%llx\n"),
> - (unsigned long long)ip->di_size, (unsigned long long)ip->di_nblocks,
> - ip->di_extsize, (unsigned long long)nextents);
> + if (ip->di_flags2 & XFS_DIFLAG2_NREXT64)
> + nextents = ip->di_big_nextents;
> + else
> + nextents = ip->di_nextents;
> + printf(_("size 0x%llx nblocks 0x%llx extsize 0x%x nextents 0x%llx\n"),
> + (unsigned long long)ip->di_size,
> + (unsigned long long)ip->di_nblocks,
> + ip->di_extsize,
> + (unsigned long long)nextents);
> +
> + if (ip->di_flags2 & XFS_DIFLAG2_NREXT64)
> + nextents = ip->di_big_anextents;
> + else
> + nextents = ip->di_anextents;
> + printf(_("naextents 0x%llx forkoff %d dmevmask 0x%x dmstate 0x%hx\n"),
> + (unsigned long long)nextents,
> + (int)ip->di_forkoff,
> + ip->di_dmevmask,
> + ip->di_dmstate);
> + printf(_("flags 0x%x gen 0x%x\n"),
> + ip->di_flags,
> + ip->di_gen);
> +
> + if (ip->di_version < 3)
> + return;
>
> - if (ip->di_flags2 & XFS_DIFLAG2_NREXT64)
> - nextents = ip->di_big_anextents;
> - else
> - nextents = ip->di_anextents;
> - printf(_("naextents 0x%llx forkoff %d dmevmask 0x%x dmstate 0x%hx\n"),
> - (unsigned long long)nextents, (int)ip->di_forkoff, ip->di_dmevmask, ip->di_dmstate);
> - printf(_("flags 0x%x gen 0x%x\n"),
> - ip->di_flags, ip->di_gen);
> - if (ip->di_version == 3) {
> - printf(_("flags2 0x%llx cowextsize 0x%x\n"),
> - (unsigned long long)ip->di_flags2, ip->di_cowextsize);
> - }
> + printf(_("flags2 0x%llx cowextsize 0x%x\n"),
> + (unsigned long long)ip->di_flags2,
> + ip->di_cowextsize);
> }
>
> static int
> --
> 2.47.3
>
--
- Andrey
^ permalink raw reply [flat|nested] 34+ messages in thread
* [PATCH 11/25] logprint: move xfs_inode_item_format_convert up
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (9 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 10/25] logprint: cleanup xlog_print_trans_inode_core Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-12-01 18:32 ` Andrey Albershteyn
2025-11-28 6:29 ` [PATCH 12/25] logprint: cleanup xlog_print_trans_inode Christoph Hellwig
` (14 subsequent siblings)
25 siblings, 1 reply; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Toward the caller. And reindent it while we're at it.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 80 +++++++++++++++++++++++----------------------
1 file changed, 41 insertions(+), 39 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index a3aa4a323193..274d25e94bbd 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -527,6 +527,39 @@ xlog_print_trans_qoff(
return 0;
}
+/*
+ * if necessary, convert an xfs_inode_log_format struct from the old 32bit version
+ * (which can have different field alignments) to the native 64 bit version
+ */
+struct xfs_inode_log_format *
+xfs_inode_item_format_convert(
+ char *src_buf,
+ uint len,
+ struct xfs_inode_log_format *in_f)
+{
+ struct xfs_inode_log_format_32 *in_f32;
+
+ /* if we have native format then just return buf without copying data */
+ if (len == sizeof(struct xfs_inode_log_format))
+ return (struct xfs_inode_log_format *)src_buf;
+
+ in_f32 = (struct xfs_inode_log_format_32 *)src_buf;
+ in_f->ilf_type = in_f32->ilf_type;
+ in_f->ilf_size = in_f32->ilf_size;
+ in_f->ilf_fields = in_f32->ilf_fields;
+ in_f->ilf_asize = in_f32->ilf_asize;
+ in_f->ilf_dsize = in_f32->ilf_dsize;
+ in_f->ilf_ino = in_f32->ilf_ino;
+ /* copy biggest field of ilf_u */
+ memcpy(&in_f->ilf_u.__pad, &in_f32->ilf_u.__pad,
+ sizeof(in_f->ilf_u.__pad));
+ in_f->ilf_blkno = in_f32->ilf_blkno;
+ in_f->ilf_len = in_f32->ilf_len;
+ in_f->ilf_boffset = in_f32->ilf_boffset;
+
+ return in_f;
+}
+
static void
xlog_print_trans_inode_core(
struct xfs_log_dinode *ip)
@@ -588,14 +621,14 @@ xlog_print_trans_inode(
int num_ops,
int continued)
{
- struct xfs_log_dinode dino;
- struct xlog_op_header *op_head;
- struct xfs_inode_log_format dst_lbuf;
- struct xfs_inode_log_format src_lbuf;
- struct xfs_inode_log_format *f;
- int mode;
- int size;
- int skip_count;
+ struct xfs_log_dinode dino;
+ struct xlog_op_header *op_head;
+ struct xfs_inode_log_format dst_lbuf;
+ struct xfs_inode_log_format src_lbuf;
+ struct xfs_inode_log_format *f;
+ int mode;
+ int size;
+ int skip_count;
/*
* print inode type header region
@@ -1582,34 +1615,3 @@ end:
printf(_("%s: logical end of log\n"), progname);
print_xlog_record_line();
}
-
-/*
- * if necessary, convert an xfs_inode_log_format struct from the old 32bit version
- * (which can have different field alignments) to the native 64 bit version
- */
-struct xfs_inode_log_format *
-xfs_inode_item_format_convert(char *src_buf, uint len, struct xfs_inode_log_format *in_f)
-{
- struct xfs_inode_log_format_32 *in_f32;
-
- /* if we have native format then just return buf without copying data */
- if (len == sizeof(struct xfs_inode_log_format)) {
- return (struct xfs_inode_log_format *)src_buf;
- }
-
- in_f32 = (struct xfs_inode_log_format_32 *)src_buf;
- in_f->ilf_type = in_f32->ilf_type;
- in_f->ilf_size = in_f32->ilf_size;
- in_f->ilf_fields = in_f32->ilf_fields;
- in_f->ilf_asize = in_f32->ilf_asize;
- in_f->ilf_dsize = in_f32->ilf_dsize;
- in_f->ilf_ino = in_f32->ilf_ino;
- /* copy biggest field of ilf_u */
- memcpy(&in_f->ilf_u.__pad, &in_f32->ilf_u.__pad,
- sizeof(in_f->ilf_u.__pad));
- in_f->ilf_blkno = in_f32->ilf_blkno;
- in_f->ilf_len = in_f32->ilf_len;
- in_f->ilf_boffset = in_f32->ilf_boffset;
-
- return in_f;
-}
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* Re: [PATCH 11/25] logprint: move xfs_inode_item_format_convert up
2025-11-28 6:29 ` [PATCH 11/25] logprint: move xfs_inode_item_format_convert up Christoph Hellwig
@ 2025-12-01 18:32 ` Andrey Albershteyn
2025-12-02 7:28 ` Christoph Hellwig
0 siblings, 1 reply; 34+ messages in thread
From: Andrey Albershteyn @ 2025-12-01 18:32 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Andrey Albershteyn, linux-xfs
On 2025-11-28 07:29:48, Christoph Hellwig wrote:
> Toward the caller. And reindent it while we're at it.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> logprint/log_misc.c | 80 +++++++++++++++++++++++----------------------
> 1 file changed, 41 insertions(+), 39 deletions(-)
>
> diff --git a/logprint/log_misc.c b/logprint/log_misc.c
> index a3aa4a323193..274d25e94bbd 100644
> --- a/logprint/log_misc.c
> +++ b/logprint/log_misc.c
> @@ -527,6 +527,39 @@ xlog_print_trans_qoff(
> return 0;
> }
>
> +/*
> + * if necessary, convert an xfs_inode_log_format struct from the old 32bit version
> + * (which can have different field alignments) to the native 64 bit version
> + */
> +struct xfs_inode_log_format *
> +xfs_inode_item_format_convert(
> + char *src_buf,
> + uint len,
> + struct xfs_inode_log_format *in_f)
one more tab here will also align with in_f32 declaration
> +{
> + struct xfs_inode_log_format_32 *in_f32;
> +
> + /* if we have native format then just return buf without copying data */
> + if (len == sizeof(struct xfs_inode_log_format))
> + return (struct xfs_inode_log_format *)src_buf;
> +
> + in_f32 = (struct xfs_inode_log_format_32 *)src_buf;
> + in_f->ilf_type = in_f32->ilf_type;
> + in_f->ilf_size = in_f32->ilf_size;
> + in_f->ilf_fields = in_f32->ilf_fields;
> + in_f->ilf_asize = in_f32->ilf_asize;
> + in_f->ilf_dsize = in_f32->ilf_dsize;
> + in_f->ilf_ino = in_f32->ilf_ino;
> + /* copy biggest field of ilf_u */
> + memcpy(&in_f->ilf_u.__pad, &in_f32->ilf_u.__pad,
> + sizeof(in_f->ilf_u.__pad));
> + in_f->ilf_blkno = in_f32->ilf_blkno;
> + in_f->ilf_len = in_f32->ilf_len;
> + in_f->ilf_boffset = in_f32->ilf_boffset;
> +
> + return in_f;
> +}
> +
> static void
> xlog_print_trans_inode_core(
> struct xfs_log_dinode *ip)
> @@ -588,14 +621,14 @@ xlog_print_trans_inode(
> int num_ops,
> int continued)
> {
> - struct xfs_log_dinode dino;
> - struct xlog_op_header *op_head;
> - struct xfs_inode_log_format dst_lbuf;
> - struct xfs_inode_log_format src_lbuf;
> - struct xfs_inode_log_format *f;
> - int mode;
> - int size;
> - int skip_count;
> + struct xfs_log_dinode dino;
> + struct xlog_op_header *op_head;
> + struct xfs_inode_log_format dst_lbuf;
> + struct xfs_inode_log_format src_lbuf;
> + struct xfs_inode_log_format *f;
Maybe make it one column with arguments then? (seems like one more
tab will align everything)
> + int mode;
> + int size;
> + int skip_count;
>
> /*
> * print inode type header region
> @@ -1582,34 +1615,3 @@ end:
> printf(_("%s: logical end of log\n"), progname);
> print_xlog_record_line();
> }
> -
> -/*
> - * if necessary, convert an xfs_inode_log_format struct from the old 32bit version
> - * (which can have different field alignments) to the native 64 bit version
> - */
> -struct xfs_inode_log_format *
> -xfs_inode_item_format_convert(char *src_buf, uint len, struct xfs_inode_log_format *in_f)
> -{
> - struct xfs_inode_log_format_32 *in_f32;
> -
> - /* if we have native format then just return buf without copying data */
> - if (len == sizeof(struct xfs_inode_log_format)) {
> - return (struct xfs_inode_log_format *)src_buf;
> - }
> -
> - in_f32 = (struct xfs_inode_log_format_32 *)src_buf;
> - in_f->ilf_type = in_f32->ilf_type;
> - in_f->ilf_size = in_f32->ilf_size;
> - in_f->ilf_fields = in_f32->ilf_fields;
> - in_f->ilf_asize = in_f32->ilf_asize;
> - in_f->ilf_dsize = in_f32->ilf_dsize;
> - in_f->ilf_ino = in_f32->ilf_ino;
> - /* copy biggest field of ilf_u */
> - memcpy(&in_f->ilf_u.__pad, &in_f32->ilf_u.__pad,
> - sizeof(in_f->ilf_u.__pad));
> - in_f->ilf_blkno = in_f32->ilf_blkno;
> - in_f->ilf_len = in_f32->ilf_len;
> - in_f->ilf_boffset = in_f32->ilf_boffset;
> -
> - return in_f;
> -}
> --
> 2.47.3
>
>
--
- Andrey
^ permalink raw reply [flat|nested] 34+ messages in thread* Re: [PATCH 11/25] logprint: move xfs_inode_item_format_convert up
2025-12-01 18:32 ` Andrey Albershteyn
@ 2025-12-02 7:28 ` Christoph Hellwig
0 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-12-02 7:28 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: Christoph Hellwig, Andrey Albershteyn, linux-xfs
On Mon, Dec 01, 2025 at 07:32:18PM +0100, Andrey Albershteyn wrote:
> > +struct xfs_inode_log_format *
> > +xfs_inode_item_format_convert(
> > + char *src_buf,
> > + uint len,
> > + struct xfs_inode_log_format *in_f)
>
> one more tab here will also align with in_f32 declaration
That means we'll need to reindent the whole function. But yes, given
the long type names it might make sense here.
> > + struct xfs_log_dinode dino;
> > + struct xlog_op_header *op_head;
> > + struct xfs_inode_log_format dst_lbuf;
> > + struct xfs_inode_log_format src_lbuf;
> > + struct xfs_inode_log_format *f;
>
> Maybe make it one column with arguments then? (seems like one more
> tab will align everything)
Sure, same as above.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [PATCH 12/25] logprint: cleanup xlog_print_trans_inode
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (10 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 11/25] logprint: move xfs_inode_item_format_convert up Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 13/25] logprint: cleanup xlog_print_trans_dquot Christoph Hellwig
` (13 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent, drop typedefs and invert a conditional to allow for an early
return.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 241 ++++++++++++++++++++++----------------------
1 file changed, 121 insertions(+), 120 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 274d25e94bbd..8cdbb7d5fe42 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -626,140 +626,141 @@ xlog_print_trans_inode(
struct xfs_inode_log_format dst_lbuf;
struct xfs_inode_log_format src_lbuf;
struct xfs_inode_log_format *f;
- int mode;
- int size;
- int skip_count;
+ int mode;
+ int size;
+ int skip_count;
+
+ /*
+ * Print inode type header region.
+ *
+ * memmove to ensure 8-byte alignment for the long longs in
+ * struct xfs_inode_log_format structure.
+ *
+ * len can be smaller than struct xfs_inode_log_format if format data
+ * is split over operations.
+ */
+ memmove(&src_lbuf, *ptr, min(sizeof(src_lbuf), len));
+ (*i)++; /* bump index */
+ *ptr += len;
+ if (continued ||
+ (len != sizeof(struct xfs_inode_log_format_32) &&
+ len != sizeof(struct xfs_inode_log_format))) {
+ ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
+ f = (struct xfs_inode_log_format *)&src_lbuf;
+ printf(_("INODE: #regs: %d Not printing rest of data\n"),
+ f->ilf_size);
+ return f->ilf_size;
+ }
- /*
- * print inode type header region
- *
- * memmove to ensure 8-byte alignment for the long longs in
- * struct xfs_inode_log_format structure
- *
- * len can be smaller than struct xfs_inode_log_format
- * if format data is split over operations
- */
- memmove(&src_lbuf, *ptr, min(sizeof(src_lbuf), len));
- (*i)++; /* bump index */
- *ptr += len;
- if (!continued &&
- (len == sizeof(struct xfs_inode_log_format_32) ||
- len == sizeof(struct xfs_inode_log_format))) {
f = xfs_inode_item_format_convert((char*)&src_lbuf, len, &dst_lbuf);
printf(_("INODE: "));
printf(_("#regs: %d ino: 0x%llx flags: 0x%x dsize: %d\n"),
- f->ilf_size, (unsigned long long)f->ilf_ino,
- f->ilf_fields, f->ilf_dsize);
+ f->ilf_size,
+ (unsigned long long)f->ilf_ino,
+ f->ilf_fields,
+ f->ilf_dsize);
printf(_(" blkno: %lld len: %d boff: %d\n"),
- (long long)f->ilf_blkno, f->ilf_len, f->ilf_boffset);
- } else {
- ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
- f = (struct xfs_inode_log_format *)&src_lbuf;
- printf(_("INODE: #regs: %d Not printing rest of data\n"),
- f->ilf_size);
- return f->ilf_size;
- }
-
- skip_count = f->ilf_size-1;
-
- if (*i >= num_ops) /* end of LR */
- return skip_count;
-
- /* core inode comes 2nd */
- op_head = (xlog_op_header_t *)*ptr;
- xlog_print_op_header(op_head, *i, ptr);
-
- if (op_head->oh_flags & XLOG_CONTINUE_TRANS) {
- return skip_count;
- }
-
- memmove(&dino, *ptr, sizeof(dino));
- mode = dino.di_mode & S_IFMT;
- size = (int)dino.di_size;
- xlog_print_trans_inode_core(&dino);
- *ptr += xfs_log_dinode_size(log->l_mp);
- skip_count--;
-
- switch (f->ilf_fields & (XFS_ILOG_DEV | XFS_ILOG_UUID)) {
- case XFS_ILOG_DEV:
- printf(_("DEV inode: no extra region\n"));
- break;
- case XFS_ILOG_UUID:
- printf(_("UUID inode: no extra region\n"));
- break;
- }
-
- /* Only the inode core is logged */
- if (f->ilf_size == 2)
- return 0;
-
- ASSERT(f->ilf_size <= 4);
- ASSERT((f->ilf_size == 3) || (f->ilf_fields & XFS_ILOG_AFORK));
+ (long long)f->ilf_blkno,
+ f->ilf_len,
+ f->ilf_boffset);
+
+ skip_count = f->ilf_size - 1;
+ if (*i >= num_ops) /* end of LR */
+ return skip_count;
+
+ /* core inode comes 2nd */
+ op_head = (struct xlog_op_header *)*ptr;
+ xlog_print_op_header(op_head, *i, ptr);
+
+ if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
+ return skip_count;
+
+ memmove(&dino, *ptr, sizeof(dino));
+ mode = dino.di_mode & S_IFMT;
+ size = (int)dino.di_size;
+ xlog_print_trans_inode_core(&dino);
+ *ptr += xfs_log_dinode_size(log->l_mp);
+ skip_count--;
+
+ switch (f->ilf_fields & (XFS_ILOG_DEV | XFS_ILOG_UUID)) {
+ case XFS_ILOG_DEV:
+ printf(_("DEV inode: no extra region\n"));
+ break;
+ case XFS_ILOG_UUID:
+ printf(_("UUID inode: no extra region\n"));
+ break;
+ }
- /* does anything come next */
- op_head = (xlog_op_header_t *)*ptr;
+ /* Only the inode core is logged */
+ if (f->ilf_size == 2)
+ return 0;
- if (f->ilf_fields & XFS_ILOG_DFORK) {
- if (*i == num_ops-1)
- return skip_count;
- (*i)++;
- xlog_print_op_header(op_head, *i, ptr);
+ ASSERT(f->ilf_size <= 4);
+ ASSERT((f->ilf_size == 3) || (f->ilf_fields & XFS_ILOG_AFORK));
- switch (f->ilf_fields & XFS_ILOG_DFORK) {
- case XFS_ILOG_DEXT:
- printf(_("EXTENTS inode data\n"));
- break;
- case XFS_ILOG_DBROOT:
- printf(_("BTREE inode data\n"));
- break;
- case XFS_ILOG_DDATA:
- printf(_("LOCAL inode data\n"));
- if (mode == S_IFDIR)
- printf(_("SHORTFORM DIRECTORY size %d\n"), size);
- break;
- default:
- ASSERT((f->ilf_fields & XFS_ILOG_DFORK) == 0);
- break;
- }
+ /* does anything come next */
+ op_head = (struct xlog_op_header *)*ptr;
- *ptr += be32_to_cpu(op_head->oh_len);
- if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
- return skip_count;
- op_head = (xlog_op_header_t *)*ptr;
- skip_count--;
- }
+ if (f->ilf_fields & XFS_ILOG_DFORK) {
+ if (*i == num_ops-1)
+ return skip_count;
+ (*i)++;
+ xlog_print_op_header(op_head, *i, ptr);
- if (f->ilf_fields & XFS_ILOG_AFORK) {
- if (*i == num_ops-1)
- return skip_count;
- (*i)++;
- xlog_print_op_header(op_head, *i, ptr);
+ switch (f->ilf_fields & XFS_ILOG_DFORK) {
+ case XFS_ILOG_DEXT:
+ printf(_("EXTENTS inode data\n"));
+ break;
+ case XFS_ILOG_DBROOT:
+ printf(_("BTREE inode data\n"));
+ break;
+ case XFS_ILOG_DDATA:
+ printf(_("LOCAL inode data\n"));
+ if (mode == S_IFDIR)
+ printf(_("SHORTFORM DIRECTORY size %d\n"),
+ size);
+ break;
+ default:
+ ASSERT((f->ilf_fields & XFS_ILOG_DFORK) == 0);
+ break;
+ }
- switch (f->ilf_fields & XFS_ILOG_AFORK) {
- case XFS_ILOG_AEXT:
- printf(_("EXTENTS attr data\n"));
- break;
- case XFS_ILOG_ABROOT:
- printf(_("BTREE attr data\n"));
- break;
- case XFS_ILOG_ADATA:
- printf(_("LOCAL attr data\n"));
- break;
- default:
- ASSERT((f->ilf_fields & XFS_ILOG_AFORK) == 0);
- break;
- }
- *ptr += be32_to_cpu(op_head->oh_len);
- if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
- return skip_count;
- skip_count--;
- }
+ *ptr += be32_to_cpu(op_head->oh_len);
+ if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
+ return skip_count;
+ op_head = (struct xlog_op_header *)*ptr;
+ skip_count--;
+ }
- ASSERT(skip_count == 0);
+ if (f->ilf_fields & XFS_ILOG_AFORK) {
+ if (*i == num_ops-1)
+ return skip_count;
+ (*i)++;
+ xlog_print_op_header(op_head, *i, ptr);
- return 0;
-} /* xlog_print_trans_inode */
+ switch (f->ilf_fields & XFS_ILOG_AFORK) {
+ case XFS_ILOG_AEXT:
+ printf(_("EXTENTS attr data\n"));
+ break;
+ case XFS_ILOG_ABROOT:
+ printf(_("BTREE attr data\n"));
+ break;
+ case XFS_ILOG_ADATA:
+ printf(_("LOCAL attr data\n"));
+ break;
+ default:
+ ASSERT((f->ilf_fields & XFS_ILOG_AFORK) == 0);
+ break;
+ }
+ *ptr += be32_to_cpu(op_head->oh_len);
+ if (op_head->oh_flags & XLOG_CONTINUE_TRANS)
+ return skip_count;
+ skip_count--;
+ }
+ ASSERT(skip_count == 0);
+ return 0;
+}
static int
xlog_print_trans_dquot(char **ptr, int len, int *i, int num_ops)
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 13/25] logprint: cleanup xlog_print_trans_dquot
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (11 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 12/25] logprint: cleanup xlog_print_trans_inode Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 14/25] logprint: re-indent print_lseek / print_lsn Christoph Hellwig
` (12 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent, drop typedefs and invert a conditional to allow for an early
return.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 103 ++++++++++++++++++++++++--------------------
1 file changed, 56 insertions(+), 47 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 8cdbb7d5fe42..73dd7ab46938 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -763,59 +763,68 @@ xlog_print_trans_inode(
}
static int
-xlog_print_trans_dquot(char **ptr, int len, int *i, int num_ops)
+xlog_print_trans_dquot(
+ char **ptr,
+ int len,
+ int *i,
+ int num_ops)
{
- xfs_dq_logformat_t *f;
- xfs_dq_logformat_t lbuf = {0};
- struct xfs_disk_dquot ddq;
- xlog_op_header_t *head = NULL;
- int num, skip;
+ struct xfs_dq_logformat *f;
+ struct xfs_dq_logformat lbuf = {0};
+ struct xfs_disk_dquot ddq;
+ struct xlog_op_header *head = NULL;
+ int num, skip;
- /*
- * print dquot header region
- *
- * memmove to ensure 8-byte alignment for the long longs in
- * xfs_dq_logformat_t structure
- */
- memmove(&lbuf, *ptr, min(sizeof(xfs_dq_logformat_t), len));
- f = &lbuf;
- (*i)++; /* bump index */
- *ptr += len;
+ /*
+ * Print dquot header region.
+ *
+ * memmove to ensure 8-byte alignment for the long longs in
+ * the xfs_dq_logformat structure.
+ */
+ memmove(&lbuf, *ptr, min(sizeof(struct xfs_dq_logformat), len));
+ f = &lbuf;
+ (*i)++; /* bump index */
+ *ptr += len;
- if (len == sizeof(xfs_dq_logformat_t)) {
- printf(_("#regs: %d id: 0x%x"), f->qlf_size, f->qlf_id);
- printf(_(" blkno: %lld len: %d boff: %d\n"),
- (long long)f->qlf_blkno, f->qlf_len, f->qlf_boffset);
- } else {
- ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
- printf(_("DQUOT: #regs: %d Not printing rest of data\n"),
- f->qlf_size);
- return f->qlf_size;
- }
- num = f->qlf_size-1;
+ if (len != sizeof(struct xfs_dq_logformat)) {
+ ASSERT(len >= 4); /* must have at least 4 bytes if != 0 */
+ printf(_("DQUOT: #regs: %d Not printing rest of data\n"),
+ f->qlf_size);
+ return f->qlf_size;
+ }
- /* Check if all regions in this log item were in the given LR ptr */
- if (*i+num > num_ops-1) {
- skip = num - (num_ops-1-*i);
- num = num_ops-1-*i;
- } else {
- skip = 0;
- }
+ printf(_("#regs: %d id: 0x%x"),
+ f->qlf_size,
+ f->qlf_id);
+ printf(_(" blkno: %lld len: %d boff: %d\n"),
+ (long long)f->qlf_blkno,
+ f->qlf_len,
+ f->qlf_boffset);
- while (num-- > 0) {
- head = (xlog_op_header_t *)*ptr;
- xlog_print_op_header(head, *i, ptr);
- ASSERT(be32_to_cpu(head->oh_len) == sizeof(struct xfs_disk_dquot));
- memmove(&ddq, *ptr, sizeof(struct xfs_disk_dquot));
- printf(_("DQUOT: magic 0x%hx flags 0%ho\n"),
- be16_to_cpu(ddq.d_magic), ddq.d_type);
- *ptr += be32_to_cpu(head->oh_len);
- }
- if (head && head->oh_flags & XLOG_CONTINUE_TRANS)
- skip++;
- return skip;
-} /* xlog_print_trans_dquot */
+ /* Check if all regions in this log item were in the given LR ptr */
+ num = f->qlf_size - 1;
+ if (*i + num > num_ops - 1) {
+ skip = num - (num_ops - 1 - *i);
+ num = num_ops - 1 - *i;
+ } else {
+ skip = 0;
+ }
+ while (num-- > 0) {
+ head = (struct xlog_op_header *)*ptr;
+ xlog_print_op_header(head, *i, ptr);
+ ASSERT(be32_to_cpu(head->oh_len) ==
+ sizeof(struct xfs_disk_dquot));
+ memmove(&ddq, *ptr, sizeof(struct xfs_disk_dquot));
+ printf(_("DQUOT: magic 0x%hx flags 0%ho\n"),
+ be16_to_cpu(ddq.d_magic),
+ ddq.d_type);
+ *ptr += be32_to_cpu(head->oh_len);
+ }
+ if (head && (head->oh_flags & XLOG_CONTINUE_TRANS))
+ skip++;
+ return skip;
+}
STATIC int
xlog_print_trans_icreate(
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 14/25] logprint: re-indent print_lseek / print_lsn
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (12 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 13/25] logprint: cleanup xlog_print_trans_dquot Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 15/25] logprint: factor out a xlog_print_process_region helper Christoph Hellwig
` (11 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 73dd7ab46938..c4486e5f6a14 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -872,10 +872,14 @@ xlog_extract_dinode_ts(
}
void
-xlog_print_lseek(struct xlog *log, int fd, xfs_daddr_t blkno, int whence)
+xlog_print_lseek(
+ struct xlog *log,
+ int fd,
+ xfs_daddr_t blkno,
+ int whence)
{
#define BBTOOFF64(bbs) (((xfs_off_t)(bbs)) << BBSHIFT)
- xfs_off_t offset;
+ xfs_off_t offset;
if (whence == SEEK_SET)
offset = BBTOOFF64(blkno+log->l_logBBstart);
@@ -886,15 +890,16 @@ xlog_print_lseek(struct xlog *log, int fd, xfs_daddr_t blkno, int whence)
progname, (long long)offset, strerror(errno));
exit(1);
}
-} /* xlog_print_lseek */
-
+}
static void
-print_lsn(char *string,
- __be64 *lsn)
+print_lsn(
+ char *string,
+ __be64 *lsn)
{
- printf("%s: %u,%u", string,
- CYCLE_LSN(be64_to_cpu(*lsn)), BLOCK_LSN(be64_to_cpu(*lsn)));
+ printf("%s: %u,%u", string,
+ CYCLE_LSN(be64_to_cpu(*lsn)),
+ BLOCK_LSN(be64_to_cpu(*lsn)));
}
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 15/25] logprint: factor out a xlog_print_process_region helper
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (13 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 14/25] logprint: re-indent print_lseek / print_lsn Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 16/25] logprint: factor out a xlog_print_op helper Christoph Hellwig
` (10 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Start splitting up xlog_print_record by moving the switch on the item
types inside the inner loop into a self-contained helper.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 187 +++++++++++++++++---------------------------
1 file changed, 70 insertions(+), 117 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index c4486e5f6a14..f10dc57a1edb 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -902,6 +902,69 @@ print_lsn(
BLOCK_LSN(be64_to_cpu(*lsn)));
}
+static int
+xlog_print_region(
+ struct xlog *log,
+ char **ptr,
+ struct xlog_op_header *ophdr,
+ int *i,
+ int num_ops,
+ bool continued)
+{
+ uint32_t len = be32_to_cpu(ophdr->oh_len);
+
+ if (*(uint *)*ptr == XFS_TRANS_HEADER_MAGIC)
+ return xlog_print_trans_header(ptr, len);
+
+ switch (*(unsigned short *)*ptr) {
+ case XFS_LI_BUF:
+ return xlog_print_trans_buffer(ptr, len, i, num_ops);
+ case XFS_LI_ICREATE:
+ return xlog_print_trans_icreate(ptr, len, i, num_ops);
+ case XFS_LI_INODE:
+ return xlog_print_trans_inode(log, ptr, len, i, num_ops,
+ continued);
+ case XFS_LI_DQUOT:
+ return xlog_print_trans_dquot(ptr, len, i, num_ops);
+ case XFS_LI_EFI_RT:
+ case XFS_LI_EFI:
+ return xlog_print_trans_efi(ptr, len, continued);
+ case XFS_LI_EFD_RT:
+ case XFS_LI_EFD:
+ return xlog_print_trans_efd(ptr, len);
+ case XFS_LI_ATTRI:
+ return xlog_print_trans_attri(ptr, len, i);
+ case XFS_LI_ATTRD:
+ return xlog_print_trans_attrd(ptr, len);
+ case XFS_LI_RUI_RT:
+ case XFS_LI_RUI:
+ return xlog_print_trans_rui(ptr, len, continued);
+ case XFS_LI_RUD_RT:
+ case XFS_LI_RUD:
+ return xlog_print_trans_rud(ptr, len);
+ case XFS_LI_CUI_RT:
+ case XFS_LI_CUI:
+ return xlog_print_trans_cui(ptr, len, continued);
+ case XFS_LI_CUD_RT:
+ case XFS_LI_CUD:
+ return xlog_print_trans_cud(ptr, len);
+ case XFS_LI_BUI:
+ return xlog_print_trans_bui(ptr, len, continued);
+ case XFS_LI_BUD:
+ return xlog_print_trans_bud(ptr, len);
+ case XFS_LI_XMI:
+ return xlog_print_trans_xmi(ptr, len, continued);
+ case XFS_LI_XMD:
+ return xlog_print_trans_xmd(ptr, len);
+ case XFS_LI_QUOTAOFF:
+ return xlog_print_trans_qoff(ptr, len);
+ case XLOG_UNMOUNT_TYPE:
+ printf(_("Unmount filesystem\n"));
+ return 0;
+ default:
+ return -1;
+ }
+}
static int
xlog_print_record(
@@ -1046,118 +1109,9 @@ xlog_print_record(
}
if (be32_to_cpu(op_head->oh_len) != 0) {
- if (*(uint *)ptr == XFS_TRANS_HEADER_MAGIC) {
- skip = xlog_print_trans_header(&ptr,
- be32_to_cpu(op_head->oh_len));
- } else {
- switch (*(unsigned short *)ptr) {
- case XFS_LI_BUF: {
- skip = xlog_print_trans_buffer(&ptr,
- be32_to_cpu(op_head->oh_len),
- &i, num_ops);
- break;
- }
- case XFS_LI_ICREATE: {
- skip = xlog_print_trans_icreate(&ptr,
- be32_to_cpu(op_head->oh_len),
- &i, num_ops);
- break;
- }
- case XFS_LI_INODE: {
- skip = xlog_print_trans_inode(log, &ptr,
- be32_to_cpu(op_head->oh_len),
- &i, num_ops, continued);
- break;
- }
- case XFS_LI_DQUOT: {
- skip = xlog_print_trans_dquot(&ptr,
- be32_to_cpu(op_head->oh_len),
- &i, num_ops);
- break;
- }
- case XFS_LI_EFI_RT:
- case XFS_LI_EFI: {
- skip = xlog_print_trans_efi(&ptr,
- be32_to_cpu(op_head->oh_len),
- continued);
- break;
- }
- case XFS_LI_EFD_RT:
- case XFS_LI_EFD: {
- skip = xlog_print_trans_efd(&ptr,
- be32_to_cpu(op_head->oh_len));
- break;
- }
- case XFS_LI_ATTRI: {
- skip = xlog_print_trans_attri(&ptr,
- be32_to_cpu(op_head->oh_len),
- &i);
- break;
- }
- case XFS_LI_ATTRD: {
- skip = xlog_print_trans_attrd(&ptr,
- be32_to_cpu(op_head->oh_len));
- break;
- }
- case XFS_LI_RUI_RT:
- case XFS_LI_RUI: {
- skip = xlog_print_trans_rui(&ptr,
- be32_to_cpu(op_head->oh_len),
- continued);
- break;
- }
- case XFS_LI_RUD_RT:
- case XFS_LI_RUD: {
- skip = xlog_print_trans_rud(&ptr,
- be32_to_cpu(op_head->oh_len));
- break;
- }
- case XFS_LI_CUI_RT:
- case XFS_LI_CUI: {
- skip = xlog_print_trans_cui(&ptr,
- be32_to_cpu(op_head->oh_len),
- continued);
- break;
- }
- case XFS_LI_CUD_RT:
- case XFS_LI_CUD: {
- skip = xlog_print_trans_cud(&ptr,
- be32_to_cpu(op_head->oh_len));
- break;
- }
- case XFS_LI_BUI: {
- skip = xlog_print_trans_bui(&ptr,
- be32_to_cpu(op_head->oh_len),
- continued);
- break;
- }
- case XFS_LI_BUD: {
- skip = xlog_print_trans_bud(&ptr,
- be32_to_cpu(op_head->oh_len));
- break;
- }
- case XFS_LI_XMI: {
- skip = xlog_print_trans_xmi(&ptr,
- be32_to_cpu(op_head->oh_len),
- continued);
- break;
- }
- case XFS_LI_XMD: {
- skip = xlog_print_trans_xmd(&ptr,
- be32_to_cpu(op_head->oh_len));
- break;
- }
- case XFS_LI_QUOTAOFF: {
- skip = xlog_print_trans_qoff(&ptr,
- be32_to_cpu(op_head->oh_len));
- break;
- }
- case XLOG_UNMOUNT_TYPE: {
- printf(_("Unmount filesystem\n"));
- skip = 0;
- break;
- }
- default: {
+ skip = xlog_print_region(log, &ptr, op_head, &i, num_ops,
+ continued);
+ if (skip == -1) {
if (bad_hdr_warn && !lost_context) {
fprintf(stderr,
_("%s: unknown log operation type (%x)\n"),
@@ -1173,11 +1127,10 @@ xlog_print_record(
skip = 0;
ptr += be32_to_cpu(op_head->oh_len);
lost_context = 0;
- }
- } /* switch */
- } /* else */
- if (skip != 0)
- xlog_print_add_to_trans(be32_to_cpu(op_head->oh_tid), skip);
+ }
+
+ if (skip)
+ xlog_print_add_to_trans(be32_to_cpu(op_head->oh_tid), skip);
}
}
printf("\n");
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 16/25] logprint: factor out a xlog_print_op helper
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (14 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 15/25] logprint: factor out a xlog_print_process_region helper Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-12-01 18:44 ` Andrey Albershteyn
2025-11-28 6:29 ` [PATCH 17/25] logprint: factor out a xlog_unpack_rec_header Christoph Hellwig
` (9 subsequent siblings)
25 siblings, 1 reply; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Split the inner printing loop from xlog_print_record into a separate
helper.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 134 ++++++++++++++++++++++++--------------------
1 file changed, 74 insertions(+), 60 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index f10dc57a1edb..873ec6673768 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -966,6 +966,72 @@ xlog_print_region(
}
}
+static bool
+xlog_print_op(
+ struct xlog *log,
+ char **ptr,
+ int *i,
+ int num_ops,
+ bool bad_hdr_warn,
+ bool *lost_context)
+{
+ struct xlog_op_header *ophdr = (struct xlog_op_header *)*ptr;
+ bool continued;
+ int skip, n;
+
+ print_xlog_op_line();
+ xlog_print_op_header(ophdr, *i, ptr);
+
+ continued = (ophdr->oh_flags & XLOG_WAS_CONT_TRANS) ||
+ (ophdr->oh_flags & XLOG_CONTINUE_TRANS);
+ if (continued && be32_to_cpu(ophdr->oh_len) == 0)
+ return true;
+
+ if (print_no_data) {
+ for (n = 0; n < be32_to_cpu(ophdr->oh_len); n++) {
+ printf("0x%02x ", (unsigned int)**ptr);
+ if (n % 16 == 15)
+ printf("\n");
+ ptr++;
+ }
+ printf("\n");
+ return true;
+ }
+
+ /* print transaction data */
+ if (xlog_print_find_tid(be32_to_cpu(ophdr->oh_tid),
+ ophdr->oh_flags & XLOG_WAS_CONT_TRANS)) {
+ printf(_("Left over region from split log item\n"));
+ /* Skip this leftover bit */
+ (*ptr) += be32_to_cpu(ophdr->oh_len);
+ /* We've lost context; don't complain if next one looks bad too */
+ *lost_context = true;
+ return true;
+ }
+
+ if (!ophdr->oh_len)
+ return true;
+
+ skip = xlog_print_region(log, ptr, ophdr, i, num_ops, continued);
+ if (skip == -1) {
+ if (bad_hdr_warn && !*lost_context) {
+ fprintf(stderr,
+ _("%s: unknown log operation type (%x)\n"),
+ progname, *(unsigned short *)*ptr);
+ if (print_exit)
+ return false;
+ } else {
+ printf(
+ _("Left over region from split log item\n"));
+ }
+ (*ptr) += be32_to_cpu(ophdr->oh_len);
+ *lost_context = false;
+ } else if (skip) {
+ xlog_print_add_to_trans(be32_to_cpu(ophdr->oh_tid), skip);
+ }
+ return true;
+}
+
static int
xlog_print_record(
struct xlog *log,
@@ -979,8 +1045,9 @@ xlog_print_record(
int bad_hdr_warn)
{
char *buf, *ptr;
- int read_len, skip, lost_context = 0;
- int ret, n, i, j, k;
+ int read_len;
+ bool lost_context = false;
+ int ret, i, j, k;
if (print_no_print)
return NO_ERROR;
@@ -1073,64 +1140,11 @@ xlog_print_record(
}
ptr = buf;
- for (i=0; i<num_ops; i++) {
- int continued;
-
- xlog_op_header_t *op_head = (xlog_op_header_t *)ptr;
-
- print_xlog_op_line();
- xlog_print_op_header(op_head, i, &ptr);
- continued = ((op_head->oh_flags & XLOG_WAS_CONT_TRANS) ||
- (op_head->oh_flags & XLOG_CONTINUE_TRANS));
-
- if (continued && be32_to_cpu(op_head->oh_len) == 0)
- continue;
-
- if (print_no_data) {
- for (n = 0; n < be32_to_cpu(op_head->oh_len); n++) {
- printf("0x%02x ", (unsigned int)*ptr);
- if (n % 16 == 15)
- printf("\n");
- ptr++;
- }
- printf("\n");
- continue;
- }
-
- /* print transaction data */
- if (xlog_print_find_tid(be32_to_cpu(op_head->oh_tid),
- op_head->oh_flags & XLOG_WAS_CONT_TRANS)) {
- printf(_("Left over region from split log item\n"));
- /* Skip this leftover bit */
- ptr += be32_to_cpu(op_head->oh_len);
- /* We've lost context; don't complain if next one looks bad too */
- lost_context = 1;
- continue;
- }
-
- if (be32_to_cpu(op_head->oh_len) != 0) {
- skip = xlog_print_region(log, &ptr, op_head, &i, num_ops,
- continued);
- if (skip == -1) {
- if (bad_hdr_warn && !lost_context) {
- fprintf(stderr,
- _("%s: unknown log operation type (%x)\n"),
- progname, *(unsigned short *)ptr);
- if (print_exit) {
- free(buf);
- return BAD_HEADER;
- }
- } else {
- printf(
- _("Left over region from split log item\n"));
- }
- skip = 0;
- ptr += be32_to_cpu(op_head->oh_len);
- lost_context = 0;
- }
-
- if (skip)
- xlog_print_add_to_trans(be32_to_cpu(op_head->oh_tid), skip);
+ for (i = 0; i < num_ops; i++) {
+ if (!xlog_print_op(log, &ptr, &i, num_ops, bad_hdr_warn,
+ &lost_context)) {
+ free(buf);
+ return BAD_HEADER;
}
}
printf("\n");
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* Re: [PATCH 16/25] logprint: factor out a xlog_print_op helper
2025-11-28 6:29 ` [PATCH 16/25] logprint: factor out a xlog_print_op helper Christoph Hellwig
@ 2025-12-01 18:44 ` Andrey Albershteyn
2025-12-02 7:29 ` Christoph Hellwig
0 siblings, 1 reply; 34+ messages in thread
From: Andrey Albershteyn @ 2025-12-01 18:44 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Andrey Albershteyn, linux-xfs
On 2025-11-28 07:29:53, Christoph Hellwig wrote:
> Split the inner printing loop from xlog_print_record into a separate
> helper.
>
> Signed-off-by: Christoph Hellwig <hch@lst.de>
> ---
> logprint/log_misc.c | 134 ++++++++++++++++++++++++--------------------
> 1 file changed, 74 insertions(+), 60 deletions(-)
>
> diff --git a/logprint/log_misc.c b/logprint/log_misc.c
> index f10dc57a1edb..873ec6673768 100644
> --- a/logprint/log_misc.c
> +++ b/logprint/log_misc.c
> @@ -966,6 +966,72 @@ xlog_print_region(
> }
> }
>
> +static bool
> +xlog_print_op(
> + struct xlog *log,
> + char **ptr,
> + int *i,
> + int num_ops,
> + bool bad_hdr_warn,
> + bool *lost_context)
> +{
> + struct xlog_op_header *ophdr = (struct xlog_op_header *)*ptr;
> + bool continued;
> + int skip, n;
> +
> + print_xlog_op_line();
> + xlog_print_op_header(ophdr, *i, ptr);
> +
> + continued = (ophdr->oh_flags & XLOG_WAS_CONT_TRANS) ||
> + (ophdr->oh_flags & XLOG_CONTINUE_TRANS);
> + if (continued && be32_to_cpu(ophdr->oh_len) == 0)
> + return true;
> +
> + if (print_no_data) {
> + for (n = 0; n < be32_to_cpu(ophdr->oh_len); n++) {
> + printf("0x%02x ", (unsigned int)**ptr);
> + if (n % 16 == 15)
> + printf("\n");
> + ptr++;
> + }
> + printf("\n");
> + return true;
> + }
> +
> + /* print transaction data */
> + if (xlog_print_find_tid(be32_to_cpu(ophdr->oh_tid),
> + ophdr->oh_flags & XLOG_WAS_CONT_TRANS)) {
> + printf(_("Left over region from split log item\n"));
> + /* Skip this leftover bit */
> + (*ptr) += be32_to_cpu(ophdr->oh_len);
> + /* We've lost context; don't complain if next one looks bad too */
> + *lost_context = true;
> + return true;
> + }
> +
> + if (!ophdr->oh_len)
> + return true;
> +
> + skip = xlog_print_region(log, ptr, ophdr, i, num_ops, continued);
> + if (skip == -1) {
> + if (bad_hdr_warn && !*lost_context) {
> + fprintf(stderr,
> + _("%s: unknown log operation type (%x)\n"),
> + progname, *(unsigned short *)*ptr);
> + if (print_exit)
> + return false;
> + } else {
> + printf(
> + _("Left over region from split log item\n"));
> + }
> + (*ptr) += be32_to_cpu(ophdr->oh_len);
> + *lost_context = false;
> + } else if (skip) {
> + xlog_print_add_to_trans(be32_to_cpu(ophdr->oh_tid), skip);
> + }
> + return true;
> +}
> +
> static int
> xlog_print_record(
> struct xlog *log,
> @@ -979,8 +1045,9 @@ xlog_print_record(
> int bad_hdr_warn)
> {
> char *buf, *ptr;
> - int read_len, skip, lost_context = 0;
> - int ret, n, i, j, k;
> + int read_len;
> + bool lost_context = false;
missing tab
> + int ret, i, j, k;
>
> if (print_no_print)
> return NO_ERROR;
> @@ -1073,64 +1140,11 @@ xlog_print_record(
> }
>
> ptr = buf;
> - for (i=0; i<num_ops; i++) {
> - int continued;
> -
> - xlog_op_header_t *op_head = (xlog_op_header_t *)ptr;
> -
> - print_xlog_op_line();
> - xlog_print_op_header(op_head, i, &ptr);
> - continued = ((op_head->oh_flags & XLOG_WAS_CONT_TRANS) ||
> - (op_head->oh_flags & XLOG_CONTINUE_TRANS));
> -
> - if (continued && be32_to_cpu(op_head->oh_len) == 0)
> - continue;
> -
> - if (print_no_data) {
> - for (n = 0; n < be32_to_cpu(op_head->oh_len); n++) {
> - printf("0x%02x ", (unsigned int)*ptr);
> - if (n % 16 == 15)
> - printf("\n");
> - ptr++;
> - }
> - printf("\n");
> - continue;
> - }
> -
> - /* print transaction data */
> - if (xlog_print_find_tid(be32_to_cpu(op_head->oh_tid),
> - op_head->oh_flags & XLOG_WAS_CONT_TRANS)) {
> - printf(_("Left over region from split log item\n"));
> - /* Skip this leftover bit */
> - ptr += be32_to_cpu(op_head->oh_len);
> - /* We've lost context; don't complain if next one looks bad too */
> - lost_context = 1;
> - continue;
> - }
> -
> - if (be32_to_cpu(op_head->oh_len) != 0) {
> - skip = xlog_print_region(log, &ptr, op_head, &i, num_ops,
> - continued);
> - if (skip == -1) {
> - if (bad_hdr_warn && !lost_context) {
> - fprintf(stderr,
> - _("%s: unknown log operation type (%x)\n"),
> - progname, *(unsigned short *)ptr);
> - if (print_exit) {
> - free(buf);
> - return BAD_HEADER;
> - }
> - } else {
> - printf(
> - _("Left over region from split log item\n"));
> - }
> - skip = 0;
> - ptr += be32_to_cpu(op_head->oh_len);
> - lost_context = 0;
> - }
> -
> - if (skip)
> - xlog_print_add_to_trans(be32_to_cpu(op_head->oh_tid), skip);
> + for (i = 0; i < num_ops; i++) {
> + if (!xlog_print_op(log, &ptr, &i, num_ops, bad_hdr_warn,
> + &lost_context)) {
> + free(buf);
> + return BAD_HEADER;
> }
> }
> printf("\n");
> --
> 2.47.3
>
--
- Andrey
^ permalink raw reply [flat|nested] 34+ messages in thread* Re: [PATCH 16/25] logprint: factor out a xlog_print_op helper
2025-12-01 18:44 ` Andrey Albershteyn
@ 2025-12-02 7:29 ` Christoph Hellwig
0 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-12-02 7:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: Christoph Hellwig, Andrey Albershteyn, linux-xfs
On Mon, Dec 01, 2025 at 07:44:43PM +0100, Andrey Albershteyn wrote:
> > - int ret, n, i, j, k;
> > + int read_len;
> > + bool lost_context = false;
>
> missing tab
Yes.
^ permalink raw reply [flat|nested] 34+ messages in thread
* [PATCH 17/25] logprint: factor out a xlog_unpack_rec_header
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (15 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 16/25] logprint: factor out a xlog_print_op helper Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 18/25] logprint: cleanup xlog_print_record Christoph Hellwig
` (8 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Split the log record validation and unpacking logic into a separate
helper.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 78 +++++++++++++++++++++++++--------------------
1 file changed, 43 insertions(+), 35 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 873ec6673768..efad679e5a81 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -1032,6 +1032,47 @@ xlog_print_op(
return true;
}
+static bool
+xlog_unpack_rec_header(
+ struct xlog_rec_header *rhead,
+ struct xlog_rec_ext_header *xhdrs,
+ char *ptr,
+ int *read_type,
+ int i)
+{
+ __be32 *cycle = (__be32 *)ptr;
+
+ /*
+ * Data should not have magicno as first word as it should be cycle
+ * number.
+ */
+ if (*cycle == cpu_to_be32(XLOG_HEADER_MAGIC_NUM))
+ return false;
+
+ /* Verify cycle number. */
+ if (be32_to_cpu(rhead->h_cycle) != be32_to_cpu(*cycle) &&
+ (*read_type == FULL_READ ||
+ be32_to_cpu(rhead->h_cycle) + 1 != be32_to_cpu(*cycle)))
+ return false;
+
+ /* Copy back the data from the header */
+ if (i < XLOG_HEADER_CYCLE_SIZE / BBSIZE) {
+ /* from 1st header */
+ *cycle = rhead->h_cycle_data[i];
+ } else {
+ int j, k;
+
+ ASSERT(xhdrs != NULL);
+
+ /* from extra headers */
+ j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
+ k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
+ *cycle = xhdrs[j - 1].xh_cycle_data[k];
+ }
+
+ return true;
+}
+
static int
xlog_print_record(
struct xlog *log,
@@ -1047,7 +1088,7 @@ xlog_print_record(
char *buf, *ptr;
int read_len;
bool lost_context = false;
- int ret, i, j, k;
+ int ret, i;
if (print_no_print)
return NO_ERROR;
@@ -1100,43 +1141,10 @@ xlog_print_record(
*/
buf = ptr;
for (i = 0; ptr < buf + read_len; ptr += BBSIZE, i++) {
- xlog_rec_header_t *rechead = (xlog_rec_header_t *)ptr;
-
- /* sanity checks */
- if (be32_to_cpu(rechead->h_magicno) == XLOG_HEADER_MAGIC_NUM) {
- /* data should not have magicno as first word
- * as it should by cycle#
- */
+ if (!xlog_unpack_rec_header(rhead, xhdrs, ptr, read_type, i)) {
free(buf);
return -1;
- } else {
- /* verify cycle#
- * FIXME: cycle+1 should be a macro pv#900369
- */
- if (be32_to_cpu(rhead->h_cycle) !=
- be32_to_cpu(*(__be32 *)ptr)) {
- if ((*read_type == FULL_READ) ||
- (be32_to_cpu(rhead->h_cycle) + 1 !=
- be32_to_cpu(*(__be32 *)ptr))) {
- free(buf);
- return -1;
- }
- }
}
-
- /* copy back the data from the header */
- if (i < XLOG_HEADER_CYCLE_SIZE / BBSIZE) {
- /* from 1st header */
- *(__be32 *)ptr = rhead->h_cycle_data[i];
- }
- else {
- ASSERT(xhdrs != NULL);
- /* from extra headers */
- j = i / (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
- k = i % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
- *(__be32 *)ptr = xhdrs[j-1].xh_cycle_data[k];
- }
-
}
ptr = buf;
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 18/25] logprint: cleanup xlog_print_record
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (16 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 17/25] logprint: factor out a xlog_unpack_rec_header Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 19/25] logprint: cleanup xlog_print_rec_head Christoph Hellwig
` (7 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Indent to the normal style, use structs instead of typedefs, and move
assignments out of conditionals.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 141 +++++++++++++++++++++++---------------------
1 file changed, 75 insertions(+), 66 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index efad679e5a81..3e67187d3fd4 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -1081,85 +1081,94 @@ xlog_print_record(
int len,
int *read_type,
char **partial_buf,
- xlog_rec_header_t *rhead,
- xlog_rec_ext_header_t *xhdrs,
+ struct xlog_rec_header *rhead,
+ struct xlog_rec_ext_header *xhdrs,
int bad_hdr_warn)
{
- char *buf, *ptr;
- int read_len;
- bool lost_context = false;
- int ret, i;
+ bool lost_context = false;
+ char *buf, *ptr;
+ int read_len;
+ int ret, i;
- if (print_no_print)
- return NO_ERROR;
+ if (print_no_print)
+ return NO_ERROR;
- if (!len) {
- printf("\n");
- return NO_ERROR;
- }
+ if (!len) {
+ printf("\n");
+ return NO_ERROR;
+ }
- /* read_len must read up to some block boundary */
- read_len = (int) BBTOB(BTOBB(len));
+ /* read_len must read up to some block boundary */
+ read_len = (int) BBTOB(BTOBB(len));
- /* read_type => don't malloc() new buffer, use old one */
- if (*read_type == FULL_READ) {
- if ((ptr = buf = malloc(read_len)) == NULL) {
- fprintf(stderr, _("%s: xlog_print_record: malloc failed\n"), progname);
- exit(1);
+ /* read_type => don't malloc() new buffer, use old one */
+ if (*read_type == FULL_READ) {
+ buf = malloc(read_len);
+ if (!buf) {
+ fprintf(stderr,
+ _("%s: xlog_print_record: malloc failed\n"), progname);
+ exit(1);
+ }
+ ptr = buf;
+ } else {
+ read_len -= *read_type;
+ buf = (char *)((intptr_t)(*partial_buf) +
+ (intptr_t)(*read_type));
+ ptr = *partial_buf;
}
- } else {
- read_len -= *read_type;
- buf = (char *)((intptr_t)(*partial_buf) + (intptr_t)(*read_type));
- ptr = *partial_buf;
- }
- if ((ret = (int) read(fd, buf, read_len)) == -1) {
- fprintf(stderr, _("%s: xlog_print_record: read error\n"), progname);
- exit(1);
- }
- /* Did we overflow the end? */
- if (*read_type == FULL_READ &&
- BLOCK_LSN(be64_to_cpu(rhead->h_lsn)) + BTOBB(read_len) >=
- logBBsize) {
- *read_type = BBTOB(logBBsize - BLOCK_LSN(be64_to_cpu(rhead->h_lsn))-1);
- *partial_buf = buf;
- return PARTIAL_READ;
- }
- /* Did we read everything? */
- if ((ret == 0 && read_len != 0) || ret != read_len) {
- *read_type = ret;
- *partial_buf = buf;
- return PARTIAL_READ;
- }
- if (*read_type != FULL_READ)
- read_len += *read_type;
+ ret = (int) read(fd, buf, read_len);
+ if (ret == -1) {
+ fprintf(stderr,
+ _("%s: xlog_print_record: read error\n"), progname);
+ exit(1);
+ }
- /* Everything read in. Start from beginning of buffer
- * Unpack the data, by putting the saved cycle-data back
- * into the first word of each BB.
- * Do some checks.
- */
- buf = ptr;
- for (i = 0; ptr < buf + read_len; ptr += BBSIZE, i++) {
- if (!xlog_unpack_rec_header(rhead, xhdrs, ptr, read_type, i)) {
- free(buf);
- return -1;
+ /* Did we overflow the end? */
+ if (*read_type == FULL_READ &&
+ BLOCK_LSN(be64_to_cpu(rhead->h_lsn)) + BTOBB(read_len) >=
+ logBBsize) {
+ *read_type = BBTOB(logBBsize -
+ BLOCK_LSN(be64_to_cpu(rhead->h_lsn))-1);
+ *partial_buf = buf;
+ return PARTIAL_READ;
}
- }
- ptr = buf;
- for (i = 0; i < num_ops; i++) {
- if (!xlog_print_op(log, &ptr, &i, num_ops, bad_hdr_warn,
- &lost_context)) {
- free(buf);
- return BAD_HEADER;
+ /* Did we read everything? */
+ if ((ret == 0 && read_len != 0) || ret != read_len) {
+ *read_type = ret;
+ *partial_buf = buf;
+ return PARTIAL_READ;
}
- }
- printf("\n");
- free(buf);
- return NO_ERROR;
-} /* xlog_print_record */
+ if (*read_type != FULL_READ)
+ read_len += *read_type;
+ /*
+ * Everything read in. Start from beginning of buffer
+ * Unpack the data, by putting the saved cycle-data back into the first
+ * word of each BB.
+ * Do some checks.
+ */
+ buf = ptr;
+ for (i = 0; ptr < buf + read_len; ptr += BBSIZE, i++) {
+ if (!xlog_unpack_rec_header(rhead, xhdrs, ptr, read_type, i)) {
+ free(buf);
+ return -1;
+ }
+ }
+
+ ptr = buf;
+ for (i = 0; i < num_ops; i++) {
+ if (!xlog_print_op(log, &ptr, &i, num_ops, bad_hdr_warn,
+ &lost_context)) {
+ free(buf);
+ return BAD_HEADER;
+ }
+ }
+ printf("\n");
+ free(buf);
+ return NO_ERROR;
+}
static int
xlog_print_rec_head(xlog_rec_header_t *head, int *len, int bad_hdr_warn)
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 19/25] logprint: cleanup xlog_print_rec_head
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (17 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 18/25] logprint: cleanup xlog_print_record Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 20/25] logprint: cleanup xlog_print_rec_xhead Christoph Hellwig
` (6 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent and drop typedefs.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 119 +++++++++++++++++++++++---------------------
1 file changed, 61 insertions(+), 58 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 3e67187d3fd4..1ac45a926c40 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -1171,78 +1171,81 @@ xlog_print_record(
}
static int
-xlog_print_rec_head(xlog_rec_header_t *head, int *len, int bad_hdr_warn)
+xlog_print_rec_head(
+ struct xlog_rec_header *head,
+ int *len,
+ int bad_hdr_warn)
{
- int i;
- char uub[64];
- int datalen,bbs;
+ int datalen, bbs;
+ char uub[64];
+ int i;
- if (print_no_print)
- return be32_to_cpu(head->h_num_logops);
+ if (print_no_print)
+ return be32_to_cpu(head->h_num_logops);
- if (!head->h_magicno)
- return ZEROED_LOG;
+ if (!head->h_magicno)
+ return ZEROED_LOG;
- if (be32_to_cpu(head->h_magicno) != XLOG_HEADER_MAGIC_NUM) {
- if (bad_hdr_warn)
- printf(_("Header 0x%x wanted 0x%x\n"),
- be32_to_cpu(head->h_magicno),
- XLOG_HEADER_MAGIC_NUM);
- return BAD_HEADER;
- }
+ if (be32_to_cpu(head->h_magicno) != XLOG_HEADER_MAGIC_NUM) {
+ if (bad_hdr_warn) {
+ printf(_("Header 0x%x wanted 0x%x\n"),
+ be32_to_cpu(head->h_magicno),
+ XLOG_HEADER_MAGIC_NUM);
+ }
+ return BAD_HEADER;
+ }
- /* check for cleared blocks written by xlog_clear_stale_blocks() */
- if (!head->h_len && !head->h_crc && !head->h_prev_block &&
- !head->h_num_logops && !head->h_size)
- return CLEARED_BLKS;
-
- datalen=be32_to_cpu(head->h_len);
- bbs=BTOBB(datalen);
-
- printf(_("cycle: %d version: %d "),
- be32_to_cpu(head->h_cycle),
- be32_to_cpu(head->h_version));
- print_lsn(" lsn", &head->h_lsn);
- print_lsn(" tail_lsn", &head->h_tail_lsn);
- printf("\n");
- printf(_("length of Log Record: %d prev offset: %d num ops: %d\n"),
- datalen,
- be32_to_cpu(head->h_prev_block),
- be32_to_cpu(head->h_num_logops));
+ /* check for cleared blocks written by xlog_clear_stale_blocks() */
+ if (!head->h_len && !head->h_crc && !head->h_prev_block &&
+ !head->h_num_logops && !head->h_size)
+ return CLEARED_BLKS;
- if (print_overwrite) {
- printf(_("cycle num overwrites: "));
- for (i=0; i< min(bbs, XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++)
- printf("%d - 0x%x ",
- i,
- be32_to_cpu(head->h_cycle_data[i]));
+ datalen = be32_to_cpu(head->h_len);
+ bbs = BTOBB(datalen);
+
+ printf(_("cycle: %d version: %d "),
+ be32_to_cpu(head->h_cycle),
+ be32_to_cpu(head->h_version));
+ print_lsn(" lsn", &head->h_lsn);
+ print_lsn(" tail_lsn", &head->h_tail_lsn);
printf("\n");
- }
+ printf(_("length of Log Record: %d prev offset: %d num ops: %d\n"),
+ datalen,
+ be32_to_cpu(head->h_prev_block),
+ be32_to_cpu(head->h_num_logops));
+
+ if (print_overwrite) {
+ printf(_("cycle num overwrites: "));
+ for (i = 0; i < min(bbs, XLOG_HEADER_CYCLE_SIZE / BBSIZE); i++)
+ printf("%d - 0x%x ",
+ i, be32_to_cpu(head->h_cycle_data[i]));
+ printf("\n");
+ }
- platform_uuid_unparse(&head->h_fs_uuid, uub);
- printf(_("uuid: %s format: "), uub);
- switch (be32_to_cpu(head->h_fmt)) {
+ platform_uuid_unparse(&head->h_fs_uuid, uub);
+ printf(_("uuid: %s format: "), uub);
+ switch (be32_to_cpu(head->h_fmt)) {
case XLOG_FMT_UNKNOWN:
- printf(_("unknown\n"));
- break;
+ printf(_("unknown\n"));
+ break;
case XLOG_FMT_LINUX_LE:
- printf(_("little endian linux\n"));
- break;
+ printf(_("little endian linux\n"));
+ break;
case XLOG_FMT_LINUX_BE:
- printf(_("big endian linux\n"));
- break;
+ printf(_("big endian linux\n"));
+ break;
case XLOG_FMT_IRIX_BE:
- printf(_("big endian irix\n"));
- break;
+ printf(_("big endian irix\n"));
+ break;
default:
- printf("? (%d)\n", be32_to_cpu(head->h_fmt));
- break;
- }
- printf(_("h_size: %d\n"), be32_to_cpu(head->h_size));
+ printf("? (%d)\n", be32_to_cpu(head->h_fmt));
+ break;
+ }
+ printf(_("h_size: %d\n"), be32_to_cpu(head->h_size));
- *len = be32_to_cpu(head->h_len);
- return(be32_to_cpu(head->h_num_logops));
-} /* xlog_print_rec_head */
+ *len = be32_to_cpu(head->h_len);
+ return(be32_to_cpu(head->h_num_logops));
+}
static void
xlog_print_rec_xhead(xlog_rec_ext_header_t *head, int coverage)
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 20/25] logprint: cleanup xlog_print_rec_xhead
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (18 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 19/25] logprint: cleanup xlog_print_rec_head Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 21/25] logprint: re-indent print_xlog_bad_* Christoph Hellwig
` (5 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent and drop typedefs.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 28 +++++++++++++++-------------
1 file changed, 15 insertions(+), 13 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 1ac45a926c40..0570cc951f04 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -1248,22 +1248,24 @@ xlog_print_rec_head(
}
static void
-xlog_print_rec_xhead(xlog_rec_ext_header_t *head, int coverage)
+xlog_print_rec_xhead(
+ struct xlog_rec_ext_header *head,
+ int coverage)
{
- int i;
+ int i;
- print_xlog_xhdr_line();
- printf(_("extended-header: cycle: %d\n"), be32_to_cpu(head->xh_cycle));
+ print_xlog_xhdr_line();
+ printf(_("extended-header: cycle: %d\n"),
+ be32_to_cpu(head->xh_cycle));
- if (print_overwrite) {
- printf(_("cycle num overwrites: "));
- for (i = 0; i < coverage; i++)
- printf("%d - 0x%x ",
- i,
- be32_to_cpu(head->xh_cycle_data[i]));
- printf("\n");
- }
-} /* xlog_print_rec_xhead */
+ if (print_overwrite) {
+ printf(_("cycle num overwrites: "));
+ for (i = 0; i < coverage; i++)
+ printf("%d - 0x%x ",
+ i, be32_to_cpu(head->xh_cycle_data[i]));
+ printf("\n");
+ }
+}
static void
print_xlog_bad_zeroed(xfs_daddr_t blkno)
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 21/25] logprint: re-indent print_xlog_bad_*
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (19 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 20/25] logprint: cleanup xlog_print_rec_xhead Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:29 ` [PATCH 22/25] logprint: cleanup xlog_reallocate_xhdrs Christoph Hellwig
` (4 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 31 +++++++++++++++++++------------
1 file changed, 19 insertions(+), 12 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 0570cc951f04..ba48c7a3190c 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -1268,40 +1268,47 @@ xlog_print_rec_xhead(
}
static void
-print_xlog_bad_zeroed(xfs_daddr_t blkno)
+print_xlog_bad_zeroed(
+ xfs_daddr_t blkno)
{
print_stars();
printf(_("* ERROR: found data after zeroed blocks block=%-21lld *\n"),
(long long)blkno);
print_stars();
if (print_exit)
- xlog_exit("Bad log - data after zeroed blocks");
-} /* print_xlog_bad_zeroed */
+ xlog_exit("Bad log - data after zeroed blocks");
+}
static void
-print_xlog_bad_header(xfs_daddr_t blkno, char *buf)
+print_xlog_bad_header(
+ xfs_daddr_t blkno,
+ char *buf)
{
print_stars();
printf(_("* ERROR: header cycle=%-11d block=%-21lld *\n"),
xlog_get_cycle(buf), (long long)blkno);
print_stars();
if (print_exit)
- xlog_exit("Bad log record header");
-} /* print_xlog_bad_header */
+ xlog_exit("Bad log record header");
+}
static void
-print_xlog_bad_data(xfs_daddr_t blkno)
+print_xlog_bad_data(
+ xfs_daddr_t blkno)
{
print_stars();
printf(_("* ERROR: data block=%-21lld *\n"),
(long long)blkno);
print_stars();
if (print_exit)
- xlog_exit("Bad data in log");
-} /* print_xlog_bad_data */
+ xlog_exit("Bad data in log");
+}
static void
-print_xlog_bad_reqd_hdrs(xfs_daddr_t blkno, int num_reqd, int num_hdrs)
+print_xlog_bad_reqd_hdrs(
+ xfs_daddr_t blkno,
+ int num_reqd,
+ int num_hdrs)
{
print_stars();
printf(_("* ERROR: for header block=%lld\n"
@@ -1310,8 +1317,8 @@ print_xlog_bad_reqd_hdrs(xfs_daddr_t blkno, int num_reqd, int num_hdrs)
(long long)blkno, num_reqd, num_hdrs);
print_stars();
if (print_exit)
- xlog_exit(_("Not enough headers for data length."));
-} /* print_xlog_bad_reqd_hdrs */
+ xlog_exit(_("Not enough headers for data length."));
+}
static void
xlog_reallocate_xhdrs(int num_hdrs, xlog_rec_ext_header_t **ret_xhdrs)
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 22/25] logprint: cleanup xlog_reallocate_xhdrs
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (20 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 21/25] logprint: re-indent print_xlog_bad_* Christoph Hellwig
@ 2025-11-28 6:29 ` Christoph Hellwig
2025-11-28 6:30 ` [PATCH 23/25] logprint: factor out a xlog_print_ext_header helper Christoph Hellwig
` (3 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent and drop typedefs.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index ba48c7a3190c..b67a2e9d91a4 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -1321,11 +1321,15 @@ print_xlog_bad_reqd_hdrs(
}
static void
-xlog_reallocate_xhdrs(int num_hdrs, xlog_rec_ext_header_t **ret_xhdrs)
+xlog_reallocate_xhdrs(
+ int num_hdrs,
+ struct xlog_rec_ext_header **ret_xhdrs)
{
- int len = (num_hdrs-1) * sizeof(xlog_rec_ext_header_t);
+ int len;
- *ret_xhdrs = (xlog_rec_ext_header_t *)realloc(*ret_xhdrs, len);
+ len = (num_hdrs - 1) * sizeof(struct xlog_rec_ext_header);
+
+ *ret_xhdrs = realloc(*ret_xhdrs, len);
if (*ret_xhdrs == NULL) {
fprintf(stderr, _("%s: xlog_print: malloc failed for ext hdrs\n"), progname);
exit(1);
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 23/25] logprint: factor out a xlog_print_ext_header helper
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (21 preceding siblings ...)
2025-11-28 6:29 ` [PATCH 22/25] logprint: cleanup xlog_reallocate_xhdrs Christoph Hellwig
@ 2025-11-28 6:30 ` Christoph Hellwig
2025-11-28 6:30 ` [PATCH 24/25] logprint: cleanup xlog_print_extended_headers Christoph Hellwig
` (2 subsequent siblings)
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:30 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Split the inner extheader printing loop into a separate helper.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 89 ++++++++++++++++++++++++++-------------------
1 file changed, 52 insertions(+), 37 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index b67a2e9d91a4..94efd3839f8b 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -1336,6 +1336,55 @@ xlog_reallocate_xhdrs(
}
}
+static int
+xlog_print_ext_header(
+ int fd,
+ int len,
+ xfs_daddr_t blkno,
+ struct xlog_rec_ext_header *xhdr,
+ bool last)
+{
+ char xhbuf[XLOG_HEADER_SIZE];
+ struct xlog_rec_ext_header *rbuf =
+ (struct xlog_rec_ext_header *)xhbuf;
+ int j;
+
+ /* read one extra header blk */
+ if (read(fd, xhbuf, 512) == 0) {
+ printf(_("%s: physical end of log\n"), progname);
+ print_xlog_record_line();
+ /* reached the end */
+ return 1;
+ }
+
+ if (print_only_data) {
+ printf(_("BLKNO: %lld\n"), (long long)blkno);
+ xlog_recover_print_data(xhbuf, 512);
+ } else {
+ int coverage_bb;
+
+ if (last) {
+ coverage_bb =
+ BTOBB(len) % (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
+ } else {
+ coverage_bb = XLOG_HEADER_CYCLE_SIZE / BBSIZE;
+ }
+ xlog_print_rec_xhead(rbuf, coverage_bb);
+ }
+
+ /*
+ * Copy from buffer into xhdrs array for later.
+ *
+ * We could endian convert here but then code later on will look
+ * asymmetric with the single header case which does endian coversion on
+ * access.
+ */
+ xhdr->xh_cycle = rbuf->xh_cycle;
+ for (j = 0; j < XLOG_HEADER_CYCLE_SIZE / BBSIZE; j++)
+ xhdr->xh_cycle_data[j] = rbuf->xh_cycle_data[j];
+ return 0;
+}
+
/* for V2 logs read each extra hdr and print it out */
static int
xlog_print_extended_headers(
@@ -1346,11 +1395,9 @@ xlog_print_extended_headers(
int *ret_num_hdrs,
xlog_rec_ext_header_t **ret_xhdrs)
{
- int i, j;
- int coverage_bb;
+ int i;
int num_hdrs;
int num_required;
- char xhbuf[XLOG_HEADER_SIZE];
xlog_rec_ext_header_t *xhdr;
num_required = howmany(len, XLOG_HEADER_CYCLE_SIZE);
@@ -1377,40 +1424,8 @@ xlog_print_extended_headers(
/* don't include 1st header */
for (i = 1, xhdr = *ret_xhdrs; i < num_hdrs; i++, (*blkno)++, xhdr++) {
- /* read one extra header blk */
- if (read(fd, xhbuf, 512) == 0) {
- printf(_("%s: physical end of log\n"), progname);
- print_xlog_record_line();
- /* reached the end so return 1 */
- return 1;
- }
- if (print_only_data) {
- printf(_("BLKNO: %lld\n"), (long long)*blkno);
- xlog_recover_print_data(xhbuf, 512);
- }
- else {
- if (i == num_hdrs - 1) {
- /* last header */
- coverage_bb = BTOBB(len) %
- (XLOG_HEADER_CYCLE_SIZE / BBSIZE);
- }
- else {
- /* earliear header */
- coverage_bb = XLOG_HEADER_CYCLE_SIZE / BBSIZE;
- }
- xlog_print_rec_xhead((xlog_rec_ext_header_t*)xhbuf, coverage_bb);
- }
-
- /* Copy from buffer into xhdrs array for later.
- * Could endian convert here but then code later on
- * will look asymmetric with the 1 hdr normal case
- * which does endian coversion on access.
- */
- xhdr->xh_cycle = ((xlog_rec_ext_header_t*)xhbuf)->xh_cycle;
- for (j = 0; j < XLOG_HEADER_CYCLE_SIZE / BBSIZE; j++) {
- xhdr->xh_cycle_data[j] =
- ((xlog_rec_ext_header_t*)xhbuf)->xh_cycle_data[j];
- }
+ if (xlog_print_ext_header(fd, len, *blkno, xhdr, i == num_hdrs - 1))
+ return 1;
}
return 0;
}
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 24/25] logprint: cleanup xlog_print_extended_headers
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (22 preceding siblings ...)
2025-11-28 6:30 ` [PATCH 23/25] logprint: factor out a xlog_print_ext_header helper Christoph Hellwig
@ 2025-11-28 6:30 ` Christoph Hellwig
2025-11-28 6:30 ` [PATCH 25/25] logprint: cleanup xfs_log_print Christoph Hellwig
2025-12-01 19:03 ` logprint cleanups, part1 Andrey Albershteyn
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:30 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent and drop typedefs.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 45 +++++++++++++++++++++------------------------
1 file changed, 21 insertions(+), 24 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index 94efd3839f8b..ea696fb282d3 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -1388,49 +1388,46 @@ xlog_print_ext_header(
/* for V2 logs read each extra hdr and print it out */
static int
xlog_print_extended_headers(
- int fd,
- int len,
- xfs_daddr_t *blkno,
- xlog_rec_header_t *hdr,
- int *ret_num_hdrs,
- xlog_rec_ext_header_t **ret_xhdrs)
+ int fd,
+ int len,
+ xfs_daddr_t *blkno,
+ struct xlog_rec_header *hdr,
+ int *ret_num_hdrs,
+ struct xlog_rec_ext_header **ret_xhdrs)
{
- int i;
- int num_hdrs;
- int num_required;
- xlog_rec_ext_header_t *xhdr;
+ int num_hdrs, num_required;
+ struct xlog_rec_ext_header *xhdr;
+ int i;
num_required = howmany(len, XLOG_HEADER_CYCLE_SIZE);
num_hdrs = be32_to_cpu(hdr->h_size) / XLOG_HEADER_CYCLE_SIZE;
if (be32_to_cpu(hdr->h_size) % XLOG_HEADER_CYCLE_SIZE)
num_hdrs++;
- if (num_required > num_hdrs) {
- print_xlog_bad_reqd_hdrs((*blkno)-1, num_required, num_hdrs);
- }
+ if (num_required > num_hdrs)
+ print_xlog_bad_reqd_hdrs(*blkno - 1, num_required, num_hdrs);
if (num_hdrs == 1) {
- free(*ret_xhdrs);
- *ret_xhdrs = NULL;
- *ret_num_hdrs = 1;
- return 0;
- }
-
- if (*ret_xhdrs == NULL || num_hdrs > *ret_num_hdrs) {
- xlog_reallocate_xhdrs(num_hdrs, ret_xhdrs);
+ free(*ret_xhdrs);
+ *ret_xhdrs = NULL;
+ *ret_num_hdrs = 1;
+ return 0;
}
+ if (*ret_xhdrs == NULL || num_hdrs > *ret_num_hdrs)
+ xlog_reallocate_xhdrs(num_hdrs, ret_xhdrs);
*ret_num_hdrs = num_hdrs;
/* don't include 1st header */
for (i = 1, xhdr = *ret_xhdrs; i < num_hdrs; i++, (*blkno)++, xhdr++) {
- if (xlog_print_ext_header(fd, len, *blkno, xhdr, i == num_hdrs - 1))
- return 1;
+ if (xlog_print_ext_header(fd, len, *blkno, xhdr,
+ i == num_hdrs - 1))
+ return 1;
}
+
return 0;
}
-
/*
* This code is gross and needs to be rewritten.
*/
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* [PATCH 25/25] logprint: cleanup xfs_log_print
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (23 preceding siblings ...)
2025-11-28 6:30 ` [PATCH 24/25] logprint: cleanup xlog_print_extended_headers Christoph Hellwig
@ 2025-11-28 6:30 ` Christoph Hellwig
2025-12-01 19:03 ` logprint cleanups, part1 Andrey Albershteyn
25 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-11-28 6:30 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: linux-xfs
Re-indent and drop typedefs.
Signed-off-by: Christoph Hellwig <hch@lst.de>
---
logprint/log_misc.c | 392 ++++++++++++++++++++++----------------------
1 file changed, 197 insertions(+), 195 deletions(-)
diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index ea696fb282d3..fbedcabedf1c 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -1431,214 +1431,216 @@ xlog_print_extended_headers(
/*
* This code is gross and needs to be rewritten.
*/
-void xfs_log_print(struct xlog *log,
- int fd,
- int print_block_start)
+void xfs_log_print(
+ struct xlog *log,
+ int fd,
+ int print_block_start)
{
- char hbuf[XLOG_HEADER_SIZE];
- xlog_rec_header_t *hdr = (xlog_rec_header_t *)&hbuf[0];
- xlog_rec_ext_header_t *xhdrs = NULL;
- int num_ops, len, num_hdrs = 1;
- xfs_daddr_t block_end = 0, block_start, blkno, error;
- xfs_daddr_t zeroed_blkno = 0, cleared_blkno = 0;
- int read_type = FULL_READ;
- char *partial_buf;
- int zeroed = 0;
- int cleared = 0;
- int first_hdr_found = 0;
-
- logBBsize = log->l_logBBsize;
-
- /*
- * Normally, block_start and block_end are the same value since we
- * are printing the entire log. However, if the start block is given,
- * we still end at the end of the logical log.
- */
- if ((error = xlog_print_find_oldest(log, &block_end))) {
- fprintf(stderr, _("%s: problem finding oldest LR\n"), progname);
- return;
- }
- if (print_block_start == -1)
- block_start = block_end;
- else
- block_start = print_block_start;
- xlog_print_lseek(log, fd, block_start, SEEK_SET);
- blkno = block_start;
-
- for (;;) {
- if (read(fd, hbuf, 512) == 0) {
- printf(_("%s: physical end of log\n"), progname);
- print_xlog_record_line();
- break;
- }
- if (print_only_data) {
- printf(_("BLKNO: %lld\n"), (long long)blkno);
- xlog_recover_print_data(hbuf, 512);
- blkno++;
- goto loop;
- }
- num_ops = xlog_print_rec_head(hdr, &len, first_hdr_found);
- blkno++;
-
- if (zeroed && num_ops != ZEROED_LOG) {
- printf(_("%s: after %d zeroed blocks\n"), progname, zeroed);
- /* once we find zeroed blocks - that's all we expect */
- print_xlog_bad_zeroed(blkno-1);
- /* reset count since we're assuming previous zeroed blocks
- * were bad
- */
- zeroed = 0;
- }
+ char hbuf[XLOG_HEADER_SIZE];
+ struct xlog_rec_header *hdr = (struct xlog_rec_header *)&hbuf[0];
+ struct xlog_rec_ext_header *xhdrs = NULL;
+ int num_ops, len, num_hdrs = 1;
+ xfs_daddr_t block_end = 0, block_start, blkno, error;
+ xfs_daddr_t zeroed_blkno = 0, cleared_blkno = 0;
+ int read_type = FULL_READ;
+ char *partial_buf;
+ int zeroed = 0;
+ int cleared = 0;
+ int first_hdr_found = 0;
+
+ logBBsize = log->l_logBBsize;
- if (num_ops == ZEROED_LOG ||
- num_ops == CLEARED_BLKS ||
- num_ops == BAD_HEADER) {
- if (num_ops == ZEROED_LOG) {
- if (zeroed == 0)
- zeroed_blkno = blkno-1;
- zeroed++;
- }
- else if (num_ops == CLEARED_BLKS) {
- if (cleared == 0)
- cleared_blkno = blkno-1;
- cleared++;
- } else {
- if (!first_hdr_found)
- block_start = blkno;
- else
- print_xlog_bad_header(blkno-1, hbuf);
- }
-
- goto loop;
+ /*
+ * Normally, block_start and block_end are the same value since we are
+ * printing the entire log. However, if the start block is given, we
+ * still end at the end of the logical log.
+ */
+ error = xlog_print_find_oldest(log, &block_end);
+ if (error) {
+ fprintf(stderr, _("%s: problem finding oldest LR\n"),
+ progname);
+ return;
}
- if (be32_to_cpu(hdr->h_version) == 2) {
- if (xlog_print_extended_headers(fd, len, &blkno, hdr, &num_hdrs, &xhdrs) != 0)
- break;
- }
+ if (print_block_start == -1)
+ block_start = block_end;
+ else
+ block_start = print_block_start;
+ xlog_print_lseek(log, fd, block_start, SEEK_SET);
+ blkno = block_start;
- error = xlog_print_record(log, fd, num_ops, len, &read_type, &partial_buf,
- hdr, xhdrs, first_hdr_found);
- first_hdr_found++;
- switch (error) {
- case 0: {
- blkno += BTOBB(len);
- if (print_block_start != -1 &&
- blkno >= block_end) /* If start specified, we */
- goto end; /* end early */
- break;
- }
- case -1: {
- print_xlog_bad_data(blkno-1);
- if (print_block_start != -1 &&
- blkno >= block_end) /* If start specified, */
- goto end; /* we end early */
- xlog_print_lseek(log, fd, blkno, SEEK_SET);
- goto loop;
- }
- case PARTIAL_READ: {
- print_xlog_record_line();
- printf(_("%s: physical end of log\n"), progname);
+ for (;;) {
+ if (read(fd, hbuf, 512) == 0) {
+ printf(_("%s: physical end of log\n"), progname);
+ print_xlog_record_line();
+ break;
+ }
+ if (print_only_data) {
+ printf(_("BLKNO: %lld\n"), (long long)blkno);
+ xlog_recover_print_data(hbuf, 512);
+ blkno++;
+ goto loop;
+ }
+ num_ops = xlog_print_rec_head(hdr, &len, first_hdr_found);
+ blkno++;
+
+ if (zeroed && num_ops != ZEROED_LOG) {
+ printf(_("%s: after %d zeroed blocks\n"),
+ progname, zeroed);
+ /* once we find zeroed blocks - that's all we expect */
+ print_xlog_bad_zeroed(blkno - 1);
+ /*
+ * Reset count since we're assuming previous zeroed
+ * blocks were bad.
+ */
+ zeroed = 0;
+ }
+
+ switch (num_ops) {
+ case ZEROED_LOG:
+ if (zeroed == 0)
+ zeroed_blkno = blkno - 1;
+ zeroed++;
+ goto loop;
+ case CLEARED_BLKS:
+ if (cleared == 0)
+ cleared_blkno = blkno - 1;
+ cleared++;
+ goto loop;
+ case BAD_HEADER:
+ if (!first_hdr_found)
+ block_start = blkno;
+ else
+ print_xlog_bad_header(blkno - 1, hbuf);
+ goto loop;
+ default:
+ break;
+ }
+
+ if (be32_to_cpu(hdr->h_version) == 2 &&
+ xlog_print_extended_headers(fd, len, &blkno, hdr, &num_hdrs,
+ &xhdrs) != 0)
+ break;
+
+ error = xlog_print_record(log, fd, num_ops, len, &read_type,
+ &partial_buf, hdr, xhdrs, first_hdr_found);
+ first_hdr_found++;
+ switch (error) {
+ case 0:
+ blkno += BTOBB(len);
+ if (print_block_start != -1 &&
+ blkno >= block_end) /* If start specified, we */
+ goto end; /* end early */
+ break;
+ case -1:
+ print_xlog_bad_data(blkno-1);
+ if (print_block_start != -1 &&
+ blkno >= block_end) /* If start specified, */
+ goto end; /* we end early */
+ xlog_print_lseek(log, fd, blkno, SEEK_SET);
+ goto loop;
+ case PARTIAL_READ:
+ print_xlog_record_line();
+ printf(_("%s: physical end of log\n"), progname);
+ print_xlog_record_line();
+ blkno = 0;
+ xlog_print_lseek(log, fd, 0, SEEK_SET);
+ /*
+ * We may have hit the end of the log when we started at 0.
+ * In this case, just end.
+ */
+ if (block_start == 0)
+ goto end;
+ goto partial_log_read;
+ default:
+ xlog_panic(_("illegal value"));
+ }
print_xlog_record_line();
- blkno = 0;
- xlog_print_lseek(log, fd, 0, SEEK_SET);
- /*
- * We may have hit the end of the log when we started at 0.
- * In this case, just end.
- */
- if (block_start == 0)
- goto end;
- goto partial_log_read;
- }
- default: xlog_panic(_("illegal value"));
- }
- print_xlog_record_line();
loop:
- if (blkno >= logBBsize) {
- if (cleared) {
- printf(_("%s: skipped %d cleared blocks in range: %lld - %lld\n"),
- progname, cleared,
- (long long)(cleared_blkno),
- (long long)(cleared + cleared_blkno - 1));
- if (cleared == logBBsize)
- printf(_("%s: totally cleared log\n"), progname);
-
- cleared=0;
- }
- if (zeroed) {
- printf(_("%s: skipped %d zeroed blocks in range: %lld - %lld\n"),
- progname, zeroed,
- (long long)(zeroed_blkno),
- (long long)(zeroed + zeroed_blkno - 1));
- if (zeroed == logBBsize)
- printf(_("%s: totally zeroed log\n"), progname);
-
- zeroed=0;
- }
- printf(_("%s: physical end of log\n"), progname);
- print_xlog_record_line();
- break;
+ if (blkno >= logBBsize) {
+ if (cleared) {
+ printf(_("%s: skipped %d cleared blocks in range: %lld - %lld\n"),
+ progname, cleared,
+ (long long)(cleared_blkno),
+ (long long)(cleared + cleared_blkno - 1));
+ if (cleared == logBBsize)
+ printf(_("%s: totally cleared log\n"), progname);
+ cleared = 0;
+ }
+ if (zeroed) {
+ printf(_("%s: skipped %d zeroed blocks in range: %lld - %lld\n"),
+ progname, zeroed,
+ (long long)(zeroed_blkno),
+ (long long)(zeroed + zeroed_blkno - 1));
+ if (zeroed == logBBsize)
+ printf(_("%s: totally zeroed log\n"), progname);
+ zeroed = 0;
+ }
+ printf(_("%s: physical end of log\n"), progname);
+ print_xlog_record_line();
+ break;
+ }
}
- }
- /* Do we need to print the first part of physical log? */
- if (block_start != 0) {
- blkno = 0;
- xlog_print_lseek(log, fd, 0, SEEK_SET);
- for (;;) {
- if (read(fd, hbuf, 512) == 0) {
- xlog_panic(_("xlog_find_head: bad read"));
- }
- if (print_only_data) {
- printf(_("BLKNO: %lld\n"), (long long)blkno);
- xlog_recover_print_data(hbuf, 512);
- blkno++;
- goto loop2;
- }
- num_ops = xlog_print_rec_head(hdr, &len, first_hdr_found);
- blkno++;
-
- if (num_ops == ZEROED_LOG ||
- num_ops == CLEARED_BLKS ||
- num_ops == BAD_HEADER) {
- /* we only expect zeroed log entries or cleared log
- * entries at the end of the _physical_ log,
- * so treat them the same as bad blocks here
- */
- print_xlog_bad_header(blkno-1, hbuf);
-
- if (blkno >= block_end)
- break;
- continue;
- }
-
- if (be32_to_cpu(hdr->h_version) == 2) {
- if (xlog_print_extended_headers(fd, len, &blkno, hdr, &num_hdrs, &xhdrs) != 0)
- break;
- }
+ /* Do we need to print the first part of physical log? */
+ if (block_start != 0) {
+ blkno = 0;
+ xlog_print_lseek(log, fd, 0, SEEK_SET);
+ for (;;) {
+ if (read(fd, hbuf, 512) == 0)
+ xlog_panic(_("xlog_find_head: bad read"));
+
+ if (print_only_data) {
+ printf(_("BLKNO: %lld\n"), (long long)blkno);
+ xlog_recover_print_data(hbuf, 512);
+ blkno++;
+ goto loop2;
+ }
+ num_ops = xlog_print_rec_head(hdr, &len,
+ first_hdr_found);
+ blkno++;
+
+ if (num_ops == ZEROED_LOG ||
+ num_ops == CLEARED_BLKS ||
+ num_ops == BAD_HEADER) {
+ /*
+ * We only expect zeroed log entries or cleared
+ * log entries at the end of the _physical_ log,
+ * so treat them the same as bad blocks here.
+ */
+ print_xlog_bad_header(blkno-1, hbuf);
+ if (blkno >= block_end)
+ break;
+ continue;
+ }
+
+ if (be32_to_cpu(hdr->h_version) == 2 &&
+ xlog_print_extended_headers(fd, len, &blkno, hdr,
+ &num_hdrs, &xhdrs) != 0)
+ break;
partial_log_read:
- error= xlog_print_record(log, fd, num_ops, len, &read_type,
- &partial_buf, (xlog_rec_header_t *)hbuf,
- xhdrs, first_hdr_found);
- if (read_type != FULL_READ)
- len -= read_type;
- read_type = FULL_READ;
- if (!error)
- blkno += BTOBB(len);
- else {
- print_xlog_bad_data(blkno-1);
- xlog_print_lseek(log, fd, blkno, SEEK_SET);
- goto loop2;
- }
- print_xlog_record_line();
+ error = xlog_print_record(log, fd, num_ops, len,
+ &read_type, &partial_buf,
+ (struct xlog_rec_header *)hbuf,
+ xhdrs, first_hdr_found);
+ if (read_type != FULL_READ)
+ len -= read_type;
+ read_type = FULL_READ;
+ if (error) {
+ print_xlog_bad_data(blkno - 1);
+ xlog_print_lseek(log, fd, blkno, SEEK_SET);
+ goto loop2;
+ }
+ blkno += BTOBB(len);
+ print_xlog_record_line();
loop2:
- if (blkno >= block_end)
- break;
+ if (blkno >= block_end)
+ break;
+ }
}
- }
end:
- printf(_("%s: logical end of log\n"), progname);
- print_xlog_record_line();
+ printf(_("%s: logical end of log\n"), progname);
+ print_xlog_record_line();
}
--
2.47.3
^ permalink raw reply related [flat|nested] 34+ messages in thread* Re: logprint cleanups, part1
2025-11-28 6:29 logprint cleanups, part1 Christoph Hellwig
` (24 preceding siblings ...)
2025-11-28 6:30 ` [PATCH 25/25] logprint: cleanup xfs_log_print Christoph Hellwig
@ 2025-12-01 19:03 ` Andrey Albershteyn
2025-12-02 7:29 ` Christoph Hellwig
25 siblings, 1 reply; 34+ messages in thread
From: Andrey Albershteyn @ 2025-12-01 19:03 UTC (permalink / raw)
To: Christoph Hellwig; +Cc: Andrey Albershteyn, linux-xfs
On 2025-11-28 07:29:37, Christoph Hellwig wrote:
> Hi all,
>
> I started to look at the userspace part of my war on struct typedefs,
> and while starting on logprint I got really annyoed with the quality
> of the code.
>
> This series touches to the log_misc.c code to cleanup the typedefs,
> switch to standard formatting, and do various other low-effort and
> mechanical cleanups.
>
> I have similar patches for the rest of logprint (which isn't quite
> as bad), as well as ideas and prototypes for some more substantial
> work. As this will be a lot of patches I'll try to split them into
> batches.
>
>
this one looks good for me, with a few nits I found, I can fix them
while applying, let me know if that's good
Reviewed-by: Andrey Albershteyn <aalbersh@kernel.org>
--
- Andrey
^ permalink raw reply [flat|nested] 34+ messages in thread* Re: logprint cleanups, part1
2025-12-01 19:03 ` logprint cleanups, part1 Andrey Albershteyn
@ 2025-12-02 7:29 ` Christoph Hellwig
0 siblings, 0 replies; 34+ messages in thread
From: Christoph Hellwig @ 2025-12-02 7:29 UTC (permalink / raw)
To: Andrey Albershteyn; +Cc: Christoph Hellwig, Andrey Albershteyn, linux-xfs
On Mon, Dec 01, 2025 at 08:03:24PM +0100, Andrey Albershteyn wrote:
> > I have similar patches for the rest of logprint (which isn't quite
> > as bad), as well as ideas and prototypes for some more substantial
> > work. As this will be a lot of patches I'll try to split them into
> > batches.
> >
> >
>
> this one looks good for me, with a few nits I found, I can fix them
> while applying, let me know if that's good
If that's fine for you go ahead, otherwise I'd be happy to resend.
^ permalink raw reply [flat|nested] 34+ messages in thread