From patchwork Mon May 11 00:45:47 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 6372321 Return-Path: X-Original-To: patchwork-linux-btrfs@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 296D99F1C2 for ; Mon, 11 May 2015 00:48:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4AEAB203E1 for ; Mon, 11 May 2015 00:48:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4A583203DA for ; Mon, 11 May 2015 00:48:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751830AbbEKAsD (ORCPT ); Sun, 10 May 2015 20:48:03 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:19150 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751705AbbEKAsA (ORCPT ); Sun, 10 May 2015 20:48:00 -0400 X-IronPort-AV: E=Sophos;i="5.04,848,1406563200"; d="scan'208";a="91947291" Received: from localhost (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 11 May 2015 08:43: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 t4B0kTW2031696 for ; Mon, 11 May 2015 08:46:30 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD02.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Mon, 11 May 2015 08:47:52 +0800 From: Qu Wenruo To: Subject: [PATCH 1/2] btrfs-progs: Fix a bug in __btrfs_map_block() always maps wrong stripe for DUP/RAID1 Date: Mon, 11 May 2015 08:45:47 +0800 Message-ID: <1431305148-18953-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.4.0 MIME-Version: 1.0 X-Originating-IP: [10.167.226.33] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_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 In __btrfs_map_block(), stripe_index is always wrong if mirror_num is given. For DUP/RAID1 case, if mirror_num is given, e.g. 1, it should return the second stripe. But codes consider the mirror_num is start from 1 and always minus 1, causing even mirror number is given as 1, __btrfs_map_block() will still map the first stripe not the second. Signed-off-by: Qu Wenruo --- volumes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/volumes.c b/volumes.c index 16dbf64..c66c02a 100644 --- a/volumes.c +++ b/volumes.c @@ -1397,7 +1397,7 @@ again: if (rw == WRITE) multi->num_stripes = map->num_stripes; else if (mirror_num) - stripe_index = mirror_num - 1; + stripe_index = mirror_num; else stripe_index = stripe_nr % map->num_stripes; } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { @@ -1416,7 +1416,7 @@ again: if (rw == WRITE) multi->num_stripes = map->num_stripes; else if (mirror_num) - stripe_index = mirror_num - 1; + stripe_index = mirror_num; } else if (map->type & (BTRFS_BLOCK_GROUP_RAID5 | BTRFS_BLOCK_GROUP_RAID6)) {