]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: add DEVICE_UNPLUG_GUEST_ERROR event support
authorDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 29 Oct 2021 19:54:26 +0000 (16:54 -0300)
committerDaniel Henrique Barboza <danielhb413@gmail.com>
Fri, 12 Nov 2021 16:44:42 +0000 (13:44 -0300)
The upcoming QEMU 6.2.0 implements a new event called
DEVICE_UNPLUG_GUEST_ERROR, a new event that reports generic device
unplug errors that were detected by the guest and reported back to QEMU.

This new event is going to be specially useful for pseries guests that
uses newer kernels (must have kernel commit 29c9a2699e71), which is the
case for Fedora 34 at this moment. These guests have the capability of
reporting CPU removal errors back to QEMU which, starting in 6.2.0, will
emit the DEVICE_UNPLUG_GUEST_ERROR event. Libvirt can use this event to
abort the device removal immediately instead of waiting for 'setvcpus'
timeout.

QEMU 6.2.0 is also going to emit DEVICE_UNPLUG_GUEST_ERROR for memory
hotunplug errors, both in pseries and ACPI guests. QEMU 6.1.0 reports
memory removal errors using the MEM_UNPLUG_ERROR event, which is going to
be deprecated by DEVICE_UNPLUG_GUEST_ERROR in 6.2.0. Given that
Libvirt wasn't handling the MEM_UNPLUG_ERROR event we don't need to
worry about it - adding support to DEVICE_UNPLUG_GUEST_ERROR will be
enough to cover all future cases.

This patch adds support to DEVICE_UNPLUG_GUEST_ERROR by adding the
minimal wiring required for Libvirt to be aware of it. The monitor
callback for this event will abort the pending removal operation of the
device reported by the "device" property of the event. Most of the heavy
lifting is already done by existing code that handles
QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_GUEST_REJECTED, making our life
easier to abort the pending removal operation.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
src/qemu/qemu_monitor.c
src/qemu/qemu_monitor.h
src/qemu/qemu_monitor_json.c
src/qemu/qemu_process.c

index 9ad8ffa422ac6efa47e15f493b83a4274076ea8c..810dac209d7b0a88fc1fb8ef86a4ee15d730c24a 100644 (file)
@@ -1348,6 +1348,18 @@ qemuMonitorEmitDeviceDeleted(qemuMonitor *mon,
 }
 
 
+void
+qemuMonitorEmitDeviceUnplugErr(qemuMonitor *mon,
+                               const char *devPath,
+                               const char *devAlias)
+{
+    VIR_DEBUG("mon=%p", mon);
+
+    QEMU_MONITOR_CALLBACK(mon, domainDeviceUnplugError, mon->vm,
+                          devPath, devAlias);
+}
+
+
 void
 qemuMonitorEmitNicRxFilterChanged(qemuMonitor *mon,
                                   const char *devAlias)
index cd1c1c429177e82a513cb2f5fba5a227c4d4f4b4..0dd7b1c4e266a70efa8180c530a3b945f1f49269 100644 (file)
@@ -294,6 +294,11 @@ typedef void (*qemuMonitorDomainDeviceDeletedCallback)(qemuMonitor *mon,
                                                        virDomainObj *vm,
                                                        const char *devAlias,
                                                        void *opaque);
+typedef void (*qemuMonitorDomainDeviceUnplugErrCallback)(qemuMonitor *mon,
+                                                         virDomainObj *vm,
+                                                         const char *devPath,
+                                                         const char *devAlias,
+                                                         void *opaque);
 typedef void (*qemuMonitorDomainNicRxFilterChangedCallback)(qemuMonitor *mon,
                                                             virDomainObj *vm,
                                                             const char *devAlias,
@@ -454,6 +459,7 @@ struct _qemuMonitorCallbacks {
     qemuMonitorDomainGuestCrashloadedCallback domainGuestCrashloaded;
     qemuMonitorDomainMemoryFailureCallback domainMemoryFailure;
     qemuMonitorDomainMemoryDeviceSizeChange domainMemoryDeviceSizeChange;
+    qemuMonitorDomainDeviceUnplugErrCallback domainDeviceUnplugError;
 };
 
 qemuMonitor *qemuMonitorOpen(virDomainObj *vm,
@@ -542,6 +548,9 @@ void qemuMonitorEmitGuestPanic(qemuMonitor *mon,
                                qemuMonitorEventPanicInfo *info);
 void qemuMonitorEmitDeviceDeleted(qemuMonitor *mon,
                                   const char *devAlias);
+void qemuMonitorEmitDeviceUnplugErr(qemuMonitor *mon,
+                                    const char *devPath,
+                                    const char *devAlias);
 void qemuMonitorEmitNicRxFilterChanged(qemuMonitor *mon,
                                        const char *devAlias);
 void qemuMonitorEmitSerialChange(qemuMonitor *mon,
index 9186d59ca2e53146a2d2ee2f78b43c209e9c1f98..4669b9135d6d7a9b94b445b27d8a3af3d5df5828 100644 (file)
@@ -113,6 +113,7 @@ static void qemuMonitorJSONHandlePRManagerStatusChanged(qemuMonitor *mon, virJSO
 static void qemuMonitorJSONHandleRdmaGidStatusChanged(qemuMonitor *mon, virJSONValue *data);
 static void qemuMonitorJSONHandleMemoryFailure(qemuMonitor *mon, virJSONValue *data);
 static void qemuMonitorJSONHandleMemoryDeviceSizeChange(qemuMonitor *mon, virJSONValue *data);
+static void qemuMonitorJSONHandleDeviceUnplugErr(qemuMonitor *mon, virJSONValue *data);
 
 typedef struct {
     const char *type;
@@ -129,6 +130,7 @@ static qemuEventHandler eventHandlers[] = {
     { "BLOCK_WRITE_THRESHOLD", qemuMonitorJSONHandleBlockThreshold, },
     { "DEVICE_DELETED", qemuMonitorJSONHandleDeviceDeleted, },
     { "DEVICE_TRAY_MOVED", qemuMonitorJSONHandleTrayChange, },
+    { "DEVICE_UNPLUG_GUEST_ERROR", qemuMonitorJSONHandleDeviceUnplugErr, },
     { "DUMP_COMPLETED", qemuMonitorJSONHandleDumpCompleted, },
     { "GUEST_CRASHLOADED", qemuMonitorJSONHandleGuestCrashloaded, },
     { "GUEST_PANICKED", qemuMonitorJSONHandleGuestPanic, },
@@ -1111,6 +1113,23 @@ qemuMonitorJSONHandleDeviceDeleted(qemuMonitor *mon, virJSONValue *data)
 }
 
 
+static void
+qemuMonitorJSONHandleDeviceUnplugErr(qemuMonitor *mon, virJSONValue *data)
+{
+    const char *device;
+    const char *path;
+
+    if (!(path = virJSONValueObjectGetString(data, "path"))) {
+        VIR_DEBUG("missing path in device unplug guest error event");
+        return;
+    }
+
+    device = virJSONValueObjectGetString(data, "device");
+
+    qemuMonitorEmitDeviceUnplugErr(mon, path, device);
+}
+
+
 static void
 qemuMonitorJSONHandleNicRxFilterChanged(qemuMonitor *mon, virJSONValue *data)
 {
index ec5e6999f556ec0c20e030174a43a12beadf97ca..b6c81dd23a010fe81e99a755801ad860aa83eb0e 100644 (file)
@@ -1322,6 +1322,42 @@ qemuProcessHandleDeviceDeleted(qemuMonitor *mon G_GNUC_UNUSED,
 }
 
 
+static void
+qemuProcessHandleDeviceUnplugErr(qemuMonitor *mon G_GNUC_UNUSED,
+                                 virDomainObj *vm,
+                                 const char *devPath,
+                                 const char *devAlias,
+                                 void *opaque)
+{
+    virQEMUDriver *driver = opaque;
+    virObjectEvent *event = NULL;
+
+    virObjectLock(vm);
+
+    VIR_DEBUG("Device %s QOM path %s failed to be removed from domain %p %s",
+              devAlias, devPath, vm, vm->def->name);
+
+    /*
+     * DEVICE_UNPLUG_GUEST_ERROR will always contain the QOM path
+     * but QEMU will not guarantee that devAlias will be provided.
+     *
+     * However, given that all Libvirt devices have a devAlias, we
+     * can ignore the case where QEMU emitted this event without it.
+     */
+    if (!devAlias)
+        goto cleanup;
+
+    qemuDomainSignalDeviceRemoval(vm, devAlias,
+                                  QEMU_DOMAIN_UNPLUGGING_DEVICE_STATUS_GUEST_REJECTED);
+
+    event = virDomainEventDeviceRemovalFailedNewFromObj(vm, devAlias);
+
+ cleanup:
+    virObjectUnlock(vm);
+    virObjectEventStateQueue(driver->domainEventState, event);
+}
+
+
 /**
  *
  * Meaning of fields reported by the event according to the ACPI standard:
@@ -1891,6 +1927,7 @@ static qemuMonitorCallbacks monitorCallbacks = {
     .domainGuestCrashloaded = qemuProcessHandleGuestCrashloaded,
     .domainMemoryFailure = qemuProcessHandleMemoryFailure,
     .domainMemoryDeviceSizeChange = qemuProcessHandleMemoryDeviceSizeChange,
+    .domainDeviceUnplugError = qemuProcessHandleDeviceUnplugErr,
 };
 
 static void