qmp: add path to device_deleted event

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>
This commit is contained in:
Michael S. Tsirkin 2013-03-11 15:11:04 +02:00
parent e998fa8df8
commit 15054fce2d
2 changed files with 8 additions and 3 deletions

View file

@ -147,9 +147,11 @@ Device removal can be initiated by the guest or by HMP/QMP commands.
Data: Data:
- "device": device name (json-string, optional) - "device": device name (json-string, optional)
- "path": device path (json-string)
{ "event": "DEVICE_DELETED", { "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 } } "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
DEVICE_TRAY_MOVED DEVICE_TRAY_MOVED

View file

@ -764,6 +764,7 @@ static void device_unparent(Object *obj)
DeviceClass *dc = DEVICE_GET_CLASS(dev); DeviceClass *dc = DEVICE_GET_CLASS(dev);
BusState *bus; BusState *bus;
QObject *event_data; QObject *event_data;
gchar *path = object_get_canonical_path(obj);
while (dev->num_child_bus) { while (dev->num_child_bus) {
bus = QLIST_FIRST(&dev->child_bus); bus = QLIST_FIRST(&dev->child_bus);
@ -784,12 +785,14 @@ static void device_unparent(Object *obj)
} }
if (dev->id) { 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 { } else {
event_data = qobject_from_jsonf("{ }"); event_data = qobject_from_jsonf("{ 'path': %s }", path);
} }
monitor_protocol_event(QEVENT_DEVICE_DELETED, event_data); monitor_protocol_event(QEVENT_DEVICE_DELETED, event_data);
qobject_decref(event_data); qobject_decref(event_data);
g_free(path);
} }
static void device_class_init(ObjectClass *class, void *data) static void device_class_init(ObjectClass *class, void *data)