]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
libxl: Fix domain startup failure error reporting
authorCole Robinson <crobinso@redhat.com>
Fri, 17 Jun 2022 21:09:32 +0000 (17:09 -0400)
committerCole Robinson <crobinso@redhat.com>
Tue, 21 Jun 2022 13:01:03 +0000 (09:01 -0400)
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>
src/libxl/libxl_domain.c

index 17b347de4e674198ede04e30539a091abda8b665..49577d63288a7e8d04a8f3969d3223cab6a01fee 100644 (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;
 }