@@ -116,6 +116,35 @@
##
{ 'command': 'device_del', 'data': {'id': 'str'} }
+##
+# @DeviceAndPath:
+#
+# In events we designate devices by both their ID (if the device has
+# one) and QOM path.
+#
+# @device: the device's ID if it has one
+#
+# @path: the device's QOM path
+#
+# Since: 8.2
+##
+
+# Rationale
+#
+# Why we need ID? User specify ID in device_add command and in
+# command line and expects same identifier in the event data.
+#
+# Why we need QOM path? Some devices don't have ID and we still want
+# to emit events for them.
+#
+# So, we have a bit of redundancy, as QOM path for device that has
+# ID is always /machine/peripheral/ID. But that's hard to change
+# keeping both simple interface for most users and universality for
+# the generic case.
+
+{ 'struct': 'DeviceAndPath',
+ 'data': { '*device': 'str', 'path': 'str' } }
+
##
# @DEVICE_DELETED:
#
@@ -124,10 +153,6 @@
# ID. Device removal can be initiated by the guest or by HMP/QMP
# commands.
#
-# @device: the device's ID if it has one
-#
-# @path: the device's QOM path
-#
# Since: 1.5
#
# Example:
@@ -137,8 +162,7 @@
# "path": "/machine/peripheral/virtio-net-pci-0" },
# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
##
-{ 'event': 'DEVICE_DELETED',
- 'data': { '*device': 'str', 'path': 'str' } }
+{ 'event': 'DEVICE_DELETED', 'data': 'DeviceAndPath' }
##
# @DEVICE_UNPLUG_GUEST_ERROR:
@@ -146,10 +170,6 @@
# Emitted when a device hot unplug fails due to a guest reported
# error.
#
-# @device: the device's ID if it has one
-#
-# @path: the device's QOM path
-#
# Since: 6.2
#
# Example:
@@ -159,5 +179,4 @@
# "path": "/machine/peripheral/core1" },
# "timestamp": { "seconds": 1615570772, "microseconds": 202844 } }
##
-{ 'event': 'DEVICE_UNPLUG_GUEST_ERROR',
- 'data': { '*device': 'str', 'path': 'str' } }
+{ 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': 'DeviceAndPath' }
DEVICE_DELETED and DEVICE_UNPLUG_GUEST_ERROR has equal data, let's refactor it to one structure. That also helps to add new events consistently. Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru> --- qapi/qdev.json | 43 +++++++++++++++++++++++++++++++------------ 1 file changed, 31 insertions(+), 12 deletions(-)