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

login
register
mail settings
Submitter Michael S. Tsirkin
Date March 21, 2013, 12:07 p.m.
Message ID <e78f366bf92dbeced4321a49b6af716381c6022c.1363633627.git.mst@redhat.com>
Download mbox | patch
Permalink /patch/229639/
State New
Headers show

Comments

Michael S. Tsirkin - March 21, 2013, 12:07 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 | 4 +++-
 hw/qdev.c          | 7 +++++--
 2 files changed, 8 insertions(+), 3 deletions(-)
Markus Armbruster - March 21, 2013, 12:23 p.m.
"Michael S. Tsirkin" <mst@redhat.com> writes:

> 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>

Acked-by: Markus Armbruster <armbru@redhat.com>

Patch

diff --git a/QMP/qmp-events.txt b/QMP/qmp-events.txt
index 24cf3e8..dcc826d 100644
--- a/QMP/qmp-events.txt
+++ b/QMP/qmp-events.txt
@@ -147,9 +147,11 @@  Device removal can be initiated by the guest or by HMP/QMP commands.
 Data:
 
 - "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 5e8a89c..0cdf568 100644
--- a/hw/qdev.c
+++ b/hw/qdev.c
@@ -764,6 +764,7 @@  static void device_unparent(Object *obj)
     DeviceClass *dc = DEVICE_GET_CLASS(dev);
     BusState *bus;
     QObject *event_data;
+    gchar *path = object_get_canonical_path(obj);
 
     while (dev->num_child_bus) {
         bus = QLIST_FIRST(&dev->child_bus);
@@ -784,12 +785,14 @@  static void device_unparent(Object *obj)
     }
 
     if (dev->id) {
-        event_data = qobject_from_jsonf("{ 'device': %s }", dev->id);
+        event_data = qobject_from_jsonf("{ 'device': %s, 'path': %s }",
+                                        dev->id, path);
     } else {
-        event_data = qobject_from_jsonf("{ }");
+        event_data = qobject_from_jsonf("{ 'path': %s }", path);
     }
     monitor_protocol_event(QEVENT_DEVICE_DELETED, event_data);
     qobject_decref(event_data);
+    g_free(path);
 }
 
 static void device_class_init(ObjectClass *class, void *data)