libxl: Fix domain startup failure error reporting

When domain startup fails, domain cleanup calls
libxlNetworkUnwindDevices, which calls virGetConnectNetwork, which
is a top level API entry point, which resets the initial saved error,
leading to clients seeing:

  error: An error occurred, but the cause is unknown

This preserves the error around the entire teardown process, similar
to what is done in the qemu driver.

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
Cole Robinson 2022-06-17 17:09:32 -04:00
parent 5f0765f90f
commit 25072c0304

View File

@ -903,10 +903,13 @@ libxlDomainCleanup(libxlDriverPrivate *driver,
virHostdevManager *hostdev_mgr = driver->hostdevMgr;
unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI;
size_t i;
virErrorPtr save_err;
VIR_DEBUG("Cleaning up domain with id '%d' and name '%s'",
vm->def->id, vm->def->name);
virErrorPreserveLast(&save_err);
hostdev_flags |= VIR_HOSTDEV_SP_USB;
/* Call hook with stopped operation. Ignore error and continue with cleanup */
@ -979,6 +982,7 @@ libxlDomainCleanup(libxlDriverPrivate *driver,
VIR_HOOK_SUBOP_END, NULL));
virDomainObjRemoveTransientDef(vm);
virErrorRestore(&save_err);
}
/*
@ -1240,6 +1244,7 @@ libxlDomainStartPrepare(libxlDriverPrivate *driver,
{
virHostdevManager *hostdev_mgr = driver->hostdevMgr;
unsigned int hostdev_flags = VIR_HOSTDEV_SP_PCI | VIR_HOSTDEV_SP_USB;
virErrorPtr save_err;
if (virDomainObjSetDefTransient(driver->xmlopt, vm, NULL) < 0)
return -1;
@ -1267,10 +1272,12 @@ libxlDomainStartPrepare(libxlDriverPrivate *driver,
return 0;
error:
virErrorPreserveLast(&save_err);
libxlNetworkUnwindDevices(vm->def);
virHostdevReAttachDomainDevices(hostdev_mgr, LIBXL_DRIVER_INTERNAL_NAME,
vm->def, hostdev_flags);
virDomainObjRemoveTransientDef(vm);
virErrorRestore(&save_err);
return -1;
}