]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
pybind/rbd: optimize rbd_list2
authorMykola Golub <mgolub@suse.com>
Fri, 7 Dec 2018 15:18:19 +0000 (17:18 +0200)
committerMykola Golub <mgolub@suse.com>
Fri, 7 Dec 2018 15:18:19 +0000 (17:18 +0200)
If rbd_list2 returns ERANGE, it sets num_images to the value required.
But it is better to retry with a bigger number, to avoid new retries
if images are added to the pool at that time.

Also the initial value for num_images looks too small.

Signed-off-by: Mykola Golub <mgolub@suse.com>
src/pybind/rbd/rbd.pyx

index 796046ba0cb003c4efbab76a5dbb5496e2009ed9..0c0feb1130973ac17f0880b3e11e734efff53994 100644 (file)
@@ -4374,7 +4374,7 @@ cdef class ImageIterator(object):
     def __init__(self, ioctx):
         self.ioctx = convert_ioctx(ioctx)
         self.images = NULL
-        self.num_images = 32
+        self.num_images = 1024
         while True:
             self.images = <rbd_image_spec_t*>realloc_chk(
                 self.images, self.num_images * sizeof(rbd_image_spec_t))
@@ -4382,7 +4382,9 @@ cdef class ImageIterator(object):
                 ret = rbd_list2(self.ioctx, self.images, &self.num_images)
             if ret >= 0:
                 break
-            elif ret != -errno.ERANGE:
+            elif ret == -errno.ERANGE:
+                self.num_images *= 2
+            else:
                 raise make_ex(ret, 'error listing images.')
 
     def __iter__(self):