From patchwork Mon Nov 9 10:56:27 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 7582501 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 B35F99F2F7 for ; Mon, 9 Nov 2015 10:58:03 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE3EA2069D for ; Mon, 9 Nov 2015 10:58:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id DAB7520697 for ; Mon, 9 Nov 2015 10:58:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752820AbbKIK55 (ORCPT ); Mon, 9 Nov 2015 05:57:57 -0500 Received: from userp1040.oracle.com ([156.151.31.81]:51088 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752754AbbKIK5t (ORCPT ); Mon, 9 Nov 2015 05:57:49 -0500 Received: from aserv0022.oracle.com (aserv0022.oracle.com [141.146.126.234]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id tA9AvmCx014246 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Mon, 9 Nov 2015 10:57:48 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0022.oracle.com (8.13.8/8.13.8) with ESMTP id tA9Avmg7004902 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=FAIL) for ; Mon, 9 Nov 2015 10:57:48 GMT Received: from abhmp0005.oracle.com (abhmp0005.oracle.com [141.146.116.11]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id tA9Avmf0003541 for ; Mon, 9 Nov 2015 10:57:48 GMT Received: from arch2.sg.oracle.com (/10.186.101.93) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 09 Nov 2015 02:57:47 -0800 From: Anand Jain To: linux-btrfs@vger.kernel.org Subject: [PATCH 13/15] btrfs: provide framework to get and put a spare device Date: Mon, 9 Nov 2015 18:56:27 +0800 Message-Id: <1447066589-3835-14-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 2.4.1 In-Reply-To: <1447066589-3835-1-git-send-email-anand.jain@oracle.com> References: <1447066589-3835-1-git-send-email-anand.jain@oracle.com> X-Source-IP: aserv0022.oracle.com [141.146.126.234] 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.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable 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 This adds functions to get and put a spare device from the list. So that hot repace code can pick a spare device when needed. Signed-off-by: Anand Jain --- fs/btrfs/super.c | 9 +++++++++ fs/btrfs/volumes.c | 37 +++++++++++++++++++++++++++++++++++++ fs/btrfs/volumes.h | 2 ++ 3 files changed, 48 insertions(+) diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c index d495790..29836ca 100644 --- a/fs/btrfs/super.c +++ b/fs/btrfs/super.c @@ -2035,6 +2035,15 @@ static int btrfs_control_open(struct inode *inode, struct file *file) return 0; } +void btrfs_put_spare_device(char *path) +{ + struct btrfs_fs_devices *fs_devices; + + if (btrfs_scan_one_device(path, FMODE_READ, + &btrfs_fs_type, &fs_devices)) + printk(KERN_INFO "failed to return spare device\n"); +} + /* * used by btrfsctl to scan devices when no FS is mounted */ diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c index 28f549d..3b90690 100644 --- a/fs/btrfs/volumes.c +++ b/fs/btrfs/volumes.c @@ -7017,3 +7017,40 @@ void btrfs_force_device_close(struct btrfs_device *dev, char *why) rcu_str_deref(dev->name), why); rcu_read_unlock(); } + +int btrfs_get_spare_device(char **path) +{ + int ret = 1; + struct btrfs_fs_devices *fs_devices; + struct btrfs_device *device; + struct list_head *fs_uuids = btrfs_get_fs_uuids(); + + mutex_lock(&uuid_mutex); + list_for_each_entry(fs_devices, fs_uuids, list) { + if (!fs_devices->spare) + continue; + + /* as of now there is only one device in the spare fs_devices */ + device = list_entry(fs_devices->devices.next, + struct btrfs_device, dev_list); + + if (!device || !device->name) + continue; + + fs_devices->spare = 0; + rcu_read_lock(); + *path = kstrdup(device->name->str, GFP_NOFS); + rcu_read_unlock(); + ret = 0; + break; + } + + if (!ret) { + btrfs_sysfs_remove_fsid(fs_devices); + list_del(&fs_devices->list); + free_fs_devices(fs_devices); + } + mutex_unlock(&uuid_mutex); + + return ret; +} diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h index 3d995b7..36184ec 100644 --- a/fs/btrfs/volumes.h +++ b/fs/btrfs/volumes.h @@ -577,5 +577,7 @@ void btrfs_reset_fs_info_ptr(struct btrfs_fs_info *fs_info); void btrfs_close_one_device(struct btrfs_device *device); int btrfs_check_degradable(struct btrfs_fs_info *fs_info, unsigned flags); void btrfs_force_device_close(struct btrfs_device *dev, char *why); +int btrfs_get_spare_device(char **path); +void btrfs_put_spare_device(char *path); #endif