This patch provides the readmirror=devid<n> feature configurable through
the mount option which is transient and can be applied during readonly
mount as well.
For example:
mount -o readmirror=devid<n>
Signed-off-by: Anand Jain <anand.jain@xxxxxxxxxx>
---
fs/btrfs/super.c | 19 +++++++++++++++++++
fs/btrfs/volumes.c | 2 ++
fs/btrfs/volumes.h | 1 +
3 files changed, 22 insertions(+)
diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 9d25a01bcecb..5aa1a4d14cd7 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -857,6 +857,25 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char *options,
info->fs_devices->readmirror_policy =
BTRFS_READMIRROR_PID;
break;
+ } else if (strncmp(args[0].from, "devid", 5) == 0) {
+ u64 devid;
+ struct btrfs_device *device;
+
+ if (kstrtoull(args[0].from + 5, 10, &devid)) {
+ ret = -EINVAL;
+ goto out;
+ }
+ info->fs_devices->readmirror_policy =
+ BTRFS_READMIRROR_DEVID;
+ device = btrfs_find_device(info->fs_devices,
+ devid, NULL, NULL,
+ false);
+ if (!device) {
+ ret = -ENODEV;
+ goto out;
+ }
+ device->type_in_ram = BTRFS_DEVICE_TYPE_READ_OPTIMIZED;
+ break;
}
ret = -EINVAL;
goto out;
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index d3b7427d6d96..637617087c83 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5569,6 +5569,8 @@ static int find_live_mirror(struct btrfs_fs_info *fs_info,
if (map->type & BTRFS_BLOCK_GROUP_RAID1) {
for (i = first; i < first + num_stripes; i++) {
if (map->stripes[i].dev->type ==
+ BTRFS_DEVICE_TYPE_READ_OPTIMIZED ||
+ map->stripes[i].dev->type_in_ram ==
BTRFS_DEVICE_TYPE_READ_OPTIMIZED) {
preferred_mirror = i;
found = true;
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 9c2e64548a11..3e534bcaf43e 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -91,6 +91,7 @@ struct btrfs_device {
u32 io_width;
/* type and info about this device */
u64 type;
+ u64 type_in_ram;
/* minimal io size for this device */
u32 sector_size;
--
1.8.3.1