From: "Darrick J. Wong" <djwong@kernel.org>
To: Allison Henderson <allison.henderson@oracle.com>
Cc: linux-xfs@vger.kernel.org
Subject: Re: [PATCH v22 27/27] xfsprogs: Add log item printing for ATTRI and ATTRD
Date: Wed, 28 Jul 2021 12:41:56 -0700 [thread overview]
Message-ID: <20210728194156.GF3601443@magnolia> (raw)
In-Reply-To: <20210727061904.11084-28-allison.henderson@oracle.com>
On Mon, Jul 26, 2021 at 11:19:04PM -0700, Allison Henderson wrote:
> 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>
/me thinks this looks ok, though I admit I'm relying on you to have
exercised logprint and made sure that the output looks right.
Reviewed-by: Darrick J. Wong <djwong@kernel.org>
--D
> ---
> logprint/log_misc.c | 48 +++++++++++-
> logprint/log_print_all.c | 12 +++
> logprint/log_redo.c | 197 +++++++++++++++++++++++++++++++++++++++++++++++
> logprint/logprint.h | 12 +++
> 4 files changed, 268 insertions(+), 1 deletion(-)
>
> diff --git a/logprint/log_misc.c b/logprint/log_misc.c
> index 35e926a..d8c6038 100644
> --- a/logprint/log_misc.c
> +++ b/logprint/log_misc.c
> @@ -54,11 +54,46 @@ print_stars(void)
> "***********************************\n");
> } /* print_stars */
>
> +void
> +print_hex_dump(char *ptr, int len) {
> + int i = 0;
> +
> + for (i = 0; i < len; i++) {
> + if (i % 16 == 0)
> + printf("%08x ", i);
> +
> + printf("%02x", ptr[i]);
> +
> + if ((i+1)%16 == 0)
> + printf("\n");
> + else if ((i+1)%2 == 0)
> + printf(" ");
> + }
> + printf("\n");
> +}
> +
> +bool
> +is_printable(char *ptr, int len) {
> + int i = 0;
> +
> + for (i = 0; i < len; i++)
> + if (!isprint(ptr[i]) )
> + return false;
> + return true;
> +}
> +
> +void print_or_dump(char *ptr, int len) {
> + if (is_printable(ptr, len))
> + printf("%.*s\n", len, ptr);
> + else
> + print_hex_dump(ptr, len);
> +}
> +
> /*
> * Given a pointer to a data segment, print out the data as if it were
> * a log operation header.
> */
> -static void
> +void
> xlog_print_op_header(xlog_op_header_t *op_head,
> int i,
> char **ptr)
> @@ -961,6 +996,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 c9c453f..89cb649 100644
> --- a/logprint/log_print_all.c
> +++ b/logprint/log_print_all.c
> @@ -404,6 +404,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;
> @@ -456,6 +462,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 297e203..502345d 100644
> --- a/logprint/log_redo.c
> +++ b/logprint/log_redo.c
> @@ -653,3 +653,200 @@ 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;
> +}
> +
> +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
> + */
> + src_f = malloc(src_len);
> + if (!src_f) {
> + 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)
> +{
> + printf(_("ATTRI: name len:%u\n"), src_len);
> + print_or_dump(*ptr, src_len);
> +
> + *ptr += src_len;
> +
> + return 0;
> +} /* xlog_print_trans_attri */
> +
> +int
> +xlog_print_trans_attri_value(
> + char **ptr,
> + uint src_len,
> + int value_len)
> +{
> + int len = value_len;
> +
> + if (len > MAX_ATTR_VAL_PRINT)
> + len = MAX_ATTR_VAL_PRINT;
> +
> + printf(_("ATTRI: value len:%u\n"), value_len);
> + print_or_dump(*ptr, len);
> +
> + *ptr += src_len;
> +
> + return 0;
> +} /* xlog_print_trans_attri_value */
> +
> +void
> +xlog_recover_print_attri(
> + struct xlog_recover_item *item)
> +{
> + struct xfs_attri_log_format *f, *src_f = NULL;
> + uint src_len, dst_len;
> +
> + 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++;
> + 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_value_len > 0) {
> + int len = f->alfi_value_len;
> +
> + if (len > MAX_ATTR_VAL_PRINT)
> + len = MAX_ATTR_VAL_PRINT;
> +
> + region++;
> + printf(_("ATTRI: value len:%u\n"), f->alfi_value_len);
> + print_or_dump((char *)item->ri_buf[region].i_addr, len);
> + }
> +
> +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(
> + struct xlog_recover_item *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 38a7d3f..b4479c2 100644
> --- a/logprint/logprint.h
> +++ b/logprint/logprint.h
> @@ -29,6 +29,9 @@ extern void xfs_log_print_trans(struct xlog *, int);
> extern void print_xlog_record_line(void);
> extern void print_xlog_op_line(void);
> extern void print_stars(void);
> +extern void print_hex_dump(char* ptr, int len);
> +extern bool is_printable(char* ptr, int len);
> +extern void print_or_dump(char* ptr, int len);
>
> extern struct xfs_inode_log_format *
> xfs_inode_item_format_convert(char *, uint, struct xfs_inode_log_format *);
> @@ -53,4 +56,13 @@ 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);
>
> +#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 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);
> +extern void xlog_print_op_header(xlog_op_header_t *op_head, int i, char **ptr);
> #endif /* LOGPRINT_H */
> --
> 2.7.4
>
prev parent reply other threads:[~2021-07-28 19:41 UTC|newest]
Thread overview: 29+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-07-27 6:18 [PATCH v22 00/27] Delayed Attributes Allison Henderson
2021-07-27 6:18 ` [PATCH v22 01/27] xfsprogs: Reverse apply 72b97ea40d Allison Henderson
2021-07-27 6:18 ` [PATCH v22 02/27] xfsprogs: Add xfs_attr_node_remove_name Allison Henderson
2021-07-27 6:18 ` [PATCH v22 03/27] xfsprogs: Refactor xfs_attr_set_shortform Allison Henderson
2021-07-27 6:18 ` [PATCH v22 04/27] xfsprogs: Separate xfs_attr_node_addname and xfs_attr_node_addname_clear_incomplete Allison Henderson
2021-07-27 6:18 ` [PATCH v22 05/27] xfsprogs: Add helper xfs_attr_node_addname_find_attr Allison Henderson
2021-07-27 6:18 ` [PATCH v22 06/27] xfsprogs: Hoist xfs_attr_node_addname Allison Henderson
2021-07-27 6:18 ` [PATCH v22 07/27] xfsprogs: Hoist xfs_attr_leaf_addname Allison Henderson
2021-07-27 6:18 ` [PATCH v22 08/27] xfsprogs: Hoist node transaction handling Allison Henderson
2021-07-27 6:18 ` [PATCH v22 09/27] xfsprogs: Add delay ready attr remove routines Allison Henderson
2021-07-27 6:18 ` [PATCH v22 10/27] xfsprogs: Add delay ready attr set routines Allison Henderson
2021-07-27 6:18 ` [PATCH v22 11/27] xfsprogs: Remove xfs_attr_rmtval_set Allison Henderson
2021-07-27 6:18 ` [PATCH v22 12/27] xfsprogs: Clean up xfs_attr_node_addname_clear_incomplete Allison Henderson
2021-07-27 6:18 ` [PATCH v22 13/27] xfsprogs: Fix default ASSERT in xfs_attr_set_iter Allison Henderson
2021-07-27 6:18 ` [PATCH v22 14/27] xfsprogs: Make attr name schemes consistent Allison Henderson
2021-07-27 6:18 ` [PATCH v22 15/27] xfs: allow setting and clearing of log incompat feature flags Allison Henderson
2021-07-27 6:18 ` [PATCH v22 16/27] xfsprogs: Return from xfs_attr_set_iter if there are no more rmtblks to process Allison Henderson
2021-07-27 6:18 ` [PATCH v22 17/27] xfsprogs: Add state machine tracepoints Allison Henderson
2021-07-27 6:18 ` [PATCH v22 18/27] xfsprogs: Rename __xfs_attr_rmtval_remove Allison Henderson
2021-07-27 6:18 ` [PATCH v22 19/27] xfsprogs: Set up infrastructure for deferred attribute operations Allison Henderson
2021-07-27 6:18 ` [PATCH v22 20/27] xfsprogs: Implement attr logging and replay Allison Henderson
2021-07-27 6:18 ` [PATCH v22 21/27] RFC xfsprogs: Skip flip flags for delayed attrs Allison Henderson
2021-07-27 6:18 ` [PATCH v22 22/27] xfsprogs: Add xfs_attr_set_deferred and xfs_attr_remove_deferred Allison Henderson
2021-07-27 6:19 ` [PATCH v22 23/27] xfsprogs: Remove unused xfs_attr_*_args Allison Henderson
2021-07-27 6:19 ` [PATCH v22 24/27] xfsprogs: Add delayed attributes error tag Allison Henderson
2021-07-27 6:19 ` [PATCH v22 25/27] xfsprogs: Merge xfs_delattr_context into xfs_attr_item Allison Henderson
2021-07-27 6:19 ` [PATCH v22 26/27] xfsprogs: Add helper function xfs_attr_leaf_addname Allison Henderson
2021-07-27 6:19 ` [PATCH v22 27/27] xfsprogs: Add log item printing for ATTRI and ATTRD Allison Henderson
2021-07-28 19:41 ` Darrick J. Wong [this message]
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=20210728194156.GF3601443@magnolia \
--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