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 25/25] logprint: cleanup xfs_log_print
Date: Fri, 28 Nov 2025 07:30:02 +0100	[thread overview]
Message-ID: <20251128063007.1495036-26-hch@lst.de> (raw)
In-Reply-To: <20251128063007.1495036-1-hch@lst.de>

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


  parent reply	other threads:[~2025-11-28  6:33 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 ` [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
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 ` Christoph Hellwig [this message]
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-26-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