diff options
author | Sandeep K Sinha <sandeepksinha@gmail.com> | 2009-06-16 02:57:08 -0400 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2009-06-16 02:57:08 -0400 |
commit | aece3d1f40879759f641dfbfdbb9e2593adeb43c (patch) | |
tree | 0264ac8e02f4d08472c11b04305f8c39695d9007 /drivers/md | |
parent | 4db7cdc859f56ecf0a186e0cfb238b5bb3af2efb (diff) |
md: Binary search in linear raid
Replace the linear search with binary search in which_dev.
Signed-off-by: Sandeep K Sinha <sandeepksinha@gmail.com>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/md')
-rw-r--r-- | drivers/md/linear.c | 22 |
1 files changed, 17 insertions, 5 deletions
diff --git a/drivers/md/linear.c b/drivers/md/linear.c index 529a3d37e3fe..9b02a73fbc6b 100644 --- a/drivers/md/linear.c +++ b/drivers/md/linear.c | |||
@@ -27,14 +27,26 @@ | |||
27 | */ | 27 | */ |
28 | static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector) | 28 | static inline dev_info_t *which_dev(mddev_t *mddev, sector_t sector) |
29 | { | 29 | { |
30 | dev_info_t *hash; | 30 | int lo, mid, hi; |
31 | linear_conf_t *conf = mddev->private; | 31 | linear_conf_t *conf = mddev->private; |
32 | 32 | ||
33 | hash = conf->disks; | 33 | lo = 0; |
34 | hi = mddev->raid_disks - 1; | ||
34 | 35 | ||
35 | while (sector >= hash->end_sector) | 36 | /* |
36 | hash++; | 37 | * Binary Search |
37 | return hash; | 38 | */ |
39 | |||
40 | while (hi > lo) { | ||
41 | |||
42 | mid = (hi + lo) / 2; | ||
43 | if (sector < conf->disks[mid].end_sector) | ||
44 | hi = mid; | ||
45 | else | ||
46 | lo = mid + 1; | ||
47 | } | ||
48 | |||
49 | return conf->disks + lo; | ||
38 | } | 50 | } |
39 | 51 | ||
40 | /** | 52 | /** |