From patchwork Wed May 28 10:49:37 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gui Hecheng X-Patchwork-Id: 4254531 X-Patchwork-Delegate: dave@jikos.cz Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 5CABABF90B for ; Wed, 28 May 2014 10:54:45 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 926962026C for ; Wed, 28 May 2014 10:54:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4DF4E2027D for ; Wed, 28 May 2014 10:54:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752800AbaE1Kyd (ORCPT ); Wed, 28 May 2014 06:54:33 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:38581 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751466AbaE1Kyc (ORCPT ); Wed, 28 May 2014 06:54:32 -0400 X-IronPort-AV: E=Sophos;i="4.98,927,1392134400"; d="scan'208";a="31125655" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 28 May 2014 18:51:54 +0800 Received: from G08CNEXCHPEKD02.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s4SAsSVx028119 for ; Wed, 28 May 2014 18:54:28 +0800 Received: from localhost.localdomain (10.167.226.111) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.146.2; Wed, 28 May 2014 18:54:33 +0800 From: Gui Hecheng To: CC: Gui Hecheng Subject: [PATCH 1/2] btrfs-progs: fix uninitialized number count in chunk-recover Date: Wed, 28 May 2014 18:49:37 +0800 Message-ID: <1401274178-4523-1-git-send-email-guihc.fnst@cn.fujitsu.com> X-Mailer: git-send-email 1.8.1.4 MIME-Version: 1.0 X-Originating-IP: [10.167.226.111] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-7.5 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When count the number of unordered device extents in chunk-recover, the counter should be reinitialized to be used. Also, introduce a new function for the counting job. Signed-off-by: Gui Hecheng --- chunk-recover.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/chunk-recover.c b/chunk-recover.c index 84fd8b7..924b2f6 100644 --- a/chunk-recover.c +++ b/chunk-recover.c @@ -1795,6 +1795,17 @@ static int insert_stripe(struct list_head *devexts, return 0; } +static inline int count_devext_records(struct list_head *record_list) +{ + int num_of_records = 0; + struct device_extent_record *devext; + + list_for_each_entry(devext, record_list, chunk_list) + num_of_records++; + + return num_of_records; +} + #define EQUAL_STRIPE (1 << 0) static int rebuild_raid_data_chunk_stripes(struct recover_control *rc, @@ -1898,8 +1909,7 @@ next_csum: fprintf(stderr, "Fetch csum failed\n"); goto fail_out; } else if (ret == 1) { - list_for_each_entry(devext, &unordered, chunk_list) - num_unordered++; + num_unordered = count_devext_records(&unordered); if (!(*flags & EQUAL_STRIPE)) *flags |= EQUAL_STRIPE; goto out; @@ -1927,8 +1937,7 @@ next_csum: } if (list_empty(&candidates)) { - list_for_each_entry(devext, &unordered, chunk_list) - num_unordered++; + num_unordered = count_devext_records(&unordered); if (chunk->type_flags & BTRFS_BLOCK_GROUP_RAID6 && num_unordered == 2) { list_splice_init(&unordered, &chunk->dextents); @@ -1963,8 +1972,7 @@ next_stripe: out: ret = 0; list_splice_init(&candidates, &unordered); - list_for_each_entry(devext, &unordered, chunk_list) - num_unordered++; + num_unordered = count_devext_records(&unordered); if (num_unordered == 1) { for (i = 0; i < chunk->num_stripes; i++) { if (!chunk->stripes[i].devid) {