From patchwork Fri Jan 13 11:05:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Tao X-Patchwork-Id: 9515237 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D1F47601DA for ; Fri, 13 Jan 2017 11:05:39 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8219284B9 for ; Fri, 13 Jan 2017 11:05:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BD23628601; Fri, 13 Jan 2017 11:05:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 43200284B9 for ; Fri, 13 Jan 2017 11:05:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751409AbdAMLFh (ORCPT ); Fri, 13 Jan 2017 06:05:37 -0500 Received: from szxga02-in.huawei.com ([119.145.14.65]:17092 "EHLO szxga02-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751553AbdAMLFd (ORCPT ); Fri, 13 Jan 2017 06:05:33 -0500 Received: from 172.24.1.36 (EHLO szxeml434-hub.china.huawei.com) ([172.24.1.36]) by szxrg02-dlp.huawei.com (MOS 4.3.7-GA FastPath queued) with ESMTP id DTI15083; Fri, 13 Jan 2017 19:05:13 +0800 (CST) Received: from huawei.com (10.175.124.28) by szxeml434-hub.china.huawei.com (10.82.67.225) with Microsoft SMTP Server id 14.3.235.1; Fri, 13 Jan 2017 19:05:07 +0800 From: Hou Tao To: CC: , Subject: [PATCH v2] xfs_logprint: handle log operation split of inode item correctly Date: Fri, 13 Jan 2017 19:05:30 +0800 Message-ID: <1484305530-19129-1-git-send-email-houtao1@huawei.com> X-Mailer: git-send-email 2.5.0 MIME-Version: 1.0 X-Originating-IP: [10.175.124.28] X-CFilter-Loop: Reflected X-Mirapoint-Virus-RAPID-Raw: score=unknown(0), refid=str=0001.0A020204.5878B46A.037A, ss=1, re=0.000, recu=0.000, reip=0.000, cl=1, cld=1, fgs=0, ip=0.0.0.0, so=2013-06-18 04:22:30, dmn=2013-03-21 17:37:32 X-Mirapoint-Loop-Id: 49c639f7d9ef2fec3536d0f4a1e67aac Sender: linux-xfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-xfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP If the data/attr fork log operations of an inode log item are splitted to the next log record, xfs_logprint doesn't check the remaining log operations in current log record and still tries to print these log operations which don't exist in the log record. The content of these log operations will be incorrect, or worse xfs_logprint will trigger a segment-fault and exit. xfs_logprint also doesn't calculate the count of the splitted log operations correctly. It just returns 1 when the current log operation is splitted to the next log record. It needs to consider the log operations behind. Signed-off-by: Hou Tao --- logprint/log_misc.c | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) v2: - rewrite the commit message to clarify the patch - use "skip_count" suggested by Brian Foster - fix the indentation v1: http://www.spinics.net/lists/linux-xfs/msg03430.html diff --git a/logprint/log_misc.c b/logprint/log_misc.c index a0f1766..4fa0ce1 100644 --- a/logprint/log_misc.c +++ b/logprint/log_misc.c @@ -524,6 +524,7 @@ xlog_print_trans_inode( xfs_inode_log_format_t *f; int mode; int size; + int skip_count; /* * print inode type header region @@ -555,15 +556,17 @@ xlog_print_trans_inode( return f->ilf_size; } + skip_count = f->ilf_size-1; + if (*i >= num_ops) /* end of LR */ - return f->ilf_size-1; + return skip_count; /* core inode comes 2nd */ op_head = (xlog_op_header_t *)*ptr; xlog_print_op_header(op_head, *i, ptr); if (op_head->oh_flags & XLOG_CONTINUE_TRANS) { - return f->ilf_size-1; + return skip_count; } memmove(&dino, *ptr, sizeof(dino)); @@ -571,13 +574,7 @@ xlog_print_trans_inode( size = (int)dino.di_size; xlog_print_trans_inode_core(&dino); *ptr += xfs_log_dinode_size(dino.di_version); - - if (*i == num_ops-1 && f->ilf_size == 3) { - return 1; - } - - /* does anything come next */ - op_head = (xlog_op_header_t *)*ptr; + skip_count--; switch (f->ilf_fields & (XFS_ILOG_DEV | XFS_ILOG_UUID)) { case XFS_ILOG_DEV: @@ -595,7 +592,12 @@ xlog_print_trans_inode( ASSERT(f->ilf_size <= 4); ASSERT((f->ilf_size == 3) || (f->ilf_fields & XFS_ILOG_AFORK)); + /* does anything come next */ + op_head = (xlog_op_header_t *)*ptr; + if (f->ilf_fields & XFS_ILOG_DFORK) { + if (*i == num_ops-1) + return skip_count; (*i)++; xlog_print_op_header(op_head, *i, ptr); @@ -618,11 +620,14 @@ xlog_print_trans_inode( *ptr += be32_to_cpu(op_head->oh_len); if (op_head->oh_flags & XLOG_CONTINUE_TRANS) - return 1; + return skip_count; op_head = (xlog_op_header_t *)*ptr; + skip_count--; } if (f->ilf_fields & XFS_ILOG_AFORK) { + if (*i == num_ops-1) + return skip_count; (*i)++; xlog_print_op_header(op_head, *i, ptr); @@ -644,7 +649,8 @@ xlog_print_trans_inode( } *ptr += be32_to_cpu(op_head->oh_len); if (op_head->oh_flags & XLOG_CONTINUE_TRANS) - return 1; + return skip_count; + skip_count--; } return 0;