All of lore.kernel.org
 help / color / mirror / Atom feed
From: Allison Henderson <allison.henderson@oracle.com>
To: linux-xfs@vger.kernel.org
Subject: [PATCH v2 22/27] xfsprogs: Add log item printing for ATTRI and ATTRD
Date: Sat,  9 Jun 2018 22:07:47 -0700	[thread overview]
Message-ID: <1528607272-11122-23-git-send-email-allison.henderson@oracle.com> (raw)
In-Reply-To: <1528607272-11122-1-git-send-email-allison.henderson@oracle.com>

This patch implements a new set of log printing functions to
print the ATTRI and ATTRD items and vectors in the log.  These
will be used during log dump and log recover operations.

Signed-off-by: Allison Henderson <allison.henderson@oracle.com>
---
 logprint/log_misc.c      |  11 ++
 logprint/log_print_all.c |  12 +++
 logprint/log_redo.c      | 262 +++++++++++++++++++++++++++++++++++++++++++++++
 logprint/logprint.h      |   6 ++
 4 files changed, 291 insertions(+)

diff --git a/logprint/log_misc.c b/logprint/log_misc.c
index fd46cc3..23946a8 100644
--- a/logprint/log_misc.c
+++ b/logprint/log_misc.c
@@ -959,6 +959,17 @@ xlog_print_record(
 					be32_to_cpu(op_head->oh_len));
 			break;
 		    }
+		    case XFS_LI_ATTRI: {
+                        skip = xlog_print_trans_attri(&ptr,
+                                        be32_to_cpu(op_head->oh_len),
+                                        &i);
+                        break;
+                    }
+                    case XFS_LI_ATTRD: {
+                        skip = xlog_print_trans_attrd(&ptr,
+                                        be32_to_cpu(op_head->oh_len));
+                        break;
+                    }
 		    case XFS_LI_RUI: {
 			skip = xlog_print_trans_rui(&ptr,
 					be32_to_cpu(op_head->oh_len),
diff --git a/logprint/log_print_all.c b/logprint/log_print_all.c
index cdaf77b..7857522 100644
--- a/logprint/log_print_all.c
+++ b/logprint/log_print_all.c
@@ -412,6 +412,12 @@ xlog_recover_print_logitem(
 	case XFS_LI_EFI:
 		xlog_recover_print_efi(item);
 		break;
+	case XFS_LI_ATTRD:
+		xlog_recover_print_attrd(item);
+		break;
+	case XFS_LI_ATTRI:
+		xlog_recover_print_attri(item);
+		break;
 	case XFS_LI_RUD:
 		xlog_recover_print_rud(item);
 		break;
@@ -464,6 +470,12 @@ xlog_recover_print_item(
 	case XFS_LI_EFI:
 		printf("EFI");
 		break;
+	case XFS_LI_ATTRD:
+		printf("ATTRD");
+		break;
+	case XFS_LI_ATTRI:
+		printf("ATTRI");
+		break;
 	case XFS_LI_RUD:
 		printf("RUD");
 		break;
diff --git a/logprint/log_redo.c b/logprint/log_redo.c
index d39f8e9..6618724 100644
--- a/logprint/log_redo.c
+++ b/logprint/log_redo.c
@@ -20,6 +20,7 @@
 #include "libxlog.h"
 
 #include "logprint.h"
+#include "xfs_attr_item.h"
 
 /* Extent Free Items */
 
@@ -665,3 +666,264 @@ xlog_recover_print_bud(
 	f = item->ri_buf[0].i_addr;
 	xlog_print_trans_bud(&f, sizeof(struct xfs_bud_log_format));
 }
+
+/* Attr Items */
+
+static int
+xfs_attri_copy_log_format(
+	char				*buf,
+	uint				len,
+	struct xfs_attri_log_format	*dst_attri_fmt)
+{
+	uint dst_len = sizeof(struct xfs_attri_log_format);
+
+	if (len == dst_len) {
+		memcpy((char *)dst_attri_fmt, buf, len);
+		return 0;
+	}
+
+	fprintf(stderr, _("%s: bad size of attri format: %u; expected %u\n"),
+		progname, len, dst_len);
+	return 1;
+}
+
+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,
+	uint				src_len,
+	int				*i)
+{
+	struct xfs_attri_log_format	*src_f = NULL;
+	xlog_op_header_t		*head = NULL;
+	uint				dst_len;
+	int				error = 0;
+
+	dst_len = sizeof(struct xfs_attri_log_format);
+	if (src_len != dst_len) {
+		fprintf(stderr, _("%s: bad size of attri format: %u; expected %u\n"),
+				progname, src_len, dst_len);
+		return 1;
+	}
+
+	/*
+	 * memmove to ensure 8-byte alignment for the long longs in
+	 * xfs_attri_log_format_t structure
+	 */
+	if ((src_f = (struct xfs_attri_log_format *)malloc(src_len)) == NULL) {
+		fprintf(stderr, _("%s: xlog_print_trans_attri: malloc failed\n"),
+				progname);
+		exit(1);
+	}
+	memmove((char*)src_f, *ptr, src_len);
+	*ptr += src_len;
+
+	printf(_("ATTRI:  #regs: %d	name_len: %d, value_len: %d  id: 0x%llx\n"),
+		src_f->alfi_size, src_f->alfi_name_len, src_f->alfi_value_len,
+				(unsigned long long)src_f->alfi_id);
+
+	if (src_f->alfi_name_len > 0) {
+		printf(_("\n"));
+		(*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));
+		if (error)
+			goto error;
+	}
+
+	if (src_f->alfi_value_len > 0) {
+		printf(_("\n"));
+		(*i)++;
+		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);
+	}
+error:
+	free(src_f);
+
+	return error;
+}	/* xlog_print_trans_attri */
+
+int
+xlog_print_trans_attri_name(
+	char				**ptr,
+	uint				src_len)
+{
+	struct xfs_parent_name_rec	*src_f = NULL;
+	uint				dst_len;
+
+	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);
+	*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);
+	return 0;
+}	/* xlog_print_trans_attri */
+
+int
+xlog_print_trans_attri_value(
+	char				**ptr,
+	uint				src_len,
+	int				value_len)
+{
+	char				*f = NULL;
+
+	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);
+	*ptr += src_len;
+
+	free(f);
+	return 0;
+}	/* xlog_print_trans_attri_value */
+
+void
+xlog_recover_print_attri(
+	xlog_recover_item_t	*item)
+{
+	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;
+	src_len = item->ri_buf[region].i_len;
+
+	/*
+	 * An xfs_attri_log_format structure contains a attribute name and
+	 * variable length value  as the last field.
+	 */
+	dst_len = sizeof(struct xfs_attri_log_format);
+
+	if ((f = ((struct xfs_attri_log_format *)malloc(dst_len))) == NULL) {
+		fprintf(stderr, _("%s: xlog_recover_print_attri: malloc failed\n"),
+			progname);
+		exit(1);
+	}
+	if (xfs_attri_copy_log_format((char*)src_f, src_len, f))
+		goto out;
+
+	printf(_("ATTRI:  #regs: %d	name_len: %d, value_len: %d  id: 0x%llx\n"),
+		f->alfi_size, f->alfi_name_len, f->alfi_value_len, (unsigned long long)f->alfi_id);
+
+	if (f->alfi_name_len > 0) {
+		region++;
+		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);
+	}
+
+	if (f->alfi_value_len > 0) {
+		region++;
+		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);
+	}
+
+out:
+	free(f);
+
+}
+
+int
+xlog_print_trans_attrd(char **ptr, uint len)
+{
+	struct xfs_attrd_log_format *f;
+	struct xfs_attrd_log_format lbuf;
+	uint core_size = sizeof(struct xfs_attrd_log_format);
+
+	memcpy(&lbuf, *ptr, MIN(core_size, len));
+	f = &lbuf;
+	*ptr += len;
+	if (len >= core_size) {
+		printf(_("ATTRD:  #regs: %d	id: 0x%llx\n"),
+			f->alfd_size,
+			(unsigned long long)f->alfd_alf_id);
+		return 0;
+	} else {
+		printf(_("ATTRD: Not enough data to decode further\n"));
+		return 1;
+	}
+}	/* xlog_print_trans_attrd */
+
+void
+xlog_recover_print_attrd(
+	xlog_recover_item_t		*item)
+{
+	struct xfs_attrd_log_format	*f;
+
+	f = (struct xfs_attrd_log_format *)item->ri_buf[0].i_addr;
+
+	printf(_("	ATTRD:  #regs: %d	id: 0x%llx\n"),
+		f->alfd_size,
+		(unsigned long long)f->alfd_alf_id);
+}
diff --git a/logprint/logprint.h b/logprint/logprint.h
index 20f1be4..52e3619 100644
--- a/logprint/logprint.h
+++ b/logprint/logprint.h
@@ -64,4 +64,10 @@ extern void xlog_recover_print_bui(struct xlog_recover_item *item);
 extern int xlog_print_trans_bud(char **ptr, uint len);
 extern void xlog_recover_print_bud(struct xlog_recover_item *item);
 
+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 void xlog_recover_print_attri(xlog_recover_item_t *item);
+extern int xlog_print_trans_attrd(char **ptr, uint len);
+extern void xlog_recover_print_attrd(xlog_recover_item_t *item);
 #endif	/* LOGPRINT_H */
-- 
2.7.4


  parent reply	other threads:[~2018-06-10  5:10 UTC|newest]

Thread overview: 51+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-10  5:07 [PATCH v2 00/27] xfsprogs: parent pointers v2 Allison Henderson
2018-06-10  5:07 ` [PATCH v2 01/27] xfsprogs: Move xfs_attr.h to libxfs Allison Henderson
2018-06-10  5:07 ` [PATCH v2 02/27] xfsprogs: Add helper function xfs_attr_try_sf_addname Allison Henderson
2018-06-10  5:07 ` [PATCH v2 03/27] xfsprogs: Add trans toggle to attr routines Allison Henderson
2018-06-10  7:02   ` Amir Goldstein
2018-06-10 16:19     ` Allison Henderson
2018-06-10  5:07 ` [PATCH v2 04/27] xfsprogs: Add attibute set and helper functions Allison Henderson
2018-06-10  5:07 ` [PATCH v2 05/27] xfsprogs: Add attibute remove " Allison Henderson
2018-06-10  5:07 ` [PATCH v2 06/27] xfsprogs: Set up infastructure for deferred attribute operations Allison Henderson
2018-06-10  5:07 ` [PATCH v2 07/27] xfsprogs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred Allison Henderson
2018-06-10  5:07 ` [PATCH v2 08/27] xfsprogs: Remove all strlen calls in all xfs_attr_* functions for attr names Allison Henderson
2018-06-10  5:07 ` [PATCH v2 09/27] xfsprogs: get directory offset when adding directory name Allison Henderson
2018-06-10  5:07 ` [PATCH v2 10/27] xfsprogs: get directory offset when removing " Allison Henderson
2018-06-10  5:07 ` [PATCH v2 11/27] xfsprogs: get directory offset when replacing a " Allison Henderson
2018-06-10  5:07 ` [PATCH v2 12/27] xfsprogs: add parent pointer support to attribute code Allison Henderson
2018-06-10  5:07 ` [PATCH v2 13/27] xfsprogs: define parent pointer xattr format Allison Henderson
2018-06-10  5:07 ` [PATCH v2 14/27] xfsprogs: extent transaction reservations for parent attributes Allison Henderson
2018-06-10  5:07 ` [PATCH v2 15/27] xfsprogs: parent pointer attribute creation Allison Henderson
2018-06-10  5:07 ` [PATCH v2 16/27] xfsprogs: Add the parent pointer support to the superblock version 5 Allison Henderson
2018-06-10  5:07 ` [PATCH v2 17/27] xfsprogs: Add helper function xfs_attr_list_context_init Allison Henderson
2018-06-10  5:07 ` [PATCH v2 18/27] xfsprogs: Add parent pointer ioctl Allison Henderson
2018-06-10  5:07 ` [PATCH v2 19/27] xfsprogs: Add delayed attributes error tag Allison Henderson
2018-06-11 17:28   ` Darrick J. Wong
2018-06-11 19:59     ` Allison Henderson
2018-06-10  5:07 ` [PATCH v2 20/27] xfsprogs: Add parent pointer flag to cmd Allison Henderson
2018-06-11 17:43   ` Darrick J. Wong
2018-06-11 20:00     ` Allison Henderson
2018-06-10  5:07 ` [PATCH v2 21/27] xfsprogs: Remove single byte array from struct parent Allison Henderson
2018-06-10 11:21   ` Amir Goldstein
2018-06-10 15:25     ` Allison Henderson
2018-06-10  5:07 ` Allison Henderson [this message]
2018-06-10  5:07 ` [PATCH v2 23/27] xfsprogs: Do not use namechecks on parent pointers Allison Henderson
2018-06-11 18:00   ` Darrick J. Wong
2018-06-11 20:00     ` Allison Henderson
2018-06-11 20:23       ` Darrick J. Wong
2018-06-11 20:38         ` Allison Henderson
2018-06-10  5:07 ` [PATCH v2 24/27] xfsprogs: Add parent pointers to recreated inodes Allison Henderson
2018-06-10 11:27   ` Amir Goldstein
2018-06-10 17:19     ` Allison Henderson
2018-06-11 17:31       ` Darrick J. Wong
2018-06-11 18:06   ` Darrick J. Wong
2018-06-11 20:00     ` Allison Henderson
2018-06-10  5:07 ` [PATCH v2 25/27] xfsprogs: Add parent pointers during protofile creation Allison Henderson
2018-06-10 11:32   ` Amir Goldstein
2018-06-11 18:15   ` Darrick J. Wong
2018-06-11 19:58     ` Allison Henderson
2018-06-10  5:07 ` [PATCH v2 26/27] xfsprogs: implement the upper half of parent pointers Allison Henderson
2018-06-10 12:06   ` Amir Goldstein
2018-06-10  5:07 ` [PATCH v2 27/27] xfsprogs: Clean up old parent pointer definitions Allison Henderson
2018-06-11 18:20   ` Darrick J. Wong
2018-06-11 20:06     ` 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=1528607272-11122-23-git-send-email-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.