]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
esxConnectListAllDomains: Don't propagate failure to lookup a single domain
authorPeter Krempa <pkrempa@redhat.com>
Tue, 25 Mar 2025 06:23:01 +0000 (07:23 +0100)
committerPeter Krempa <pkrempa@redhat.com>
Tue, 1 Apr 2025 14:15:24 +0000 (16:15 +0200)
In esxConnectListAllDomains if the lookup of the VM name and UUID fails
for a single VM (possible e.g. with broken storage) the whole API would
return failure even when there are working VMs.

Rework the lookup so that if a subset fails we ignore the failure on
those. We report an error only if lookup of all of the objects failed.
Failure is reported from the last one.

Resolves: https://issues.redhat.com/browse/RHEL-80606
Signed-off-by: Peter Krempa <pkrempa@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
src/esx/esx_driver.c

index 554fb3e18f69781418192083a3ac9eac8f4d014c..6ae4ef9658e91210a30fc0c81eedafe8428fc413 100644 (file)
@@ -4792,18 +4792,20 @@ esxConnectListAllDomains(virConnectPtr conn,
          virtualMachine = virtualMachine->_next) {
         g_autofree char *name = NULL;
 
-        if (needIdentity) {
-            if (esxVI_GetVirtualMachineIdentity(virtualMachine, &id,
-                                                &name, uuid) < 0) {
+        /* If the lookup of the required properties fails for some of the machines
+         * in the list it's preferrable to return the valid objects instead of
+         * failing outright */
+        if ((needIdentity && esxVI_GetVirtualMachineIdentity(virtualMachine, &id, &name, uuid) < 0) ||
+            (needPowerState && esxVI_GetVirtualMachinePowerState(virtualMachine, &powerState) < 0)) {
+
+            /* Raise error only if we didn't successfuly fill any domain */
+            if (count == 0 && !virtualMachine->_next)
                 goto cleanup;
-            }
-        }
 
-        if (needPowerState) {
-            if (esxVI_GetVirtualMachinePowerState(virtualMachine,
-                                                  &powerState) < 0) {
-                goto cleanup;
-            }
+            /* failure to fetch information of a single VM must not interrupt
+             * the lookup of the rest */
+            virResetLastError();
+            continue;
         }
 
         /* filter by active state */