From patchwork Sat Apr 2 01:30:48 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anand Jain X-Patchwork-Id: 8730051 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 CA1219FC82 for ; Sat, 2 Apr 2016 01:31:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id F1D3B203A0 for ; Sat, 2 Apr 2016 01:31:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 83BE3203A1 for ; Sat, 2 Apr 2016 01:31:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932367AbcDBBb3 (ORCPT ); Fri, 1 Apr 2016 21:31:29 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:48442 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932241AbcDBBb0 (ORCPT ); Fri, 1 Apr 2016 21:31:26 -0400 Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u321VNpo032139 (version=TLSv1 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 2 Apr 2016 01:31:24 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by userv0021.oracle.com (8.13.8/8.13.8) with ESMTP id u321VNnW023885 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Sat, 2 Apr 2016 01:31:23 GMT Received: from abhmp0019.oracle.com (abhmp0019.oracle.com [141.146.116.25]) by aserv0121.oracle.com (8.13.8/8.13.8) with ESMTP id u321VN6Q021464; Sat, 2 Apr 2016 01:31:23 GMT Received: from arch2.localdomain (/42.60.24.64) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Fri, 01 Apr 2016 18:31:22 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: yauhen.kharuzhy@zavadatar.com, dsterba@suse.cz Subject: [PATCH 10/13] btrfs: introduce helper functions to perform hot replace Date: Sat, 2 Apr 2016 09:30:48 +0800 Message-Id: <1459560651-14809-11-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1459560651-14809-1-git-send-email-anand.jain@oracle.com> References: <1459560651-14809-1-git-send-email-anand.jain@oracle.com> X-Source-IP: userv0021.oracle.com [156.151.31.71] 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.9 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 Hot replace / auto replace is important volume manager feature and is critical to the data center operations, so that the degraded volume can be brought back to a healthy state at the earliest and without manual intervention. This modifies the existing replace code to suite the need of auto replace, in the long run I hope both the codes to be merged. Signed-off-by: Anand Jain Tested-by: Austin S. Hemmelgarn --- fs/btrfs/dev-replace.c | 43 +++++++++++++++++++++++++++++++++++++++++++ fs/btrfs/dev-replace.h | 1 + 2 files changed, 44 insertions(+) diff --git a/fs/btrfs/dev-replace.c b/fs/btrfs/dev-replace.c index 2b926867d136..ceab4c51db32 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -957,3 +957,46 @@ void btrfs_bio_counter_inc_blocked(struct btrfs_fs_info *fs_info) &fs_info->fs_state)); } } + +int btrfs_auto_replace_start(struct btrfs_root *root, + struct btrfs_device *src_device) +{ + int ret; + char *tgt_path; + char *src_path; + struct btrfs_fs_info *fs_info = root->fs_info; + + if (fs_info->sb->s_flags & MS_RDONLY) + return -EROFS; + + btrfs_dev_replace_lock(&fs_info->dev_replace, 0); + if (btrfs_dev_replace_is_ongoing(&fs_info->dev_replace)) { + btrfs_dev_replace_unlock(&fs_info->dev_replace, 0); + return -EBUSY; + } + btrfs_dev_replace_unlock(&fs_info->dev_replace, 0); + + if (btrfs_get_spare_device(&tgt_path)) { + btrfs_err(root->fs_info, + "No spare device found/configured in the kernel"); + return -EINVAL; + } + + rcu_read_lock(); + src_path = kstrdup(rcu_str_deref(src_device->name), GFP_ATOMIC); + rcu_read_unlock(); + if (!src_path) { + kfree(tgt_path); + return -ENOMEM; + } + ret = btrfs_dev_replace_start(root, tgt_path, + src_device->devid, src_path, + BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_AVOID); + if (ret) + btrfs_put_spare_device(tgt_path); + + kfree(tgt_path); + kfree(src_path); + + return 0; +} diff --git a/fs/btrfs/dev-replace.h b/fs/btrfs/dev-replace.h index e922b42d91df..b918b9d6e5df 100644 --- a/fs/btrfs/dev-replace.h +++ b/fs/btrfs/dev-replace.h @@ -46,4 +46,5 @@ static inline void btrfs_dev_replace_stats_inc(atomic64_t *stat_value) { atomic64_inc(stat_value); } +int btrfs_auto_replace_start(struct btrfs_root *root, struct btrfs_device *src_device); #endif