Commit 57ddcc23 (v0.9.11) introduced the pmwakeup event, with
an optional 'reason' field reserved for possible future expansion.
But it failed to wire the field through RPC, so even if we do
add a reason in the future, we will be unable to get it back
to the user.
Worse, commit 7ba5defb (v1.0.0) repeated the same mistake with
the pmsuspend_disk event.
As long as we are adding new RPC calls, we might as well fix
the events to actually match the signature so that we don't have
to add yet another RPC in the future if we do decide to start
using the reason field.
* src/remote/remote_protocol.x
(remote_domain_event_callback_pmwakeup_msg)
(remote_domain_event_callback_pmsuspend_msg)
(remote_domain_event_callback_pmsuspend_disk_msg): Add reason
field.
* daemon/remote.c (remoteRelayDomainEventPMWakeup)
(remoteRelayDomainEventPMSuspend)
(remoteRelayDomainEventPMSuspendDisk): Pass reason to client.
* src/conf/domain_event.h (virDomainEventPMWakeupNewFromDom)
(virDomainEventPMSuspendNewFromDom)
(virDomainEventPMSuspendDiskNewFromDom): Require additional
parameter.
* src/conf/domain_event.c (virDomainEventPMClass): New class.
(virDomainEventPMDispose): New function.
(virDomainEventPMWakeupNew*, virDomainEventPMSuspendNew*)
(virDomainEventPMSuspendDiskNew*)
(virDomainEventDispatchDefaultFunc): Use new class.
* src/remote/remote_driver.c (remoteDomainBuildEvent*PM*): Pass
reason through.
* src/remote_protocol-structs: Regenerate.
Signed-off-by: Eric Blake <eblake(a)redhat.com>
---
daemon/remote.c | 12 ++---
src/conf/domain_event.c | 106 ++++++++++++++++++++++++++++++++-----------
src/conf/domain_event.h | 6 +--
src/remote/remote_driver.c | 30 +++++++-----
src/remote/remote_protocol.x | 3 ++
src/remote_protocol-structs | 3 ++
6 files changed, 112 insertions(+), 48 deletions(-)
diff --git a/daemon/remote.c b/daemon/remote.c
index 48c707d..932f65f 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -714,7 +714,7 @@ remoteRelayDomainEventTrayChange(virConnectPtr conn,
static int
remoteRelayDomainEventPMWakeup(virConnectPtr conn,
virDomainPtr dom,
- int reason ATTRIBUTE_UNUSED,
+ int reason,
void *opaque)
{
daemonClientEventCallbackPtr callback = opaque;
@@ -737,7 +737,7 @@ remoteRelayDomainEventPMWakeup(virConnectPtr conn,
(xdrproc_t)xdr_remote_domain_event_pmwakeup_msg,
&data);
} else {
remote_domain_event_callback_pmwakeup_msg msg = { callback->callbackID,
- data };
+ reason, data };
remoteDispatchObjectEventSend(callback->client, remoteProgram,
REMOTE_PROC_DOMAIN_EVENT_CALLBACK_PMWAKEUP,
@@ -750,7 +750,7 @@ remoteRelayDomainEventPMWakeup(virConnectPtr conn,
static int
remoteRelayDomainEventPMSuspend(virConnectPtr conn,
virDomainPtr dom,
- int reason ATTRIBUTE_UNUSED,
+ int reason,
void *opaque)
{
daemonClientEventCallbackPtr callback = opaque;
@@ -773,7 +773,7 @@ remoteRelayDomainEventPMSuspend(virConnectPtr conn,
(xdrproc_t)xdr_remote_domain_event_pmsuspend_msg,
&data);
} else {
remote_domain_event_callback_pmsuspend_msg msg = { callback->callbackID,
- data };
+ reason, data };
remoteDispatchObjectEventSend(callback->client, remoteProgram,
REMOTE_PROC_DOMAIN_EVENT_CALLBACK_PMSUSPEND,
@@ -824,7 +824,7 @@ remoteRelayDomainEventBalloonChange(virConnectPtr conn,
static int
remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn,
virDomainPtr dom,
- int reason ATTRIBUTE_UNUSED,
+ int reason,
void *opaque)
{
daemonClientEventCallbackPtr callback = opaque;
@@ -847,7 +847,7 @@ remoteRelayDomainEventPMSuspendDisk(virConnectPtr conn,
(xdrproc_t)xdr_remote_domain_event_pmsuspend_disk_msg, &data);
} else {
remote_domain_event_callback_pmsuspend_disk_msg msg = { callback->callbackID,
- data };
+ reason, data };
remoteDispatchObjectEventSend(callback->client, remoteProgram,
REMOTE_PROC_DOMAIN_EVENT_CALLBACK_PMSUSPEND_DISK,
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index a490fe5..9c18922 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -47,6 +47,7 @@ static virClassPtr virDomainEventDiskChangeClass;
static virClassPtr virDomainEventTrayChangeClass;
static virClassPtr virDomainEventBalloonChangeClass;
static virClassPtr virDomainEventDeviceRemovedClass;
+static virClassPtr virDomainEventPMClass;
static void virDomainEventDispose(void *obj);
@@ -60,6 +61,7 @@ static void virDomainEventDiskChangeDispose(void *obj);
static void virDomainEventTrayChangeDispose(void *obj);
static void virDomainEventBalloonChangeDispose(void *obj);
static void virDomainEventDeviceRemovedDispose(void *obj);
+static void virDomainEventPMDispose(void *obj);
static void
virDomainEventDispatchDefaultFunc(virConnectPtr conn,
@@ -171,6 +173,14 @@ struct _virDomainEventDeviceRemoved {
typedef struct _virDomainEventDeviceRemoved virDomainEventDeviceRemoved;
typedef virDomainEventDeviceRemoved *virDomainEventDeviceRemovedPtr;
+struct _virDomainEventPM {
+ virDomainEvent parent;
+
+ int reason;
+};
+typedef struct _virDomainEventPM virDomainEventPM;
+typedef virDomainEventPM *virDomainEventPMPtr;
+
static int
virDomainEventsOnceInit(void)
@@ -241,6 +251,12 @@ virDomainEventsOnceInit(void)
sizeof(virDomainEventDeviceRemoved),
virDomainEventDeviceRemovedDispose)))
return -1;
+ if (!(virDomainEventPMClass =
+ virClassNew(virDomainEventClass,
+ "virDomainEventPM",
+ sizeof(virDomainEventPM),
+ virDomainEventPMDispose)))
+ return -1;
return 0;
}
@@ -359,6 +375,13 @@ virDomainEventDeviceRemovedDispose(void *obj)
VIR_FREE(event->devAlias);
}
+static void
+virDomainEventPMDispose(void *obj)
+{
+ virDomainEventPMPtr event = obj;
+ VIR_DEBUG("obj=%p", event);
+}
+
static void *
virDomainEventNew(virClassPtr klass,
@@ -907,19 +930,21 @@ virDomainEventTrayChangeNewFromDom(virDomainPtr dom,
static virObjectEventPtr
virDomainEventPMWakeupNew(int id,
const char *name,
- unsigned char *uuid)
+ unsigned char *uuid,
+ int reason)
{
- virObjectEventPtr ev;
+ virDomainEventPMPtr ev;
if (virDomainEventsInitialize() < 0)
return NULL;
- if (!(ev = virDomainEventNew(virDomainEventClass,
+ if (!(ev = virDomainEventNew(virDomainEventPMClass,
VIR_DOMAIN_EVENT_ID_PMWAKEUP,
id, name, uuid)))
return NULL;
- return ev;
+ ev->reason = reason;
+ return (virObjectEventPtr)ev;
}
virObjectEventPtr
@@ -927,31 +952,34 @@ virDomainEventPMWakeupNewFromObj(virDomainObjPtr obj)
{
return virDomainEventPMWakeupNew(obj->def->id,
obj->def->name,
- obj->def->uuid);
+ obj->def->uuid,
+ 0);
}
virObjectEventPtr
-virDomainEventPMWakeupNewFromDom(virDomainPtr dom)
+virDomainEventPMWakeupNewFromDom(virDomainPtr dom, int reason)
{
- return virDomainEventPMWakeupNew(dom->id, dom->name, dom->uuid);
+ return virDomainEventPMWakeupNew(dom->id, dom->name, dom->uuid, reason);
}
static virObjectEventPtr
virDomainEventPMSuspendNew(int id,
const char *name,
- unsigned char *uuid)
+ unsigned char *uuid,
+ int reason)
{
- virObjectEventPtr ev;
+ virDomainEventPMPtr ev;
if (virDomainEventsInitialize() < 0)
return NULL;
- if (!(ev = virDomainEventNew(virDomainEventClass,
+ if (!(ev = virDomainEventNew(virDomainEventPMClass,
VIR_DOMAIN_EVENT_ID_PMSUSPEND,
id, name, uuid)))
return NULL;
- return ev;
+ ev->reason = reason;
+ return (virObjectEventPtr)ev;
}
virObjectEventPtr
@@ -959,30 +987,34 @@ virDomainEventPMSuspendNewFromObj(virDomainObjPtr obj)
{
return virDomainEventPMSuspendNew(obj->def->id,
obj->def->name,
- obj->def->uuid);
+ obj->def->uuid,
+ 0);
}
virObjectEventPtr
-virDomainEventPMSuspendNewFromDom(virDomainPtr dom)
+virDomainEventPMSuspendNewFromDom(virDomainPtr dom, int reason)
{
- return virDomainEventPMSuspendNew(dom->id, dom->name, dom->uuid);
+ return virDomainEventPMSuspendNew(dom->id, dom->name, dom->uuid, reason);
}
static virObjectEventPtr
virDomainEventPMSuspendDiskNew(int id,
const char *name,
- unsigned char *uuid)
+ unsigned char *uuid,
+ int reason)
{
- virObjectEventPtr ev;
+ virDomainEventPMPtr ev;
if (virDomainEventsInitialize() < 0)
return NULL;
- if (!(ev = virDomainEventNew(virDomainEventClass,
+ if (!(ev = virDomainEventNew(virDomainEventPMClass,
VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK,
id, name, uuid)))
return NULL;
- return ev;
+
+ ev->reason = reason;
+ return (virObjectEventPtr)ev;
}
virObjectEventPtr
@@ -990,13 +1022,15 @@ virDomainEventPMSuspendDiskNewFromObj(virDomainObjPtr obj)
{
return virDomainEventPMSuspendDiskNew(obj->def->id,
obj->def->name,
- obj->def->uuid);
+ obj->def->uuid,
+ 0);
}
virObjectEventPtr
-virDomainEventPMSuspendDiskNewFromDom(virDomainPtr dom)
+virDomainEventPMSuspendDiskNewFromDom(virDomainPtr dom, int reason)
{
- return virDomainEventPMSuspendDiskNew(dom->id, dom->name, dom->uuid);
+ return virDomainEventPMSuspendDiskNew(dom->id, dom->name, dom->uuid,
+ reason);
}
virObjectEventPtr
@@ -1217,12 +1251,24 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
}
case VIR_DOMAIN_EVENT_ID_PMWAKEUP:
- ((virConnectDomainEventPMWakeupCallback)cb)(conn, dom, 0, cbopaque);
- goto cleanup;
+ {
+ virDomainEventPMPtr pmEvent = (virDomainEventPMPtr)event;
+
+ ((virConnectDomainEventPMWakeupCallback)cb)(conn, dom,
+ pmEvent->reason,
+ cbopaque);
+ goto cleanup;
+ }
case VIR_DOMAIN_EVENT_ID_PMSUSPEND:
- ((virConnectDomainEventPMSuspendCallback)cb)(conn, dom, 0, cbopaque);
- goto cleanup;
+ {
+ virDomainEventPMPtr pmEvent = (virDomainEventPMPtr)event;
+
+ ((virConnectDomainEventPMSuspendCallback)cb)(conn, dom,
+ pmEvent->reason,
+ cbopaque);
+ goto cleanup;
+ }
case VIR_DOMAIN_EVENT_ID_BALLOON_CHANGE:
{
@@ -1236,8 +1282,14 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
}
case VIR_DOMAIN_EVENT_ID_PMSUSPEND_DISK:
- ((virConnectDomainEventPMSuspendDiskCallback)cb)(conn, dom, 0, cbopaque);
- goto cleanup;
+ {
+ virDomainEventPMPtr pmEvent = (virDomainEventPMPtr)event;
+
+ ((virConnectDomainEventPMSuspendDiskCallback)cb)(conn, dom,
+ pmEvent->reason,
+ cbopaque);
+ goto cleanup;
+ }
case VIR_DOMAIN_EVENT_ID_DEVICE_REMOVED:
{
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index be577e9..300c41b 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -149,11 +149,11 @@ virDomainEventTrayChangeNewFromDom(virDomainPtr dom,
virObjectEventPtr
virDomainEventPMWakeupNewFromObj(virDomainObjPtr obj);
virObjectEventPtr
-virDomainEventPMWakeupNewFromDom(virDomainPtr dom);
+virDomainEventPMWakeupNewFromDom(virDomainPtr dom, int reason);
virObjectEventPtr
virDomainEventPMSuspendNewFromObj(virDomainObjPtr obj);
virObjectEventPtr
-virDomainEventPMSuspendNewFromDom(virDomainPtr dom);
+virDomainEventPMSuspendNewFromDom(virDomainPtr dom, int reason);
virObjectEventPtr
virDomainEventBalloonChangeNewFromDom(virDomainPtr dom,
@@ -165,7 +165,7 @@ virDomainEventBalloonChangeNewFromObj(virDomainObjPtr obj,
virObjectEventPtr
virDomainEventPMSuspendDiskNewFromObj(virDomainObjPtr obj);
virObjectEventPtr
-virDomainEventPMSuspendDiskNewFromDom(virDomainPtr dom);
+virDomainEventPMSuspendDiskNewFromDom(virDomainPtr dom, int reason);
virObjectEventPtr
virDomainEventDeviceRemovedNewFromObj(virDomainObjPtr obj,
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 4cdce81..955465a 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -5189,7 +5189,8 @@ remoteDomainBuildEventCallbackTrayChange(virNetClientProgramPtr prog
ATTRIBUTE_U
static void
remoteDomainBuildEventPMWakeupHelper(virConnectPtr conn,
remote_domain_event_pmwakeup_msg *msg,
- int callbackID)
+ int callbackID,
+ int reason)
{
struct private_data *priv = conn->privateData;
virDomainPtr dom;
@@ -5199,7 +5200,7 @@ remoteDomainBuildEventPMWakeupHelper(virConnectPtr conn,
if (!dom)
return;
- event = virDomainEventPMWakeupNewFromDom(dom);
+ event = virDomainEventPMWakeupNewFromDom(dom, reason);
virDomainFree(dom);
@@ -5212,7 +5213,7 @@ remoteDomainBuildEventPMWakeup(virNetClientProgramPtr prog
ATTRIBUTE_UNUSED,
{
virConnectPtr conn = opaque;
remote_domain_event_pmwakeup_msg *msg = evdata;
- remoteDomainBuildEventPMWakeupHelper(conn, msg, -1);
+ remoteDomainBuildEventPMWakeupHelper(conn, msg, -1, 0);
}
static void
remoteDomainBuildEventCallbackPMWakeup(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
@@ -5221,13 +5222,15 @@ remoteDomainBuildEventCallbackPMWakeup(virNetClientProgramPtr prog
ATTRIBUTE_UNU
{
virConnectPtr conn = opaque;
remote_domain_event_callback_pmwakeup_msg *msg = evdata;
- remoteDomainBuildEventPMWakeupHelper(conn, &msg->msg, msg->callbackID);
+ remoteDomainBuildEventPMWakeupHelper(conn, &msg->msg, msg->callbackID,
+ msg->reason);
}
static void
remoteDomainBuildEventPMSuspendHelper(virConnectPtr conn,
remote_domain_event_pmsuspend_msg *msg,
- int callbackID)
+ int callbackID,
+ int reason)
{
struct private_data *priv = conn->privateData;
virDomainPtr dom;
@@ -5237,7 +5240,7 @@ remoteDomainBuildEventPMSuspendHelper(virConnectPtr conn,
if (!dom)
return;
- event = virDomainEventPMSuspendNewFromDom(dom);
+ event = virDomainEventPMSuspendNewFromDom(dom, reason);
virDomainFree(dom);
@@ -5250,7 +5253,7 @@ remoteDomainBuildEventPMSuspend(virNetClientProgramPtr prog
ATTRIBUTE_UNUSED,
{
virConnectPtr conn = opaque;
remote_domain_event_pmsuspend_msg *msg = evdata;
- remoteDomainBuildEventPMSuspendHelper(conn, msg, -1);
+ remoteDomainBuildEventPMSuspendHelper(conn, msg, -1, 0);
}
static void
remoteDomainBuildEventCallbackPMSuspend(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
@@ -5259,7 +5262,8 @@ remoteDomainBuildEventCallbackPMSuspend(virNetClientProgramPtr prog
ATTRIBUTE_UN
{
virConnectPtr conn = opaque;
remote_domain_event_callback_pmsuspend_msg *msg = evdata;
- remoteDomainBuildEventPMSuspendHelper(conn, &msg->msg, msg->callbackID);
+ remoteDomainBuildEventPMSuspendHelper(conn, &msg->msg, msg->callbackID,
+ msg->reason);
}
@@ -5304,7 +5308,8 @@ remoteDomainBuildEventCallbackBalloonChange(virNetClientProgramPtr
prog ATTRIBUT
static void
remoteDomainBuildEventPMSuspendDiskHelper(virConnectPtr conn,
remote_domain_event_pmsuspend_disk_msg *msg,
- int callbackID)
+ int callbackID,
+ int reason)
{
struct private_data *priv = conn->privateData;
virDomainPtr dom;
@@ -5314,7 +5319,7 @@ remoteDomainBuildEventPMSuspendDiskHelper(virConnectPtr conn,
if (!dom)
return;
- event = virDomainEventPMSuspendDiskNewFromDom(dom);
+ event = virDomainEventPMSuspendDiskNewFromDom(dom, reason);
virDomainFree(dom);
@@ -5327,7 +5332,7 @@ remoteDomainBuildEventPMSuspendDisk(virNetClientProgramPtr prog
ATTRIBUTE_UNUSED
{
virConnectPtr conn = opaque;
remote_domain_event_pmsuspend_disk_msg *msg = evdata;
- remoteDomainBuildEventPMSuspendDiskHelper(conn, msg, -1);
+ remoteDomainBuildEventPMSuspendDiskHelper(conn, msg, -1, 0);
}
static void
remoteDomainBuildEventCallbackPMSuspendDisk(virNetClientProgramPtr prog
ATTRIBUTE_UNUSED,
@@ -5336,7 +5341,8 @@ remoteDomainBuildEventCallbackPMSuspendDisk(virNetClientProgramPtr
prog ATTRIBUT
{
virConnectPtr conn = opaque;
remote_domain_event_callback_pmsuspend_disk_msg *msg = evdata;
- remoteDomainBuildEventPMSuspendDiskHelper(conn, &msg->msg,
msg->callbackID);
+ remoteDomainBuildEventPMSuspendDiskHelper(conn, &msg->msg,
msg->callbackID,
+ msg->reason);
}
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 8238405..9dc8253 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2378,6 +2378,7 @@ struct remote_domain_event_pmwakeup_msg {
};
struct remote_domain_event_callback_pmwakeup_msg {
int callbackID;
+ int reason;
remote_domain_event_pmwakeup_msg msg;
};
@@ -2386,6 +2387,7 @@ struct remote_domain_event_pmsuspend_msg {
};
struct remote_domain_event_callback_pmsuspend_msg {
int callbackID;
+ int reason;
remote_domain_event_pmsuspend_msg msg;
};
@@ -2403,6 +2405,7 @@ struct remote_domain_event_pmsuspend_disk_msg {
};
struct remote_domain_event_callback_pmsuspend_disk_msg {
int callbackID;
+ int reason;
remote_domain_event_pmsuspend_disk_msg msg;
};
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index fdff787..5636d55 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -1824,6 +1824,7 @@ struct remote_domain_event_pmwakeup_msg {
};
struct remote_domain_event_callback_pmwakeup_msg {
int callbackID;
+ int reason;
remote_domain_event_pmwakeup_msg msg;
};
struct remote_domain_event_pmsuspend_msg {
@@ -1831,6 +1832,7 @@ struct remote_domain_event_pmsuspend_msg {
};
struct remote_domain_event_callback_pmsuspend_msg {
int callbackID;
+ int reason;
remote_domain_event_pmsuspend_msg msg;
};
struct remote_domain_event_balloon_change_msg {
@@ -1846,6 +1848,7 @@ struct remote_domain_event_pmsuspend_disk_msg {
};
struct remote_domain_event_callback_pmsuspend_disk_msg {
int callbackID;
+ int reason;
remote_domain_event_pmsuspend_disk_msg msg;
};
struct remote_domain_managed_save_args {
--
1.8.5.3