All of lore.kernel.org
 help / color / mirror / Atom feed
From: allison.henderson@oracle.com
To: linux-xfs@vger.kernel.org
Subject: [PATCH v5 22/25] xfsprogs: Print pptrs in ATTRI items
Date: Thu, 10 Nov 2022 14:05:24 -0700	[thread overview]
Message-ID: <20221110210527.56628-23-allison.henderson@oracle.com> (raw)
In-Reply-To: <20221110210527.56628-1-allison.henderson@oracle.com>

From: Allison Henderson <allison.henderson@oracle.com>

This patch modifies the ATTRI print routines to look for the parent pointer flag,
and print the log entry name as a parent pointer name record.  Values are printed as
strings since they contain the file name.

Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
---
 logprint/log_redo.c | 191 ++++++++++++++++++++++++++++++++++++++------
 logprint/logprint.h |   5 +-
 2 files changed, 171 insertions(+), 25 deletions(-)

diff --git a/logprint/log_redo.c b/logprint/log_redo.c
index 65d365d8f02f..015df0bf02f2 100644
--- a/logprint/log_redo.c
+++ b/logprint/log_redo.c
@@ -674,6 +674,31 @@ 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,
@@ -714,7 +739,8 @@ 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));
+		error = xlog_print_trans_attri_name(ptr, be32_to_cpu(head->oh_len),
+						    src_f->alfi_attr_filter);
 		if (error)
 			goto error;
 	}
@@ -724,7 +750,8 @@ 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));
+		error = xlog_print_trans_attri_name(ptr, be32_to_cpu(head->oh_len),
+						    src_f->alfi_attr_filter);
 		if (error)
 			goto error;
 	}
@@ -735,7 +762,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_value_len, src_f->alfi_attr_filter);
 	}
 error:
 	free(src_f);
@@ -746,13 +773,45 @@ error:
 int
 xlog_print_trans_attri_name(
 	char				**ptr,
-	uint				src_len)
+	uint				src_len,
+	uint				attr_flags)
 {
-	printf(_("ATTRI:  name len:%u\n"), src_len);
-	print_or_dump(*ptr, src_len);
+	struct xfs_parent_name_rec	*src_f = NULL;
+	uint				dst_len;
 
-	*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 */
 
@@ -760,15 +819,32 @@ int
 xlog_print_trans_attri_value(
 	char				**ptr,
 	uint				src_len,
-	int				value_len)
+	int				value_len,
+	uint				attr_flags)
 {
 	int len = min(value_len, src_len);
+	char				*f = NULL;
 
-	printf(_("ATTRI:  value len:%u\n"), value_len);
-	print_or_dump(*ptr, len);
+	/*
+	 * 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;
+	}
 
-	*ptr += src_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 */
 
@@ -779,6 +855,9 @@ 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;
@@ -803,27 +882,93 @@ xlog_recover_print_attri(
 
 	if (f->alfi_name_len > 0) {
 		region++;
-		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_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);
+		}
 	}
 
 	if (f->alfi_nname_len > 0) {
 		region++;
-		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_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);
+		}
 	}
 
 	if (f->alfi_value_len > 0) {
-		int len = f->alfi_value_len;
+		region++;
 
-		if (len > MAX_ATTR_VAL_PRINT)
-			len = MAX_ATTR_VAL_PRINT;
+		if (f->alfi_attr_filter & XFS_ATTR_PARENT) {
+			src_value = (char *)item->ri_buf[region].i_addr;
 
-		region++;
-		printf(_("ATTRI:  value len:%u\n"), f->alfi_value_len);
-		print_or_dump((char *)item->ri_buf[region].i_addr, len);
+			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);
+		}
 	}
 
 out:
diff --git a/logprint/logprint.h b/logprint/logprint.h
index b4479c240d94..b8e1c9328ce3 100644
--- a/logprint/logprint.h
+++ b/logprint/logprint.h
@@ -59,8 +59,9 @@ 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);
-extern int xlog_print_trans_attri_value(char **ptr, uint src_len, int value_len);
+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 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);
-- 
2.25.1


  parent reply	other threads:[~2022-11-10 21:07 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-10 21:05 [PATCH v5 00/25] xfsprogs: parent pointers for v5 allison.henderson
2022-11-10 21:05 ` [PATCH v5 01/25] xfsprogs: Fix default superblock attr bits allison.henderson
2022-11-10 21:05 ` [PATCH v5 02/25] xfsprogs: Add new name to attri/d allison.henderson
2022-11-10 21:05 ` [PATCH v5 03/25] xfsprogs: Increase XFS_DEFER_OPS_NR_INODES to 5 allison.henderson
2022-11-10 21:05 ` [PATCH v5 04/25] xfsprogs: get directory offset when adding directory name allison.henderson
2022-11-10 21:05 ` [PATCH v5 05/25] xfsprogs: get directory offset when removing " allison.henderson
2022-11-10 21:05 ` [PATCH v5 06/25] xfsprogs: get directory offset when replacing a " allison.henderson
2022-11-10 21:05 ` [PATCH v5 07/25] xfsprogs: add parent pointer support to attribute code allison.henderson
2022-11-10 21:05 ` [PATCH v5 08/25] xfsprogs: define parent pointer xattr format allison.henderson
2022-11-10 21:05 ` [PATCH v5 09/25] xfsprogs: Add xfs_verify_pptr allison.henderson
2022-11-10 21:05 ` [PATCH v5 10/25] xfsprogs: Increase rename inode reservation allison.henderson
2022-11-10 21:05 ` [PATCH v5 11/25] xfsprogs: extend transaction reservations for parent attributes allison.henderson
2022-11-10 21:05 ` [PATCH v5 12/25] xfsprogs: add parent attributes to link allison.henderson
2022-11-10 21:05 ` [PATCH v5 13/25] xfsprogs: add parent attributes to symlink allison.henderson
2022-11-10 21:05 ` [PATCH v5 14/25] xfsprogs: parent pointer attribute creation allison.henderson
2022-11-10 21:05 ` [PATCH v5 15/25] xfsprogs: remove parent pointers in unlink allison.henderson
2022-11-10 21:05 ` [PATCH v5 16/25] xfsprogs: Add parent pointers to rename allison.henderson
2022-11-10 21:05 ` [PATCH v5 17/25] xfsprogs: Add the parent pointer support to the superblock version 5 allison.henderson
2022-11-10 21:05 ` [PATCH v5 18/25] xfsprogs: Add parent pointer ioctl allison.henderson
2022-11-10 21:05 ` [PATCH v5 19/25] xfsprogs: fix unit conversion error in xfs_log_calc_max_attrsetm_res allison.henderson
2022-11-10 21:05 ` [PATCH v5 20/25] xfsprogs: drop compatibility minimum log size computations for reflink allison.henderson
2022-11-10 21:05 ` [PATCH v5 21/25] xfsprogs: Add parent pointer flag to cmd allison.henderson
2022-11-10 21:05 ` allison.henderson [this message]
2022-11-10 21:05 ` [PATCH v5 23/25] xfsprogs: implement the upper half of parent pointers allison.henderson
2022-11-10 21:05 ` [PATCH v5 24/25] xfsprogs: Add parent pointers during protofile creation allison.henderson
2022-11-10 21:05 ` [PATCH v5 25/25] xfsprogs: Add i, n and f flags to parent command allison.henderson

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=20221110210527.56628-23-allison.henderson@oracle.com \
    --to=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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.