Patchwork [PATCHv5,3/3] qmp: add path to device_deleted event

login
register
mail settings
Submitter Michael S. Tsirkin
Date March 11, 2013, 6:06 p.m.
Message ID <7280a9f7817eff8410fcac56b3ef7d690d96fb5a.1363025039.git.mst@redhat.com>
Download mbox | patch
Permalink /patch/226631/
State New
Headers show

Comments

Michael S. Tsirkin - March 11, 2013, 6:06 p.m.
Add QOM path to device deleted event.  It now becomes useful to report
it for devices which don't have an ID assigned.

Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
 QMP/qmp-events.txt |  9 +++++----
 hw/qdev.c          | 11 ++++++++---
 2 files changed, 13 insertions(+), 7 deletions(-)

Patch

diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
index 0ab5017..dcc826d 100644
--- a/QMP/qmp-events.txt
+++ b/QMP/qmp-events.txt
@@ -140,17 +140,18 @@  DEVICE_DELETED
 -----------------
 
 Emitted whenever the device removal completion is acknowledged
-by the guest. This event is only emitted for devices with
-a user-specified ID.
+by the guest.
 At this point, it's safe to reuse the specified device ID.
 Device removal can be initiated by the guest or by HMP/QMP commands.
 
 Data:
 
-- "device": device name (json-string)
+- "device": device name (json-string, optional)
+- "path": device path (json-string)
 
 { "event": "DEVICE_DELETED",
-  "data": { "device": "virtio-net-pci-0" },
+  "data": { "device": "virtio-net-pci-0",
+            "path": "/machine/peripheral/virtio-net-pci-0" },
   "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
 
 DEVICE_TRAY_MOVED
diff --git a/hw/qdev.c b/hw/qdev.c
index 8ee8a97..2c861c1 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -761,6 +761,7 @@  static void device_unparent(Object *obj, const char *path)
     DeviceState *dev = DEVICE(obj);
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
     BusState *bus;
+    QObject *event_data;
 
     while (dev->num_child_bus) {
         bus = QLIST_FIRST(&dev->child_bus);
@@ -779,11 +780,15 @@  static void device_unparent(Object *obj, const char *path)
         object_unref(OBJECT(dev->parent_bus));
         dev->parent_bus = NULL;
     }
+
     if (dev->id) {
-        QObject *data = qobject_from_jsonf("{ 'device': %s }", dev->id);
-        monitor_protocol_event(QEVENT_DEVICE_DELETED, data);
-        qobject_decref(data);
+        event_data = qobject_from_jsonf("{ 'device': %s, 'path': %s }",
+                                        dev->id, path);
+    } else {
+        event_data = qobject_from_jsonf("{ 'path': %s }", path);
     }
+    monitor_protocol_event(QEVENT_DEVICE_DELETED, event_data);
+    qobject_decref(event_data);
 }
 
 static void device_class_init(ObjectClass *class, void *data)