9de337
From fa8ad24ae3ff0e43c22b5045a6b99bbddf750121 Mon Sep 17 00:00:00 2001
9de337
Message-Id: <fa8ad24ae3ff0e43c22b5045a6b99bbddf750121@dist-git>
9de337
From: Michal Privoznik <mprivozn@redhat.com>
9de337
Date: Tue, 3 Aug 2021 16:04:36 +0200
9de337
Subject: [PATCH] vmx: Parse vm.genid
9de337
MIME-Version: 1.0
9de337
Content-Type: text/plain; charset=UTF-8
9de337
Content-Transfer-Encoding: 8bit
9de337
9de337
The VMware metadata file contains genid but we are not parsing
9de337
and thus reporting it in domain XML. However, it's not as
9de337
straightforward as one might think. The UUID reported by VMware
9de337
is not in its usual string form, but split into two signed long
9de337
longs. That means, we have to do a bit of trickery when parsing.
9de337
But looking around it's the same magic that libguestfs does:
9de337
9de337
https://github.com/libguestfs/virt-v2v/blob/master/v2v/input_vmx.ml#L421
9de337
9de337
It's also explained by Rich on qemu-devel:
9de337
9de337
https://lists.nongnu.org/archive/html/qemu-devel/2018-07/msg02019.html
9de337
9de337
Resolves: https://bugzilla.redhat.com/show_bug.cgi?id=1598348
9de337
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9de337
Reviewed-by: Richard W.M. Jones <rjones@redhat.com>
9de337
(cherry picked from commit 7d661d6e20fe82e5472d5ab6dcd97ed76291f256)
9de337
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
9de337
Message-Id: <5f6ef3e615301e5d318234949f707bedf9112f85.1627998922.git.mprivozn@redhat.com>
9de337
Reviewed-by: Ján Tomko <jtomko@redhat.com>
9de337
---
9de337
 src/vmx/vmx.c                                 | 30 +++++++++++++++++++
9de337
 .../vmx2xml-esx-in-the-wild-10.xml            |  1 +
9de337
 2 files changed, 31 insertions(+)
9de337
9de337
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
9de337
index 1cd5a82227..04eabff18a 100644
9de337
--- a/src/vmx/vmx.c
9de337
+++ b/src/vmx/vmx.c
9de337
@@ -1337,6 +1337,32 @@ virVMXConfigScanResultsCollector(const char* name,
9de337
 }
9de337
 
9de337
 
9de337
+static int
9de337
+virVMXParseGenID(virConf *conf,
9de337
+                 virDomainDef *def)
9de337
+{
9de337
+    long long vmid[2] = { 0 };
9de337
+    g_autofree char *uuidstr = NULL;
9de337
+
9de337
+    if (virVMXGetConfigLong(conf, "vm.genid", &vmid[0], 0, true) < 0 ||
9de337
+        virVMXGetConfigLong(conf, "vm.genidX", &vmid[1], 0, true) < 0)
9de337
+        return -1;
9de337
+
9de337
+    if (vmid[0] == 0 && vmid[1] == 0)
9de337
+        return 0;
9de337
+
9de337
+    uuidstr = g_strdup_printf("%.16llx%.16llx", vmid[0], vmid[1]);
9de337
+    if (virUUIDParse(uuidstr, def->genid) < 0) {
9de337
+        virReportError(VIR_ERR_INTERNAL_ERROR,
9de337
+                       _("Could not parse UUID from string '%s'"), uuidstr);
9de337
+        return -1;
9de337
+    }
9de337
+    def->genidRequested = true;
9de337
+
9de337
+    return 0;
9de337
+}
9de337
+
9de337
+
9de337
 
9de337
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
9de337
  * VMX -> Domain XML
9de337
@@ -1466,6 +1492,10 @@ virVMXParseConfig(virVMXContext *ctx,
9de337
         }
9de337
     }
9de337
 
9de337
+    /* vmx:vm.genid + vm.genidX -> def:genid */
9de337
+    if (virVMXParseGenID(conf, def) < 0)
9de337
+        goto cleanup;
9de337
+
9de337
     /* vmx:annotation -> def:description */
9de337
     if (virVMXGetConfigString(conf, "annotation", &def->description,
9de337
                               true) < 0) {
9de337
diff --git a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-10.xml b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-10.xml
9de337
index b8c522af1f..47ed637920 100644
9de337
--- a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-10.xml
9de337
+++ b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-10.xml
9de337
@@ -1,6 +1,7 @@
9de337
 <domain type='vmware'>
9de337
   <name>w2019biosvmware</name>
9de337
   <uuid>421a6177-5aa9-abb7-5924-fc376c18a1b4</uuid>
9de337
+  <genid>13c67c91-9f47-526f-b0d6-e4dd2e4bb4f9</genid>
9de337
   <memory unit='KiB'>4194304</memory>
9de337
   <currentMemory unit='KiB'>4194304</currentMemory>
9de337
   <vcpu placement='static'>2</vcpu>
9de337
-- 
9de337
2.32.0
9de337