From: Anand Jain <anand.jain@oracle.com>
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 [thread overview]
Message-ID: <1462888911-5227-12-git-send-email-anand.jain@oracle.com> (raw)
In-Reply-To: <1462888911-5227-1-git-send-email-anand.jain@oracle.com>
From: Anand Jain <Anand.Jain@oracle.com>
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 <anand.jain@oracle.com>
Tested-by: Austin S. Hemmelgarn <ahferroin7@gmail.com>
Tested-by: Yauhen Kharuzhy <yauhen.kharuzhy@zavadatar.com>
---
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
--
2.7.0
next prev parent reply other threads:[~2016-05-10 14:02 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-05-10 14:01 [PATCH v6 00/13] Introduce device state 'failed', spare device and auto replace Anand Jain
2016-05-10 14:01 ` [PATCH 01/13] btrfs: Introduce a new function to check if all chunks a OK for degraded mount Anand Jain
2016-05-10 14:01 ` [PATCH 1/1] btrfs: introduce helper functions to perform hot replace Anand Jain
2016-05-10 14:01 ` [PATCH 02/13] btrfs: Do per-chunk check for mount time check Anand Jain
2016-05-10 14:01 ` [PATCH 03/13] btrfs: Do per-chunk degraded check for remount Anand Jain
2016-05-10 14:01 ` [PATCH 04/13] btrfs: Allow barrier_all_devices to do per-chunk device check Anand Jain
2016-05-10 14:01 ` [PATCH 05/13] btrfs: Cleanup num_tolerated_disk_barrier_failures Anand Jain
2016-05-10 14:01 ` [PATCH] btrfs: introduce BTRFS_FEATURE_INCOMPAT_SPARE_DEV Anand Jain
2016-05-10 14:01 ` [PATCH 07/13] btrfs: add check not to mount a spare device Anand Jain
2016-05-10 14:01 ` [PATCH 08/13] btrfs: support btrfs dev scan for " Anand Jain
2016-05-10 14:01 ` [PATCH 09/13] btrfs: provide framework to get and put a " Anand Jain
2016-05-10 14:01 ` Anand Jain [this message]
2016-05-10 14:01 ` [PATCH 1/1] btrfs: introduce device dynamic state transition to offline or failed Anand Jain
2016-05-10 14:01 ` [PATCH 1/1] btrfs: check device for critical errors and mark failed Anand Jain
2016-05-10 14:01 ` [PATCH 13/13] btrfs: check for failed device and hot replace Anand Jain
-- strict thread matches above, loose matches on Subject: below --
2016-05-10 14:09 [PATCH v6 00/13] Introduce device state 'failed', spare device and auto replace Anand Jain
2016-05-10 14:09 ` [PATCH 1/1] btrfs: introduce helper functions to perform hot replace Anand Jain
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1462888911-5227-12-git-send-email-anand.jain@oracle.com \
--to=anand.jain@oracle.com \
--cc=dsterba@suse.cz \
--cc=linux-btrfs@vger.kernel.org \
--cc=yauhen.kharuzhy@zavadatar.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).