Blob Blame History Raw
From fa8ad24ae3ff0e43c22b5045a6b99bbddf750121 Mon Sep 17 00:00:00 2001
Message-Id: <fa8ad24ae3ff0e43c22b5045a6b99bbddf750121@dist-git>
From: Michal Privoznik <mprivozn@redhat.com>
Date: Tue, 3 Aug 2021 16:04:36 +0200
Subject: [PATCH] vmx: Parse vm.genid
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

The VMware metadata file contains genid but we are not parsing
and thus reporting it in domain XML. However, it's not as
straightforward as one might think. The UUID reported by VMware
is not in its usual string form, but split into two signed long
longs. That means, we have to do a bit of trickery when parsing.
But looking around it's the same magic that libguestfs does:

https://github.com/libguestfs/virt-v2v/blob/master/v2v/input_vmx.ml#L421

It's also explained by Rich on qemu-devel:

https://lists.nongnu.org/archive/html/qemu-devel/2018-07/msg02019.html

Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1598348
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
(cherry picked from commit 7d661d6e20fe82e5472d5ab6dcd97ed76291f256)
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Message-Id: <5f6ef3e615301e5d318234949f707bedf9112f85.1627998922.git.mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
---
 src/vmx/vmx.c                                 | 30 +++++++++++++++++++
 .../vmx2xml-esx-in-the-wild-10.xml            |  1 +
 2 files changed, 31 insertions(+)

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 1cd5a82227..04eabff18a 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1337,6 +1337,32 @@ virVMXConfigScanResultsCollector(const char* name,
 }
 
 
+static int
+virVMXParseGenID(virConf *conf,
+                 virDomainDef *def)
+{
+    long long vmid[2] = { 0 };
+    g_autofree char *uuidstr = NULL;
+
+    if (virVMXGetConfigLong(conf, "vm.genid", &vmid[0], 0, true) < 0 ||
+        virVMXGetConfigLong(conf, "vm.genidX", &vmid[1], 0, true) < 0)
+        return -1;
+
+    if (vmid[0] == 0 && vmid[1] == 0)
+        return 0;
+
+    uuidstr = g_strdup_printf("%.16llx%.16llx", vmid[0], vmid[1]);
+    if (virUUIDParse(uuidstr, def->genid) < 0) {
+        virReportError(VIR_ERR_INTERNAL_ERROR,
+                       _("Could not parse UUID from string '%s'"), uuidstr);
+        return -1;
+    }
+    def->genidRequested = true;
+
+    return 0;
+}
+
+
 
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
  * VMX -> Domain XML
@@ -1466,6 +1492,10 @@ virVMXParseConfig(virVMXContext *ctx,
         }
     }
 
+    /* vmx:vm.genid + vm.genidX -> def:genid */
+    if (virVMXParseGenID(conf, def) < 0)
+        goto cleanup;
+
     /* vmx:annotation -> def:description */
     if (virVMXGetConfigString(conf, "annotation", &def->description,
                               true) < 0) {
diff --git a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-10.xml b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-10.xml
index b8c522af1f..47ed637920 100644
--- a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-10.xml
+++ b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-10.xml
@@ -1,6 +1,7 @@
 <domain type='vmware'>
   <name>w2019biosvmware</name>
   <uuid>421a6177-5aa9-abb7-5924-fc376c18a1b4</uuid>
+  <genid>13c67c91-9f47-526f-b0d6-e4dd2e4bb4f9</genid>
   <memory unit='KiB'>4194304</memory>
   <currentMemory unit='KiB'>4194304</currentMemory>
   <vcpu placement='static'>2</vcpu>
-- 
2.32.0