From patchwork Mon Sep 21 02:10:40 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 7226951 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.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 37F5BBEEC1 for ; Mon, 21 Sep 2015 02:13:02 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 4A09120A14 for ; Mon, 21 Sep 2015 02:13:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 5091620779 for ; Mon, 21 Sep 2015 02:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755831AbbIUCMt (ORCPT ); Sun, 20 Sep 2015 22:12:49 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:21058 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1755827AbbIUCMs (ORCPT ); Sun, 20 Sep 2015 22:12:48 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100917992" Received: from bogon (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 21 Sep 2015 10:15:34 +0800 Received: from G08CNEXCHPEKD01.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id t8L2CTNo003275 for ; Mon, 21 Sep 2015 10:12:29 +0800 Received: from localhost.localdomain (10.167.226.33) by G08CNEXCHPEKD01.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.181.6; Mon, 21 Sep 2015 10:12:46 +0800 From: Qu Wenruo To: Subject: [PATCH 2/5] btrfs: Do per-chunk check for mount time check Date: Mon, 21 Sep 2015 10:10:40 +0800 Message-ID: <1442801443-5132-3-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.5.2 In-Reply-To: <1442801443-5132-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1442801443-5132-1-git-send-email-quwenruo@cn.fujitsu.com> 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 Now use the btrfs_check_degraded() to do mount time degraded check. With this patch, now we can mount with the following case: # mkfs.btrfs -f -m raid1 -d single /dev/sdb /dev/sdc # wipefs -a /dev/sdc # mount /dev/sdb /mnt/btrfs -o degraded As the single data chunk is only in sdb, so it's OK to mount as degraded, as missing one device is OK for RAID1. But still fail with the following case as expected: # mkfs.btrfs -f -m raid1 -d single /dev/sdb /dev/sdc # wipefs -a /dev/sdb # mount /dev/sdc /mnt/btrfs -o degraded As the data chunk is only in sdb, so it's not OK to mount it as degraded. Reported-by: Zhao Lei Reported-by: Anand Jain Signed-off-by: Qu Wenruo --- fs/btrfs/disk-io.c | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c index 0b658d0..d64299f 100644 --- a/fs/btrfs/disk-io.c +++ b/fs/btrfs/disk-io.c @@ -2858,6 +2858,16 @@ int open_ctree(struct super_block *sb, goto fail_tree_roots; } + ret = btrfs_check_degradable(fs_info, fs_info->sb->s_flags); + if (ret < 0) { + btrfs_error(fs_info, ret, "degraded writable mount failed"); + goto fail_tree_roots; + } else if (ret > 0 && !btrfs_test_opt(chunk_root, DEGRADED)) { + btrfs_warn(fs_info, + "Some device missing, but still degraded mountable, please mount with -o degraded option"); + ret = -EACCES; + goto fail_tree_roots; + } /* * keep the device that is marked to be the target device for the * dev_replace procedure @@ -2947,14 +2957,6 @@ retry_root_backup: } fs_info->num_tolerated_disk_barrier_failures = btrfs_calc_num_tolerated_disk_barrier_failures(fs_info); - if (fs_info->fs_devices->missing_devices > - fs_info->num_tolerated_disk_barrier_failures && - !(sb->s_flags & MS_RDONLY)) { - pr_warn("BTRFS: missing devices(%llu) exceeds the limit(%d), writeable mount is not allowed\n", - fs_info->fs_devices->missing_devices, - fs_info->num_tolerated_disk_barrier_failures); - goto fail_sysfs; - } fs_info->cleaner_kthread = kthread_run(cleaner_kthread, tree_root, "btrfs-cleaner");