1
0
mirror of https://gitlab.com/libvirt/libvirt-python.git synced 2025-07-28 15:41:52 +03:00

libvirtaio: Fix return types of callback

libvirt defines the signature for the callback functions, e.g. the
functions for remove() must return -1 on error and 0 on success. Raising
an exception violates that contract.

_remove_timeout() did not explicitly handle a double-remove and
implicitly passed on the exception.

update() expects no return value, so remove the pointless return to pass
on None.

Signed-off-by: Philipp Hahn <hahn@univention.de>
This commit is contained in:
Philipp Hahn
2020-04-27 09:44:57 +02:00
parent b595e59b48
commit cfcf988a98

View File

@ -370,13 +370,13 @@ class virEventAsyncIOImpl(object):
https://libvirt.org/html/libvirt-libvirt-event.html#virEventUpdateHandleFunc
'''
self.log.debug('update_handle(watch=%d, event=%d)', watch, event)
return self.callbacks[watch].update(event=event)
self.callbacks[watch].update(event=event)
def _remove_handle(self, watch):
'''Unregister a callback from a file handle.
:param int watch: file descriptor watch to stop listening on
:returns: None (see source for explanation)
:returns: -1 on error, 0 on success
.. seealso::
https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveHandleFunc
@ -386,12 +386,13 @@ class virEventAsyncIOImpl(object):
callback = self.callbacks.pop(watch)
except KeyError as err:
self.log.warning('remove_handle(): no such handle: %r', err.args[0])
raise
return -1
fd = callback.descriptor.fd
assert callback is self.descriptors[fd].remove_handle(watch)
if len(self.descriptors[fd].callbacks) == 0:
del self.descriptors[fd]
callback.close()
return 0
def _add_timeout(self, timeout, cb, opaque):
'''Register a callback for a timer event
@ -425,20 +426,25 @@ class virEventAsyncIOImpl(object):
https://libvirt.org/html/libvirt-libvirt-event.html#virEventUpdateTimeoutFunc
'''
self.log.debug('update_timeout(timer=%d, timeout=%d)', timer, timeout)
return self.callbacks[timer].update(timeout=timeout)
self.callbacks[timer].update(timeout=timeout)
def _remove_timeout(self, timer):
'''Unregister a callback for a timer
:param int timer: the timer to remove
:returns: None (see source for explanation)
:returns: -1 on error, 0 on success
.. seealso::
https://libvirt.org/html/libvirt-libvirt-event.html#virEventRemoveTimeoutFunc
'''
self.log.debug('remove_timeout(timer=%d)', timer)
callback = self.callbacks.pop(timer)
try:
callback = self.callbacks.pop(timer)
except KeyError as err:
self.log.warning('remove_timeout(): no such timeout: %r', err.args[0])
return -1
callback.close()
return 0
_current_impl = None