]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
ch: preserve last error in virCHProcessStop()
authorKirill Shchetiniuk <kshcheti@redhat.com>
Fri, 14 Mar 2025 11:51:18 +0000 (12:51 +0100)
committerMichal Privoznik <mprivozn@redhat.com>
Mon, 17 Mar 2025 13:02:45 +0000 (14:02 +0100)
If starting a CH domain fails an error is reported and
virCHProcessStart() calls virCHProcessStop() to clean up any
residues. Problem is, inside of virCHProcessStop() some public
APIs might be called (e.g. virNetworkLookupByName(),
virNetworkPortLookupByUUID() and/or virNetworkPortDelete()). Per
our design, public APIs reset last error which means the useful
error reported earlier is lost.

Fix this by calling virErrorPreserveLast() + virErrorRestore()
combo inside of virCHProcessStop().

Signed-off-by: Kirill Shchetiniuk <kshcheti@redhat.com>
Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
src/ch/ch_process.c

index ee86430e084b2962a749b03bfd4186a21fcd806a..b3eddd61e86fc77b7dabebd552260446621d169e 100644 (file)
@@ -999,11 +999,14 @@ virCHProcessStop(virCHDriver *driver,
     unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI;
     virCHDomainObjPrivate *priv = vm->privateData;
     virDomainDef *def = vm->def;
+    virErrorPtr orig_err = NULL;
     size_t i;
 
     VIR_DEBUG("Stopping VM name=%s pid=%d reason=%d",
               vm->def->name, (int)vm->pid, (int)reason);
 
+    virErrorPreserveLast(&orig_err);
+
     if (priv->monitor) {
         g_clear_pointer(&priv->monitor, virCHMonitorClose);
     }
@@ -1036,6 +1039,8 @@ virCHProcessStop(virCHDriver *driver,
 
     virHostdevReAttachDomainDevices(driver->hostdevMgr, CH_DRIVER_NAME, def,
                                     hostdev_flags);
+
+    virErrorRestore(&orig_err);
     return 0;
 }