]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
osd/OSDMap: make get prev/next up osd more efficient 12976/head
authorMingxin Liu <mingxin@xsky.com>
Wed, 18 Jan 2017 10:31:52 +0000 (18:31 +0800)
committerMingxin Liu <mingxin@xsky.com>
Wed, 18 Jan 2017 10:38:57 +0000 (18:38 +0800)
what's more, in get_previous_up_osd_before(), if arg n = 0, run into endless loop

Signed-off-by: Mingxin Liu <mingxin@xsky.com>
src/osd/OSDMap.h

index 1d966e0321aae898cf73d995aef88db147dbfd14..c662bdcea8dc8ad8a108115d8a791220b2a9f3b1 100644 (file)
@@ -525,6 +525,8 @@ public:
   }
   
   int get_next_up_osd_after(int n) const {
+    if (get_max_osd() == 0)
+      return -1;
     for (int i = n + 1; i != n; ++i) {
       if (i >= get_max_osd())
        i = 0;
@@ -537,6 +539,8 @@ public:
   }
 
   int get_previous_up_osd_before(int n) const {
+    if (get_max_osd() == 0)
+      return -1;
     for (int i = n - 1; i != n; --i) {
       if (i < 0)
        i = get_max_osd() - 1;