From patchwork Wed Sep 16 03:43:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 7190651 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 E960DBEEC1 for ; Wed, 16 Sep 2015 03:44:05 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D544B2087A for ; Wed, 16 Sep 2015 03:44:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 9ECAE20875 for ; Wed, 16 Sep 2015 03:44:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752140AbbIPDn4 (ORCPT ); Tue, 15 Sep 2015 23:43:56 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:2777 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1751960AbbIPDnz (ORCPT ); Tue, 15 Sep 2015 23:43:55 -0400 X-IronPort-AV: E=Sophos;i="5.15,520,1432569600"; d="scan'208";a="100765397" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 16 Sep 2015 11:46:44 +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 t8G3hbR6012777 for ; Wed, 16 Sep 2015 11:43:37 +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; Wed, 16 Sep 2015 11:43:52 +0800 From: Qu Wenruo To: Subject: [PATCH 1/2] btrfs: Do per-chunk degrade mode check at mount time Date: Wed, 16 Sep 2015 11:43:50 +0800 Message-ID: <1442375031-18212-1-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 2.5.2 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 Btrfs supports different raid profile for meta/data/sys, and as different profile support different tolerated missing device, it's better to check if it can be mounted degraded at a per-chunk base. So this patch will add check for read_one_chunk() against its profile, other than checking it against with the lowest duplication profile. Reported-by: Zhao Lei Reported-by: Anand Jain Signed-off-by: Qu Wenruo --- fs/btrfs/volumes.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 644e070..3272187 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -6164,12 +6164,15 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, struct btrfs_chunk *chunk) { struct btrfs_mapping_tree *map_tree = &root->fs_info->mapping_tree; + struct super_block *sb = root->fs_info->sb; struct map_lookup *map; struct extent_map *em; u64 logical; u64 length; u64 devid; u8 uuid[BTRFS_UUID_SIZE]; + int missing = 0; + int max_tolerated; int num_stripes; int ret; int i; @@ -6238,7 +6241,21 @@ static int read_one_chunk(struct btrfs_root *root, struct btrfs_key *key, btrfs_warn(root->fs_info, "devid %llu uuid %pU is missing", devid, uuid); } + if (map->stripes[i].dev->missing) + missing++; map->stripes[i].dev->in_fs_metadata = 1; + + } + + /* XXX: Why the function name is SO LOOOOOOOOOOOOOOOOONG?! */ + max_tolerated = + btrfs_get_num_tolerated_disk_barrier_failures(map->type); + if (missing > max_tolerated && !(sb->s_flags & MS_RDONLY)) { + free_extent_map(em); + btrfs_error(root->fs_info, -EIO, + "missing device(%d) exceeds the limit(%d), writeable mount is not allowed\n", + missing, max_tolerated); + return -EIO; } write_lock(&map_tree->map_tree.lock);