| From 4e19de3be14c9390e63271effb5b95ab50f298f4 Mon Sep 17 00:00:00 2001 |
| From: NeilBrown <neilb@suse.de> |
| Date: Thu, 27 Sep 2012 12:35:21 +1000 |
| Subject: md/raid10: fix "enough" function for detecting if array is failed. |
| MIME-Version: 1.0 |
| Content-Type: text/plain; charset=UTF-8 |
| Content-Transfer-Encoding: 8bit |
| |
| From: NeilBrown <neilb@suse.de> |
| |
| commit 80b4812407c6b1f66a4f2430e69747a13f010839 upstream. |
| |
| The 'enough' function is written to work with 'near' arrays only |
| in that is implicitly assumes that the offset from one 'group' of |
| devices to the next is the same as the number of copies. |
| In reality it is the number of 'near' copies. |
| |
| So change it to make this number explicit. |
| |
| This bug makes it possible to run arrays without enough drives |
| present, which is dangerous. |
| It is appropriate for an -stable kernel, but will almost certainly |
| need to be modified for some of them. |
| |
| Reported-by: Jakub Husรกk <jakub@gooseman.cz> |
| Signed-off-by: NeilBrown <neilb@suse.de> |
| [bwh: Backported to 3.2: s/geo->/conf->/] |
| Signed-off-by: Ben Hutchings <ben@decadent.org.uk> |
| Cc: Rui Xiang <rui.xiang@huawei.com> |
| Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> |
| |
| --- |
| drivers/md/raid10.c | 8 +++++--- |
| 1 file changed, 5 insertions(+), 3 deletions(-) |
| |
| --- a/drivers/md/raid10.c |
| +++ b/drivers/md/raid10.c |
| @@ -1419,14 +1419,16 @@ static int enough(struct r10conf *conf, |
| do { |
| int n = conf->copies; |
| int cnt = 0; |
| + int this = first; |
| while (n--) { |
| - if (conf->mirrors[first].rdev && |
| - first != ignore) |
| + if (conf->mirrors[this].rdev && |
| + this != ignore) |
| cnt++; |
| - first = (first+1) % conf->raid_disks; |
| + this = (this+1) % conf->raid_disks; |
| } |
| if (cnt == 0) |
| return 0; |
| + first = (first + conf->near_copies) % conf->raid_disks; |
| } while (first != 0); |
| return 1; |
| } |