public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: Andrey Albershteyn <aalbersh@kernel.org>
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 16/25] logprint: factor out a xlog_print_op helper
Date: Fri, 28 Nov 2025 07:29:53 +0100	[thread overview]
Message-ID: <20251128063007.1495036-17-hch@lst.de> (raw)
In-Reply-To: <20251128063007.1495036-1-hch@lst.de>

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


  parent reply	other threads:[~2025-11-28  6:32 UTC|newest]

Thread overview: 34+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 ` [PATCH 03/25] logprint: re-indent printing helpers Christoph Hellwig
2025-11-28  6:29 ` [PATCH 04/25] logprint: cleanup xlog_print_op_header Christoph Hellwig
2025-11-28  6:29 ` [PATCH 05/25] logprint: cleanup struct xlog_split_item handling Christoph Hellwig
2025-11-28  6:29 ` [PATCH 06/25] logprint: cleanup xlog_print_trans_header Christoph Hellwig
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 ` [PATCH 08/25] logprint: cleanup xlog_print_trans_buffer Christoph Hellwig
2025-11-28  6:29 ` [PATCH 09/25] logprint: cleanup xlog_print_trans_qoff Christoph Hellwig
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
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
2025-11-28  6:29 ` [PATCH 12/25] logprint: cleanup xlog_print_trans_inode Christoph Hellwig
2025-11-28  6:29 ` [PATCH 13/25] logprint: cleanup xlog_print_trans_dquot Christoph Hellwig
2025-11-28  6:29 ` [PATCH 14/25] logprint: re-indent print_lseek / print_lsn Christoph Hellwig
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 [this message]
2025-12-01 18:44   ` [PATCH 16/25] logprint: factor out a xlog_print_op helper Andrey Albershteyn
2025-12-02  7:29     ` Christoph Hellwig
2025-11-28  6:29 ` [PATCH 17/25] logprint: factor out a xlog_unpack_rec_header Christoph Hellwig
2025-11-28  6:29 ` [PATCH 18/25] logprint: cleanup xlog_print_record Christoph Hellwig
2025-11-28  6:29 ` [PATCH 19/25] logprint: cleanup xlog_print_rec_head Christoph Hellwig
2025-11-28  6:29 ` [PATCH 20/25] logprint: cleanup xlog_print_rec_xhead Christoph Hellwig
2025-11-28  6:29 ` [PATCH 21/25] logprint: re-indent print_xlog_bad_* Christoph Hellwig
2025-11-28  6:29 ` [PATCH 22/25] logprint: cleanup xlog_reallocate_xhdrs Christoph Hellwig
2025-11-28  6:30 ` [PATCH 23/25] logprint: factor out a xlog_print_ext_header helper Christoph Hellwig
2025-11-28  6:30 ` [PATCH 24/25] logprint: cleanup xlog_print_extended_headers 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
2025-12-02  7:29   ` Christoph Hellwig

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=20251128063007.1495036-17-hch@lst.de \
    --to=hch@lst.de \
    --cc=aalbersh@kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /path/to/YOUR_REPLY

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

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox