Adds the mount option:
  mount -o read_mirror_policy=<devid>

To set the devid of the device which should be used for read. That
means all the normal reads will go to that particular device only.

This also helps testing and gives a better control for the test
scripts including mount context reads.

Signed-off-by: Anand Jain <anand.j...@oracle.com>
---
 fs/btrfs/super.c   | 21 +++++++++++++++++++++
 fs/btrfs/volumes.c | 10 ++++++++++
 fs/btrfs/volumes.h |  2 ++
 3 files changed, 33 insertions(+)

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index dfe6b3c67df3..d3aad8cccc7e 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -847,6 +847,27 @@ int btrfs_parse_options(struct btrfs_fs_info *info, char 
*options,
                                        BTRFS_READ_MIRROR_BY_PID;
                                break;
                        }
+
+                       intarg = 0;
+                       if (match_int(&args[0], &intarg) == 0) {
+                               struct btrfs_device *device;
+
+                               device = btrfs_find_device(info, intarg,
+                                                          NULL, NULL);
+                               if (!device) {
+                                       btrfs_err(info,
+                                         "read_mirror_policy: invalid devid 
%d",
+                                         intarg);
+                                       ret = -EINVAL;
+                                       goto out;
+                               }
+                               info->read_mirror_policy =
+                                               BTRFS_READ_MIRROR_BY_DEV;
+                               set_bit(BTRFS_DEV_STATE_READ_MIRROR,
+                                       &device->dev_state);
+                               break;
+                       }
+
                        ret = -EINVAL;
                        goto out;
                case Opt_err:
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 39ba59832f38..478623e6e074 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -5270,6 +5270,16 @@ static int find_live_mirror(struct btrfs_fs_info 
*fs_info,
                num = map->num_stripes;
 
        switch(fs_info->read_mirror_policy) {
+       case BTRFS_READ_MIRROR_BY_DEV:
+               optimal = first;
+               if (test_bit(BTRFS_DEV_STATE_READ_MIRROR,
+                            &map->stripes[optimal].dev->dev_state))
+                       break;
+               if (test_bit(BTRFS_DEV_STATE_READ_MIRROR,
+                            &map->stripes[++optimal].dev->dev_state))
+                       break;
+               optimal = first;
+               break;
        case BTRFS_READ_MIRROR_DEFAULT:
        case BTRFS_READ_MIRROR_BY_PID:
        default:
diff --git a/fs/btrfs/volumes.h b/fs/btrfs/volumes.h
index 78f35d299a61..7281f55dea05 100644
--- a/fs/btrfs/volumes.h
+++ b/fs/btrfs/volumes.h
@@ -50,6 +50,7 @@ struct btrfs_pending_bios {
 enum btrfs_read_mirror_type {
        BTRFS_READ_MIRROR_DEFAULT,
        BTRFS_READ_MIRROR_BY_PID,
+       BTRFS_READ_MIRROR_BY_DEV,
 };
 
 #define BTRFS_DEV_STATE_WRITEABLE      (0)
@@ -57,6 +58,7 @@ enum btrfs_read_mirror_type {
 #define BTRFS_DEV_STATE_MISSING                (2)
 #define BTRFS_DEV_STATE_REPLACE_TGT    (3)
 #define BTRFS_DEV_STATE_FLUSH_SENT     (4)
+#define BTRFS_DEV_STATE_READ_MIRROR    (5)
 
 struct btrfs_device {
        struct list_head dev_list;
-- 
2.7.0

--
To unsubscribe from this list: send the line "unsubscribe linux-btrfs" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to