[PATCH] qemuDomainRestoreInternal: Preserve error on cleanup path

Peter Krempa via Devel posted 1 patch 6 days, 11 hours ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/e6a7e0f4e496a8bf5676803c0abb690edf2d8e39.1787066193.git.pkrempa@redhat.com
src/qemu/qemu_driver.c | 3 +++
1 file changed, 3 insertions(+)
[PATCH] qemuDomainRestoreInternal: Preserve error on cleanup path
Posted by Peter Krempa via Devel 6 days, 11 hours ago
From: Peter Krempa <pkrempa@redhat.com>

Preserve the error on cleanup path as cleanup of the 'libivrt_iohelper'
process may overwrite it with an unactionable error, such as when
attempting to restore a save image while the VM is already running:

  $ virsh list
   Id   Name       State
  --------------------------
   9    cd         running

  $ virsh restore /tmp/cd.save
  error: Failed to restore domain from /tmp/cd.save
  error: internal error: Child process (LIBVIRT_LOG_OUTPUTS=1:stderr /home/pipo/build/libvirt/gcc/src/libvirt_iohelper /tmp/cd.save 0) unexpected fatal signal 13

After this patch the original error is reported:

  $ virsh restore /tmp/cd.save
  error: Failed to restore domain from /tmp/cd.save
  error: Requested operation is not valid: domain 'cd' is already active

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

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 61d95bfbbf..25ba6695bb 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -5985,6 +5985,7 @@ qemuDomainRestoreInternal(virQEMUDriver *driver,
     bool sparse = false;
     bool bypass_cache = (flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) != 0;
     g_autoptr(qemuMigrationParams) restoreParams = NULL;
+    virErrorPtr save_err = NULL;

     virCheckFlags(QEMU_DOMAIN_RESTORE_FLAGS, -1);

@@ -6109,6 +6110,7 @@ qemuDomainRestoreInternal(virQEMUDriver *driver,
         qemuProcessEndJob(vmNew);

  cleanup:
+    virErrorPreserveLast(&save_err);
     VIR_FORCE_CLOSE(fd);
     if (virFileWrapperFdClose(wrapperFd) < 0)
         ret = -1;
@@ -6117,6 +6119,7 @@ qemuDomainRestoreInternal(virQEMUDriver *driver,
     if (vmNew && ret < 0)
         qemuDomainRemoveInactive(vmNew, 0, false);
     virDomainObjEndAPI(&vmNew);
+    virErrorRestore(&save_err);
     return ret;
 }

-- 
2.55.0
Re: [PATCH] qemuDomainRestoreInternal: Preserve error on cleanup path
Posted by Pavel Hrdina via Devel 6 days, 10 hours ago
On Tue, Aug 18, 2026 at 05:16:33PM +0200, Peter Krempa via Devel wrote:
> From: Peter Krempa <pkrempa@redhat.com>
> 
> Preserve the error on cleanup path as cleanup of the 'libivrt_iohelper'

s/libivrt_iohelper/libvirt_iohelper/

> process may overwrite it with an unactionable error, such as when
> attempting to restore a save image while the VM is already running:
> 
>   $ virsh list
>    Id   Name       State
>   --------------------------
>    9    cd         running
> 
>   $ virsh restore /tmp/cd.save
>   error: Failed to restore domain from /tmp/cd.save
>   error: internal error: Child process (LIBVIRT_LOG_OUTPUTS=1:stderr /home/pipo/build/libvirt/gcc/src/libvirt_iohelper /tmp/cd.save 0) unexpected fatal signal 13
> 
> After this patch the original error is reported:
> 
>   $ virsh restore /tmp/cd.save
>   error: Failed to restore domain from /tmp/cd.save
>   error: Requested operation is not valid: domain 'cd' is already active
> 
> Signed-off-by: Peter Krempa <pkrempa@redhat.com>
> ---
>  src/qemu/qemu_driver.c | 3 +++
>  1 file changed, 3 insertions(+)

Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
Re: [PATCH] qemuDomainRestoreInternal: Preserve error on cleanup path
Posted by Martin Kletzander via Devel 6 days, 10 hours ago
On Tue, Aug 18, 2026 at 05:16:33PM +0200, Peter Krempa via Devel wrote:
>From: Peter Krempa <pkrempa@redhat.com>
>
>Preserve the error on cleanup path as cleanup of the 'libivrt_iohelper'
>process may overwrite it with an unactionable error, such as when
>attempting to restore a save image while the VM is already running:
>
>  $ virsh list
>   Id   Name       State
>  --------------------------
>   9    cd         running
>
>  $ virsh restore /tmp/cd.save
>  error: Failed to restore domain from /tmp/cd.save
>  error: internal error: Child process (LIBVIRT_LOG_OUTPUTS=1:stderr /home/pipo/build/libvirt/gcc/src/libvirt_iohelper /tmp/cd.save 0) unexpected fatal signal 13
>
>After this patch the original error is reported:
>
>  $ virsh restore /tmp/cd.save
>  error: Failed to restore domain from /tmp/cd.save
>  error: Requested operation is not valid: domain 'cd' is already active
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>

Reviewed-by: Martin Kletzander <mkletzan@redhat.com>

>---
> src/qemu/qemu_driver.c | 3 +++
> 1 file changed, 3 insertions(+)
>
>diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
>index 61d95bfbbf..25ba6695bb 100644
>--- a/src/qemu/qemu_driver.c
>+++ b/src/qemu/qemu_driver.c
>@@ -5985,6 +5985,7 @@ qemuDomainRestoreInternal(virQEMUDriver *driver,
>     bool sparse = false;
>     bool bypass_cache = (flags & VIR_DOMAIN_SAVE_BYPASS_CACHE) != 0;
>     g_autoptr(qemuMigrationParams) restoreParams = NULL;
>+    virErrorPtr save_err = NULL;
>
>     virCheckFlags(QEMU_DOMAIN_RESTORE_FLAGS, -1);
>
>@@ -6109,6 +6110,7 @@ qemuDomainRestoreInternal(virQEMUDriver *driver,
>         qemuProcessEndJob(vmNew);
>
>  cleanup:
>+    virErrorPreserveLast(&save_err);
>     VIR_FORCE_CLOSE(fd);
>     if (virFileWrapperFdClose(wrapperFd) < 0)
>         ret = -1;
>@@ -6117,6 +6119,7 @@ qemuDomainRestoreInternal(virQEMUDriver *driver,
>     if (vmNew && ret < 0)
>         qemuDomainRemoveInactive(vmNew, 0, false);
>     virDomainObjEndAPI(&vmNew);
>+    virErrorRestore(&save_err);
>     return ret;
> }
>
>-- 
>2.55.0
>