]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
crush: reject on empty bucket (and avoid divide by zero)
authorSage Weil <sage@newdream.net>
Tue, 6 Oct 2009 20:55:26 +0000 (13:55 -0700)
committerSage Weil <sage@newdream.net>
Tue, 6 Oct 2009 21:00:54 +0000 (14:00 -0700)
src/crush/mapper.c

index 0f0730c62695d029716b4a0918e113464ca8a99c..213b5c0c075d21f7626bf44a75966f0cb41dfcd4 100644 (file)
@@ -316,6 +316,7 @@ static int crush_choose(struct crush_map *map,
                        /* choose through intervening buckets */
                        flocal = 0;
                        do {
+                               collide = 0;
                                retry_bucket = 0;
                                r = rep;
                                if (in->alg == CRUSH_BUCKET_UNIFORM) {
@@ -340,6 +341,10 @@ static int crush_choose(struct crush_map *map,
                                }
 
                                /* bucket choose */
+                               if (in->size == 0) {
+                                       reject = 1;
+                                       goto reject;
+                               }
                                if (flocal >= (in->size>>1) &&
                                    flocal > orig_tries)
                                        item = bucket_perm_choose(in, x, r);
@@ -363,7 +368,6 @@ static int crush_choose(struct crush_map *map,
                                }
 
                                /* collision? */
-                               collide = 0;
                                for (i = 0; i < outpos; i++) {
                                        if (out[i] == item) {
                                                collide = 1;
@@ -388,6 +392,7 @@ static int crush_choose(struct crush_map *map,
                                                reject = 0;
                                }
 
+reject:
                                if (reject || collide) {
                                        ftotal++;
                                        flocal++;