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. Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx> --- src/qemu/qemu_monitor.c | 12 ++++++++++++ src/qemu/qemu_monitor.h | 9 +++++++++ src/qemu/qemu_monitor_json.c | 19 ++++++++++++++++++ src/qemu/qemu_process.c | 37 ++++++++++++++++++++++++++++++++++++ 4 files changed, 77 insertions(+) diff --git a/src/qemu/qemu_monitor.c b/src/qemu/qemu_monitor.c index 908ee0d302..abfc8c62ca 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -1353,6 +1353,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) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index b54c1cf87a..ba529c5241 100644 --- a/src/qemu/qemu_monitor.h +++ b/src/qemu/qemu_monitor.h @@ -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, diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c index e9be9bdabd..065ba0dc39 100644 --- a/src/qemu/qemu_monitor_json.c +++ b/src/qemu/qemu_monitor_json.c @@ -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) { diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c index d5f8a47ac2..6ad04363b9 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -1341,6 +1341,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: @@ -1910,6 +1946,7 @@ static qemuMonitorCallbacks monitorCallbacks = { .domainGuestCrashloaded = qemuProcessHandleGuestCrashloaded, .domainMemoryFailure = qemuProcessHandleMemoryFailure, .domainMemoryDeviceSizeChange = qemuProcessHandleMemoryDeviceSizeChange, + .domainDeviceUnplugError = qemuProcessHandleDeviceUnplugErr, }; static void -- 2.31.1