Skip to content

Commit

Permalink
Merge pull request ceph#23664 from zy751713126/delete_redundant_code
Browse files Browse the repository at this point in the history
pybind/rbd: make the code more concise

Reviewed-by: Jason Dillaman <[email protected]>
Reviewed-by: Kefu Chai <[email protected]>
  • Loading branch information
tchaikov authored Aug 23, 2018
2 parents b2733c0 + 79a25fc commit 58ab935
Showing 1 changed file with 24 additions and 30 deletions.
54 changes: 24 additions & 30 deletions src/pybind/rbd/rbd.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -2096,7 +2096,7 @@ cdef class Image(object):
with nogil:
ret = rbd_resize(self.image, _size)
if ret < 0:
raise make_ex(ret, 'error resizing image %s' % (self.name,))
raise make_ex(ret, 'error resizing image %s' % self.name)

def stat(self):
"""
Expand Down Expand Up @@ -2128,7 +2128,7 @@ cdef class Image(object):
with nogil:
ret = rbd_stat(self.image, &info, sizeof(info))
if ret != 0:
raise make_ex(ret, 'error getting info for image %s' % (self.name,))
raise make_ex(ret, 'error getting info for image %s' % self.name)
return {
'size' : info.size,
'obj_size' : info.obj_size,
Expand Down Expand Up @@ -2156,7 +2156,7 @@ cdef class Image(object):
ret = rbd_get_name(self.image, image_name, &size)

if ret != 0:
raise make_ex(ret, 'error getting name for image %s' % (self.name,))
raise make_ex(ret, 'error getting name for image %s' % self.name)
return decode_cstr(image_name)
finally:
free(image_name)
Expand All @@ -2180,7 +2180,7 @@ cdef class Image(object):
size *= 2

if ret != 0:
raise make_ex(ret, 'error getting id for image %s' % (self.name,))
raise make_ex(ret, 'error getting id for image %s' % self.name)
return decode_cstr(image_id)
finally:
free(image_id)
Expand All @@ -2204,7 +2204,7 @@ cdef class Image(object):
size *= 2

if ret != 0:
raise make_ex(ret, 'error getting block name prefix for image %s' % (self.name,))
raise make_ex(ret, 'error getting block name prefix for image %s' % self.name)
return decode_cstr(prefix)
finally:
free(prefix)
Expand Down Expand Up @@ -2243,7 +2243,7 @@ cdef class Image(object):
size *= 2

if ret != 0:
raise make_ex(ret, 'error getting parent info for image %s' % (self.name,))
raise make_ex(ret, 'error getting parent info for image %s' % self.name)
return (decode_cstr(pool), decode_cstr(name), decode_cstr(snapname))
finally:
free(pool)
Expand Down Expand Up @@ -2271,7 +2271,7 @@ cdef class Image(object):
size *= 2

if ret != 0:
raise make_ex(ret, 'error getting parent id for image %s' % (self.name,))
raise make_ex(ret, 'error getting parent id for image %s' % self.name)
return decode_cstr(parent_id)
finally:
free(parent_id)
Expand Down Expand Up @@ -2394,7 +2394,7 @@ cdef class Image(object):
with nogil:
ret = rbd_get_group(self.image, &info, sizeof(info))
if ret != 0:
raise make_ex(ret, 'error getting group for image %s' % (self.name,))
raise make_ex(ret, 'error getting group for image %s' % self.name)
result = {
'pool' : info.pool,
'name' : decode_cstr(info.name)
Expand Down Expand Up @@ -2906,7 +2906,7 @@ cdef class Image(object):
if ret == <ssize_t>length:
return ret
elif ret < 0:
raise make_ex(ret, "error writing to %s" % (self.name,))
raise make_ex(ret, "error writing to %s" % self.name)
elif ret < <ssize_t>length:
raise IncompleteWriteError("Wrote only %ld out of %ld bytes" % (ret, length))
else:
Expand Down Expand Up @@ -3226,8 +3226,7 @@ written." % (self.name, ret, length))
with nogil:
ret = rbd_mirror_image_enable(self.image)
if ret < 0:
raise make_ex(ret, 'error enabling mirroring for image %s'
% (self.name,))
raise make_ex(ret, 'error enabling mirroring for image %s' % self.name)

def mirror_image_disable(self, force):
"""
Expand All @@ -3240,8 +3239,7 @@ written." % (self.name, ret, length))
with nogil:
ret = rbd_mirror_image_disable(self.image, c_force)
if ret < 0:
raise make_ex(ret, 'error disabling mirroring for image %s' %
(self.name,))
raise make_ex(ret, 'error disabling mirroring for image %s' % self.name)

def mirror_image_promote(self, force):
"""
Expand All @@ -3254,8 +3252,7 @@ written." % (self.name, ret, length))
with nogil:
ret = rbd_mirror_image_promote(self.image, c_force)
if ret < 0:
raise make_ex(ret, 'error promoting image %s to primary' %
(self.name,))
raise make_ex(ret, 'error promoting image %s to primary' % self.name)

def mirror_image_demote(self):
"""
Expand All @@ -3264,8 +3261,7 @@ written." % (self.name, ret, length))
with nogil:
ret = rbd_mirror_image_demote(self.image)
if ret < 0:
raise make_ex(ret, 'error demoting image %s to secondary' %
(self.name,))
raise make_ex(ret, 'error demoting image %s to secondary' % self.name)

def mirror_image_resync(self):
"""
Expand All @@ -3274,7 +3270,7 @@ written." % (self.name, ret, length))
with nogil:
ret = rbd_mirror_image_resync(self.image)
if ret < 0:
raise make_ex(ret, 'error to resync image %s' % (self.name,))
raise make_ex(ret, 'error to resync image %s' % self.name)

def mirror_image_get_info(self):
"""
Expand All @@ -3292,8 +3288,7 @@ written." % (self.name, ret, length))
with nogil:
ret = rbd_mirror_image_get_info(self.image, &c_info, sizeof(c_info))
if ret != 0:
raise make_ex(ret, 'error getting mirror info for image %s' %
(self.name,))
raise make_ex(ret, 'error getting mirror info for image %s' % self.name)
info = {
'global_id' : decode_cstr(c_info.global_id),
'state' : int(c_info.state),
Expand Down Expand Up @@ -3325,8 +3320,7 @@ written." % (self.name, ret, length))
ret = rbd_mirror_image_get_status(self.image, &c_status,
sizeof(c_status))
if ret != 0:
raise make_ex(ret, 'error getting mirror status for image %s' %
(self.name,))
raise make_ex(ret, 'error getting mirror status for image %s' % self.name)
status = {
'name' : decode_cstr(c_status.name),
'info' : {
Expand Down Expand Up @@ -3514,7 +3508,7 @@ written." % (self.name, ret, length))
raise KeyError('no metadata %s for image %s' % (key, self.name))
if ret != 0:
raise make_ex(ret, 'error getting metadata %s for image %s' %
(key, self.name,))
(key, self.name))
return decode_cstr(value)
finally:
free(value)
Expand All @@ -3538,7 +3532,7 @@ written." % (self.name, ret, length))

if ret != 0:
raise make_ex(ret, 'error setting metadata %s for image %s' %
(key, self.name,))
(key, self.name))


def metadata_remove(self, key):
Expand All @@ -3558,7 +3552,7 @@ written." % (self.name, ret, length))
raise KeyError('no metadata %s for image %s' % (key, self.name))
if ret != 0:
raise make_ex(ret, 'error removing metadata %s for image %s' %
(key, self.name,))
(key, self.name))

def metadata_list(self):
"""
Expand Down Expand Up @@ -3689,7 +3683,7 @@ cdef class LockOwnerIterator(object):
if ret >= 0:
break
elif ret != -errno.ERANGE:
raise make_ex(ret, 'error listing lock owners for image %s' % (image.name,))
raise make_ex(ret, 'error listing lock owners for image %s' % image.name)

def __iter__(self):
for i in range(self.num_lock_owners):
Expand Down Expand Up @@ -3757,7 +3751,7 @@ cdef class MetadataIterator(object):
break
elif ret != -errno.ERANGE:
raise make_ex(ret, 'error listing metadata for image %s' %
(self.image_name,))
self.image_name)
keys = [decode_cstr(key) for key in
c_keys[:keys_size].split(b'\0') if key]
vals = [decode_cstr(val) for val in
Expand Down Expand Up @@ -3809,7 +3803,7 @@ cdef class SnapIterator(object):
self.num_snaps = ret
break
elif ret != -errno.ERANGE:
raise make_ex(ret, 'error listing snapshots for image %s' % (image.name,))
raise make_ex(ret, 'error listing snapshots for image %s' % image.name)

def __iter__(self):
for i in range(self.num_snaps):
Expand Down Expand Up @@ -4030,7 +4024,7 @@ cdef class GroupImageIterator(object):
if ret >= 0:
break
elif ret != -errno.ERANGE:
raise make_ex(ret, 'error listing images for group %s' % (group.name,), group_errno_to_exception)
raise make_ex(ret, 'error listing images for group %s' % group.name, group_errno_to_exception)

def __iter__(self):
for i in range(self.num_images):
Expand Down Expand Up @@ -4080,7 +4074,7 @@ cdef class GroupSnapIterator(object):
if ret >= 0:
break
elif ret != -errno.ERANGE:
raise make_ex(ret, 'error listing snapshots for group %s' % (group.name,), group_errno_to_exception)
raise make_ex(ret, 'error listing snapshots for group %s' % group.name, group_errno_to_exception)

def __iter__(self):
for i in range(self.num_snaps):
Expand Down

0 comments on commit 58ab935

Please sign in to comment.