linux-xfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Darrick J. Wong" <djwong@kernel.org>
To: djwong@kernel.org
Cc: allison.henderson@oracle.com, linux-xfs@vger.kernel.org
Subject: [PATCH 1/4] xfs: revert "xfsprogs: Print pptrs in ATTRI items"
Date: Thu, 16 Mar 2023 12:32:08 -0700	[thread overview]
Message-ID: <167899416806.17000.4113016671170150035.stgit@frogsfrogsfrogs> (raw)
In-Reply-To: <167899416793.17000.8105050564560343480.stgit@frogsfrogsfrogs>

From: Darrick J. Wong <djwong@kernel.org>

Parent pointers are stored inside extended attributes, which means that
they're a higher level data structure.  logprint shouldn't be reporting
parent pointers as "ATTRI" items, so let's replace all that with proper
helpers that will decode a parent pointer xattri log item.

But first, get rid of all this code that adds a bunch of repetitive
logic and unnecessary heap allocations.

Signed-off-by: Darrick J. Wong <djwong@kernel.org>
---
 logprint/log_redo.c |  193 ++++++---------------------------------------------
 logprint/logprint.h |    5 +
 2 files changed, 26 insertions(+), 172 deletions(-)


diff --git a/logprint/log_redo.c b/logprint/log_redo.c
index f7e9c9ad9..b596af02c 100644
--- a/logprint/log_redo.c
+++ b/logprint/log_redo.c
@@ -674,31 +674,6 @@ xfs_attri_copy_log_format(
 	return 1;
 }
 
-/* iovec length must be 32-bit aligned */
-static inline size_t ATTR_NVEC_SIZE(size_t size)
-{
-	return round_up(size, sizeof(int32_t));
-}
-
-static int
-xfs_attri_copy_name_format(
-	char                            *buf,
-	uint                            len,
-	struct xfs_parent_name_rec     *dst_attri_fmt)
-{
-	uint dst_len = ATTR_NVEC_SIZE(sizeof(struct xfs_parent_name_rec));
-
-	if (len == dst_len) {
-		memcpy((char *)dst_attri_fmt, buf, len);
-		return 0;
-	}
-
-	fprintf(stderr, _("%s: bad size of attri name format: %u; expected %u\n"),
-		progname, len, dst_len);
-
-	return 1;
-}
-
 int
 xlog_print_trans_attri(
 	char				**ptr,
@@ -739,8 +714,7 @@ xlog_print_trans_attri(
 		(*i)++;
 		head = (xlog_op_header_t *)*ptr;
 		xlog_print_op_header(head, *i, ptr);
-		error = xlog_print_trans_attri_name(ptr, be32_to_cpu(head->oh_len),
-						    src_f->alfi_attr_filter);
+		error = xlog_print_trans_attri_name(ptr, be32_to_cpu(head->oh_len));
 		if (error)
 			goto error;
 	}
@@ -750,8 +724,7 @@ xlog_print_trans_attri(
 		(*i)++;
 		head = (xlog_op_header_t *)*ptr;
 		xlog_print_op_header(head, *i, ptr);
-		error = xlog_print_trans_attri_name(ptr, be32_to_cpu(head->oh_len),
-						    src_f->alfi_attr_filter);
+		error = xlog_print_trans_attri_name(ptr, be32_to_cpu(head->oh_len));
 		if (error)
 			goto error;
 	}
@@ -762,7 +735,7 @@ xlog_print_trans_attri(
 		head = (xlog_op_header_t *)*ptr;
 		xlog_print_op_header(head, *i, ptr);
 		error = xlog_print_trans_attri_value(ptr, be32_to_cpu(head->oh_len),
-				src_f->alfi_value_len, src_f->alfi_attr_filter);
+				src_f->alfi_value_len);
 	}
 error:
 	free(src_f);
@@ -773,45 +746,13 @@ xlog_print_trans_attri(
 int
 xlog_print_trans_attri_name(
 	char				**ptr,
-	uint				src_len,
-	uint				attr_flags)
+	uint				src_len)
 {
-	struct xfs_parent_name_rec	*src_f = NULL;
-	uint				dst_len;
+	printf(_("ATTRI:  name len:%u\n"), src_len);
+	print_or_dump(*ptr, src_len);
 
-	/*
-	 * If this is not a parent pointer, just do a bin dump
-	 */
-	if (!(attr_flags & XFS_ATTR_PARENT)) {
-		printf(_("ATTRI:  name len:%u\n"), src_len);
-		print_or_dump(*ptr, src_len);
-		goto out;
-	}
-
-	dst_len	= ATTR_NVEC_SIZE(sizeof(struct xfs_parent_name_rec));
-	if (dst_len != src_len) {
-		fprintf(stderr, _("%s: bad size of attri name format: %u; expected %u\n"),
-			progname, src_len, dst_len);
-		return 1;
-	}
-
-	/*
-	 * memmove to ensure 8-byte alignment for the long longs in
-	 * xfs_parent_name_rec structure
-	 */
-	if ((src_f = (struct xfs_parent_name_rec *)malloc(src_len)) == NULL) {
-		fprintf(stderr, _("%s: xlog_print_trans_attri_name: malloc failed\n"), progname);
-		exit(1);
-	}
-	memmove((char*)src_f, *ptr, src_len);
-
-	printf(_("ATTRI:  #p_ino: %llu	p_gen: %u, p_diroffset: %u\n"),
-		be64_to_cpu(src_f->p_ino), be32_to_cpu(src_f->p_gen),
-				be32_to_cpu(src_f->p_diroffset));
-
-	free(src_f);
-out:
 	*ptr += src_len;
+
 	return 0;
 }	/* xlog_print_trans_attri */
 
@@ -819,32 +760,15 @@ int
 xlog_print_trans_attri_value(
 	char				**ptr,
 	uint				src_len,
-	int				value_len,
-	uint				attr_flags)
+	int				value_len)
 {
 	int len = min(value_len, src_len);
-	char				*f = NULL;
 
-	/*
-	 * If this is not a parent pointer, just do a bin dump
-	 */
-	if (!(attr_flags & XFS_ATTR_PARENT)) {
-		printf(_("ATTRI:  value len:%u\n"), value_len);
-		print_or_dump(*ptr, min(len, MAX_ATTR_VAL_PRINT));
-		goto out;
-	}
+	printf(_("ATTRI:  value len:%u\n"), value_len);
+	print_or_dump(*ptr, len);
 
-	if ((f = (char *)malloc(src_len)) == NULL) {
-		fprintf(stderr, _("%s: xlog_print_trans_attri: malloc failed\n"), progname);
-		exit(1);
-	}
-
-	memcpy(f, *ptr, value_len);
-	printf(_("ATTRI:  value: %.*s\n"), value_len, f);
-
-	free(f);
-out:
 	*ptr += src_len;
+
 	return 0;
 }	/* xlog_print_trans_attri_value */
 
@@ -855,9 +779,6 @@ xlog_recover_print_attri(
 	struct xfs_attri_log_format	*f, *src_f = NULL;
 	uint				src_len, dst_len;
 
-	struct xfs_parent_name_rec 	*rec, *src_rec = NULL;
-	char				*value, *src_value = NULL;
-
 	int				region = 0;
 
 	src_f = (struct xfs_attri_log_format *)item->ri_buf[0].i_addr;
@@ -882,93 +803,27 @@ xlog_recover_print_attri(
 
 	if (f->alfi_name_len > 0) {
 		region++;
-
-		if (f->alfi_attr_filter & XFS_ATTR_PARENT) {
-			src_rec = (struct xfs_parent_name_rec *)item->ri_buf[region].i_addr;
-			src_len = item->ri_buf[region].i_len;
-
-			dst_len = ATTR_NVEC_SIZE(sizeof(struct xfs_parent_name_rec));
-
-			if ((rec = ((struct xfs_parent_name_rec *)malloc(dst_len))) == NULL) {
-				fprintf(stderr, _("%s: xlog_recover_print_attri: malloc failed\n"),
-					progname);
-				exit(1);
-			}
-			if (xfs_attri_copy_name_format((char *)src_rec, src_len, rec)) {
-				goto out;
-			}
-
-			printf(_("ATTRI:  #inode: %llu     gen: %u, offset: %u\n"),
-				be64_to_cpu(rec->p_ino), be32_to_cpu(rec->p_gen),
-				be32_to_cpu(rec->p_diroffset));
-
-			free(rec);
-		}
-		else {
-			printf(_("ATTRI:  name len:%u\n"), f->alfi_name_len);
-			print_or_dump((char *)item->ri_buf[region].i_addr,
-					f->alfi_name_len);
-		}
+		printf(_("ATTRI:  name len:%u\n"), f->alfi_name_len);
+		print_or_dump((char *)item->ri_buf[region].i_addr,
+			       f->alfi_name_len);
 	}
 
 	if (f->alfi_nname_len > 0) {
 		region++;
-
-		if (f->alfi_attr_filter & XFS_ATTR_PARENT) {
-			src_rec = (struct xfs_parent_name_rec *)item->ri_buf[region].i_addr;
-			src_len = item->ri_buf[region].i_len;
-
-			dst_len = ATTR_NVEC_SIZE(sizeof(struct xfs_parent_name_rec));
-
-			if ((rec = ((struct xfs_parent_name_rec *)malloc(dst_len))) == NULL) {
-				fprintf(stderr, _("%s: xlog_recover_print_attri: malloc failed\n"),
-					progname);
-				exit(1);
-			}
-			if (xfs_attri_copy_name_format((char *)src_rec, src_len, rec)) {
-				goto out;
-			}
-
-			printf(_("ATTRI:  new #inode: %llu     gen: %u, offset: %u\n"),
-				be64_to_cpu(rec->p_ino), be32_to_cpu(rec->p_gen),
-				be32_to_cpu(rec->p_diroffset));
-
-			free(rec);
-		}
-		else {
-			printf(_("ATTRI:  nname len:%u\n"), f->alfi_nname_len);
-			print_or_dump((char *)item->ri_buf[region].i_addr,
-				       f->alfi_nname_len);
-		}
+		printf(_("ATTRI:  nname len:%u\n"), f->alfi_nname_len);
+		print_or_dump((char *)item->ri_buf[region].i_addr,
+			       f->alfi_nname_len);
 	}
 
 	if (f->alfi_value_len > 0) {
+		int len = f->alfi_value_len;
+
+		if (len > MAX_ATTR_VAL_PRINT)
+			len = MAX_ATTR_VAL_PRINT;
+
 		region++;
-
-		if (f->alfi_attr_filter & XFS_ATTR_PARENT) {
-			src_value = (char *)item->ri_buf[region].i_addr;
-
-			if ((value = ((char *)malloc(f->alfi_value_len))) == NULL) {
-				fprintf(stderr, _("%s: xlog_recover_print_attri: malloc failed\n"),
-					progname);
-				exit(1);
-			}
-
-			memcpy((char *)value, (char *)src_value, f->alfi_value_len);
-			printf("ATTRI:  value: %.*s\n", f->alfi_value_len, value);
-
-			free(value);
-		}
-		else {
-			int len = f->alfi_value_len;
-
-			if (len > MAX_ATTR_VAL_PRINT)
-				len = MAX_ATTR_VAL_PRINT;
-
-			printf(_("ATTRI:  value len:%u\n"), f->alfi_value_len);
-			print_or_dump((char *)item->ri_buf[region].i_addr,
-					len);
-		}
+		printf(_("ATTRI:  value len:%u\n"), f->alfi_value_len);
+		print_or_dump((char *)item->ri_buf[region].i_addr, len);
 	}
 
 out:
diff --git a/logprint/logprint.h b/logprint/logprint.h
index b8e1c9328..b4479c240 100644
--- a/logprint/logprint.h
+++ b/logprint/logprint.h
@@ -59,9 +59,8 @@ extern void xlog_recover_print_bud(struct xlog_recover_item *item);
 #define MAX_ATTR_VAL_PRINT	128
 
 extern int xlog_print_trans_attri(char **ptr, uint src_len, int *i);
-extern int xlog_print_trans_attri_name(char **ptr, uint src_len, uint attr_flags);
-extern int xlog_print_trans_attri_value(char **ptr, uint src_len, int value_len,
-					uint attr_flags);
+extern int xlog_print_trans_attri_name(char **ptr, uint src_len);
+extern int xlog_print_trans_attri_value(char **ptr, uint src_len, int value_len);
 extern void xlog_recover_print_attri(struct xlog_recover_item *item);
 extern int xlog_print_trans_attrd(char **ptr, uint len);
 extern void xlog_recover_print_attrd(struct xlog_recover_item *item);


  reply	other threads:[~2023-03-16 19:32 UTC|newest]

Thread overview: 94+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-16 18:54 [RFC DELUGE v10r1d2] xfs: Parent Pointers Darrick J. Wong
2023-03-16 19:17 ` [PATCHSET v10r1d2 0/7] xfs: bug fixes for parent pointers Darrick J. Wong
2023-03-16 19:19   ` [PATCH 1/7] xfs: validate parent pointer xattrs in getparent Darrick J. Wong
2023-03-16 19:20   ` [PATCH 2/7] xfs: rename xfs_pptr_info to xfs_getparents Darrick J. Wong
2023-03-16 19:20   ` [PATCH 3/7] xfs: rename xfs_parent_ptr Darrick J. Wong
2023-03-16 19:20   ` [PATCH 4/7] xfs: fix GETPARENTS ioctl Darrick J. Wong
2023-03-16 19:20   ` [PATCH 5/7] xfs: add tracing to the " Darrick J. Wong
2023-03-16 19:21   ` [PATCH 6/7] xfs: shorten parent pointer function names Darrick J. Wong
2023-03-16 19:21   ` [PATCH 7/7] xfs: rearrange bits of the parent pointer apis for fsck Darrick J. Wong
2023-03-16 19:17 ` [PATCHSET v10r1d2 00/17] xfs: encode parent pointer name in xattr key Darrick J. Wong
2023-03-16 19:21   ` [PATCH 01/17] xfs: document the ri_total validation in xlog_recover_attri_commit_pass2 Darrick J. Wong
2023-03-16 19:22   ` [PATCH 02/17] xfs: make xfs_attr_set require XFS_DA_OP_REMOVE Darrick J. Wong
2023-03-16 19:22   ` [PATCH 03/17] xfs: allow xattr matching on value for local/sf attrs Darrick J. Wong
2023-03-16 19:22   ` [PATCH 04/17] xfs: preserve VLOOKUP in xfs_attr_set Darrick J. Wong
2023-03-16 19:22   ` [PATCH 05/17] xfs: restructure xfs_attr_complete_op a bit Darrick J. Wong
2023-03-16 19:23   ` [PATCH 06/17] xfs: use helpers to extract xattr op from opflags Darrick J. Wong
2023-03-16 19:23   ` [PATCH 07/17] xfs: validate recovered name buffers when recovering xattr items Darrick J. Wong
2023-03-16 19:23   ` [PATCH 08/17] xfs: always set args->value in xfs_attri_item_recover Darrick J. Wong
2023-03-16 19:23   ` [PATCH 09/17] xfs: flip nvreplace detection in xfs_attr_complete_op Darrick J. Wong
2023-03-16 19:24   ` [PATCH 10/17] xfs: log VLOOKUP xattr removal operations Darrick J. Wong
2023-03-16 19:24   ` [PATCH 11/17] xfs: log VLOOKUP xattr setting operations Darrick J. Wong
2023-03-16 19:24   ` [PATCH 12/17] xfs: overlay alfi_nname_len atop alfi_name_len for NVREPLACE Darrick J. Wong
2023-03-16 19:24   ` [PATCH 13/17] xfs: refactor value length in xlog_recover_attri_commit_pass2 Darrick J. Wong
2023-03-16 19:25   ` [PATCH 14/17] xfs: rename nname to newname Darrick J. Wong
2023-03-16 19:25   ` [PATCH 15/17] xfs: log VLOOKUP xattr nvreplace operations Darrick J. Wong
2023-03-16 19:25   ` [PATCH 16/17] xfs: log new xattr values for NVREPLACEXXX operations Darrick J. Wong
2023-03-16 19:25   ` [PATCH 17/17] xfs: replace parent pointer diroffset with full dirent name Darrick J. Wong
2023-03-24 17:10   ` [PATCHSET v10r1d2 00/17] xfs: encode parent pointer name in xattr key Allison Henderson
2023-03-25  7:59     ` Amir Goldstein
2023-03-25 17:01       ` Darrick J. Wong
2023-03-26  3:21         ` Amir Goldstein
2023-03-28  1:29           ` Darrick J. Wong
2023-03-28  7:21             ` Amir Goldstein
2023-03-28 22:29             ` Dave Chinner
2023-03-28 23:54               ` Darrick J. Wong
2023-03-29  0:19                 ` Dave Chinner
2023-03-29  0:46                   ` Darrick J. Wong
2023-03-30  1:56                     ` Darrick J. Wong
2023-03-25 17:03     ` Darrick J. Wong
2023-03-16 19:17 ` [PATCHSET v10r1d2 0/9] xfsprogs: tool fixes for parent pointers Darrick J. Wong
2023-03-16 19:26   ` [PATCH 1/9] libxfs: initialize the slab cache for parent defer items Darrick J. Wong
2023-03-16 19:26   ` [PATCH 2/9] mkfs: fix libxfs api misuse Darrick J. Wong
2023-03-16 19:26   ` [PATCH 3/9] libxfs: create new files with attr forks if necessary Darrick J. Wong
2023-03-16 19:26   ` [PATCH 4/9] mkfs: fix subdir parent pointer creation Darrick J. Wong
2023-03-16 19:27   ` [PATCH 5/9] xfs_db: report parent pointer keys Darrick J. Wong
2023-03-16 19:27   ` [PATCH 6/9] xfs_db: obfuscate dirent and pptr names consistently Darrick J. Wong
2023-03-16 19:27   ` [PATCH 7/9] xfs_io: print path in path_print Darrick J. Wong
2023-03-16 19:27   ` [PATCH 8/9] xfs_io: parent command is not experts-only Darrick J. Wong
2023-03-16 19:28   ` [PATCH 9/9] xfs_repair: fix incorrect dabtree hashval comparison Darrick J. Wong
2023-03-16 19:18 ` [PATCHSET v10r1d2 0/2] xfsprogs: actually use getparent ioctl Darrick J. Wong
2023-03-16 19:28   ` [PATCH 1/2] xfs_scrub: revert unnecessary code from "implement the upper half of parent pointers" Darrick J. Wong
2023-03-16 19:28   ` [PATCH 2/2] xfs_scrub: use parent pointers when possible to report file operations Darrick J. Wong
2023-03-16 19:18 ` [PATCHSET v10r1d2 0/7] libfrog: fix parent pointer library code Darrick J. Wong
2023-03-16 19:29   ` [PATCH 1/7] xfs_io: move parent pointer filtering and formatting flags out of libhandle Darrick J. Wong
2023-03-16 19:29   ` [PATCH 2/7] libfrog: remove all the parent pointer code from libhandle Darrick J. Wong
2023-03-16 19:29   ` [PATCH 3/7] libfrog: fix indenting errors in xfss_pptr_alloc Darrick J. Wong
2023-03-16 19:29   ` [PATCH 4/7] libfrog: return positive errno in pptrs.c Darrick J. Wong
2023-03-16 19:30   ` [PATCH 5/7] libfrog: only walk one parent pointer at a time in handle_walk_parent_path_ptr Darrick J. Wong
2023-03-16 19:30   ` [PATCH 6/7] libfrog: trim trailing slashes when printing pptr paths Darrick J. Wong
2023-03-16 19:30   ` [PATCH 7/7] libfrog: fix a buffer overrun in path_list_to_string Darrick J. Wong
2023-03-16 19:18 ` [PATCHSET v10r1d2 0/5] xfsprogs: bug fixes for parent pointers Darrick J. Wong
2023-03-16 19:30   ` [PATCH 1/5] xfs: rename xfs_pptr_info to xfs_getparents Darrick J. Wong
2023-03-16 19:31   ` [PATCH 2/5] xfs: rename xfs_parent_ptr Darrick J. Wong
2023-03-16 19:31   ` [PATCH 3/5] xfs: fix GETPARENTS ioctl Darrick J. Wong
2023-03-16 19:31   ` [PATCH 4/5] xfs: shorten parent pointer function names Darrick J. Wong
2023-03-16 19:31   ` [PATCH 5/5] xfs: rearrange bits of the parent pointer apis for fsck Darrick J. Wong
2023-03-16 19:18 ` [PATCHSET v10r1d2 0/4] xfs_logprint: clean up attri/pptr dumping Darrick J. Wong
2023-03-16 19:32   ` Darrick J. Wong [this message]
2023-03-16 19:32   ` [PATCH 2/4] xfs_logprint: print missing attri header fields Darrick J. Wong
2023-03-16 19:32   ` [PATCH 3/4] xfs: make logprint note attr names and newnames consistently Darrick J. Wong
2023-03-16 19:32   ` [PATCH 4/4] xfs_logprint: decode parent pointers fully Darrick J. Wong
2023-03-16 19:19 ` [PATCHSET v10r1d2 00/14] fstests: adjust tests for xfs parent pointers Darrick J. Wong
2023-03-16 19:33   ` [PATCH 01/14] xfs/122: update for " Darrick J. Wong
2023-03-16 19:33   ` [PATCH 02/14] populate: create hardlinks " Darrick J. Wong
2023-03-16 19:33   ` [PATCH 03/14] xfs/021: adapt golden output files " Darrick J. Wong
2023-03-16 19:33   ` [PATCH 04/14] generic/050: adapt " Darrick J. Wong
2023-03-16 19:34   ` [PATCH 05/14] xfs/018: disable parent pointers for this test Darrick J. Wong
2023-03-16 19:34   ` [PATCH 06/14] xfs/306: fix formatting failures with parent pointers Darrick J. Wong
2023-03-16 19:34   ` [PATCH 07/14] common: add helpers for parent pointer tests Darrick J. Wong
2023-03-16 19:35   ` [PATCH 08/14] xfs: add parent pointer test Darrick J. Wong
2023-03-16 19:35   ` [PATCH 09/14] xfs: add multi link " Darrick J. Wong
2023-03-16 19:35   ` [PATCH 10/14] xfs: add parent pointer inject test Darrick J. Wong
2023-03-16 19:35   ` [PATCH 11/14] common/parent: add license and copyright Darrick J. Wong
2023-03-16 19:36   ` [PATCH 12/14] common/parent: don't _fail on missing parent pointer components Darrick J. Wong
2023-03-16 19:36   ` [PATCH 13/14] common/parent: check xfs_io parent command paths Darrick J. Wong
2023-03-16 19:36   ` [PATCH 14/14] xfs/851: test xfs_io parent -p too Darrick J. Wong
2023-03-16 19:19 ` [PATCHSET v10r1d2 0/1] xfs: bug fixes for parent pointers Darrick J. Wong
2023-03-16 19:36   ` [PATCH 1/1] xfs/122: fix parent pointer ioctl structure sizes Darrick J. Wong
2023-03-16 19:19 ` [PATCHSET v10r1d2 0/1] fstests: encode parent pointer name in xattr key Darrick J. Wong
2023-03-16 19:37   ` [PATCH 1/1] xfs/{021,122}: adjust parent pointer encoding format Darrick J. Wong
2023-03-17 19:06 ` [RFC DELUGE v10r1d2] xfs: Parent Pointers Allison Henderson
2023-03-17 23:45   ` Darrick J. Wong
2023-03-21 21:14     ` Allison Henderson
2023-03-25 17:02       ` Darrick J. Wong

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=167899416806.17000.4113016671170150035.stgit@frogsfrogsfrogs \
    --to=djwong@kernel.org \
    --cc=allison.henderson@oracle.com \
    --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;
as well as URLs for NNTP newsgroup(s).