提交 b28813a6 编写于 作者: S Sage Weil

ceph: gracefully avoid empty crush buckets

This avoids a divide by zero when the input and/or map are
malformed.
Signed-off-by: NSage Weil <sage@newdream.net>
上级 b195befd
...@@ -299,7 +299,7 @@ static int crush_choose(struct crush_map *map, ...@@ -299,7 +299,7 @@ static int crush_choose(struct crush_map *map,
struct crush_bucket *in = bucket; struct crush_bucket *in = bucket;
int r; int r;
int i; int i;
int item; int item = 0;
int itemtype; int itemtype;
int collide, reject; int collide, reject;
const int orig_tries = 5; /* attempts before we fall back to search */ const int orig_tries = 5; /* attempts before we fall back to search */
...@@ -316,6 +316,7 @@ static int crush_choose(struct crush_map *map, ...@@ -316,6 +316,7 @@ static int crush_choose(struct crush_map *map,
/* choose through intervening buckets */ /* choose through intervening buckets */
flocal = 0; flocal = 0;
do { do {
collide = 0;
retry_bucket = 0; retry_bucket = 0;
r = rep; r = rep;
if (in->alg == CRUSH_BUCKET_UNIFORM) { if (in->alg == CRUSH_BUCKET_UNIFORM) {
...@@ -340,6 +341,10 @@ static int crush_choose(struct crush_map *map, ...@@ -340,6 +341,10 @@ static int crush_choose(struct crush_map *map,
} }
/* bucket choose */ /* bucket choose */
if (in->size == 0) {
reject = 1;
goto reject;
}
if (flocal >= (in->size>>1) && if (flocal >= (in->size>>1) &&
flocal > orig_tries) flocal > orig_tries)
item = bucket_perm_choose(in, x, r); item = bucket_perm_choose(in, x, r);
...@@ -363,7 +368,6 @@ static int crush_choose(struct crush_map *map, ...@@ -363,7 +368,6 @@ static int crush_choose(struct crush_map *map,
} }
/* collision? */ /* collision? */
collide = 0;
for (i = 0; i < outpos; i++) { for (i = 0; i < outpos; i++) {
if (out[i] == item) { if (out[i] == item) {
collide = 1; collide = 1;
...@@ -388,6 +392,7 @@ static int crush_choose(struct crush_map *map, ...@@ -388,6 +392,7 @@ static int crush_choose(struct crush_map *map,
reject = 0; reject = 0;
} }
reject:
if (reject || collide) { if (reject || collide) {
ftotal++; ftotal++;
flocal++; flocal++;
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册