From patchwork Fri Dec 18 07:25:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Allison Henderson X-Patchwork-Id: 11981345 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-18.8 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, UNPARSEABLE_RELAY,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8CD79C4361B for ; Fri, 18 Dec 2020 07:28:55 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5F59523A5B for ; Fri, 18 Dec 2020 07:28:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732915AbgLRH2z (ORCPT ); Fri, 18 Dec 2020 02:28:55 -0500 Received: from aserp2120.oracle.com ([141.146.126.78]:57026 "EHLO aserp2120.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732686AbgLRH2y (ORCPT ); Fri, 18 Dec 2020 02:28:54 -0500 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI7K0uk122157 for ; Fri, 18 Dec 2020 07:28:11 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : subject : date : message-id : in-reply-to : references; s=corp-2020-01-29; bh=YDXZ4rNB/xEsw5s+AgL6HrhFem2mrzrxBrGGkvzlJvU=; b=n7senyT/qpmIjJr5d1eNuoS73h6As5hKGbbf0Is2VnqFMbpFEeGSfFba30RQxoctvuNP Aevy0yxKc0JfJ3wMeFG2mhryfbAmJRZCcv9nh6yYuI6KjfaR636rEBxiPOJTrchzbzJa BAR3IZd6m1cESxeQOF3HRfj4Za9ERboWmBlXK7PmIVkglA6h90mVnqeP8gbJbj9ccWrL s1i9tHeGj+ryWHxHmc57jg3OsL/uip03m8KlC1hcFc63qWpC2/J+DSHCXf70RYn13uVR ke5HP6Ob4EB7aOIVbqRrDwGivxz2K0gnbDIEkziytMdNqCdov6OdzT6vJXUUHHko4k7N rA== Received: from aserp3020.oracle.com (aserp3020.oracle.com [141.146.126.70]) by aserp2120.oracle.com with ESMTP id 35cntmgy7g-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Fri, 18 Dec 2020 07:28:11 +0000 Received: from pps.filterd (aserp3020.oracle.com [127.0.0.1]) by aserp3020.oracle.com (8.16.0.42/8.16.0.42) with SMTP id 0BI7LKXv120974 for ; Fri, 18 Dec 2020 07:26:11 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by aserp3020.oracle.com with ESMTP id 35e6eud6xy-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Fri, 18 Dec 2020 07:26:11 +0000 Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0122.oracle.com (8.14.4/8.14.4) with ESMTP id 0BI7QATt002848 for ; Fri, 18 Dec 2020 07:26:10 GMT Received: from localhost.localdomain (/67.1.214.41) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Thu, 17 Dec 2020 23:26:10 -0800 From: Allison Henderson To: linux-xfs@vger.kernel.org Subject: [PATCH v14 14/14] xfsprogs: Add log item printing for ATTRI and ATTRD Date: Fri, 18 Dec 2020 00:25:55 -0700 Message-Id: <20201218072555.16694-15-allison.henderson@oracle.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20201218072555.16694-1-allison.henderson@oracle.com> References: <20201218072555.16694-1-allison.henderson@oracle.com> X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 adultscore=0 mlxscore=0 phishscore=0 bulkscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180052 X-Proofpoint-Virus-Version: vendor=nai engine=6000 definitions=9838 signatures=668683 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 phishscore=0 mlxscore=0 lowpriorityscore=0 spamscore=0 adultscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 impostorscore=0 priorityscore=1501 clxscore=1015 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2009150000 definitions=main-2012180052 Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org 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. RFC: Though most attributes are strings, the attribute operations accept any binary payload, so we cannot assume them printable. This was done intentionally in preparation for parent pointers. And until parent pointers get here, attributes have no discernible format. So the print routines are just a simple hex dump for now. It's not pretty, but works for now. Signed-off-by: Allison Henderson --- logprint/log_misc.c | 48 +++++++++++- logprint/log_print_all.c | 12 +++ logprint/log_redo.c | 198 +++++++++++++++++++++++++++++++++++++++++++++++ logprint/logprint.h | 12 +++ 4 files changed, 269 insertions(+), 1 deletion(-) diff --git a/logprint/log_misc.c b/logprint/log_misc.c index afcd2ce..88087f0 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 f32c932..579f470 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..601a2d7 100644 --- a/logprint/log_redo.c +++ b/logprint/log_redo.c @@ -8,6 +8,7 @@ #include "libxlog.h" #include "logprint.h" +#include "xfs_attr_item.h" /* Extent Free Items */ @@ -653,3 +654,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 248fe7b..7b5df8c 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 */