[PATCH v2 08/15] qemuProcessHandleIOError: Populate I/O error reason to virStorageSource

Peter Krempa posted 15 patches 7 months, 1 week ago
[PATCH v2 08/15] qemuProcessHandleIOError: Populate I/O error reason to virStorageSource
Posted by Peter Krempa 7 months, 1 week ago
Record the last I/O error reason and timestamp which happened with the
corresponding virStorageSource struct.

This will later allow querying the last error e.g. via the
virDomainGetMessages() API.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/qemu/qemu_process.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 4497d089d0..d73c52542b 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -840,6 +840,7 @@ qemuProcessHandleIOError(qemuMonitor *mon G_GNUC_UNUSED,
     const char *eventReason = "";
     virDomainDiskDef *disk = NULL;
     virStorageSource *src = NULL;
+    g_autofree char *timestamp = NULL;

     virObjectLock(vm);
     priv = QEMU_DOMAIN_PRIVATE(vm);
@@ -865,6 +866,15 @@ qemuProcessHandleIOError(qemuMonitor *mon G_GNUC_UNUSED,
     ioErrorEvent = virDomainEventIOErrorNewFromObj(vm, eventPath, eventAlias, action);
     ioErrorEvent2 = virDomainEventIOErrorReasonNewFromObj(vm, eventPath, eventAlias, action, eventReason);

+    if ((timestamp = virTimeStringNow()) != NULL) {
+        if (src) {
+            g_free(src->ioerror_timestamp);
+            g_free(src->ioerror_message);
+            src->ioerror_timestamp = g_steal_pointer(&timestamp);
+            src->ioerror_message = g_strdup(reason);
+        }
+    }
+
     if (action == VIR_DOMAIN_EVENT_IO_ERROR_PAUSE &&
         virDomainObjGetState(vm, NULL) == VIR_DOMAIN_RUNNING) {
         VIR_WARN("Transitioned guest %s to paused state due to IO error", vm->def->name);
-- 
2.48.1
Re: [PATCH v2 08/15] qemuProcessHandleIOError: Populate I/O error reason to virStorageSource
Posted by Daniel P. Berrangé 7 months, 1 week ago
On Tue, Jan 28, 2025 at 05:28:12PM +0100, Peter Krempa wrote:
> Record the last I/O error reason and timestamp which happened with the
> corresponding virStorageSource struct.
> 
> This will later allow querying the last error e.g. via the
> virDomainGetMessages() API.
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/qemu/qemu_process.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)

Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>


With regards,
Daniel
-- 
|: https://berrange.com      -o-    https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org         -o-            https://fstop138.berrange.com :|
|: https://entangle-photo.org    -o-    https://www.instagram.com/dberrange :|