From 696cb63d7e78b5201b42cb1763a7cec41528708d Mon Sep 17 00:00:00 2001 From: zhangdaolong Date: Tue, 24 Mar 2020 08:51:44 +0800 Subject: [PATCH] pybind/rbd: fix no lockers are obtained, ImageNotFound exception will be output MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit No lockers are obtained, ImageNotFound exception will be output, but tht image is always exist.when lockers number is zero, Should not output any exceptions。 Fixes: https://tracker.ceph.com/issues/44613 Signed-off-by: zhangdaolong (cherry picked from commit a183aac978dac69f996250324975073a78cb476b) --- src/pybind/rbd/rbd.pyx | 3 +++ src/test/pybind/test_rbd.py | 5 ++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/pybind/rbd/rbd.pyx b/src/pybind/rbd/rbd.pyx index f7685d60e06c9..a389a3d10cea0 100644 --- a/src/pybind/rbd/rbd.pyx +++ b/src/pybind/rbd/rbd.pyx @@ -4721,6 +4721,9 @@ cdef class LockOwnerIterator(object): &self.num_lock_owners) if ret >= 0: break + elif ret == -errno.ENOENT: + self.num_lock_owners = 0 + break elif ret != -errno.ERANGE: raise make_ex(ret, 'error listing lock owners for image %s' % image.name) diff --git a/src/test/pybind/test_rbd.py b/src/test/pybind/test_rbd.py index 214266515fe4c..a353075e9a9d4 100644 --- a/src/test/pybind/test_rbd.py +++ b/src/test/pybind/test_rbd.py @@ -1728,10 +1728,13 @@ class TestExclusiveLock(object): rados2.conf_set('rbd_blacklist_on_break_lock', 'true') with Image(ioctx2, image_name) as image, \ Image(blacklist_ioctx, image_name) as blacklist_image: + + lock_owners = list(image.lock_get_owners()) + eq(0, len(lock_owners)) + blacklist_image.lock_acquire(RBD_LOCK_MODE_EXCLUSIVE) assert_raises(ReadOnlyImage, image.lock_acquire, RBD_LOCK_MODE_EXCLUSIVE) - lock_owners = list(image.lock_get_owners()) eq(1, len(lock_owners)) eq(RBD_LOCK_MODE_EXCLUSIVE, lock_owners[0]['mode']) -- 2.39.5