From: Christoph Hellwig <hch@lst.de>
To: Andrey Albershteyn <aalbersh@kernel.org>
Cc: linux-xfs@vger.kernel.org
Subject: [PATCH 18/25] logprint: cleanup xlog_print_record
Date: Fri, 28 Nov 2025 07:29:55 +0100 [thread overview]
Message-ID: <20251128063007.1495036-19-hch@lst.de> (raw)
In-Reply-To: <20251128063007.1495036-1-hch@lst.de>
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
next prev 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 ` [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 ` Christoph Hellwig [this message]
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-19-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