1
0
mirror of https://gitlab.com/libvirt/libvirt.git synced 2025-04-01 20:05:19 +00:00

ch: preserve last error in virCHProcessStop()

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>
This commit is contained in:
Kirill Shchetiniuk 2025-03-14 12:51:18 +01:00 committed by Michal Privoznik
parent 5a20684788
commit 1db1244752

View 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;
}