[PATCH v2 14/15] include: libvirt-domain: Add 'hypervisor-message' @reason of VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON

Peter Krempa posted 15 patches 7 months, 1 week ago
[PATCH v2 14/15] include: libvirt-domain: Add 'hypervisor-message' @reason of VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON
Posted by Peter Krempa 7 months, 1 week ago
In case when the hypervisor does report the reason for the I/O error as
an unstable string to display to users we can add a @reason possibility
for the I/O error event noting that the error is available.

Add 'hypervisor-message' as a reason enumeration value and document it
to instruct users to look at the logs or virDomainGetMessages().

The resulting event looks like:

 event 'io-error' for domain 'cd': /dev/mapper/errdev0 (virtio-disk0) report due to hypervisor-message

Users then can look at the virDomainGetMessages() API:

 I/O error: disk='vda', index='1', path='/dev/mapper/errdev0', timestamp='2025-01-28 15:47:52.776+0000', message'Input/output error'

Or at the VM log file:

 2025-01-28 15:47:52.776+0000: IO error device='virtio-disk0' node-name='libvirt-1-storage' reason='Input/output error'

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 include/libvirt/libvirt-domain.h | 4 ++++
 src/qemu/qemu_process.c          | 2 ++
 2 files changed, 6 insertions(+)

diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
index 941e67aab1..2615d7b76a 100644
--- a/include/libvirt/libvirt-domain.h
+++ b/include/libvirt/libvirt-domain.h
@@ -4812,6 +4812,10 @@ typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
  * - "enospc": The I/O error is known to be caused by an ENOSPC condition in
  *             the host. Resizing the disk source to be larger will allow the
  *             guest to be resumed as if nothing happened.
+ * - "hypervisor-message": The hypervisor reported a string description of the
+ *                         I/O error. The errors are usually logged into the
+ *                         domain log file or the last instance of the error
+ *                         string can be queried via virDomainGetMessages().
  *
  * Since: 0.8.1
  */
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index e9342287ab..cf6e0517ef 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -862,6 +862,8 @@ qemuProcessHandleIOError(qemuMonitor *mon G_GNUC_UNUSED,

     if (nospace)
         eventReason = "enospc";
+    else if (reason)
+        eventReason = "hypervisor-message";

     ioErrorEvent = virDomainEventIOErrorNewFromObj(vm, eventPath, eventAlias, action);
     ioErrorEvent2 = virDomainEventIOErrorReasonNewFromObj(vm, eventPath, eventAlias, action, eventReason);
-- 
2.48.1
Re: [PATCH v2 14/15] include: libvirt-domain: Add 'hypervisor-message' @reason of VIR_DOMAIN_EVENT_ID_IO_ERROR_REASON
Posted by Daniel P. Berrangé 7 months, 1 week ago
On Tue, Jan 28, 2025 at 05:28:18PM +0100, Peter Krempa wrote:
> In case when the hypervisor does report the reason for the I/O error as
> an unstable string to display to users we can add a @reason possibility
> for the I/O error event noting that the error is available.
> 
> Add 'hypervisor-message' as a reason enumeration value and document it
> to instruct users to look at the logs or virDomainGetMessages().
> 
> The resulting event looks like:
> 
>  event 'io-error' for domain 'cd': /dev/mapper/errdev0 (virtio-disk0) report due to hypervisor-message
> 
> Users then can look at the virDomainGetMessages() API:
> 
>  I/O error: disk='vda', index='1', path='/dev/mapper/errdev0', timestamp='2025-01-28 15:47:52.776+0000', message'Input/output error'
> 
> Or at the VM log file:
> 
>  2025-01-28 15:47:52.776+0000: IO error device='virtio-disk0' node-name='libvirt-1-storage' reason='Input/output error'
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  include/libvirt/libvirt-domain.h | 4 ++++
>  src/qemu/qemu_process.c          | 2 ++
>  2 files changed, 6 insertions(+)

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

> 
> diff --git a/include/libvirt/libvirt-domain.h b/include/libvirt/libvirt-domain.h
> index 941e67aab1..2615d7b76a 100644
> --- a/include/libvirt/libvirt-domain.h
> +++ b/include/libvirt/libvirt-domain.h
> @@ -4812,6 +4812,10 @@ typedef void (*virConnectDomainEventIOErrorCallback)(virConnectPtr conn,
>   * - "enospc": The I/O error is known to be caused by an ENOSPC condition in
>   *             the host. Resizing the disk source to be larger will allow the
>   *             guest to be resumed as if nothing happened.
> + * - "hypervisor-message": The hypervisor reported a string description of the
> + *                         I/O error. The errors are usually logged into the
> + *                         domain log file or the last instance of the error
> + *                         string can be queried via virDomainGetMessages().

Or shorten it to just "message" ?


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 :|