From patchwork Tue May 10 14:01: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: 9058101 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 ADBBEBF29F for ; Tue, 10 May 2016 14:02:51 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CE4D220103 for ; Tue, 10 May 2016 14:02:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E034820154 for ; Tue, 10 May 2016 14:02:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752650AbcEJOCP (ORCPT ); Tue, 10 May 2016 10:02:15 -0400 Received: from userp1040.oracle.com ([156.151.31.81]:46639 "EHLO userp1040.oracle.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752196AbcEJOCO (ORCPT ); Tue, 10 May 2016 10:02:14 -0400 Received: from userv0022.oracle.com (userv0022.oracle.com [156.151.31.74]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id u4AE2B9P032354 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 10 May 2016 14:02:11 GMT Received: from aserv0122.oracle.com (aserv0122.oracle.com [141.146.126.236]) by userv0022.oracle.com (8.14.4/8.13.8) with ESMTP id u4AE2A8g025470 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Tue, 10 May 2016 14:02:11 GMT Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by aserv0122.oracle.com (8.13.8/8.13.8) with ESMTP id u4AE28LQ001372; Tue, 10 May 2016 14:02:09 GMT Received: from arch2.sg.oracle.com (/10.186.101.65) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 10 May 2016 07:02:07 -0700 From: Anand Jain To: linux-btrfs@vger.kernel.org Cc: dsterba@suse.cz, yauhen.kharuzhy@zavadatar.com Subject: [PATCH 1/1] btrfs: introduce helper functions to perform hot replace Date: Tue, 10 May 2016 22:01:48 +0800 Message-Id: <1462888911-5227-12-git-send-email-anand.jain@oracle.com> X-Mailer: git-send-email 2.7.0 In-Reply-To: <1462888911-5227-1-git-send-email-anand.jain@oracle.com> References: <1462888911-5227-1-git-send-email-anand.jain@oracle.com> X-Source-IP: userv0022.oracle.com [156.151.31.74] Sender: linux-btrfs-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-btrfs@vger.kernel.org X-Spam-Status: No, score=-9.0 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 From: Anand Jain 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 Tested-by: Yauhen Kharuzhy --- v6: update the printk for space device error to ratelimit 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 5ec7fa860391..83af64907547 100644 --- a/fs/btrfs/dev-replace.c +++ b/fs/btrfs/dev-replace.c @@ -937,3 +937,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, u64 src_devid) +{ + int ret; + char *tgt_path; + struct btrfs_fs_info *fs_info = root->fs_info; + + if (!src_devid) + return -EINVAL; + + 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_info_rl(root->fs_info, + "No spare device found/configured in the kernel"); + return -EINVAL; + } + + if (atomic_xchg( + &root->fs_info->mutually_exclusive_operation_running, 1)) { + ret = BTRFS_ERROR_DEV_EXCL_RUN_IN_PROGRESS; + } else { + ret = btrfs_dev_replace_start(root, tgt_path, src_devid, NULL, + BTRFS_IOCTL_DEV_REPLACE_CONT_READING_FROM_SRCDEV_MODE_ALWAYS); + atomic_set( + &root->fs_info->mutually_exclusive_operation_running, 0); + } + + if (ret) + btrfs_put_spare_device(tgt_path); + + kfree(tgt_path); + + return ret; +} diff --git a/fs/btrfs/dev-replace.h b/fs/btrfs/dev-replace.h index e922b42d91df..54b0812c8ba4 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, u64 src_devid); #endif