[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH v2 6/6] qapi: introduce CONFIG_READ event
From: |
Vladimir Sementsov-Ogievskiy |
Subject: |
[PATCH v2 6/6] qapi: introduce CONFIG_READ event |
Date: |
Fri, 1 Mar 2024 20:11:43 +0300 |
Send a new event when guest reads virtio-pci config after
virtio_notify_config() call.
That's useful to check that guest fetched modified config, for example
after resizing disk backend.
Signed-off-by: Vladimir Sementsov-Ogievskiy <vsementsov@yandex-team.ru>
---
hw/virtio/virtio-pci.c | 9 +++++++++
include/monitor/qdev.h | 2 ++
monitor/monitor.c | 1 +
qapi/qdev.json | 26 ++++++++++++++++++++++++++
stubs/qdev.c | 6 ++++++
system/qdev-monitor.c | 6 ++++++
6 files changed, 50 insertions(+)
diff --git a/hw/virtio/virtio-pci.c b/hw/virtio/virtio-pci.c
index 1197341a3c..fab49a2410 100644
--- a/hw/virtio/virtio-pci.c
+++ b/hw/virtio/virtio-pci.c
@@ -23,6 +23,7 @@
#include "hw/boards.h"
#include "hw/virtio/virtio.h"
#include "migration/qemu-file-types.h"
+#include "monitor/qdev.h"
#include "hw/pci/pci.h"
#include "hw/pci/pci_bus.h"
#include "hw/qdev-properties.h"
@@ -530,6 +531,10 @@ static uint64_t virtio_pci_config_read(void *opaque,
hwaddr addr,
}
addr -= config;
+ if (vdev->generation > 0) {
+ qdev_virtio_config_read_event(DEVICE(proxy));
+ }
+
switch (size) {
case 1:
val = virtio_config_readb(vdev, addr);
@@ -1735,6 +1740,10 @@ static uint64_t virtio_pci_device_read(void *opaque,
hwaddr addr,
return UINT64_MAX;
}
+ if (vdev->generation > 0) {
+ qdev_virtio_config_read_event(DEVICE(proxy));
+ }
+
switch (size) {
case 1:
val = virtio_config_modern_readb(vdev, addr);
diff --git a/include/monitor/qdev.h b/include/monitor/qdev.h
index 1d57bf6577..fc9a834dca 100644
--- a/include/monitor/qdev.h
+++ b/include/monitor/qdev.h
@@ -36,4 +36,6 @@ DeviceState *qdev_device_add_from_qdict(const QDict *opts,
*/
const char *qdev_set_id(DeviceState *dev, char *id, Error **errp);
+void qdev_virtio_config_read_event(DeviceState *dev);
+
#endif
diff --git a/monitor/monitor.c b/monitor/monitor.c
index 01ede1babd..5b06146503 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -316,6 +316,7 @@ static MonitorQAPIEventConf
monitor_qapi_event_conf[QAPI_EVENT__MAX] = {
[QAPI_EVENT_VSERPORT_CHANGE] = { 1000 * SCALE_MS },
[QAPI_EVENT_MEMORY_DEVICE_SIZE_CHANGE] = { 1000 * SCALE_MS },
[QAPI_EVENT_HV_BALLOON_STATUS_REPORT] = { 1000 * SCALE_MS },
+ [QAPI_EVENT_VIRTIO_CONFIG_READ] = { 300 * SCALE_MS },
};
/*
diff --git a/qapi/qdev.json b/qapi/qdev.json
index 6ece164172..ffc5e3be18 100644
--- a/qapi/qdev.json
+++ b/qapi/qdev.json
@@ -179,3 +179,29 @@
{ 'command': 'device-sync-config',
'features': [ 'unstable' ],
'data': {'id': 'str'} }
+
+##
+# @VIRTIO_CONFIG_READ:
+#
+# Emitted whenever guest reads virtio device config after config change.
+#
+# @device: device name
+#
+# @path: device path
+#
+# Features:
+#
+# @unstable: The event is experimental.
+#
+# Since: 9.0
+#
+# Example:
+#
+# <- { "event": "VIRTIO_CONFIG_READ",
+# "data": { "device": "virtio-net-pci-0",
+# "path": "/machine/peripheral/virtio-net-pci-0" },
+# "timestamp": { "seconds": 1265044230, "microseconds": 450486 } }
+##
+{ 'event': 'VIRTIO_CONFIG_READ',
+ 'features': [ 'unstable' ],
+ 'data': { '*device': 'str', 'path': 'str' } }
diff --git a/stubs/qdev.c b/stubs/qdev.c
index 6869f6f90a..ab6c4afe0b 100644
--- a/stubs/qdev.c
+++ b/stubs/qdev.c
@@ -26,3 +26,9 @@ void qapi_event_send_device_unplug_guest_error(const char
*device,
{
/* Nothing to do. */
}
+
+void qapi_event_send_virtio_config_read(const char *device,
+ const char *path)
+{
+ /* Nothing to do. */
+}
diff --git a/system/qdev-monitor.c b/system/qdev-monitor.c
index b83b5d23c9..29b8242a2d 100644
--- a/system/qdev-monitor.c
+++ b/system/qdev-monitor.c
@@ -26,6 +26,7 @@
#include "sysemu/runstate.h"
#include "qapi/error.h"
#include "qapi/qapi-commands-qdev.h"
+#include "qapi/qapi-events-qdev.h"
#include "qapi/qmp/dispatch.h"
#include "qapi/qmp/qdict.h"
#include "qapi/qmp/qerror.h"
@@ -1206,3 +1207,8 @@ bool qmp_command_available(const QmpCommand *cmd, Error
**errp)
}
return true;
}
+
+void qdev_virtio_config_read_event(DeviceState *dev)
+{
+ qapi_event_send_virtio_config_read(dev->id, dev->canonical_path);
+}
--
2.34.1
[PATCH v2 6/6] qapi: introduce CONFIG_READ event,
Vladimir Sementsov-Ogievskiy <=
[PATCH v2 1/6] vhost-user-blk: simplify and fix vhost_user_blk_handle_config_change, Vladimir Sementsov-Ogievskiy, 2024/03/01
[PATCH v2 2/6] qdev-monitor: fix error message in find_device_state(), Vladimir Sementsov-Ogievskiy, 2024/03/01
[PATCH v2 5/6] qapi: device-sync-config: check runstate, Vladimir Sementsov-Ogievskiy, 2024/03/01
[PATCH v2 4/6] qapi: introduce device-sync-config, Vladimir Sementsov-Ogievskiy, 2024/03/01