This event represents device runtime errors to give time and reason why device is broken.
Signed-off-by: Konstantin Khlebnikov <khlebni...@yandex-team.ru> --- hw/core/qdev.c | 7 +++++++ include/hw/qdev-core.h | 1 + qapi/qdev.json | 26 ++++++++++++++++++++++++++ 3 files changed, 34 insertions(+) diff --git a/hw/core/qdev.c b/hw/core/qdev.c index 84f3019440..e95ceb071b 100644 --- a/hw/core/qdev.c +++ b/hw/core/qdev.c @@ -347,6 +347,13 @@ void qdev_unrealize(DeviceState *dev) object_property_set_bool(OBJECT(dev), "realized", false, &error_abort); } +void qdev_report_runtime_error(DeviceState *dev, const Error *err) +{ + qapi_event_send_device_runtime_error(!!dev->id, dev->id, + dev->canonical_path, + error_get_pretty(err)); +} + static int qdev_assert_realized_properly_cb(Object *obj, void *opaque) { DeviceState *dev = DEVICE(object_dynamic_cast(obj, TYPE_DEVICE)); diff --git a/include/hw/qdev-core.h b/include/hw/qdev-core.h index 92c3d65208..9ced2e0f09 100644 --- a/include/hw/qdev-core.h +++ b/include/hw/qdev-core.h @@ -396,6 +396,7 @@ bool qdev_realize_and_unref(DeviceState *dev, BusState *bus, Error **errp); * the life of the simulation and should not be unrealized and freed. */ void qdev_unrealize(DeviceState *dev); +void qdev_report_runtime_error(DeviceState *dev, const Error *err); void qdev_set_legacy_instance_id(DeviceState *dev, int alias_id, int required_for_version); HotplugHandler *qdev_get_bus_hotplug_handler(DeviceState *dev); diff --git a/qapi/qdev.json b/qapi/qdev.json index 26cd10106b..89ef32eef7 100644 --- a/qapi/qdev.json +++ b/qapi/qdev.json @@ -159,3 +159,29 @@ ## { 'event': 'DEVICE_UNPLUG_GUEST_ERROR', 'data': { '*device': 'str', 'path': 'str' } } + +## +# @DEVICE_RUNTIME_ERROR: +# +# Emitted when a device fails in runtime. +# +# @device: the device's ID if it has one +# +# @path: the device's QOM path +# +# @reason: human readable description +# +# Since: 7.1 +# +# Example: +# +# <- { "event": "DEVICE_RUNTIME_ERROR" +# "data": { "device": "virtio-net-pci-0", +# "path": "/machine/peripheral/virtio-net-pci-0", +# "reason": "virtio-net header incorrect" }, +# }, +# "timestamp": { "seconds": 1615570772, "microseconds": 202844 } } +# +## +{ 'event': 'DEVICE_RUNTIME_ERROR', + 'data': { '*device': 'str', 'path': 'str', 'reason': 'str' } }