[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[libvirt] [PATCH 01/11] Add support for event tray moved of removable disks



This patch introduces a new event type for the QMP event
DEVICE_TRAY_MOVED, which occurs when the tray of a removable
disk is moved (i.e opened or closed):

    VIR_DOMAIN_EVENT_ID_TRAY_CHANGE

The event's data includes the device alias and the reason
for tray status' changing, which indicates why the tray
status was changed. Thus the callback definition for the event
is:

enum {
    VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN = 0,
    VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE,

\#ifdef VIR_ENUM_SENTINELS
    VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST
\#endif
} virDomainEventTrayChangeReason;

typedef void
(*virConnectDomainEventTrayChangeCallback)(virConnectPtr conn,
                                           virDomainPtr dom,
                                           const char *devAlias,
                                           int reason,
                                           void *opaque);
---
 daemon/remote.c                                    |   33 +++++++++++
 examples/domain-events/events-c/event-test.c       |   26 +++++++++-
 examples/domain-events/events-python/event-test.py |    4 ++
 include/libvirt/libvirt.h.in                       |   35 ++++++++++++
 python/libvirt-override-virConnect.py              |   10 ++++
 python/libvirt-override.c                          |   50 +++++++++++++++++
 src/conf/domain_event.c                            |   58 ++++++++++++++++++++
 src/conf/domain_event.h                            |    6 ++
 src/libvirt_private.syms                           |    2 +
 src/qemu/qemu_monitor.c                            |   13 +++++
 src/qemu/qemu_monitor.h                            |   10 +++-
 src/qemu/qemu_monitor_json.c                       |   27 +++++++++
 src/qemu/qemu_process.c                            |   32 +++++++++++
 src/remote/remote_driver.c                         |   34 ++++++++++++
 src/remote/remote_protocol.x                       |    9 +++-
 src/remote_protocol-structs                        |    6 ++
 16 files changed, 350 insertions(+), 5 deletions(-)

diff --git a/daemon/remote.c b/daemon/remote.c
index 0dd4f2e..060f77b 100644
--- a/daemon/remote.c
+++ b/daemon/remote.c
@@ -506,6 +506,38 @@ mem_error:
 }
 
 
+static int remoteRelayDomainEventTrayChange(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                            virDomainPtr dom,
+                                            const char *devAlias,
+                                            int reason,
+                                            void *opaque) {
+    virNetServerClientPtr client = opaque;
+    remote_domain_event_tray_change_msg data;
+
+    if (!client)
+        return -1;
+
+    VIR_DEBUG("Relaying domain %s %d tray change devAlias: %s reason: %d",
+              dom->name, dom->id, devAlias, reason);
+
+    /* build return data */
+    memset(&data, 0, sizeof data);
+
+    if (!(data.devAlias = strdup(devAlias))) {
+        virReportOOMError();
+        return -1;
+    }
+    data.reason = reason;
+
+    make_nonnull_domain(&data.dom, dom);
+
+    remoteDispatchDomainEventSend(client, remoteProgram,
+                                  REMOTE_PROC_DOMAIN_EVENT_TRAY_CHANGE,
+                                  (xdrproc_t)xdr_remote_domain_event_tray_change_msg, &data);
+
+    return 0;
+}
+
 static virConnectDomainEventGenericCallback domainEventCallbacks[] = {
     VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventLifecycle),
     VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventReboot),
@@ -517,6 +549,7 @@ static virConnectDomainEventGenericCallback domainEventCallbacks[] = {
     VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventControlError),
     VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventBlockJob),
     VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventDiskChange),
+    VIR_DOMAIN_EVENT_CALLBACK(remoteRelayDomainEventTrayChange),
 };
 
 verify(ARRAY_CARDINALITY(domainEventCallbacks) == VIR_DOMAIN_EVENT_ID_LAST);
diff --git a/examples/domain-events/events-c/event-test.c b/examples/domain-events/events-c/event-test.c
index f4938c4..cca9a1a 100644
--- a/examples/domain-events/events-c/event-test.c
+++ b/examples/domain-events/events-c/event-test.c
@@ -313,6 +313,22 @@ static int myDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
     return 0;
 }
 
+const char *trayChangeReasonStrings[] = {
+    "open",
+    "close",
+};
+
+static int myDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                           virDomainPtr dom,
+                                           const char *devAlias,
+                                           int reason,
+                                           void *opaque ATTRIBUTE_UNUSED)
+{
+    printf("%s EVENT: Domain %s(%d) removable disk's tray change devAlias: %s reason: %s\n",
+           __func__, virDomainGetName(dom), virDomainGetID(dom),
+           devAlias, trayChangeReasonStrings[reason]);
+    return 0;
+}
 
 static void myFreeFunc(void *opaque)
 {
@@ -349,6 +365,7 @@ int main(int argc, char **argv)
     int callback7ret = -1;
     int callback8ret = -1;
     int callback9ret = -1;
+    int callback10ret = -1;
     struct sigaction action_stop;
 
     memset(&action_stop, 0, sizeof action_stop);
@@ -419,6 +436,11 @@ int main(int argc, char **argv)
                                                     VIR_DOMAIN_EVENT_ID_DISK_CHANGE,
                                                     VIR_DOMAIN_EVENT_CALLBACK(myDomainEventDiskChangeCallback),
                                                     strdup("disk change"), myFreeFunc);
+    callback10ret = virConnectDomainEventRegisterAny(dconn,
+                                                     NULL,
+                                                     VIR_DOMAIN_EVENT_ID_TRAY_CHANGE,
+                                                     VIR_DOMAIN_EVENT_CALLBACK(myDomainEventTrayChangeCallback),
+                                                     strdup("tray change"), myFreeFunc);
 
     if ((callback1ret != -1) &&
         (callback2ret != -1) &&
@@ -427,7 +449,8 @@ int main(int argc, char **argv)
         (callback5ret != -1) &&
         (callback6ret != -1) &&
         (callback7ret != -1) &&
-        (callback9ret != -1)) {
+        (callback9ret != -1) &&
+        (callback10ret != -1)) {
         if (virConnectSetKeepAlive(dconn, 5, 3) < 0) {
             virErrorPtr err = virGetLastError();
             fprintf(stderr, "Failed to start keepalive protocol: %s\n",
@@ -452,6 +475,7 @@ int main(int argc, char **argv)
         virConnectDomainEventDeregisterAny(dconn, callback6ret);
         virConnectDomainEventDeregisterAny(dconn, callback7ret);
         virConnectDomainEventDeregisterAny(dconn, callback9ret);
+        virConnectDomainEventDeregisterAny(dconn, callback10ret);
         if (callback8ret != -1)
             virConnectDomainEventDeregisterAny(dconn, callback8ret);
     }
diff --git a/examples/domain-events/events-python/event-test.py b/examples/domain-events/events-python/event-test.py
index 0c75091..6e0409d 100644
--- a/examples/domain-events/events-python/event-test.py
+++ b/examples/domain-events/events-python/event-test.py
@@ -474,6 +474,9 @@ def myDomainEventGraphicsCallback(conn, dom, phase, localAddr, remoteAddr, authS
 def myDomainEventDiskChangeCallback(conn, dom, oldSrcPath, newSrcPath, devAlias, reason, opaque):
     print "myDomainEventDiskChangeCallback: Domain %s(%s) disk change oldSrcPath: %s newSrcPath: %s devAlias: %s reason: %s" % (
             dom.name(), dom.ID(), oldSrcPath, newSrcPath, devAlias, reason)
+def myDomainEventTrayChangeCallback(conn, dom, devAlias, reason, opaque):
+    print "myDomainEventTrayChangeCallback: Domain %s(%s) tray change devAlias: %s reason: %s" % (
+            dom.name(), dom.ID(), devAlias, reason)
 def usage(out=sys.stderr):
     print >>out, "usage: "+os.path.basename(sys.argv[0])+" [-hdl] [uri]"
     print >>out, "   uri will default to qemu:///system"
@@ -532,6 +535,7 @@ def main():
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_WATCHDOG, myDomainEventWatchdogCallback, None)
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_GRAPHICS, myDomainEventGraphicsCallback, None)
     vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_DISK_CHANGE, myDomainEventDiskChangeCallback, None)
+    vc.domainEventRegisterAny(None, libvirt.VIR_DOMAIN_EVENT_ID_TRAY_CHANGE, myDomainEventTrayChangeCallback, None)
 
     vc.setKeepAlive(5, 3)
 
diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in
index 7d41642..7bf1004 100644
--- a/include/libvirt/libvirt.h.in
+++ b/include/libvirt/libvirt.h.in
@@ -3668,6 +3668,40 @@ typedef void (*virConnectDomainEventDiskChangeCallback)(virConnectPtr conn,
                                                        void *opaque);
 
 /**
+ * virConnectDomainEventTrayChangeReason:
+ *
+ * The reason describing why the callback was called
+ */
+enum {
+    VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN = 0,
+    VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE,
+
+#ifdef VIR_ENUM_SENTINELS
+    VIR_DOMAIN_EVENT_TRAY_CHANGE_LAST
+#endif
+} virDomainEventTrayChangeReason;
+
+/**
+ * virConnectDomainEventTrayChangeCallback:
+ * @conn: connection object
+ * @dom: domain on which the event occurred
+ * @devAlias: device alias
+ * @reason: why the tray status was changed?
+ * @opaque: application specified data
+ *
+ * This callback occurs when the tray of a removable device is moved.
+ *
+ * The callback signature to use when registering for an event of type
+ * VIR_DOMAIN_EVENT_ID_TRAY_CHANGE with virConnectDomainEventRegisterAny()
+ */
+typedef void (*virConnectDomainEventTrayChangeCallback)(virConnectPtr conn,
+                                                        virDomainPtr dom,
+                                                        const char *devAlias,
+                                                        int reason,
+                                                        void *opaque);
+
+
+/**
  * VIR_DOMAIN_EVENT_CALLBACK:
  *
  * Used to cast the event specific callback into the generic one
@@ -3687,6 +3721,7 @@ typedef enum {
     VIR_DOMAIN_EVENT_ID_CONTROL_ERROR = 7,   /* virConnectDomainEventGenericCallback */
     VIR_DOMAIN_EVENT_ID_BLOCK_JOB = 8,       /* virConnectDomainEventBlockJobCallback */
     VIR_DOMAIN_EVENT_ID_DISK_CHANGE = 9,     /* virConnectDomainEventDiskChangeCallback */
+    VIR_DOMAIN_EVENT_ID_TRAY_CHANGE = 10,    /* virConnectDomainEventTrayChangeCallback */
 
 #ifdef VIR_ENUM_SENTINELS
     /*
diff --git a/python/libvirt-override-virConnect.py b/python/libvirt-override-virConnect.py
index b908b32..82c2437 100644
--- a/python/libvirt-override-virConnect.py
+++ b/python/libvirt-override-virConnect.py
@@ -134,6 +134,16 @@
         cb(self, virDomain(self, _obj=dom), oldSrcPath, newSrcPath, devAlias, reason, opaque)
         return 0;
 
+    def _dispatchDomainEventTrayChangeCallback(self, dom, devAlias, reason, cbData):
+        """Dispatches event to python user domain trayChange event callbacks
+        """
+        cb = cbData["cb"]
+        opaque = cbData["opaque"]
+
+        cb(self, virDomain(self, _obj=dom), devAlias, reason, opaque)
+        return 0;
+
+
     def domainEventDeregisterAny(self, callbackID):
         """Removes a Domain Event Callback. De-registering for a
            domain callback will disable delivery of this event type """
diff --git a/python/libvirt-override.c b/python/libvirt-override.c
index 792cfa3..915ebd2 100644
--- a/python/libvirt-override.c
+++ b/python/libvirt-override.c
@@ -4927,6 +4927,53 @@ libvirt_virConnectDomainEventDiskChangeCallback(virConnectPtr conn ATTRIBUTE_UNU
     return ret;
 }
 
+static int
+libvirt_virConnectDomainEventTrayChangeCallback(virConnectPtr conn ATTRIBUTE_UNUSED,
+                                                virDomainPtr dom,
+                                                const char *devAlias,
+                                                int reason,
+                                                void *opaque)
+{
+    PyObject *pyobj_cbData = (PyObject*)opaque;
+    PyObject *pyobj_dom;
+    PyObject *pyobj_ret;
+    PyObject *pyobj_conn;
+    PyObject *dictKey;
+    int ret = -1;
+
+    LIBVIRT_ENSURE_THREAD_STATE;
+    /* Create a python instance of this virDomainPtr */
+    virDomainRef(dom);
+
+    pyobj_dom = libvirt_virDomainPtrWrap(dom);
+    Py_INCREF(pyobj_cbData);
+
+    dictKey = libvirt_constcharPtrWrap("conn");
+    pyobj_conn = PyDict_GetItem(pyobj_cbData, dictKey);
+    Py_DECREF(dictKey);
+
+    /* Call the Callback Dispatcher */
+    pyobj_ret = PyObject_CallMethod(pyobj_conn,
+                                    (char*)"_dispatchDomainEventTrayChangeCallback",
+                                    (char*)"OsiO",
+                                    pyobj_dom,
+                                    devAlias, reason, pyobj_cbData);
+
+    Py_DECREF(pyobj_cbData);
+    Py_DECREF(pyobj_dom);
+
+    if(!pyobj_ret) {
+        DEBUG("%s - ret:%p\n", __FUNCTION__, pyobj_ret);
+        PyErr_Print();
+    } else {
+        Py_DECREF(pyobj_ret);
+        ret = 0;
+    }
+
+    LIBVIRT_RELEASE_THREAD_STATE;
+    return ret;
+}
+
 static PyObject *
 libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self,
                                          PyObject * args)
@@ -4987,6 +5034,9 @@ libvirt_virConnectDomainEventRegisterAny(ATTRIBUTE_UNUSED PyObject * self,
     case VIR_DOMAIN_EVENT_ID_DISK_CHANGE:
         cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventDiskChangeCallback);
         break;
+    case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
+        cb = VIR_DOMAIN_EVENT_CALLBACK(libvirt_virConnectDomainEventTrayChangeCallback);
+        break;
     }
 
     if (!cb) {
diff --git a/src/conf/domain_event.c b/src/conf/domain_event.c
index 1d8b45d..9c2a052 100644
--- a/src/conf/domain_event.c
+++ b/src/conf/domain_event.c
@@ -117,6 +117,10 @@ struct _virDomainEvent {
             char *devAlias;
             int reason;
         } diskChange;
+        struct {
+            char *devAlias;
+            int reason;
+        } trayChange;
     } data;
 };
 
@@ -546,6 +550,9 @@ void virDomainEventFree(virDomainEventPtr event)
         VIR_FREE(event->data.diskChange.newSrcPath);
         VIR_FREE(event->data.diskChange.devAlias);
         break;
+    case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
+        VIR_FREE(event->data.trayChange.devAlias);
+        break;
     }
 
     VIR_FREE(event->dom.name);
@@ -1043,6 +1050,50 @@ virDomainEventPtr virDomainEventDiskChangeNewFromDom(virDomainPtr dom,
                                        devAlias, reason);
 }
 
+static virDomainEventPtr
+virDomainEventTrayChangeNew(int id, const char *name,
+                            unsigned char *uuid,
+                            const char *devAlias,
+                            int reason)
+{
+    virDomainEventPtr ev =
+        virDomainEventNewInternal(VIR_DOMAIN_EVENT_ID_TRAY_CHANGE,
+                                  id, name, uuid);
+
+    if (ev) {
+        if (!(ev->data.trayChange.devAlias = strdup(devAlias)))
+            goto error;
+
+        ev->data.trayChange.reason = reason;
+    }
+
+    return ev;
+
+error:
+    virReportOOMError();
+    virDomainEventFree(ev);
+    return NULL;
+}
+
+virDomainEventPtr virDomainEventTrayChangeNewFromObj(virDomainObjPtr obj,
+                                                     const char *devAlias,
+                                                     int reason)
+{
+    return virDomainEventTrayChangeNew(obj->def->id,
+                                       obj->def->name,
+                                       obj->def->uuid,
+                                       devAlias,
+                                       reason);
+}
+
+virDomainEventPtr virDomainEventTrayChangeNewFromDom(virDomainPtr dom,
+                                                     const char *devAlias,
+                                                     int reason)
+{
+    return virDomainEventTrayChangeNew(dom->id, dom->name, dom->uuid,
+                                       devAlias, reason);
+}
+
 
 /**
  * virDomainEventQueuePush:
@@ -1167,6 +1218,13 @@ virDomainEventDispatchDefaultFunc(virConnectPtr conn,
                                                       cbopaque);
         break;
 
+    case VIR_DOMAIN_EVENT_ID_TRAY_CHANGE:
+        ((virConnectDomainEventTrayChangeCallback)cb)(conn, dom,
+                                                      event->data.trayChange.devAlias,
+                                                      event->data.trayChange.reason,
+                                                      cbopaque);
+        break;
+
     default:
         VIR_WARN("Unexpected event ID %d", event->eventID);
         break;
diff --git a/src/conf/domain_event.h b/src/conf/domain_event.h
index 0e7cd75..e5010a3 100644
--- a/src/conf/domain_event.h
+++ b/src/conf/domain_event.h
@@ -114,6 +114,12 @@ virDomainEventPtr virDomainEventDiskChangeNewFromDom(virDomainPtr dom,
                                                      const char *newSrcPath,
                                                      const char *devAlias,
                                                      int reason);
+virDomainEventPtr virDomainEventTrayChangeNewFromObj(virDomainObjPtr obj,
+                                                     const char *devAlias,
+                                                     int reason);
+virDomainEventPtr virDomainEventTrayChangeNewFromDom(virDomainPtr dom,
+                                                     const char *devAlias,
+                                                     int reason);
 
 void virDomainEventFree(virDomainEventPtr event);
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 1f55f5d..e247472 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -525,6 +525,8 @@ virDomainEventStateRegisterID;
 virDomainEventStateFree;
 virDomainEventStateNew;
 virDomainEventStateQueue;
+virDomainEventTrayChangeNewFromDom;
+virDomainEventTrayChangeNewFromObj;
 virDomainEventWatchdogNewFromDom;
 virDomainEventWatchdogNewFromObj;
 
diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c
index 78eb492..90b8e12 100644
--- a/src/qemu/qemu_monitor.c
+++ b/src/qemu/qemu_monitor.c
@@ -1040,6 +1040,19 @@ int qemuMonitorEmitGraphics(qemuMonitorPtr mon,
     return ret;
 }
 
+int qemuMonitorEmitTrayChange(qemuMonitorPtr mon,
+                              const char *devAlias,
+                              int reason)
+{
+    int ret = -1;
+    VIR_DEBUG("mon=%p", mon);
+
+    QEMU_MONITOR_CALLBACK(mon, ret, domainTrayChange, mon->vm,
+                          devAlias, reason);
+
+    return ret;
+}
+
 int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
                             const char *diskAlias,
                             int type,
diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h
index 654d9bd..b5a0c30 100644
--- a/src/qemu/qemu_monitor.h
+++ b/src/qemu/qemu_monitor.h
@@ -124,9 +124,12 @@ struct _qemuMonitorCallbacks {
                           const char *diskAlias,
                           int type,
                           int status);
+    int (*domainTrayChange)(qemuMonitorPtr mon,
+                            virDomainObjPtr vm,
+                            const char *devAlias,
+                            int reason);
 };
 
-
 char *qemuMonitorEscapeArg(const char *in);
 char *qemuMonitorUnescapeArg(const char *in);
 
@@ -191,13 +194,14 @@ int qemuMonitorEmitGraphics(qemuMonitorPtr mon,
                             const char *authScheme,
                             const char *x509dname,
                             const char *saslUsername);
+int qemuMonitorEmitTrayChange(qemuMonitorPtr mon,
+                              const char *devAlias,
+                              int reason);
 int qemuMonitorEmitBlockJob(qemuMonitorPtr mon,
                             const char *diskAlias,
                             int type,
                             int status);
 
-
-
 int qemuMonitorStartCPUs(qemuMonitorPtr mon,
                          virConnectPtr conn);
 int qemuMonitorStopCPUs(qemuMonitorPtr mon);
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index 1a0ee94..0312ca7 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -59,6 +59,7 @@ static void qemuMonitorJSONHandleVNCConnect(qemuMonitorPtr mon, virJSONValuePtr
 static void qemuMonitorJSONHandleVNCInitialize(qemuMonitorPtr mon, virJSONValuePtr data);
 static void qemuMonitorJSONHandleVNCDisconnect(qemuMonitorPtr mon, virJSONValuePtr data);
 static void qemuMonitorJSONHandleBlockJob(qemuMonitorPtr mon, virJSONValuePtr data);
+static void qemuMonitorJSONHandleTrayChange(qemuMonitorPtr mon, virJSONValuePtr data);
 
 static struct {
     const char *type;
@@ -75,6 +76,7 @@ static struct {
     { "VNC_INITIALIZED", qemuMonitorJSONHandleVNCInitialize, },
     { "VNC_DISCONNECTED", qemuMonitorJSONHandleVNCDisconnect, },
     { "BLOCK_JOB_COMPLETED", qemuMonitorJSONHandleBlockJob, },
+    { "DEVICE_TRAY_MOVED", qemuMonitorJSONHandleTrayChange, },
 };
 
 
@@ -725,6 +727,31 @@ out:
     qemuMonitorEmitBlockJob(mon, device, type, status);
 }
 
+static void
+qemuMonitorJSONHandleTrayChange(qemuMonitorPtr mon,
+                                virJSONValuePtr data)
+{
+    const char *devAlias = NULL;
+    bool trayOpened;
+    int reason;
+
+    if ((devAlias = virJSONValueObjectGetString(data, "device")) == NULL) {
+        VIR_WARN("missing device in tray change event");
+        return;
+    }
+
+    if (virJSONValueObjectGetBoolean(data, "tray-open", &trayOpened) < 0) {
+        VIR_WARN("missing tray-open in tray change event");
+        return;
+    }
+
+    if (trayOpened)
+        reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_OPEN;
+    else
+        reason = VIR_DOMAIN_EVENT_TRAY_CHANGE_CLOSE;
+
+    qemuMonitorEmitTrayChange(mon, devAlias, reason);
+}
 
 int
 qemuMonitorJSONHumanCommandWithFd(qemuMonitorPtr mon,
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index ef311d1..b6e14ad 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -1021,6 +1021,37 @@ static void qemuProcessHandleMonitorDestroy(qemuMonitorPtr mon,
         virDomainObjUnlock(vm);
 }
 
+static int
+qemuProcessHandleTrayChange(qemuMonitorPtr mon ATTRIBUTE_UNUSED,
+                            virDomainObjPtr vm,
+                            const char *devAlias,
+                            int reason)
+{
+    struct qemud_driver *driver = qemu_driver;
+    virDomainEventPtr event = NULL;
+    virDomainDiskDefPtr disk;
+
+    virDomainObjLock(vm);
+    disk = qemuProcessFindDomainDiskByAlias(vm, devAlias);
+
+    if (disk) {
+        event = virDomainEventTrayChangeNewFromObj(vm,
+                                                   devAlias,
+                                                   reason);
+    }
+
+    virDomainObjUnlock(vm);
+
+    if (event) {
+        qemuDriverLock(driver);
+        qemuDomainEventQueue(driver, event);
+        qemuDriverUnlock(driver);
+    }
+
+    return 0;
+}
+
+
 static qemuMonitorCallbacks monitorCallbacks = {
     .destroy = qemuProcessHandleMonitorDestroy,
     .eofNotify = qemuProcessHandleMonitorEOF,
@@ -1034,6 +1065,7 @@ static qemuMonitorCallbacks monitorCallbacks = {
     .domainIOError = qemuProcessHandleIOError,
     .domainGraphics = qemuProcessHandleGraphics,
     .domainBlockJob = qemuProcessHandleBlockJob,
+    .domainTrayChange = qemuProcessHandleTrayChange,
 };
 
 static int
diff --git a/src/remote/remote_driver.c b/src/remote/remote_driver.c
index 031167a..ac95dcc 100644
--- a/src/remote/remote_driver.c
+++ b/src/remote/remote_driver.c
@@ -238,6 +238,11 @@ remoteDomainBuildEventDiskChange(virNetClientProgramPtr prog,
                                  virNetClientPtr client,
                                  void *evdata, void *opaque);
 
+static void
+remoteDomainBuildEventTrayChange(virNetClientProgramPtr prog,
+                                 virNetClientPtr client,
+                                 void *evdata, void *opaque);
+
 static virNetClientProgramEvent remoteDomainEvents[] = {
     { REMOTE_PROC_DOMAIN_EVENT_RTC_CHANGE,
       remoteDomainBuildEventRTCChange,
@@ -279,6 +284,10 @@ static virNetClientProgramEvent remoteDomainEvents[] = {
       remoteDomainBuildEventDiskChange,
       sizeof(remote_domain_event_disk_change_msg),
       (xdrproc_t)xdr_remote_domain_event_disk_change_msg },
+    { REMOTE_PROC_DOMAIN_EVENT_TRAY_CHANGE,
+      remoteDomainBuildEventTrayChange,
+      sizeof(remote_domain_event_tray_change_msg),
+      (xdrproc_t)xdr_remote_domain_event_tray_change_msg },
 };
 
 enum virDrvOpenRemoteFlags {
@@ -3645,6 +3654,31 @@ remoteDomainBuildEventDiskChange(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
 }
 
 
+static void
+remoteDomainBuildEventTrayChange(virNetClientProgramPtr prog ATTRIBUTE_UNUSED,
+                                 virNetClientPtr client ATTRIBUTE_UNUSED,
+                                 void *evdata, void *opaque)
+{
+    virConnectPtr conn = opaque;
+    struct private_data *priv = conn->privateData;
+    remote_domain_event_tray_change_msg *msg = evdata;
+    virDomainPtr dom;
+    virDomainEventPtr event = NULL;
+
+    dom = get_nonnull_domain(conn, msg->dom);
+    if (!dom)
+        return;
+
+    event = virDomainEventTrayChangeNewFromDom(dom,
+                                               msg->devAlias,
+                                               msg->reason);
+
+    virDomainFree(dom);
+
+    remoteDomainEventQueue(priv, event);
+}
+
+
 static virDrvOpenStatus ATTRIBUTE_NONNULL (1)
 remoteSecretOpen(virConnectPtr conn, virConnectAuthPtr auth,
                  unsigned int flags)
diff --git a/src/remote/remote_protocol.x b/src/remote/remote_protocol.x
index 4d845e7..6c8c497 100644
--- a/src/remote/remote_protocol.x
+++ b/src/remote/remote_protocol.x
@@ -2178,6 +2178,12 @@ struct remote_domain_event_disk_change_msg {
     int reason;
 };
 
+struct remote_domain_event_tray_change_msg {
+    remote_nonnull_domain dom;
+    remote_nonnull_string devAlias;
+    int reason;
+};
+
 struct remote_domain_managed_save_args {
     remote_nonnull_domain dom;
     unsigned int flags;
@@ -2765,7 +2771,8 @@ enum remote_procedure {
     REMOTE_PROC_DOMAIN_SET_METADATA = 264, /* autogen autogen */
     REMOTE_PROC_DOMAIN_GET_METADATA = 265, /* autogen autogen */
     REMOTE_PROC_DOMAIN_BLOCK_REBASE = 266, /* autogen autogen */
-    REMOTE_PROC_DOMAIN_PM_WAKEUP = 267 /* autogen autogen */
+    REMOTE_PROC_DOMAIN_PM_WAKEUP = 267, /* autogen autogen */
+    REMOTE_PROC_DOMAIN_EVENT_TRAY_CHANGE = 268 /* autogen autogen */
 
     /*
      * Notice how the entries are grouped in sets of 10 ?
diff --git a/src/remote_protocol-structs b/src/remote_protocol-structs
index 8f882b7..0ce7c1c 100644
--- a/src/remote_protocol-structs
+++ b/src/remote_protocol-structs
@@ -1650,6 +1650,11 @@ struct remote_domain_event_disk_change_msg {
         remote_nonnull_string      devAlias;
         int                        reason;
 };
+struct remote_domain_event_tray_change_msg {
+        remote_nonnull_domain      dom;
+        remote_nonnull_string      devAlias;
+        int                        reason;
+}
 struct remote_domain_managed_save_args {
         remote_nonnull_domain      dom;
         u_int                      flags;
@@ -2178,4 +2183,5 @@ enum remote_procedure {
         REMOTE_PROC_DOMAIN_GET_METADATA = 265,
         REMOTE_PROC_DOMAIN_BLOCK_REBASE = 266,
         REMOTE_PROC_DOMAIN_PM_WAKEUP = 267,
+        REMOTE_PROC_DOMAIN_TRAY_CHANGE = 268,
 };
-- 
1.7.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]