From df194c5c0879c2a933d6a3320268539184898830 Mon Sep 17 00:00:00 2001 From: Daniel Henrique Barboza Date: Fri, 29 Oct 2021 16:54:26 -0300 Subject: [PATCH] qemu: add DEVICE_UNPLUG_GUEST_ERROR event support 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 Signed-off-by: Daniel Henrique Barboza --- 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 9ad8ffa422..810dac209d 100644 --- a/src/qemu/qemu_monitor.c +++ b/src/qemu/qemu_monitor.c @@ -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) diff --git a/src/qemu/qemu_monitor.h b/src/qemu/qemu_monitor.h index cd1c1c4291..0dd7b1c4e2 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 9186d59ca2..4669b9135d 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 ec5e6999f5..b6c81dd23a 100644 --- a/src/qemu/qemu_process.c +++ b/src/qemu/qemu_process.c @@ -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