From patchwork Tue May 6 06:33:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Qu Wenruo X-Patchwork-Id: 4118961 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 9BB5EBFF02 for ; Tue, 6 May 2014 06:32:21 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A1F5B201F7 for ; Tue, 6 May 2014 06:32:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C7285201ED for ; Tue, 6 May 2014 06:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933958AbaEFGcO (ORCPT ); Tue, 6 May 2014 02:32:14 -0400 Received: from cn.fujitsu.com ([59.151.112.132]:63896 "EHLO heian.cn.fujitsu.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S933953AbaEFGcN (ORCPT ); Tue, 6 May 2014 02:32:13 -0400 X-IronPort-AV: E=Sophos;i="4.97,994,1389715200"; d="scan'208";a="30122607" Received: from unknown (HELO edo.cn.fujitsu.com) ([10.167.33.5]) by heian.cn.fujitsu.com with ESMTP; 06 May 2014 14:29:39 +0800 Received: from G08CNEXCHPEKD03.g08.fujitsu.local (localhost.localdomain [127.0.0.1]) by edo.cn.fujitsu.com (8.14.3/8.13.1) with ESMTP id s466W9Yf025153; Tue, 6 May 2014 14:32:09 +0800 Received: from adam-work.lan (10.167.226.24) by G08CNEXCHPEKD03.g08.fujitsu.local (10.167.33.89) with Microsoft SMTP Server (TLS) id 14.3.146.2; Tue, 6 May 2014 14:32:16 +0800 From: Qu Wenruo To: CC: Anand Jain Subject: [RFC PATCH 1/2] btrfs: Add missing device check in dev_info/rm_dev ioctl Date: Tue, 6 May 2014 14:33:12 +0800 Message-ID: <1399357993-9254-2-git-send-email-quwenruo@cn.fujitsu.com> X-Mailer: git-send-email 1.9.2 In-Reply-To: <1399357993-9254-1-git-send-email-quwenruo@cn.fujitsu.com> References: <1399357993-9254-1-git-send-email-quwenruo@cn.fujitsu.com> MIME-Version: 1.0 X-Originating-IP: [10.167.226.24] 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 Old btrfs can't find a missing btrfs device since there is no mechanism for block layer to inform fs layer. But we can use a workaround that only check status(by using request_queue->queue_flags) of every device in a btrfs filesystem when calling dev_info/rm_dev ioctl, since other ioctls do not really cares about missing device. Cc: Anand Jain Signed-off-by: Qu Wenruo --- fs/btrfs/ioctl.c | 1 + fs/btrfs/volumes.c | 25 ++++++++++++++++++++++++- fs/btrfs/volumes.h | 2 ++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c index 0401397..7680a40 100644 --- a/fs/btrfs/ioctl.c +++ b/fs/btrfs/ioctl.c @@ -2606,6 +2606,7 @@ static long btrfs_ioctl_dev_info(struct btrfs_root *root, void __user *arg) goto out; } + btrfs_check_dev_missing(root, dev, 1); di_args->devid = dev->devid; di_args->bytes_used = dev->bytes_used; di_args->total_bytes = dev->total_bytes; diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index d241130a..c7d7908 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -1548,9 +1548,10 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) * is held. */ list_for_each_entry(tmp, devices, dev_list) { + btrfs_check_dev_missing(root, tmp, 0); if (tmp->in_fs_metadata && !tmp->is_tgtdev_for_dev_replace && - !tmp->bdev) { + (!tmp->bdev || tmp->missing)) { device = tmp; break; } @@ -6300,3 +6301,25 @@ int btrfs_scratch_superblock(struct btrfs_device *device) return 0; } + +/* If need_lock is set, uuid_mutex will be used */ +int btrfs_check_dev_missing(struct btrfs_root *root, struct btrfs_device *dev, + int need_lock) +{ + struct request_queue *q; + + if (unlikely(!dev || !dev->bdev || !dev->bdev->bd_queue)) + return -ENOENT; + q = dev->bdev->bd_queue; + + if (need_lock) + mutex_lock(&uuid_mutex); + if (test_bit(QUEUE_FLAG_DEAD, &q->queue_flags) || + test_bit(QUEUE_FLAG_DYING, &q->queue_flags)) { + dev->missing = 1; + root->fs_info->fs_devices->missing_devices++; + } + if (need_lock) + mutex_unlock(&uuid_mutex); + return 0; +} diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 80754f9..47a44af 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -356,6 +356,8 @@ unsigned long btrfs_full_stripe_len(struct btrfs_root *root, int btrfs_finish_chunk_alloc(struct btrfs_trans_handle *trans, struct btrfs_root *extent_root, u64 chunk_offset, u64 chunk_size); +int btrfs_check_dev_missing(struct btrfs_root *root, struct btrfs_device *dev, + int need_lock); static inline void btrfs_dev_stat_inc(struct btrfs_device *dev, int index) {