From bc28c3af4dda4a255008cc1f53a4f2ce02e158ea Mon Sep 17 00:00:00 2001 From: Mykola Golub Date: Fri, 7 Dec 2018 17:18:19 +0200 Subject: [PATCH] pybind/rbd: optimize rbd_list2 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 --- src/pybind/rbd/rbd.pyx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index 796046ba0cb..0c0feb11309 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -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 = 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):