The newly added DEVICE_NOT_DELETED QAPI event is adequate to be
sent when the hotunplug timeout expires, letting users know that
something happened inside the guest and the pseries machine didn't
delete the device from QOM.

After this patch, if an user try to hotunplug the last online CPU of
the guest, the "DEIVCE_NOT_DELETED" event will be issued when the
hotunplug timeout for 'core1' is expired:

{"execute": "device_del", "arguments": {"id": "core1"} }
{"return": {}}

{"execute": "device_del", "arguments": {"id": "core1"} }
{"error": {"class": "GenericError",
           "desc": "core-id 1 unplug is still pending, 12 seconds timeout 
remaining"}}

{"execute": "device_del", "arguments": {"id": "core1"} }
{"error": {"class": "GenericError",
           "desc": "core-id 1 unplug is still pending, 5 seconds timeout 
remaining"}}

{"timestamp": {"seconds": 1615570254, "microseconds": 573986},
  "event": "DEVICE_NOT_DELETED",
  "data": {"device": "core1", "path": "/machine/peripheral/core1"}}

Signed-off-by: Daniel Henrique Barboza <danielhb...@gmail.com>
---
 hw/ppc/spapr_drc.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/hw/ppc/spapr_drc.c b/hw/ppc/spapr_drc.c
index 8a71b03800..14f39cec71 100644
--- a/hw/ppc/spapr_drc.c
+++ b/hw/ppc/spapr_drc.c
@@ -13,6 +13,7 @@
 #include "qemu/osdep.h"
 #include "qapi/error.h"
 #include "qapi/qmp/qnull.h"
+#include "qapi/qapi-events-qdev.h"
 #include "cpu.h"
 #include "qemu/cutils.h"
 #include "hw/ppc/spapr_drc.h"
@@ -529,9 +530,16 @@ static const VMStateDescription vmstate_spapr_drc = {
 static void drc_unplug_timeout_cb(void *opaque)
 {
     SpaprDrc *drc = opaque;
+    DeviceState *dev = drc->dev;
 
     if (drc->unplug_requested) {
         drc->unplug_requested = false;
+
+        if (dev) {
+            qapi_event_send_device_not_deleted(!!dev->id,
+                                               dev->id,
+                                               dev->canonical_path);
+        }
     }
 }
 
-- 
2.29.2


Reply via email to