
On Wed, Dec 11, 2013 at 11:38:01AM +0100, Cédric Bosdonnat wrote:
--- daemon/libvirtd.h | 1 + daemon/remote.c | 139 +++++++++++++++++++++++++++++++++++++++++++ src/remote/remote_driver.c | 127 +++++++++++++++++++++++++++++++++++++++ src/remote/remote_protocol.x | 46 +++++++++++++- 4 files changed, 312 insertions(+), 1 deletion(-)
diff --git a/daemon/libvirtd.h b/daemon/libvirtd.h index d0afdc8..47f2589 100644 --- a/daemon/libvirtd.h +++ b/daemon/libvirtd.h @@ -50,6 +50,7 @@ struct daemonClientPrivate { virMutex lock;
int domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LAST]; + int networkEventCallbackID[VIR_NETWORK_EVENT_ID_LAST];
# if WITH_SASL virNetSASLSessionPtr sasl; diff --git a/daemon/remote.c b/daemon/remote.c index f060006..bcd73d4 100644 --- a/daemon/remote.c +++ b/daemon/remote.c @@ -49,6 +49,7 @@ #include "qemu_protocol.h" #include "lxc_protocol.h" #include "virstring.h" +#include "object_event.h"
#define VIR_FROM_THIS VIR_FROM_RPC
@@ -653,6 +654,38 @@ static virConnectDomainEventGenericCallback domainEventCallbacks[] = {
verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST);
+static int remoteRelayNetworkEventLifecycle(virConnectPtr conn ATTRIBUTE_UNUSED, + virNetworkPtr net, + int event, + int detail, + void *opaque)
Indent.
@@ -5216,6 +5261,100 @@ cleanup: }
+static int +remoteDispatchConnectNetworkEventRegisterAny(virNetServerPtr server ATTRIBUTE_UNUSED, + virNetServerClientPtr client ATTRIBUTE_UNUSED, + virNetMessagePtr msg ATTRIBUTE_UNUSED, + virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED, + remote_connect_network_event_register_any_args *args, + remote_connect_network_event_register_any_ret *ret ATTRIBUTE_UNUSED) +{ + int callbackID; + int rv = -1; + struct daemonClientPrivate *priv = + virNetServerClientGetPrivateData(client); + + if (!priv->conn) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open")); + goto cleanup; + } + + virMutexLock(&priv->lock); + + if ((args->eventID & 0xFF) >= VIR_NETWORK_EVENT_ID_LAST) {
We can drop the "& 0xFF" bit now namespaces aren't visible on the wire
+ virReportError(VIR_ERR_INTERNAL_ERROR, _("unsupported network event ID %d"), args->eventID); + goto cleanup; + } + + if (priv->networkEventCallbackID[args->eventID] != -1) { + virReportError(VIR_ERR_INTERNAL_ERROR, _("network event %d already registered"), args->eventID); + goto cleanup; + } + + if ((callbackID = virConnectNetworkEventRegisterAny(priv->conn, + NULL, + args->eventID, + networkEventCallbacks[args->eventID], + client, NULL)) < 0) + goto cleanup; + + priv->networkEventCallbackID[args->eventID & 0xFF] = callbackID;
And again here.
+ + rv = 0; + +cleanup: + if (rv < 0) + virNetMessageSaveError(rerr); + virMutexUnlock(&priv->lock); + return rv; +} + + +static int +remoteDispatchConnectNetworkEventDeregisterAny(virNetServerPtr server ATTRIBUTE_UNUSED, + virNetServerClientPtr client ATTRIBUTE_UNUSED, + virNetMessagePtr msg ATTRIBUTE_UNUSED, + virNetMessageErrorPtr rerr ATTRIBUTE_UNUSED, + remote_connect_network_event_deregister_any_args *args, + remote_connect_network_event_deregister_any_ret *ret ATTRIBUTE_UNUSED) +{ + int callbackID = -1; + int rv = -1; + struct daemonClientPrivate *priv = + virNetServerClientGetPrivateData(client); + + if (!priv->conn) { + virReportError(VIR_ERR_INTERNAL_ERROR, "%s", _("connection not open")); + goto cleanup; + } + + virMutexLock(&priv->lock); + + if ((args->eventID & 0xFF) >= VIR_NETWORK_EVENT_ID_LAST) {
And here
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c index 4a84a52..046f424 100644 --- a/src/remote/remote_driver.c +++ b/src/remote/remote_driver.c @@ -2902,6 +2912,99 @@ done: }
static int +remoteConnectNetworkEventRegisterAny(virConnectPtr conn, + virNetworkPtr net, + int eventID, + virConnectNetworkEventGenericCallback callback, + void *opaque, + virFreeCallback freecb) +{ + int rv = -1; + struct private_data *priv = conn->privateData; + remote_connect_network_event_register_any_args args; + int callbackID; + int count; + + remoteDriverLock(priv); + + if ((count = virNetworkEventStateRegisterID(conn, + priv->domainEventState, + net, eventID, + VIR_OBJECT_EVENT_CALLBACK(callback), + opaque, freecb, + &callbackID)) < 0) {
Indent
+ virReportError(VIR_ERR_RPC, "%s", _("adding cb to list")); + goto done; + } + + /* If this is the first callback for this eventID, we need to enable + * events on the server */ + if (count == 1) { + args.eventID = eventID; + + if (call(conn, priv, 0, REMOTE_PROC_CONNECT_NETWORK_EVENT_REGISTER_ANY, + (xdrproc_t) xdr_remote_connect_network_event_register_any_args, (char *) &args, + (xdrproc_t) xdr_void, (char *)NULL) == -1) { + virObjectEventStateDeregisterID(conn, + priv->domainEventState, + callbackID); + goto done; + } + } + + rv = callbackID; + +done: + remoteDriverUnlock(priv); + return rv; +} + + +static int +remoteConnectNetworkEventDeregisterAny(virConnectPtr conn, + int callbackID) +{ + struct private_data *priv = conn->privateData; + int rv = -1; + remote_connect_network_event_deregister_any_args args; + int eventID; + int count; + + remoteDriverLock(priv); + + if ((eventID = virObjectEventStateEventID(conn, + priv->domainEventState, + callbackID)) < 0) { + virReportError(VIR_ERR_RPC, _("unable to find callback ID %d"), callbackID); + goto done; + } + + if ((count = virObjectEventStateDeregisterID(conn, + priv->domainEventState, + callbackID)) < 0) { + virReportError(VIR_ERR_RPC, _("unable to find callback ID %d"), callbackID); + goto done; + } + + /* If that was the last callback for this eventID, we need to disable + * events on the server */ + if (count == 0) { + args.eventID = eventID; + + if (call(conn, priv, 0, REMOTE_PROC_CONNECT_NETWORK_EVENT_DEREGISTER_ANY, + (xdrproc_t) xdr_remote_connect_network_event_deregister_any_args, (char *) &args, + (xdrproc_t) xdr_void, (char *) NULL) == -1) + goto done; + } + + rv = 0; + +done: + remoteDriverUnlock(priv); + return rv; +} + +static int remoteConnectListAllInterfaces(virConnectPtr conn, virInterfacePtr **ifaces, unsigned int flags)
ACK, will fix the minor issues when pushing. Daniel -- |: http://berrange.com -o- http://www.flickr.com/photos/dberrange/ :| |: http://libvirt.org -o- http://virt-manager.org :| |: http://autobuild.org -o- http://search.cpan.org/~danberr/ :| |: http://entangle-photo.org -o- http://live.gnome.org/gtk-vnc :|