This wires up the remote driver to handle the new events APIs.
The public API allows an application to request a callback filters
events to a specific domain object, and register multiple callbacks
for the same event type. On the wire there are two strategies for
this
- Register multiple callbacks with the remote daemon, each
with filtering as needed
- Register only one callback per event type, with no filtering
Both approaches have potential inefficiency. In the first scheme,
the same event gets sent over the wire many times if multiple
callbacks are registered. With the second scheme, unneccessary
events get sent over the wire if a per-domain filter is set on
the client. The second scheme is far easier to implement though,
so this patch takes that approach.
* daemon/dispatch.h: Don't export remoteRelayDomainEvent since it
is no longer needed for unregistering callbacks, instead the
unique callback ID is used
* daemon/libvirtd.c, daemon/libvirtd.h: Track and unregister
callbacks based on callback ID, instead of function pointer
* daemon/remote.c: Switch over to using virConnectDomainEventRegisterAny
instead of legacy virConnectDomainEventRegister function. Refactor
remoteDispatchDomainEventSend() to cope with arbitrary event types
* src/driver.h, src/driver.c: Move verify() call into source file
instead of header, to avoid polluting the global namespace with
the verify function name
* src/remote/remote_driver.c: Implement new APIs for event
registration. Refactor processCallDispatchMessage() to cope
with arbitrary incoming event types. Merge remoteDomainQueueEvent()
into processCallDispatchMessage() to avoid duplication of code.
Rename remoteDomainReadEvent() to remoteDomainReadEventLifecycle()
* src/remote/remote_protocol.x: Define wire format for the new
virConnectDomainEventRegisterAny and virConnectDomainEventDeregisterAny
functions
---
daemon/dispatch.h | 10 --
daemon/libvirtd.c | 20 +++-
daemon/libvirtd.h | 2 +-
daemon/remote.c | 160 +++++++++++++++++++-----
daemon/remote_dispatch_args.h | 2 +
daemon/remote_dispatch_prototypes.h | 16 +++
daemon/remote_dispatch_table.h | 10 ++
src/driver.c | 4 +
src/driver.h | 4 -
src/remote/remote_driver.c | 240 +++++++++++++++++++++++-----------
src/remote/remote_protocol.c | 18 +++
src/remote/remote_protocol.h | 104 +++++++++-------
src/remote/remote_protocol.x | 13 ++-
13 files changed, 429 insertions(+), 174 deletions(-)
diff --git a/daemon/dispatch.h b/daemon/dispatch.h
index 1371b05..85f8fc3 100644
--- a/daemon/dispatch.h
+++ b/daemon/dispatch.h
@@ -60,16 +60,6 @@ remoteSerializeStreamError(struct qemud_client *client,
int proc,
int serial);
-/* Having this here is dubious. It should be in remote.h
- * but qemud.c shouldn't depend on that header directly.
- * Refactor this later to deal with this properly.
- */
-int remoteRelayDomainEvent (virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- int event,
- int detail,
- void *opaque);
-
int
remoteSendStreamData(struct qemud_client *client,
diff --git a/daemon/libvirtd.c b/daemon/libvirtd.c
index d59a2ab..0d89c53 100644
--- a/daemon/libvirtd.c
+++ b/daemon/libvirtd.c
@@ -1275,6 +1275,7 @@ static int qemudDispatchServer(struct qemud_server *server, struct
qemud_socket
socklen_t addrlen = (socklen_t) (sizeof addr);
struct qemud_client *client;
int no_slow_start = 1;
+ int i;
if ((fd = accept(sock->fd, (struct sockaddr *)&addr, &addrlen)) < 0) {
char ebuf[1024];
@@ -1346,6 +1347,10 @@ static int qemudDispatchServer(struct qemud_server *server, struct
qemud_socket
memcpy (&client->addr, &addr, sizeof addr);
client->addrlen = addrlen;
+ for (i = 0 ; i < VIR_DOMAIN_EVENT_ID_LAST ; i++) {
+ client->domainEventCallbackID[i] = -1;
+ }
+
/* Prepare one for packet receive */
if (VIR_ALLOC(client->rx) < 0)
goto cleanup;
@@ -1415,7 +1420,6 @@ static int qemudDispatchServer(struct qemud_server *server, struct
qemud_socket
if (server->nclients > server->nactiveworkers &&
server->nactiveworkers < server->nworkers) {
- int i;
for (i = 0 ; i < server->nworkers ; i++) {
if (!server->workers[i].hasThread) {
if (qemudStartWorker(server, &server->workers[i]) < 0)
@@ -1454,9 +1458,17 @@ void qemudDispatchClientFailure(struct qemud_client *client) {
}
/* Deregister event delivery callback */
- if (client->conn && client->domain_events_registered) {
- DEBUG0("Deregistering to relay remote events");
- virConnectDomainEventDeregister(client->conn, remoteRelayDomainEvent);
+ if (client->conn) {
+ int i;
+
+ for (i = 0 ; i < VIR_DOMAIN_EVENT_ID_LAST ; i++) {
+ if (client->domainEventCallbackID[i] != -1) {
+ DEBUG("Deregistering to relay remote events %d", i);
+ virConnectDomainEventDeregisterAny(client->conn,
+ client->domainEventCallbackID[i]);
+ }
+ client->domainEventCallbackID[i] = -1;
+ }
}
#if HAVE_SASL
diff --git a/daemon/libvirtd.h b/daemon/libvirtd.h
index d30fcd7..d292681 100644
--- a/daemon/libvirtd.h
+++ b/daemon/libvirtd.h
@@ -177,7 +177,7 @@ struct qemud_client {
int watch;
unsigned int readonly :1;
unsigned int closing :1;
- unsigned int domain_events_registered :1;
+ int domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LAST];
struct sockaddr_storage addr;
socklen_t addrlen;
diff --git a/daemon/remote.c b/daemon/remote.c
index 7c4339f..fd3aa4e 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -94,36 +94,48 @@ const dispatch_data const *remoteGetDispatchData(int proc)
/* Prototypes */
static void
remoteDispatchDomainEventSend (struct qemud_client *client,
- remote_domain_event_msg *data);
+ int procnr,
+ xdrproc_t proc,
+ void *data);
-int remoteRelayDomainEvent (virConnectPtr conn ATTRIBUTE_UNUSED,
- virDomainPtr dom,
- int event,
- int detail,
- void *opaque)
+static int remoteRelayDomainEventLifecycle(virConnectPtr conn ATTRIBUTE_UNUSED,
+ virDomainPtr dom,
+ int event,
+ int detail,
+ void *opaque)
{
struct qemud_client *client = opaque;
- REMOTE_DEBUG("Relaying domain event %d %d", event, detail);
+ remote_domain_event_msg data;
- if (client) {
- remote_domain_event_msg data;
+ if (!client)
+ return -1;
+
+ REMOTE_DEBUG("Relaying domain lifecycle event %d %d", event, detail);
- virMutexLock(&client->lock);
+ virMutexLock(&client->lock);
- /* build return data */
- memset(&data, 0, sizeof data);
- make_nonnull_domain (&data.dom, dom);
- data.event = event;
- data.detail = detail;
+ /* build return data */
+ memset(&data, 0, sizeof data);
+ make_nonnull_domain (&data.dom, dom);
+ data.event = event;
+ data.detail = detail;
- remoteDispatchDomainEventSend (client, &data);
+ remoteDispatchDomainEventSend (client,
+ REMOTE_PROC_DOMAIN_EVENT,
+ (xdrproc_t)xdr_remote_domain_event_msg, &data);
+
+ virMutexUnlock(&client->lock);
- virMutexUnlock(&client->lock);
- }
return 0;
}
+static virConnectDomainEventGenericCallback
domainEventCallbacks[VIR_DOMAIN_EVENT_ID_LAST] = {
+ VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle),
+};
+
+verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST);
+
/*----- Functions. -----*/
static int
@@ -4818,18 +4830,24 @@ remoteDispatchDomainEventsRegister (struct qemud_server *server
ATTRIBUTE_UNUSED
remote_domain_events_register_ret *ret
ATTRIBUTE_UNUSED)
{
CHECK_CONN(client);
+ int callbackID;
+
+ if (client->domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LIFECYCLE] != -1) {
+ remoteDispatchFormatError(rerr, _("domain event %d already
registered"), VIR_DOMAIN_EVENT_ID_LIFECYCLE);
+ return -1;
+ }
- if (virConnectDomainEventRegister(conn,
- remoteRelayDomainEvent,
- client, NULL) < 0) {
+ if ((callbackID = virConnectDomainEventRegisterAny(conn,
+ NULL,
+ VIR_DOMAIN_EVENT_ID_LIFECYCLE,
+
VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle),
+ client, NULL)) < 0) {
remoteDispatchConnError(rerr, conn);
return -1;
}
- if (ret)
- ret->cb_registered = 1;
+ client->domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LIFECYCLE] = callbackID;
- client->domain_events_registered = 1;
return 0;
}
@@ -4844,21 +4862,26 @@ remoteDispatchDomainEventsDeregister (struct qemud_server *server
ATTRIBUTE_UNUS
{
CHECK_CONN(client);
- if (virConnectDomainEventDeregister(conn, remoteRelayDomainEvent) < 0) {
- remoteDispatchConnError(rerr, conn);
+ if (client->domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LIFECYCLE] == -1) {
+ remoteDispatchFormatError(rerr, _("domain event %d not registered"),
VIR_DOMAIN_EVENT_ID_LIFECYCLE);
return -1;
}
- if (ret)
- ret->cb_registered = 0;
+ if (virConnectDomainEventDeregisterAny(conn,
+
client->domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LIFECYCLE]) < 0) {
+ remoteDispatchConnError(rerr, conn);
+ return -1;
+ }
- client->domain_events_registered = 0;
+ client->domainEventCallbackID[VIR_DOMAIN_EVENT_ID_LIFECYCLE] = -1;
return 0;
}
static void
remoteDispatchDomainEventSend (struct qemud_client *client,
- remote_domain_event_msg *data)
+ int procnr,
+ xdrproc_t proc,
+ void *data)
{
struct qemud_client_message *msg = NULL;
XDR xdr;
@@ -4869,7 +4892,7 @@ remoteDispatchDomainEventSend (struct qemud_client *client,
msg->hdr.prog = REMOTE_PROGRAM;
msg->hdr.vers = REMOTE_PROTOCOL_VERSION;
- msg->hdr.proc = REMOTE_PROC_DOMAIN_EVENT;
+ msg->hdr.proc = procnr;
msg->hdr.type = REMOTE_MESSAGE;
msg->hdr.serial = 1;
msg->hdr.status = REMOTE_OK;
@@ -4887,8 +4910,10 @@ remoteDispatchDomainEventSend (struct qemud_client *client,
if (xdr_setpos (&xdr, msg->bufferOffset) == 0)
goto xdr_error;
- if (!xdr_remote_domain_event_msg(&xdr, data))
+ if (!(proc)(&xdr, data)) {
+ VIR_WARN("Failed to serialize domain event %d", procnr);
goto xdr_error;
+ }
/* Update length word to include payload*/
len = msg->bufferOffset = xdr_getpos (&xdr);
@@ -5463,6 +5488,77 @@ remoteDispatchDomainAbortJob (struct qemud_server *server
ATTRIBUTE_UNUSED,
}
+static int
+remoteDispatchDomainEventsRegisterAny (struct qemud_server *server ATTRIBUTE_UNUSED,
+ struct qemud_client *client ATTRIBUTE_UNUSED,
+ virConnectPtr conn,
+ remote_message_header *hdr ATTRIBUTE_UNUSED,
+ remote_error *rerr ATTRIBUTE_UNUSED,
+ remote_domain_events_register_any_args *args,
+ void *ret ATTRIBUTE_UNUSED)
+{
+ CHECK_CONN(client);
+ int callbackID;
+
+ if (args->eventID >= VIR_DOMAIN_EVENT_ID_LAST ||
+ args->eventID < 0) {
+ remoteDispatchFormatError(rerr, _("unsupported event ID %d"),
args->eventID);
+ return -1;
+ }
+
+ if (client->domainEventCallbackID[args->eventID] != -1) {
+ remoteDispatchFormatError(rerr, _("domain event %d already
registered"), args->eventID);
+ return -1;
+ }
+
+ if ((callbackID = virConnectDomainEventRegisterAny(conn,
+ NULL,
+ args->eventID,
+
domainEventCallbacks[args->eventID],
+ client, NULL)) < 0) {
+ remoteDispatchConnError(rerr, conn);
+ return -1;
+ }
+
+ client->domainEventCallbackID[args->eventID] = callbackID;
+
+ return 0;
+}
+
+static int
+remoteDispatchDomainEventsDeregisterAny (struct qemud_server *server ATTRIBUTE_UNUSED,
+ struct qemud_client *client ATTRIBUTE_UNUSED,
+ virConnectPtr conn,
+ remote_message_header *hdr ATTRIBUTE_UNUSED,
+ remote_error *rerr ATTRIBUTE_UNUSED,
+ remote_domain_events_deregister_any_args *args,
+ void *ret ATTRIBUTE_UNUSED)
+{
+ CHECK_CONN(client);
+ int callbackID = -1;
+
+ if (args->eventID >= VIR_DOMAIN_EVENT_ID_LAST ||
+ args->eventID < 0) {
+ remoteDispatchFormatError(rerr, _("unsupported event ID %d"),
args->eventID);
+ return -1;
+ }
+
+ callbackID = client->domainEventCallbackID[args->eventID];
+ if (callbackID < 0) {
+ remoteDispatchFormatError(rerr, _("domain event %d not registered"),
args->eventID);
+ return -1;
+ }
+
+ if (virConnectDomainEventDeregisterAny(conn, callbackID) < 0) {
+ remoteDispatchConnError(rerr, conn);
+ return -1;
+ }
+
+ client->domainEventCallbackID[args->eventID] = -1;
+ return 0;
+}
+
+
/*----- Helpers. -----*/
/* get_nonnull_domain and get_nonnull_network turn an on-wire
diff --git a/daemon/remote_dispatch_args.h b/daemon/remote_dispatch_args.h
index f97155b..699c584 100644
--- a/daemon/remote_dispatch_args.h
+++ b/daemon/remote_dispatch_args.h
@@ -140,3 +140,5 @@
remote_cpu_baseline_args val_remote_cpu_baseline_args;
remote_domain_get_job_info_args val_remote_domain_get_job_info_args;
remote_domain_abort_job_args val_remote_domain_abort_job_args;
+ remote_domain_events_register_any_args val_remote_domain_events_register_any_args;
+ remote_domain_events_deregister_any_args
val_remote_domain_events_deregister_any_args;
diff --git a/daemon/remote_dispatch_prototypes.h b/daemon/remote_dispatch_prototypes.h
index b81c8c3..18558d2 100644
--- a/daemon/remote_dispatch_prototypes.h
+++ b/daemon/remote_dispatch_prototypes.h
@@ -178,6 +178,14 @@ static int remoteDispatchDomainEventsDeregister(
remote_error *err,
void *args,
remote_domain_events_deregister_ret *ret);
+static int remoteDispatchDomainEventsDeregisterAny(
+ struct qemud_server *server,
+ struct qemud_client *client,
+ virConnectPtr conn,
+ remote_message_header *hdr,
+ remote_error *err,
+ remote_domain_events_deregister_any_args *args,
+ void *ret);
static int remoteDispatchDomainEventsRegister(
struct qemud_server *server,
struct qemud_client *client,
@@ -186,6 +194,14 @@ static int remoteDispatchDomainEventsRegister(
remote_error *err,
void *args,
remote_domain_events_register_ret *ret);
+static int remoteDispatchDomainEventsRegisterAny(
+ struct qemud_server *server,
+ struct qemud_client *client,
+ virConnectPtr conn,
+ remote_message_header *hdr,
+ remote_error *err,
+ remote_domain_events_register_any_args *args,
+ void *ret);
static int remoteDispatchDomainGetAutostart(
struct qemud_server *server,
struct qemud_client *client,
diff --git a/daemon/remote_dispatch_table.h b/daemon/remote_dispatch_table.h
index 5ad6bff..6abf0ff 100644
--- a/daemon/remote_dispatch_table.h
+++ b/daemon/remote_dispatch_table.h
@@ -827,3 +827,13 @@
.args_filter = (xdrproc_t) xdr_remote_domain_abort_job_args,
.ret_filter = (xdrproc_t) xdr_void,
},
+{ /* DomainEventsRegisterAny => 165 */
+ .fn = (dispatch_fn) remoteDispatchDomainEventsRegisterAny,
+ .args_filter = (xdrproc_t) xdr_remote_domain_events_register_any_args,
+ .ret_filter = (xdrproc_t) xdr_void,
+},
+{ /* DomainEventsDeregisterAny => 166 */
+ .fn = (dispatch_fn) remoteDispatchDomainEventsDeregisterAny,
+ .args_filter = (xdrproc_t) xdr_remote_domain_events_deregister_any_args,
+ .ret_filter = (xdrproc_t) xdr_void,
+},
diff --git a/src/driver.c b/src/driver.c
index c247f14..e6f3aaa 100644
--- a/src/driver.c
+++ b/src/driver.c
@@ -31,6 +31,10 @@
#define DEFAULT_DRIVER_DIR LIBDIR "/libvirt/drivers"
+/* Make sure ... INTERNAL_CALL can not be set by the caller */
+verify((VIR_SECRET_GET_VALUE_INTERNAL_CALL &
+ VIR_SECRET_GET_VALUE_FLAGS_MASK) == 0);
+
#ifdef WITH_DRIVER_MODULES
/* XXX re-implment this for other OS, or use libtools helper lib ? */
diff --git a/src/driver.h b/src/driver.h
index 805b2b1..c461a70 100644
--- a/src/driver.h
+++ b/src/driver.h
@@ -897,10 +897,6 @@ enum {
VIR_SECRET_GET_VALUE_INTERNAL_CALL = 1 << 16
};
-/* Make sure ... INTERNAL_CALL can not be set by the caller */
-verify((VIR_SECRET_GET_VALUE_INTERNAL_CALL &
- VIR_SECRET_GET_VALUE_FLAGS_MASK) == 0);
-
typedef virSecretPtr
(*virDrvSecretLookupByUUID) (virConnectPtr conn,
const unsigned char *uuid);
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 2c3a70e..eba29f2 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -260,7 +260,6 @@ static void make_nonnull_storage_pool (remote_nonnull_storage_pool
*pool_dst, vi
static void make_nonnull_storage_vol (remote_nonnull_storage_vol *vol_dst,
virStorageVolPtr vol_src);
static void make_nonnull_secret (remote_nonnull_secret *secret_dst, virSecretPtr
secret_src);
void remoteDomainEventFired(int watch, int fd, int event, void *data);
-static void remoteDomainQueueEvent(virConnectPtr conn, XDR *xdr);
void remoteDomainEventQueueFlush(int timer, void *opaque);
/*----------------------------------------------------------------------*/
@@ -6784,10 +6783,10 @@ remoteAuthPolkit (virConnectPtr conn, struct private_data *priv,
int in_open,
#endif /* HAVE_POLKIT */
/*----------------------------------------------------------------------*/
-static int remoteDomainEventRegister (virConnectPtr conn,
- virConnectDomainEventCallback callback,
- void *opaque,
- virFreeCallback freecb)
+static int remoteDomainEventRegister(virConnectPtr conn,
+ virConnectDomainEventCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
{
int rv = -1;
struct private_data *priv = conn->privateData;
@@ -6804,7 +6803,7 @@ static int remoteDomainEventRegister (virConnectPtr conn,
goto done;
}
- if ( priv->callbackList->count == 1 ) {
+ if (virDomainEventCallbackListCountID(conn, priv->callbackList,
VIR_DOMAIN_EVENT_ID_LIFECYCLE) == 1) {
/* Tell the server when we are the first callback deregistering */
if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_REGISTER,
(xdrproc_t) xdr_void, (char *) NULL,
@@ -6819,8 +6818,8 @@ done:
return rv;
}
-static int remoteDomainEventDeregister (virConnectPtr conn,
- virConnectDomainEventCallback callback)
+static int remoteDomainEventDeregister(virConnectPtr conn,
+ virConnectDomainEventCallback callback)
{
struct private_data *priv = conn->privateData;
int rv = -1;
@@ -6839,14 +6838,14 @@ static int remoteDomainEventDeregister (virConnectPtr conn,
error (conn, VIR_ERR_RPC, _("removing cb from list"));
goto done;
}
+ }
- if ( priv->callbackList->count == 0 ) {
- /* Tell the server when we are the last callback deregistering */
- if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER,
- (xdrproc_t) xdr_void, (char *) NULL,
- (xdrproc_t) xdr_void, (char *) NULL) == -1)
- goto done;
- }
+ if (virDomainEventCallbackListCountID(conn, priv->callbackList,
VIR_DOMAIN_EVENT_ID_LIFECYCLE) == 0) {
+ /* Tell the server when we are the last callback deregistering */
+ if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER,
+ (xdrproc_t) xdr_void, (char *) NULL,
+ (xdrproc_t) xdr_void, (char *) NULL) == -1)
+ goto done;
}
rv = 0;
@@ -6856,6 +6855,38 @@ done:
return rv;
}
+/**
+ * remoteDomainReadEventLifecycle
+ *
+ * Read the domain lifecycle event data off the wire
+ */
+static virDomainEventPtr
+remoteDomainReadEventLifecycle(virConnectPtr conn, XDR *xdr)
+{
+ remote_domain_event_msg msg;
+ virDomainPtr dom;
+ virDomainEventPtr event = NULL;
+ memset (&msg, 0, sizeof msg);
+
+ /* unmarshall parameters, and process it*/
+ if (! xdr_remote_domain_event_msg(xdr, &msg) ) {
+ error (conn, VIR_ERR_RPC,
+ _("unable to demarshall lifecycle event"));
+ return NULL;
+ }
+
+ dom = get_nonnull_domain(conn,msg.dom);
+ if (!dom)
+ return NULL;
+
+ event = virDomainEventNewFromDom(dom, msg.event, msg.detail);
+ xdr_free ((xdrproc_t) &xdr_remote_domain_event_msg, (char *) &msg);
+
+ virDomainFree(dom);
+ return event;
+}
+
+
static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
remoteSecretOpen (virConnectPtr conn,
virConnectAuthPtr auth,
@@ -7707,6 +7738,101 @@ done:
}
+static int remoteDomainEventRegisterAny(virConnectPtr conn,
+ virDomainPtr dom,
+ int eventID,
+ virConnectDomainEventGenericCallback callback,
+ void *opaque,
+ virFreeCallback freecb)
+{
+ int rv = -1;
+ struct private_data *priv = conn->privateData;
+ remote_domain_events_register_any_args args;
+ int callbackID;
+
+ remoteDriverLock(priv);
+
+ if (priv->eventFlushTimer < 0) {
+ error (conn, VIR_ERR_NO_SUPPORT, _("no event support"));
+ goto done;
+ }
+
+ if ((callbackID = virDomainEventCallbackListAddID(conn, priv->callbackList,
+ dom, eventID,
+ callback, opaque, freecb)) < 0)
{
+ error (conn, VIR_ERR_RPC, _("adding cb to list"));
+ goto done;
+ }
+
+ /* If this is the first callback for this eventID, we need to enable
+ * events on the server */
+ if (virDomainEventCallbackListCountID(conn, priv->callbackList, eventID) == 1) {
+ args.eventID = eventID;
+
+ if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_REGISTER_ANY,
+ (xdrproc_t) xdr_remote_domain_events_register_any_args, (char *)
&args,
+ (xdrproc_t) xdr_void, (char *)NULL) == -1) {
+ virDomainEventCallbackListRemoveID(conn, priv->callbackList, callbackID);
+ goto done;
+ }
+ }
+
+ rv = callbackID;
+
+done:
+ remoteDriverUnlock(priv);
+ return rv;
+}
+
+
+static int remoteDomainEventDeregisterAny(virConnectPtr conn,
+ int callbackID)
+{
+ struct private_data *priv = conn->privateData;
+ int rv = -1;
+ remote_domain_events_deregister_any_args args;
+ int eventID;
+
+ remoteDriverLock(priv);
+
+ if ((eventID = virDomainEventCallbackListEventID(conn, priv->callbackList,
callbackID)) < 0) {
+ errorf (conn, VIR_ERR_RPC, _("unable to find callback ID %d"),
callbackID);
+ goto done;
+ }
+
+ if (priv->domainEventDispatching) {
+ if (virDomainEventCallbackListMarkDeleteID(conn, priv->callbackList,
+ callbackID) < 0) {
+ error (conn, VIR_ERR_RPC, _("marking cb for deletion"));
+ goto done;
+ }
+ } else {
+ if (virDomainEventCallbackListRemoveID(conn, priv->callbackList,
+ callbackID) < 0) {
+ error (conn, VIR_ERR_RPC, _("removing cb from list"));
+ goto done;
+ }
+ }
+
+ /* If that was the last callback for this eventID, we need to disable
+ * events on the server */
+ if (virDomainEventCallbackListCountID(conn, priv->callbackList, eventID) == 0) {
+ args.eventID = eventID;
+
+ if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY,
+ (xdrproc_t) xdr_remote_domain_events_deregister_any_args, (char *)
&args,
+ (xdrproc_t) xdr_void, (char *) NULL) == -1)
+ goto done;
+ }
+
+ rv = 0;
+
+done:
+ remoteDriverUnlock(priv);
+ return rv;
+}
+
+
/*----------------------------------------------------------------------*/
@@ -8258,6 +8384,7 @@ processCallDispatchMessage(virConnectPtr conn, struct private_data
*priv,
int in_open,
remote_message_header *hdr,
XDR *xdr) {
+ virDomainEventPtr event = NULL;
/* An async message has come in while we were waiting for the
* response. Process it to pull it off the wire, and try again
*/
@@ -8268,13 +8395,26 @@ processCallDispatchMessage(virConnectPtr conn, struct private_data
*priv,
return -1;
}
- if (hdr->proc == REMOTE_PROC_DOMAIN_EVENT) {
- remoteDomainQueueEvent(conn, xdr);
- virEventUpdateTimeout(priv->eventFlushTimer, 0);
- } else {
- return -1;
+ switch (hdr->proc) {
+ case REMOTE_PROC_DOMAIN_EVENT:
+ event = remoteDomainReadEventLifecycle(conn, xdr);
+ break;
+
+ default:
DEBUG("Unexpected event proc %d", hdr->proc);
+ break;
}
+
+ if (!event)
+ return -1;
+
+ if (virDomainEventQueuePush(priv->domainEvents,
+ event) < 0) {
+ DEBUG0("Error adding event to queue");
+ virDomainEventFree(event);
+ }
+ virEventUpdateTimeout(priv->eventFlushTimer, 0);
+
return 0;
}
@@ -8798,54 +8938,6 @@ call (virConnectPtr conn, struct private_data *priv,
}
-
-/**
- * remoteDomainReadEvent
- *
- * Read the event data off the wire
- */
-static virDomainEventPtr
-remoteDomainReadEvent(virConnectPtr conn, XDR *xdr)
-{
- remote_domain_event_msg msg;
- virDomainPtr dom;
- virDomainEventPtr event = NULL;
- memset (&msg, 0, sizeof msg);
-
- /* unmarshall parameters, and process it*/
- if (! xdr_remote_domain_event_msg(xdr, &msg) ) {
- error (conn, VIR_ERR_RPC,
- _("remoteDomainProcessEvent: unmarshalling msg"));
- return NULL;
- }
-
- dom = get_nonnull_domain(conn,msg.dom);
- if (!dom)
- return NULL;
-
- event = virDomainEventNewFromDom(dom, msg.event, msg.detail);
-
- virDomainFree(dom);
- return event;
-}
-
-static void
-remoteDomainQueueEvent(virConnectPtr conn, XDR *xdr)
-{
- struct private_data *priv = conn->privateData;
- virDomainEventPtr event;
-
- event = remoteDomainReadEvent(conn, xdr);
- if (!event)
- return;
-
- if (virDomainEventQueuePush(priv->domainEvents,
- event) < 0) {
- DEBUG0("Error adding event to queue");
- virDomainEventFree(event);
- }
-}
-
/** remoteDomainEventFired:
*
* The callback for monitoring the remote socket
@@ -8927,14 +9019,6 @@ remoteDomainEventQueueFlush(int timer ATTRIBUTE_UNUSED, void
*opaque)
/* Purge any deleted callbacks */
virDomainEventCallbackListPurgeMarked(priv->callbackList);
- if ( priv->callbackList->count == 0 ) {
- /* Tell the server when we are the last callback deregistering */
- if (call (conn, priv, 0, REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER,
- (xdrproc_t) xdr_void, (char *) NULL,
- (xdrproc_t) xdr_void, (char *) NULL) == -1)
- VIR_WARN0("Failed to de-register events");
- }
-
priv->domainEventDispatching = 0;
remoteDriverUnlock(priv);
@@ -9126,8 +9210,8 @@ static virDriver remote_driver = {
remoteCPUBaseline, /* cpuBaseline */
remoteDomainGetJobInfo, /* domainGetJobInfo */
remoteDomainAbortJob, /* domainFinishJob */
- NULL, /* domainEventRegisterAny */
- NULL, /* domainEventDeregisterAny */
+ remoteDomainEventRegisterAny, /* domainEventRegisterAny */
+ remoteDomainEventDeregisterAny, /* domainEventDeregisterAny */
};
static virNetworkDriver network_driver = {
diff --git a/src/remote/remote_protocol.c b/src/remote/remote_protocol.c
index 701acab..3f4af38 100644
--- a/src/remote/remote_protocol.c
+++ b/src/remote/remote_protocol.c
@@ -3009,6 +3009,24 @@ xdr_remote_domain_abort_job_args (XDR *xdrs,
remote_domain_abort_job_args *objp)
}
bool_t
+xdr_remote_domain_events_register_any_args (XDR *xdrs,
remote_domain_events_register_any_args *objp)
+{
+
+ if (!xdr_int (xdrs, &objp->eventID))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
+xdr_remote_domain_events_deregister_any_args (XDR *xdrs,
remote_domain_events_deregister_any_args *objp)
+{
+
+ if (!xdr_int (xdrs, &objp->eventID))
+ return FALSE;
+ return TRUE;
+}
+
+bool_t
xdr_remote_procedure (XDR *xdrs, remote_procedure *objp)
{
diff --git a/src/remote/remote_protocol.h b/src/remote/remote_protocol.h
index f76e6e5..40e1094 100644
--- a/src/remote/remote_protocol.h
+++ b/src/remote/remote_protocol.h
@@ -4,51 +4,51 @@
*/
#ifndef _RP_H_RPCGEN
-# define _RP_H_RPCGEN
+#define _RP_H_RPCGEN
-# include <rpc/rpc.h>
+#include <rpc/rpc.h>
-# ifdef __cplusplus
+#ifdef __cplusplus
extern "C" {
-# endif
+#endif
-# include "internal.h"
-# include <arpa/inet.h>
-# define REMOTE_MESSAGE_MAX 262144
-# define REMOTE_MESSAGE_HEADER_MAX 24
-# define REMOTE_MESSAGE_PAYLOAD_MAX 262120
-# define REMOTE_STRING_MAX 65536
+#include "internal.h"
+#include <arpa/inet.h>
+#define REMOTE_MESSAGE_MAX 262144
+#define REMOTE_MESSAGE_HEADER_MAX 24
+#define REMOTE_MESSAGE_PAYLOAD_MAX 262120
+#define REMOTE_STRING_MAX 65536
typedef char *remote_nonnull_string;
typedef remote_nonnull_string *remote_string;
-# define REMOTE_DOMAIN_ID_LIST_MAX 16384
-# define REMOTE_DOMAIN_NAME_LIST_MAX 1024
-# define REMOTE_CPUMAP_MAX 256
-# define REMOTE_VCPUINFO_MAX 2048
-# define REMOTE_CPUMAPS_MAX 16384
-# define REMOTE_MIGRATE_COOKIE_MAX 256
-# define REMOTE_NETWORK_NAME_LIST_MAX 256
-# define REMOTE_INTERFACE_NAME_LIST_MAX 256
-# define REMOTE_DEFINED_INTERFACE_NAME_LIST_MAX 256
-# define REMOTE_STORAGE_POOL_NAME_LIST_MAX 256
-# define REMOTE_STORAGE_VOL_NAME_LIST_MAX 1024
-# define REMOTE_NODE_DEVICE_NAME_LIST_MAX 16384
-# define REMOTE_NODE_DEVICE_CAPS_LIST_MAX 16384
-# define REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX 16
-# define REMOTE_NODE_MAX_CELLS 1024
-# define REMOTE_AUTH_SASL_DATA_MAX 65536
-# define REMOTE_AUTH_TYPE_LIST_MAX 20
-# define REMOTE_DOMAIN_MEMORY_STATS_MAX 1024
-# define REMOTE_DOMAIN_BLOCK_PEEK_BUFFER_MAX 65536
-# define REMOTE_DOMAIN_MEMORY_PEEK_BUFFER_MAX 65536
-# define REMOTE_SECURITY_MODEL_MAX VIR_SECURITY_MODEL_BUFLEN
-# define REMOTE_SECURITY_LABEL_MAX VIR_SECURITY_LABEL_BUFLEN
-# define REMOTE_SECURITY_DOI_MAX VIR_SECURITY_DOI_BUFLEN
-# define REMOTE_SECRET_VALUE_MAX 65536
-# define REMOTE_SECRET_UUID_LIST_MAX 16384
-# define REMOTE_CPU_BASELINE_MAX 256
+#define REMOTE_DOMAIN_ID_LIST_MAX 16384
+#define REMOTE_DOMAIN_NAME_LIST_MAX 1024
+#define REMOTE_CPUMAP_MAX 256
+#define REMOTE_VCPUINFO_MAX 2048
+#define REMOTE_CPUMAPS_MAX 16384
+#define REMOTE_MIGRATE_COOKIE_MAX 256
+#define REMOTE_NETWORK_NAME_LIST_MAX 256
+#define REMOTE_INTERFACE_NAME_LIST_MAX 256
+#define REMOTE_DEFINED_INTERFACE_NAME_LIST_MAX 256
+#define REMOTE_STORAGE_POOL_NAME_LIST_MAX 256
+#define REMOTE_STORAGE_VOL_NAME_LIST_MAX 1024
+#define REMOTE_NODE_DEVICE_NAME_LIST_MAX 16384
+#define REMOTE_NODE_DEVICE_CAPS_LIST_MAX 16384
+#define REMOTE_DOMAIN_SCHEDULER_PARAMETERS_MAX 16
+#define REMOTE_NODE_MAX_CELLS 1024
+#define REMOTE_AUTH_SASL_DATA_MAX 65536
+#define REMOTE_AUTH_TYPE_LIST_MAX 20
+#define REMOTE_DOMAIN_MEMORY_STATS_MAX 1024
+#define REMOTE_DOMAIN_BLOCK_PEEK_BUFFER_MAX 65536
+#define REMOTE_DOMAIN_MEMORY_PEEK_BUFFER_MAX 65536
+#define REMOTE_SECURITY_MODEL_MAX VIR_SECURITY_MODEL_BUFLEN
+#define REMOTE_SECURITY_LABEL_MAX VIR_SECURITY_LABEL_BUFLEN
+#define REMOTE_SECURITY_DOI_MAX VIR_SECURITY_DOI_BUFLEN
+#define REMOTE_SECRET_VALUE_MAX 65536
+#define REMOTE_SECRET_UUID_LIST_MAX 16384
+#define REMOTE_CPU_BASELINE_MAX 256
typedef char remote_uuid[VIR_UUID_BUFLEN];
@@ -1704,8 +1704,18 @@ struct remote_domain_abort_job_args {
remote_nonnull_domain dom;
};
typedef struct remote_domain_abort_job_args remote_domain_abort_job_args;
-# define REMOTE_PROGRAM 0x20008086
-# define REMOTE_PROTOCOL_VERSION 1
+
+struct remote_domain_events_register_any_args {
+ int eventID;
+};
+typedef struct remote_domain_events_register_any_args
remote_domain_events_register_any_args;
+
+struct remote_domain_events_deregister_any_args {
+ int eventID;
+};
+typedef struct remote_domain_events_deregister_any_args
remote_domain_events_deregister_any_args;
+#define REMOTE_PROGRAM 0x20008086
+#define REMOTE_PROTOCOL_VERSION 1
enum remote_procedure {
REMOTE_PROC_OPEN = 1,
@@ -1872,6 +1882,8 @@ enum remote_procedure {
REMOTE_PROC_CPU_BASELINE = 162,
REMOTE_PROC_DOMAIN_GET_JOB_INFO = 163,
REMOTE_PROC_DOMAIN_ABORT_JOB = 164,
+ REMOTE_PROC_DOMAIN_EVENTS_REGISTER_ANY = 165,
+ REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY = 166,
};
typedef enum remote_procedure remote_procedure;
@@ -1889,7 +1901,7 @@ enum remote_message_status {
REMOTE_CONTINUE = 2,
};
typedef enum remote_message_status remote_message_status;
-# define REMOTE_MESSAGE_HEADER_XDR_LEN 4
+#define REMOTE_MESSAGE_HEADER_XDR_LEN 4
struct remote_message_header {
u_int prog;
@@ -1903,7 +1915,7 @@ typedef struct remote_message_header remote_message_header;
/* the xdr functions */
-# if defined(__STDC__) || defined(__cplusplus)
+#if defined(__STDC__) || defined(__cplusplus)
extern bool_t xdr_remote_nonnull_string (XDR *, remote_nonnull_string*);
extern bool_t xdr_remote_string (XDR *, remote_string*);
extern bool_t xdr_remote_uuid (XDR *, remote_uuid);
@@ -2181,12 +2193,14 @@ extern bool_t xdr_remote_cpu_baseline_ret (XDR *,
remote_cpu_baseline_ret*);
extern bool_t xdr_remote_domain_get_job_info_args (XDR *,
remote_domain_get_job_info_args*);
extern bool_t xdr_remote_domain_get_job_info_ret (XDR *,
remote_domain_get_job_info_ret*);
extern bool_t xdr_remote_domain_abort_job_args (XDR *, remote_domain_abort_job_args*);
+extern bool_t xdr_remote_domain_events_register_any_args (XDR *,
remote_domain_events_register_any_args*);
+extern bool_t xdr_remote_domain_events_deregister_any_args (XDR *,
remote_domain_events_deregister_any_args*);
extern bool_t xdr_remote_procedure (XDR *, remote_procedure*);
extern bool_t xdr_remote_message_type (XDR *, remote_message_type*);
extern bool_t xdr_remote_message_status (XDR *, remote_message_status*);
extern bool_t xdr_remote_message_header (XDR *, remote_message_header*);
-# else /* K&R C */
+#else /* K&R C */
extern bool_t xdr_remote_nonnull_string ();
extern bool_t xdr_remote_string ();
extern bool_t xdr_remote_uuid ();
@@ -2464,15 +2478,17 @@ extern bool_t xdr_remote_cpu_baseline_ret ();
extern bool_t xdr_remote_domain_get_job_info_args ();
extern bool_t xdr_remote_domain_get_job_info_ret ();
extern bool_t xdr_remote_domain_abort_job_args ();
+extern bool_t xdr_remote_domain_events_register_any_args ();
+extern bool_t xdr_remote_domain_events_deregister_any_args ();
extern bool_t xdr_remote_procedure ();
extern bool_t xdr_remote_message_type ();
extern bool_t xdr_remote_message_status ();
extern bool_t xdr_remote_message_header ();
-# endif /* K&R C */
+#endif /* K&R C */
-# ifdef __cplusplus
+#ifdef __cplusplus
}
-# endif
+#endif
#endif /* !_RP_H_RPCGEN */
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 5e33da5..60435f4 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -1517,6 +1517,15 @@ struct remote_domain_abort_job_args {
};
+struct remote_domain_events_register_any_args {
+ int eventID;
+};
+
+struct remote_domain_events_deregister_any_args {
+ int eventID;
+};
+
+
/*----- Protocol. -----*/
/* Define the program number, protocol version and procedure numbers here. */
@@ -1703,7 +1712,9 @@ enum remote_procedure {
REMOTE_PROC_DOMAIN_DETACH_DEVICE_FLAGS = 161,
REMOTE_PROC_CPU_BASELINE = 162,
REMOTE_PROC_DOMAIN_GET_JOB_INFO = 163,
- REMOTE_PROC_DOMAIN_ABORT_JOB = 164
+ REMOTE_PROC_DOMAIN_ABORT_JOB = 164,
+ REMOTE_PROC_DOMAIN_EVENTS_REGISTER_ANY = 165,
+ REMOTE_PROC_DOMAIN_EVENTS_DEREGISTER_ANY = 166
/*
* Notice how the entries are grouped in sets of 10 ?
--
1.6.6.1