qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1] monitor: Consider "id" when rate-limiting MEMORY_DEVICE_SIZE_CHANGE qapi events
@ 2021-09-21 10:24 David Hildenbrand
  2021-09-22 12:11 ` Markus Armbruster
  0 siblings, 1 reply; 4+ messages in thread
From: David Hildenbrand @ 2021-09-21 10:24 UTC (permalink / raw)
  To: qemu-devel
  Cc: Michael S . Tsirkin, Michal Privoznik, David Hildenbrand,
	Markus Armbruster, Dr. David Alan Gilbert, Igor Mammedov,
	Eric Blake

We have to consider the device id, otherwise we'll lose some events for
unrelated devices. If the device does not have a device id (very unlikely),
the target of the notifications has to update the size of all devices
manually either way.

This was noticed by starting a VM with two virtio-mem devices that each
have a requested size > 0. The Linux guest will initialize both devices
in parallel, resulting in losing MEMORY_DEVICE_SIZE_CHANGE events for
one of the devices.

Fixes: 722a3c783ef4 ("virtio-pci: Send qapi events when the virtio-mem size changes")
Cc: "Dr. David Alan Gilbert" <dgilbert@redhat.com> (maintainer:Human Monitor (HMP))
Cc: Markus Armbruster <armbru@redhat.com> (supporter:QMP)
Cc: Michael S. Tsirkin <mst@redhat.com>
Cc: Eric Blake <eblake@redhat.com>
Cc: Igor Mammedov <imammedo@redhat.com>
Cc: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: David Hildenbrand <david@redhat.com>
---
 monitor/monitor.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/monitor/monitor.c b/monitor/monitor.c
index 46a171bca6..05c0b32b67 100644
--- a/monitor/monitor.c
+++ b/monitor/monitor.c
@@ -474,6 +474,11 @@ static unsigned int qapi_event_throttle_hash(const void *key)
         hash += g_str_hash(qdict_get_str(evstate->data, "node-name"));
     }
 
+    if (evstate->event == QAPI_EVENT_MEMORY_DEVICE_SIZE_CHANGE &&
+        qdict_get(evstate->data, "id")) {
+        hash += g_str_hash(qdict_get_str(evstate->data, "id"));
+    }
+
     return hash;
 }
 
@@ -496,6 +501,20 @@ static gboolean qapi_event_throttle_equal(const void *a, const void *b)
                        qdict_get_str(evb->data, "node-name"));
     }
 
+    if (eva->event == QAPI_EVENT_MEMORY_DEVICE_SIZE_CHANGE) {
+        const bool id_a = qdict_get(eva->data, "id");
+        const bool id_b = qdict_get(evb->data, "id");
+
+        if (!id_a && !id_b) {
+            return TRUE;
+        } else if (id_a ^ id_b) {
+            return FALSE;
+        }
+
+        return !strcmp(qdict_get_str(eva->data, "id"),
+                       qdict_get_str(evb->data, "id"));
+    }
+
     return TRUE;
 }
 
-- 
2.31.1



^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-09-22 12:49 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-09-21 10:24 [PATCH v1] monitor: Consider "id" when rate-limiting MEMORY_DEVICE_SIZE_CHANGE qapi events David Hildenbrand
2021-09-22 12:11 ` Markus Armbruster
2021-09-22 12:20   ` David Hildenbrand
2021-09-22 12:45     ` David Hildenbrand

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).