aboutsummaryrefslogtreecommitdiffstats
path: root/fs
diff options
context:
space:
mode:
authorChris Mason <chris.mason@oracle.com>2008-04-21 12:01:38 -0400
committerChris Mason <chris.mason@oracle.com>2008-09-25 11:04:02 -0400
commit3c12ac7205d4bd679fefa722aa9b61385e4b4749 (patch)
tree6582fba4c63ce451be7a338acb351cf17b9d766d /fs
parentf2d8d74d7874f8f81222363cd6459a365796e35a (diff)
Btrfs: Simplify device selection for mirrored reads
Signed-off-by: Chris Mason <chris.mason@oracle.com>
Diffstat (limited to 'fs')
-rw-r--r--fs/btrfs/extent-tree.c8
-rw-r--r--fs/btrfs/volumes.c23
2 files changed, 11 insertions, 20 deletions
diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c
index 593011e5d455..cc0d7f30c36b 100644
--- a/fs/btrfs/extent-tree.c
+++ b/fs/btrfs/extent-tree.c
@@ -640,7 +640,7 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
640 if (!path) 640 if (!path)
641 return -ENOMEM; 641 return -ENOMEM;
642 642
643 path->reada = 0; 643 path->reada = 1;
644 key.objectid = bytenr; 644 key.objectid = bytenr;
645 btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY); 645 btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY);
646 key.offset = num_bytes; 646 key.offset = num_bytes;
@@ -660,7 +660,7 @@ int btrfs_inc_extent_ref(struct btrfs_trans_handle *trans,
660 660
661 btrfs_release_path(root->fs_info->extent_root, path); 661 btrfs_release_path(root->fs_info->extent_root, path);
662 662
663 path->reada = 0; 663 path->reada = 1;
664 ret = btrfs_insert_extent_backref(trans, root->fs_info->extent_root, 664 ret = btrfs_insert_extent_backref(trans, root->fs_info->extent_root,
665 path, bytenr, root_objectid, 665 path, bytenr, root_objectid,
666 ref_generation, owner, owner_offset); 666 ref_generation, owner, owner_offset);
@@ -692,7 +692,7 @@ static int lookup_extent_ref(struct btrfs_trans_handle *trans,
692 692
693 WARN_ON(num_bytes < root->sectorsize); 693 WARN_ON(num_bytes < root->sectorsize);
694 path = btrfs_alloc_path(); 694 path = btrfs_alloc_path();
695 path->reada = 0; 695 path->reada = 1;
696 key.objectid = bytenr; 696 key.objectid = bytenr;
697 key.offset = num_bytes; 697 key.offset = num_bytes;
698 btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY); 698 btrfs_set_key_type(&key, BTRFS_EXTENT_ITEM_KEY);
@@ -1328,7 +1328,7 @@ static int __free_extent(struct btrfs_trans_handle *trans, struct btrfs_root
1328 if (!path) 1328 if (!path)
1329 return -ENOMEM; 1329 return -ENOMEM;
1330 1330
1331 path->reada = 0; 1331 path->reada = 1;
1332 ret = lookup_extent_backref(trans, extent_root, path, 1332 ret = lookup_extent_backref(trans, extent_root, path,
1333 bytenr, root_objectid, 1333 bytenr, root_objectid,
1334 ref_generation, 1334 ref_generation,
diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 460240706505..107fc74c3ab8 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -1029,19 +1029,8 @@ again:
1029 else if (mirror_num) { 1029 else if (mirror_num) {
1030 stripe_index = mirror_num - 1; 1030 stripe_index = mirror_num - 1;
1031 } else { 1031 } else {
1032 int i; 1032 u64 orig_stripe_nr = stripe_nr;
1033 u64 least = (u64)-1; 1033 stripe_index = do_div(orig_stripe_nr, num_stripes);
1034 struct btrfs_device *cur;
1035
1036 for (i = 0; i < map->num_stripes; i++) {
1037 cur = map->stripes[i].dev;
1038 spin_lock(&cur->io_lock);
1039 if (cur->total_ios < least) {
1040 least = cur->total_ios;
1041 stripe_index = i;
1042 }
1043 spin_unlock(&cur->io_lock);
1044 }
1045 } 1034 }
1046 } else if (map->type & BTRFS_BLOCK_GROUP_DUP) { 1035 } else if (map->type & BTRFS_BLOCK_GROUP_DUP) {
1047 if (rw & (1 << BIO_RW)) 1036 if (rw & (1 << BIO_RW))
@@ -1050,7 +1039,6 @@ again:
1050 stripe_index = mirror_num - 1; 1039 stripe_index = mirror_num - 1;
1051 } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) { 1040 } else if (map->type & BTRFS_BLOCK_GROUP_RAID10) {
1052 int factor = map->num_stripes / map->sub_stripes; 1041 int factor = map->num_stripes / map->sub_stripes;
1053 int orig_stripe_nr = stripe_nr;
1054 1042
1055 stripe_index = do_div(stripe_nr, factor); 1043 stripe_index = do_div(stripe_nr, factor);
1056 stripe_index *= map->sub_stripes; 1044 stripe_index *= map->sub_stripes;
@@ -1059,8 +1047,11 @@ again:
1059 num_stripes = map->sub_stripes; 1047 num_stripes = map->sub_stripes;
1060 else if (mirror_num) 1048 else if (mirror_num)
1061 stripe_index += mirror_num - 1; 1049 stripe_index += mirror_num - 1;
1062 else 1050 else {
1063 stripe_index += orig_stripe_nr % map->sub_stripes; 1051 u64 orig_stripe_nr = stripe_nr;
1052 stripe_index += do_div(orig_stripe_nr,
1053 map->sub_stripes);
1054 }
1064 } else { 1055 } else {
1065 /* 1056 /*
1066 * after this do_div call, stripe_nr is the number of stripes 1057 * after this do_div call, stripe_nr is the number of stripes