[PATCH] esx: Do not return root objects in a lookup

Martin Kletzander mkletzan at redhat.com
Sat Jan 22 21:54:28 UTC 2022

The lookups in esx_vi work a bit differently that we are used to.  The filters
(travelsalSpec and selectSet) choose how to look up the objects, but given a
root object the lookup lists all the objects of a requested type inside it as
well as the root object itself.  We then go through the results and find the one
which has the same name as was requested.  However in a case with nested folders
of a same name this could break when the first returned object in the list is
the parent folder as we'd select it only based on the name.  To avoid this also
add a check that the candidate we are trying to pick is not exactly the same
object (reference) as the root object.


Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
 src/esx/esx_vi.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/src/esx/esx_vi.c b/src/esx/esx_vi.c
index 6f964cc470d1..80ed6199e3ac 100644
--- a/src/esx/esx_vi.c
+++ b/src/esx/esx_vi.c
@@ -4973,6 +4973,11 @@ esxVI_LookupManagedObjectHelper(esxVI_Context *ctx,
              candidate = candidate->_next) {
             name_candidate = NULL;
+            if (candidate->obj->_type == root->_type &&
+                g_strcmp0(candidate->obj->type, root->type) == 0 &&
+                g_strcmp0(candidate->obj->value, root->value) == 0)
+                continue;
             if (esxVI_GetStringValue(candidate, "name", &name_candidate,
                                      esxVI_Occurrence_RequiredItem) < 0) {
                 goto cleanup;

More information about the libvir-list mailing list