From patchwork Wed May 31 05:56:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 9755837 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 1432F602CC for ; Wed, 31 May 2017 05:56:36 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0757F284C3 for ; Wed, 31 May 2017 05:56:36 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F057C284C5; Wed, 31 May 2017 05:56:35 +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 99B7F284C3 for ; Wed, 31 May 2017 05:56:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1750970AbdEaF41 (ORCPT ); Wed, 31 May 2017 01:56:27 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:62129 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1750912AbdEaF4Z (ORCPT ); Wed, 31 May 2017 01:56:25 -0400 X-IronPort-AV: E=Sophos;i="5.22,518,1449504000"; d="scan'208";a="19480383" Received: from unknown (HELO cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 31 May 2017 13:56:21 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (unknown [10.167.33.83]) by cn.fujitsu.com (Postfix) with ESMTP id 8925947C6D4F; Wed, 31 May 2017 13:56:21 +0800 (CST) Received: from localhost.localdomain (10.167.226.34) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.319.2; Wed, 31 May 2017 13:56:19 +0800 From: Qu Wenruo To: CC: Subject: [PATCH v2 1/6] btrfs-progs: Cleanup open-coded btrfs_chunk_item_size Date: Wed, 31 May 2017 13:56:05 +0800 Message-ID: <20170531055610.11606-2-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.13.0 In-Reply-To: <20170531055610.11606-1-quwenruo@cn.fujitsu.com> References: <20170531055610.11606-1-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.34] X-yoursite-MailScanner-ID: 8925947C6D4F.AD352 X-yoursite-MailScanner: Found to be clean X-yoursite-MailScanner-From: quwenruo@cn.fujitsu.com Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP In btrfs_check_chunk_valid() we calculates chunk item using open code. use btrfs_chunk_item_size() to replace them. Signed-off-by: Qu Wenruo --- volumes.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/volumes.c b/volumes.c index b350e259..62e23aee 100644 --- a/volumes.c +++ b/volumes.c @@ -1685,6 +1685,7 @@ int btrfs_check_chunk_valid(struct btrfs_root *root, u16 num_stripes; u16 sub_stripes; u64 type; + u32 chunk_ondisk_size; length = btrfs_chunk_length(leaf, chunk); stripe_len = btrfs_chunk_stripe_len(leaf, chunk); @@ -1724,16 +1725,16 @@ int btrfs_check_chunk_valid(struct btrfs_root *root, BTRFS_BLOCK_GROUP_PROFILE_MASK) & type); return -EIO; } + + chunk_ondisk_size = btrfs_chunk_item_size(num_stripes); /* * Btrfs_chunk contains at least one stripe, and for sys_chunk * it can't exceed the system chunk array size * For normal chunk, it should match its chunk item size. */ if (num_stripes < 1 || - (slot == -1 && sizeof(struct btrfs_stripe) * num_stripes > - BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) || - (slot >= 0 && sizeof(struct btrfs_stripe) * (num_stripes - 1) > - btrfs_item_size_nr(leaf, slot))) { + (slot == -1 && chunk_ondisk_size > BTRFS_SYSTEM_CHUNK_ARRAY_SIZE) || + (slot >= 0 && chunk_ondisk_size > btrfs_item_size_nr(leaf, slot))) { error("invalid num_stripes: %u", num_stripes); return -EIO; }