mirror of https://gitee.com/openkylin/libvirt.git
event: make deregister return value match docs
Ever since their introduction (commit1509b80
in v0.5.0 for virConnectDomainEventRegister, commit4445723
in v0.8.0 for virConnectDomainEventDeregisterAny), the event deregistration functions have been documented as returning 0 on success; likewise for older registration (only the newer RegisterAny must return a non-zero callbackID). And now that we are adding virConnectNetworkEventDeregisterAny for v1.2.1, it should have the same semantics. Fortunately, all of the stateful drivers have been obeying the docs and returning 0, thanks to the way the remote_driver tracks things (in fact, the RPC wire protocol is unable to send a return value for DomainEventRegisterAny, at least not without adding a new RPC number). Well, except for vbox, which was always failing deregistration, due to failure to set the return value to anything besides its initial -1. But for local drivers, such as test:///default, we've been returning non-zero numbers; worse, the non-zero numbers have differed over time. For example, in Fedora 12 (libvirt 0.8.2), calling Register twice would return 0 and 1 [the callbackID generated under the hood]; while in Fedora 20 (libvirt 1.1.3), it returns 1 and 2 [the number of callbacks registered for that event type]. Since we have changed the behavior over time, and since it differs by local vs. remote, we can safely argue that no one could have been reasonably relying on any particular behavior, so we might as well obey the docs, as well as prepare callers that might deal with older clients to not be surprised if the docs are not strictly followed. For consistency, this patch fixes the code for all drivers, even though it only makes an impact for vbox and for local drivers. By fixing all drivers, future copy and paste from a remote driver to a local driver is less likely to reintroduce the bug. Finally, update the testsuite to gain some coverage of the issue for local drivers, including the first test of old-style domain event registration via function pointer instead of event id. * src/libvirt.c (virConnectDomainEventRegister) (virConnectDomainEventDeregister) (virConnectDomainEventDeregisterAny): Clarify docs. * src/libxl/libxl_driver.c (libxlConnectDomainEventRegister) (libxlConnectDomainEventDeregister) (libxlConnectDomainEventDeregisterAny): Match documentation. * src/lxc/lxc_driver.c (lxcConnectDomainEventRegister) (lxcConnectDomainEventDeregister) (lxcConnectDomainEventDeregisterAny): Likewise. * src/test/test_driver.c (testConnectDomainEventRegister) (testConnectDomainEventDeregister) (testConnectDomainEventDeregisterAny) (testConnectNetworkEventDeregisterAny): Likewise. * src/uml/uml_driver.c (umlConnectDomainEventRegister) (umlConnectDomainEventDeregister) (umlConnectDomainEventDeregisterAny): Likewise. * src/vbox/vbox_tmpl.c (vboxConnectDomainEventRegister) (vboxConnectDomainEventDeregister) (vboxConnectDomainEventDeregisterAny): Likewise. * src/xen/xen_driver.c (xenUnifiedConnectDomainEventRegister) (xenUnifiedConnectDomainEventDeregister) (xenUnifiedConnectDomainEventDeregisterAny): Likewise. * src/network/bridge_driver.c (networkConnectNetworkEventDeregisterAny): Likewise. * tests/objecteventtest.c (testDomainCreateXMLOld): New test. (mymain): Run it. (testDomainCreateXML): Check return values. Signed-off-by: Eric Blake <eblake@redhat.com>
This commit is contained in:
parent
088ff08ce9
commit
31b5bad9ff
|
@ -15564,7 +15564,9 @@ error:
|
||||||
* The reference can be released once the object is no longer required
|
* The reference can be released once the object is no longer required
|
||||||
* by calling virDomainFree.
|
* by calling virDomainFree.
|
||||||
*
|
*
|
||||||
* Returns 0 on success, -1 on failure.
|
* Returns 0 on success, -1 on failure. Older versions of some hypervisors
|
||||||
|
* sometimes returned a positive number on success, but without any reliable
|
||||||
|
* semantics on what that number represents.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virConnectDomainEventRegister(virConnectPtr conn,
|
virConnectDomainEventRegister(virConnectPtr conn,
|
||||||
|
@ -15598,14 +15600,16 @@ error:
|
||||||
* @conn: pointer to the connection
|
* @conn: pointer to the connection
|
||||||
* @cb: callback to the function handling domain events
|
* @cb: callback to the function handling domain events
|
||||||
*
|
*
|
||||||
* Removes a callback previously registered with the virConnectDomainEventRegister
|
* Removes a callback previously registered with the
|
||||||
* function.
|
* virConnectDomainEventRegister() function.
|
||||||
*
|
*
|
||||||
* Use of this method is no longer recommended. Instead applications
|
* Use of this method is no longer recommended. Instead applications
|
||||||
* should try virConnectDomainEventDeregisterAny() which has a more flexible
|
* should try virConnectDomainEventDeregisterAny() which has a more flexible
|
||||||
* API contract
|
* API contract
|
||||||
*
|
*
|
||||||
* Returns 0 on success, -1 on failure
|
* Returns 0 on success, -1 on failure. Older versions of some hypervisors
|
||||||
|
* sometimes returned a positive number on success, but without any reliable
|
||||||
|
* semantics on what that number represents.
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
virConnectDomainEventDeregister(virConnectPtr conn,
|
virConnectDomainEventDeregister(virConnectPtr conn,
|
||||||
|
@ -18509,8 +18513,9 @@ error:
|
||||||
* Removes an event callback. The callbackID parameter should be the
|
* Removes an event callback. The callbackID parameter should be the
|
||||||
* value obtained from a previous virConnectDomainEventRegisterAny() method.
|
* value obtained from a previous virConnectDomainEventRegisterAny() method.
|
||||||
*
|
*
|
||||||
* Returns 0 on success, -1 on failure
|
* Returns 0 on success, -1 on failure. Older versions of some hypervisors
|
||||||
*/
|
* sometimes returned a positive number on success, but without any reliable
|
||||||
|
* semantics on what that number represents. */
|
||||||
int
|
int
|
||||||
virConnectDomainEventDeregisterAny(virConnectPtr conn,
|
virConnectDomainEventDeregisterAny(virConnectPtr conn,
|
||||||
int callbackID)
|
int callbackID)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* libxl_driver.c: core driver methods for managing libxenlight domains
|
* libxl_driver.c: core driver methods for managing libxenlight domains
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2013 Red Hat, Inc.
|
* Copyright (C) 2006-2014 Red Hat, Inc.
|
||||||
* Copyright (C) 2011-2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
* Copyright (C) 2011-2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||||
* Copyright (C) 2011 Univention GmbH.
|
* Copyright (C) 2011 Univention GmbH.
|
||||||
*
|
*
|
||||||
|
@ -3643,20 +3643,21 @@ cleanup:
|
||||||
|
|
||||||
static int
|
static int
|
||||||
libxlConnectDomainEventRegister(virConnectPtr conn,
|
libxlConnectDomainEventRegister(virConnectPtr conn,
|
||||||
virConnectDomainEventCallback callback, void *opaque,
|
virConnectDomainEventCallback callback,
|
||||||
|
void *opaque,
|
||||||
virFreeCallback freecb)
|
virFreeCallback freecb)
|
||||||
{
|
{
|
||||||
libxlDriverPrivatePtr driver = conn->privateData;
|
libxlDriverPrivatePtr driver = conn->privateData;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (virConnectDomainEventRegisterEnsureACL(conn) < 0)
|
if (virConnectDomainEventRegisterEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = virDomainEventStateRegister(conn,
|
if (virDomainEventStateRegister(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callback, opaque, freecb);
|
callback, opaque, freecb) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3665,16 +3666,16 @@ libxlConnectDomainEventDeregister(virConnectPtr conn,
|
||||||
virConnectDomainEventCallback callback)
|
virConnectDomainEventCallback callback)
|
||||||
{
|
{
|
||||||
libxlDriverPrivatePtr driver = conn->privateData;
|
libxlDriverPrivatePtr driver = conn->privateData;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (virConnectDomainEventDeregisterEnsureACL(conn) < 0)
|
if (virConnectDomainEventDeregisterEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = virDomainEventStateDeregister(conn,
|
if (virDomainEventStateDeregister(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callback);
|
callback) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -4270,16 +4271,16 @@ static int
|
||||||
libxlConnectDomainEventDeregisterAny(virConnectPtr conn, int callbackID)
|
libxlConnectDomainEventDeregisterAny(virConnectPtr conn, int callbackID)
|
||||||
{
|
{
|
||||||
libxlDriverPrivatePtr driver = conn->privateData;
|
libxlDriverPrivatePtr driver = conn->privateData;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
|
if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = virObjectEventStateDeregisterID(conn,
|
if (virObjectEventStateDeregisterID(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callbackID);
|
callbackID) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1287,16 +1287,16 @@ lxcConnectDomainEventRegister(virConnectPtr conn,
|
||||||
virFreeCallback freecb)
|
virFreeCallback freecb)
|
||||||
{
|
{
|
||||||
virLXCDriverPtr driver = conn->privateData;
|
virLXCDriverPtr driver = conn->privateData;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (virConnectDomainEventRegisterEnsureACL(conn) < 0)
|
if (virConnectDomainEventRegisterEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = virDomainEventStateRegister(conn,
|
if (virDomainEventStateRegister(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callback, opaque, freecb);
|
callback, opaque, freecb) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1305,16 +1305,16 @@ lxcConnectDomainEventDeregister(virConnectPtr conn,
|
||||||
virConnectDomainEventCallback callback)
|
virConnectDomainEventCallback callback)
|
||||||
{
|
{
|
||||||
virLXCDriverPtr driver = conn->privateData;
|
virLXCDriverPtr driver = conn->privateData;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (virConnectDomainEventDeregisterEnsureACL(conn) < 0)
|
if (virConnectDomainEventDeregisterEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = virDomainEventStateDeregister(conn,
|
if (virDomainEventStateDeregister(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callback);
|
callback) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1347,16 +1347,16 @@ lxcConnectDomainEventDeregisterAny(virConnectPtr conn,
|
||||||
int callbackID)
|
int callbackID)
|
||||||
{
|
{
|
||||||
virLXCDriverPtr driver = conn->privateData;
|
virLXCDriverPtr driver = conn->privateData;
|
||||||
int ret;
|
|
||||||
|
|
||||||
if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
|
if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
ret = virObjectEventStateDeregisterID(conn,
|
if (virObjectEventStateDeregisterID(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callbackID);
|
callbackID) < 0)
|
||||||
|
return -1;
|
||||||
|
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* bridge_driver.c: core driver methods for managing network
|
* bridge_driver.c: core driver methods for managing network
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2013 Red Hat, Inc.
|
* Copyright (C) 2006-2014 Red Hat, Inc.
|
||||||
* Copyright (C) 2006 Daniel P. Berrange
|
* Copyright (C) 2006 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
|
@ -2329,9 +2329,12 @@ networkConnectNetworkEventDeregisterAny(virConnectPtr conn,
|
||||||
if (virConnectNetworkEventDeregisterAnyEnsureACL(conn) < 0)
|
if (virConnectNetworkEventDeregisterAnyEnsureACL(conn) < 0)
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
|
||||||
ret = virObjectEventStateDeregisterID(conn,
|
if (virObjectEventStateDeregisterID(conn,
|
||||||
driver->networkEventState,
|
driver->networkEventState,
|
||||||
callbackID);
|
callbackID) < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* test.c: A "mock" hypervisor for use by application unit tests
|
* test.c: A "mock" hypervisor for use by application unit tests
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2013 Red Hat, Inc.
|
* Copyright (C) 2006-2014 Red Hat, Inc.
|
||||||
* Copyright (C) 2006 Daniel P. Berrange
|
* Copyright (C) 2006 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
|
@ -5993,12 +5993,13 @@ testConnectDomainEventRegister(virConnectPtr conn,
|
||||||
virFreeCallback freecb)
|
virFreeCallback freecb)
|
||||||
{
|
{
|
||||||
testConnPtr driver = conn->privateData;
|
testConnPtr driver = conn->privateData;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
testDriverLock(driver);
|
testDriverLock(driver);
|
||||||
ret = virDomainEventStateRegister(conn,
|
if (virDomainEventStateRegister(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callback, opaque, freecb);
|
callback, opaque, freecb) < 0)
|
||||||
|
ret = -1;
|
||||||
testDriverUnlock(driver);
|
testDriverUnlock(driver);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -6010,12 +6011,13 @@ testConnectDomainEventDeregister(virConnectPtr conn,
|
||||||
virConnectDomainEventCallback callback)
|
virConnectDomainEventCallback callback)
|
||||||
{
|
{
|
||||||
testConnPtr driver = conn->privateData;
|
testConnPtr driver = conn->privateData;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
testDriverLock(driver);
|
testDriverLock(driver);
|
||||||
ret = virDomainEventStateDeregister(conn,
|
if (virDomainEventStateDeregister(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callback);
|
callback) < 0)
|
||||||
|
ret = -1;
|
||||||
testDriverUnlock(driver);
|
testDriverUnlock(driver);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -6049,12 +6051,13 @@ testConnectDomainEventDeregisterAny(virConnectPtr conn,
|
||||||
int callbackID)
|
int callbackID)
|
||||||
{
|
{
|
||||||
testConnPtr driver = conn->privateData;
|
testConnPtr driver = conn->privateData;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
testDriverLock(driver);
|
testDriverLock(driver);
|
||||||
ret = virObjectEventStateDeregisterID(conn,
|
if (virObjectEventStateDeregisterID(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callbackID);
|
callbackID) < 0)
|
||||||
|
ret = -1;
|
||||||
testDriverUnlock(driver);
|
testDriverUnlock(driver);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -6089,12 +6092,13 @@ testConnectNetworkEventDeregisterAny(virConnectPtr conn,
|
||||||
int callbackID)
|
int callbackID)
|
||||||
{
|
{
|
||||||
testConnPtr driver = conn->privateData;
|
testConnPtr driver = conn->privateData;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
testDriverLock(driver);
|
testDriverLock(driver);
|
||||||
ret = virObjectEventStateDeregisterID(conn,
|
if (virObjectEventStateDeregisterID(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callbackID);
|
callbackID) < 0)
|
||||||
|
ret = -1;
|
||||||
testDriverUnlock(driver);
|
testDriverUnlock(driver);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
/*
|
/*
|
||||||
* uml_driver.c: core driver methods for managing UML guests
|
* uml_driver.c: core driver methods for managing UML guests
|
||||||
*
|
*
|
||||||
* Copyright (C) 2006-2013 Red Hat, Inc.
|
* Copyright (C) 2006-2014 Red Hat, Inc.
|
||||||
* Copyright (C) 2006-2008 Daniel P. Berrange
|
* Copyright (C) 2006-2008 Daniel P. Berrange
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
|
@ -2610,15 +2610,16 @@ umlConnectDomainEventRegister(virConnectPtr conn,
|
||||||
virFreeCallback freecb)
|
virFreeCallback freecb)
|
||||||
{
|
{
|
||||||
struct uml_driver *driver = conn->privateData;
|
struct uml_driver *driver = conn->privateData;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
if (virConnectDomainEventRegisterEnsureACL(conn) < 0)
|
if (virConnectDomainEventRegisterEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
umlDriverLock(driver);
|
umlDriverLock(driver);
|
||||||
ret = virDomainEventStateRegister(conn,
|
if (virDomainEventStateRegister(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callback, opaque, freecb);
|
callback, opaque, freecb) < 0)
|
||||||
|
ret = -1;
|
||||||
umlDriverUnlock(driver);
|
umlDriverUnlock(driver);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -2629,15 +2630,16 @@ umlConnectDomainEventDeregister(virConnectPtr conn,
|
||||||
virConnectDomainEventCallback callback)
|
virConnectDomainEventCallback callback)
|
||||||
{
|
{
|
||||||
struct uml_driver *driver = conn->privateData;
|
struct uml_driver *driver = conn->privateData;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
if (virConnectDomainEventDeregisterEnsureACL(conn) < 0)
|
if (virConnectDomainEventDeregisterEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
umlDriverLock(driver);
|
umlDriverLock(driver);
|
||||||
ret = virDomainEventStateDeregister(conn,
|
if (virDomainEventStateDeregister(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callback);
|
callback) < 0)
|
||||||
|
ret = -1;
|
||||||
umlDriverUnlock(driver);
|
umlDriverUnlock(driver);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -2674,15 +2676,16 @@ umlConnectDomainEventDeregisterAny(virConnectPtr conn,
|
||||||
int callbackID)
|
int callbackID)
|
||||||
{
|
{
|
||||||
struct uml_driver *driver = conn->privateData;
|
struct uml_driver *driver = conn->privateData;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
|
if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
umlDriverLock(driver);
|
umlDriverLock(driver);
|
||||||
ret = virObjectEventStateDeregisterID(conn,
|
if (virObjectEventStateDeregisterID(conn,
|
||||||
driver->domainEventState,
|
driver->domainEventState,
|
||||||
callbackID);
|
callbackID) < 0)
|
||||||
|
ret = -1;
|
||||||
umlDriverUnlock(driver);
|
umlDriverUnlock(driver);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (C) 2010-2013 Red Hat, Inc.
|
* Copyright (C) 2010-2014 Red Hat, Inc.
|
||||||
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
|
* Copyright (C) 2008-2009 Sun Microsystems, Inc.
|
||||||
*
|
*
|
||||||
* This file is part of a free software library; you can redistribute
|
* This file is part of a free software library; you can redistribute
|
||||||
|
@ -7284,10 +7284,12 @@ static void vboxReadCallback(int watch ATTRIBUTE_UNUSED,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vboxConnectDomainEventRegister(virConnectPtr conn,
|
static int
|
||||||
virConnectDomainEventCallback callback,
|
vboxConnectDomainEventRegister(virConnectPtr conn,
|
||||||
void *opaque,
|
virConnectDomainEventCallback callback,
|
||||||
virFreeCallback freecb) {
|
void *opaque,
|
||||||
|
virFreeCallback freecb)
|
||||||
|
{
|
||||||
VBOX_OBJECT_CHECK(conn, int, -1);
|
VBOX_OBJECT_CHECK(conn, int, -1);
|
||||||
int vboxRet = -1;
|
int vboxRet = -1;
|
||||||
nsresult rc;
|
nsresult rc;
|
||||||
|
@ -7338,7 +7340,7 @@ static int vboxConnectDomainEventRegister(virConnectPtr conn,
|
||||||
vboxDriverUnlock(data);
|
vboxDriverUnlock(data);
|
||||||
|
|
||||||
if (ret >= 0) {
|
if (ret >= 0) {
|
||||||
return ret;
|
return 0;
|
||||||
} else {
|
} else {
|
||||||
if (data->vboxObj && data->vboxCallback) {
|
if (data->vboxObj && data->vboxCallback) {
|
||||||
data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback);
|
data->vboxObj->vtbl->UnregisterCallback(data->vboxObj, data->vboxCallback);
|
||||||
|
@ -7347,8 +7349,10 @@ static int vboxConnectDomainEventRegister(virConnectPtr conn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vboxConnectDomainEventDeregister(virConnectPtr conn,
|
static int
|
||||||
virConnectDomainEventCallback callback) {
|
vboxConnectDomainEventDeregister(virConnectPtr conn,
|
||||||
|
virConnectDomainEventCallback callback)
|
||||||
|
{
|
||||||
VBOX_OBJECT_CHECK(conn, int, -1);
|
VBOX_OBJECT_CHECK(conn, int, -1);
|
||||||
int cnt;
|
int cnt;
|
||||||
|
|
||||||
|
@ -7371,6 +7375,9 @@ static int vboxConnectDomainEventDeregister(virConnectPtr conn,
|
||||||
|
|
||||||
vboxDriverUnlock(data);
|
vboxDriverUnlock(data);
|
||||||
|
|
||||||
|
if (cnt >= 0)
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -7441,8 +7448,10 @@ static int vboxConnectDomainEventRegisterAny(virConnectPtr conn,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static int vboxConnectDomainEventDeregisterAny(virConnectPtr conn,
|
static int
|
||||||
int callbackID) {
|
vboxConnectDomainEventDeregisterAny(virConnectPtr conn,
|
||||||
|
int callbackID)
|
||||||
|
{
|
||||||
VBOX_OBJECT_CHECK(conn, int, -1);
|
VBOX_OBJECT_CHECK(conn, int, -1);
|
||||||
int cnt;
|
int cnt;
|
||||||
|
|
||||||
|
@ -7465,6 +7474,9 @@ static int vboxConnectDomainEventDeregisterAny(virConnectPtr conn,
|
||||||
|
|
||||||
vboxDriverUnlock(data);
|
vboxDriverUnlock(data);
|
||||||
|
|
||||||
|
if (cnt >= 0)
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2312,7 +2312,7 @@ xenUnifiedConnectDomainEventRegister(virConnectPtr conn,
|
||||||
virFreeCallback freefunc)
|
virFreeCallback freefunc)
|
||||||
{
|
{
|
||||||
xenUnifiedPrivatePtr priv = conn->privateData;
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
||||||
int ret;
|
int ret = 0;
|
||||||
|
|
||||||
if (virConnectDomainEventRegisterEnsureACL(conn) < 0)
|
if (virConnectDomainEventRegisterEnsureACL(conn) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -2325,8 +2325,9 @@ xenUnifiedConnectDomainEventRegister(virConnectPtr conn,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virDomainEventStateRegister(conn, priv->domainEvents,
|
if (virDomainEventStateRegister(conn, priv->domainEvents,
|
||||||
callback, opaque, freefunc);
|
callback, opaque, freefunc) < 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
xenUnifiedUnlock(priv);
|
xenUnifiedUnlock(priv);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -2337,7 +2338,7 @@ static int
|
||||||
xenUnifiedConnectDomainEventDeregister(virConnectPtr conn,
|
xenUnifiedConnectDomainEventDeregister(virConnectPtr conn,
|
||||||
virConnectDomainEventCallback callback)
|
virConnectDomainEventCallback callback)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
xenUnifiedPrivatePtr priv = conn->privateData;
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
||||||
|
|
||||||
if (virConnectDomainEventDeregisterEnsureACL(conn) < 0)
|
if (virConnectDomainEventDeregisterEnsureACL(conn) < 0)
|
||||||
|
@ -2351,9 +2352,10 @@ xenUnifiedConnectDomainEventDeregister(virConnectPtr conn,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virDomainEventStateDeregister(conn,
|
if (virDomainEventStateDeregister(conn,
|
||||||
priv->domainEvents,
|
priv->domainEvents,
|
||||||
callback);
|
callback) < 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
xenUnifiedUnlock(priv);
|
xenUnifiedUnlock(priv);
|
||||||
return ret;
|
return ret;
|
||||||
|
@ -2395,7 +2397,7 @@ static int
|
||||||
xenUnifiedConnectDomainEventDeregisterAny(virConnectPtr conn,
|
xenUnifiedConnectDomainEventDeregisterAny(virConnectPtr conn,
|
||||||
int callbackID)
|
int callbackID)
|
||||||
{
|
{
|
||||||
int ret;
|
int ret = 0;
|
||||||
xenUnifiedPrivatePtr priv = conn->privateData;
|
xenUnifiedPrivatePtr priv = conn->privateData;
|
||||||
|
|
||||||
if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
|
if (virConnectDomainEventDeregisterAnyEnsureACL(conn) < 0)
|
||||||
|
@ -2409,9 +2411,10 @@ xenUnifiedConnectDomainEventDeregisterAny(virConnectPtr conn,
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
ret = virObjectEventStateDeregisterID(conn,
|
if (virObjectEventStateDeregisterID(conn,
|
||||||
priv->domainEvents,
|
priv->domainEvents,
|
||||||
callbackID);
|
callbackID) < 0)
|
||||||
|
ret = -1;
|
||||||
|
|
||||||
xenUnifiedUnlock(priv);
|
xenUnifiedUnlock(priv);
|
||||||
return ret;
|
return ret;
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2014 Red Hat, Inc.
|
||||||
* Copyright (C) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
* Copyright (C) 2013 SUSE LINUX Products GmbH, Nuernberg, Germany.
|
||||||
*
|
*
|
||||||
* This library is free software; you can redistribute it and/or
|
* This library is free software; you can redistribute it and/or
|
||||||
|
@ -125,36 +126,80 @@ networkLifecycleCb(virConnectPtr conn ATTRIBUTE_UNUSED,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static int
|
||||||
|
testDomainCreateXMLOld(const void *data)
|
||||||
|
{
|
||||||
|
const objecteventTest *test = data;
|
||||||
|
lifecycleEventCounter counter;
|
||||||
|
virDomainPtr dom = NULL;
|
||||||
|
int ret = -1;
|
||||||
|
bool registered = false;
|
||||||
|
|
||||||
|
lifecycleEventCounter_reset(&counter);
|
||||||
|
|
||||||
|
if (virConnectDomainEventRegister(test->conn,
|
||||||
|
domainLifecycleCb,
|
||||||
|
&counter, NULL) != 0)
|
||||||
|
goto cleanup;
|
||||||
|
registered = true;
|
||||||
|
dom = virDomainCreateXML(test->conn, domainDef, 0);
|
||||||
|
|
||||||
|
if (dom == NULL || virEventRunDefaultImpl() < 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (counter.startEvents != 1 || counter.unexpectedEvents > 0)
|
||||||
|
goto cleanup;
|
||||||
|
|
||||||
|
if (virConnectDomainEventDeregister(test->conn, domainLifecycleCb) != 0)
|
||||||
|
goto cleanup;
|
||||||
|
registered = false;
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
|
cleanup:
|
||||||
|
if (registered)
|
||||||
|
virConnectDomainEventDeregister(test->conn, domainLifecycleCb);
|
||||||
|
if (dom) {
|
||||||
|
virDomainDestroy(dom);
|
||||||
|
virDomainFree(dom);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
testDomainCreateXML(const void *data)
|
testDomainCreateXML(const void *data)
|
||||||
{
|
{
|
||||||
const objecteventTest *test = data;
|
const objecteventTest *test = data;
|
||||||
lifecycleEventCounter counter;
|
lifecycleEventCounter counter;
|
||||||
int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
|
int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
|
||||||
virDomainPtr dom;
|
virDomainPtr dom = NULL;
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = -1;
|
||||||
|
|
||||||
lifecycleEventCounter_reset(&counter);
|
lifecycleEventCounter_reset(&counter);
|
||||||
|
|
||||||
id = virConnectDomainEventRegisterAny(test->conn, NULL, eventId,
|
id = virConnectDomainEventRegisterAny(test->conn, NULL, eventId,
|
||||||
VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
|
VIR_DOMAIN_EVENT_CALLBACK(&domainLifecycleCb),
|
||||||
&counter, NULL);
|
&counter, NULL);
|
||||||
|
if (id < 0)
|
||||||
|
goto cleanup;
|
||||||
dom = virDomainCreateXML(test->conn, domainDef, 0);
|
dom = virDomainCreateXML(test->conn, domainDef, 0);
|
||||||
|
|
||||||
if (dom == NULL || virEventRunDefaultImpl() < 0) {
|
if (dom == NULL || virEventRunDefaultImpl() < 0)
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
|
||||||
if (counter.startEvents != 1 || counter.unexpectedEvents > 0) {
|
if (counter.startEvents != 1 || counter.unexpectedEvents > 0)
|
||||||
ret = -1;
|
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
|
||||||
|
if (virConnectDomainEventDeregisterAny(test->conn, id) != 0)
|
||||||
|
goto cleanup;
|
||||||
|
id = -1;
|
||||||
|
ret = 0;
|
||||||
|
|
||||||
cleanup:
|
cleanup:
|
||||||
virConnectDomainEventDeregisterAny(test->conn, id);
|
if (id >= 0)
|
||||||
if (dom != NULL) {
|
virConnectDomainEventDeregisterAny(test->conn, id);
|
||||||
|
if (dom) {
|
||||||
virDomainDestroy(dom);
|
virDomainDestroy(dom);
|
||||||
virDomainFree(dom);
|
virDomainFree(dom);
|
||||||
}
|
}
|
||||||
|
@ -168,7 +213,7 @@ testDomainDefine(const void *data)
|
||||||
const objecteventTest *test = data;
|
const objecteventTest *test = data;
|
||||||
lifecycleEventCounter counter;
|
lifecycleEventCounter counter;
|
||||||
int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
|
int eventId = VIR_DOMAIN_EVENT_ID_LIFECYCLE;
|
||||||
virDomainPtr dom;
|
virDomainPtr dom = NULL;
|
||||||
int id;
|
int id;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
|
|
||||||
|
@ -388,7 +433,11 @@ mymain(void)
|
||||||
virtTestQuiesceLibvirtErrors(false);
|
virtTestQuiesceLibvirtErrors(false);
|
||||||
|
|
||||||
/* Domain event tests */
|
/* Domain event tests */
|
||||||
if (virtTestRun("Domain createXML start event ", testDomainCreateXML, &test) < 0)
|
if (virtTestRun("Domain createXML start event (old API)",
|
||||||
|
testDomainCreateXMLOld, &test) < 0)
|
||||||
|
ret = EXIT_FAILURE;
|
||||||
|
if (virtTestRun("Domain createXML start event (new API)",
|
||||||
|
testDomainCreateXML, &test) < 0)
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
if (virtTestRun("Domain (un)define events", testDomainDefine, &test) < 0)
|
if (virtTestRun("Domain (un)define events", testDomainDefine, &test) < 0)
|
||||||
ret = EXIT_FAILURE;
|
ret = EXIT_FAILURE;
|
||||||
|
|
Loading…
Reference in New Issue