From patchwork Thu Nov 2 00:54:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Liu Bo X-Patchwork-Id: 10037863 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 78AE4603B5 for ; Thu, 2 Nov 2017 01:56:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6CC7828CA1 for ; Thu, 2 Nov 2017 01:56:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 61F2128CA4; Thu, 2 Nov 2017 01:56:48 +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, UNPARSEABLE_RELAY 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 0410928CA1 for ; Thu, 2 Nov 2017 01:56:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934033AbdKBB4q (ORCPT ); Wed, 1 Nov 2017 21:56:46 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:37957 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752380AbdKBB4k (ORCPT ); Wed, 1 Nov 2017 21:56:40 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id vA21ud68013776 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 2 Nov 2017 01:56:39 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0022.oracle.com (8.14.4/8.14.4) with ESMTP id vA21udjH023363 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Thu, 2 Nov 2017 01:56:39 GMT Received: from abhmp0011.oracle.com (abhmp0011.oracle.com [141.146.116.17]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id vA21udw6016826 for ; Thu, 2 Nov 2017 01:56:39 GMT Received: from dhcp-10-211-47-181.usdhcp.oraclecorp.com.com (/10.211.47.181) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 01 Nov 2017 18:56:38 -0700 From: Liu Bo To: linux-btrfs@vger.kernel.org Subject: [PATCH 3/4] Btrfs: make raid1 and raid10 be aware of device flag In_sync Date: Wed, 1 Nov 2017 18:54:04 -0600 Message-Id: <20171102005405.20420-4-bo.li.liu@oracle.com> X-Mailer: git-send-email 2.9.4 In-Reply-To: <20171102005405.20420-1-bo.li.liu@oracle.com> References: <20171102005405.20420-1-bo.li.liu@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] 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 If a device is not in_sync, avoid reading data from it as data on it might be stale. Although checksum can detect stale data so we won't return stale data to users , this helps us read the good copy directly. Signed-off-by: Liu Bo --- fs/btrfs/volumes.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 7b29b1a..b83b7c8 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -5175,6 +5175,7 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info, int i; int tolerance; struct btrfs_device *srcdev; + struct btrfs_device *curr; if (dev_replace_is_ongoing && fs_info->dev_replace.cont_reading_from_srcdev_mode == @@ -5184,17 +5185,25 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info, srcdev = NULL; /* - * try to avoid the drive that is the source drive for a - * dev-replace procedure, only choose it if no other non-missing - * mirror is available + * try to avoid the drive that is + * + * a) the source drive for a dev-replace procedure, + * b) not in_sync + * + * only choose it if no other non-missing mirror is available. */ for (tolerance = 0; tolerance < 2; tolerance++) { - if (map->stripes[optimal].dev->bdev && - (tolerance || map->stripes[optimal].dev != srcdev)) + curr = map->stripes[optimal].dev; + if (curr->bdev && + test_bit(In_sync, &curr->flags) && + (tolerance || curr != srcdev)) return optimal; + for (i = first; i < first + num; i++) { - if (map->stripes[i].dev->bdev && - (tolerance || map->stripes[i].dev != srcdev)) + curr = map->stripes[i].dev; + if (curr->bdev && + test_bit(In_sync, &curr->flags) && + (tolerance || curr != srcdev)) return i; } }