147b37
From 00b89ea9a9e0713ed663c4426f1f4f2e44d846b6 Mon Sep 17 00:00:00 2001
147b37
Message-Id: <00b89ea9a9e0713ed663c4426f1f4f2e44d846b6@dist-git>
147b37
From: Pino Toscano <ptoscano@redhat.com>
147b37
Date: Thu, 12 Apr 2018 17:26:21 +0200
147b37
Subject: [PATCH] vmx: convert any amount of NICs
147b37
MIME-Version: 1.0
147b37
Content-Type: text/plain; charset=UTF-8
147b37
Content-Transfer-Encoding: 8bit
147b37
147b37
Scan the parsed VMX file, and gather the biggest index of the network
147b37
interfaces there: this way, it is possible to parse all the available
147b37
network interfaces, instead of just 4 maximum.
147b37
147b37
Add the VMX file attached to RHBZ#1560917 as testcase esx-in-the-wild-8.
147b37
147b37
https://bugzilla.redhat.com/show_bug.cgi?id=1560917
147b37
147b37
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
147b37
(cherry picked from commit 5c744a2d445c01fdb9d83a9c3857ba6c0091d834)
147b37
147b37
https://bugzilla.redhat.com/show_bug.cgi?id=1566524
147b37
147b37
Signed-off-by: Pino Toscano <ptoscano@redhat.com>
147b37
Reviewed-by: Ján Tomko <jtomko@redhat.com>
147b37
---
147b37
 src/vmx/vmx.c                                 |  43 ++++-
147b37
 .../vmx2xmldata/vmx2xml-esx-in-the-wild-8.vmx | 163 ++++++++++++++++++
147b37
 .../vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml |  89 ++++++++++
147b37
 tests/vmx2xmltest.c                           |   1 +
147b37
 4 files changed, 288 insertions(+), 8 deletions(-)
147b37
 create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.vmx
147b37
 create mode 100644 tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml
147b37
147b37
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
147b37
index 3433f39d5c..2afb2e9b34 100644
147b37
--- a/src/vmx/vmx.c
147b37
+++ b/src/vmx/vmx.c
147b37
@@ -1286,6 +1286,36 @@ virVMXGatherSCSIControllers(virVMXContext *ctx, virDomainDefPtr def,
147b37
     return result;
147b37
 }
147b37
 
147b37
+struct virVMXConfigScanResults {
147b37
+    int networks_max_index;
147b37
+};
147b37
+
147b37
+static int
147b37
+virVMXConfigScanResultsCollector(const char* name,
147b37
+                                 virConfValuePtr value ATTRIBUTE_UNUSED,
147b37
+                                 void *opaque)
147b37
+{
147b37
+    struct virVMXConfigScanResults *results = opaque;
147b37
+
147b37
+    if (STRCASEPREFIX(name, "ethernet")) {
147b37
+        unsigned int idx;
147b37
+        char *p;
147b37
+
147b37
+        if (virStrToLong_uip(name + 8, &p, 10, &idx) < 0 ||
147b37
+            *p != '.') {
147b37
+            virReportError(VIR_ERR_INTERNAL_ERROR,
147b37
+                           _("failed to parse the index of the VMX key '%s'"),
147b37
+                           name);
147b37
+            return -1;
147b37
+        }
147b37
+
147b37
+        if ((int) idx > results->networks_max_index)
147b37
+            results->networks_max_index = (int) idx;
147b37
+    }
147b37
+
147b37
+    return 0;
147b37
+}
147b37
+
147b37
 
147b37
 
147b37
 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
147b37
@@ -1322,6 +1352,7 @@ virVMXParseConfig(virVMXContext *ctx,
147b37
     bool hgfs_disabled = true;
147b37
     long long sharedFolder_maxNum = 0;
147b37
     int cpumasklen;
147b37
+    struct virVMXConfigScanResults results = { -1 };
147b37
 
147b37
     if (ctx->parseFileName == NULL) {
147b37
         virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
147b37
@@ -1357,6 +1388,9 @@ virVMXParseConfig(virVMXContext *ctx,
147b37
             goto cleanup;
147b37
     }
147b37
 
147b37
+    if (virConfWalk(conf, virVMXConfigScanResultsCollector, &results) < 0)
147b37
+        goto cleanup;
147b37
+
147b37
     /* Allocate domain def */
147b37
     if (!(def = virDomainDefNew()))
147b37
         goto cleanup;
147b37
@@ -1751,7 +1785,7 @@ virVMXParseConfig(virVMXContext *ctx,
147b37
     }
147b37
 
147b37
     /* def:nets */
147b37
-    for (controller = 0; controller < 4; ++controller) {
147b37
+    for (controller = 0; controller <= results.networks_max_index; ++controller) {
147b37
         virDomainNetDefPtr net = NULL;
147b37
         if (virVMXParseEthernet(conf, controller, &net) < 0)
147b37
             goto cleanup;
147b37
@@ -2539,13 +2573,6 @@ virVMXParseEthernet(virConfPtr conf, int controller, virDomainNetDefPtr *def)
147b37
         return -1;
147b37
     }
147b37
 
147b37
-    if (controller < 0 || controller > 3) {
147b37
-        virReportError(VIR_ERR_INTERNAL_ERROR,
147b37
-                       _("Ethernet controller index %d out of [0..3] range"),
147b37
-                       controller);
147b37
-        return -1;
147b37
-    }
147b37
-
147b37
     snprintf(prefix, sizeof(prefix), "ethernet%d", controller);
147b37
 
147b37
     VMX_BUILD_NAME(present);
147b37
diff --git a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.vmx b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.vmx
147b37
new file mode 100644
147b37
index 0000000000..1e3dbf23ce
147b37
--- /dev/null
147b37
+++ b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.vmx
147b37
@@ -0,0 +1,163 @@
147b37
+.encoding = "UTF-8"
147b37
+config.version = "8"
147b37
+virtualHW.version = "11"
147b37
+vmci0.present = "TRUE"
147b37
+svga.vramSize = "8388608"
147b37
+memSize = "2048"
147b37
+sched.cpu.units = "mhz"
147b37
+tools.upgrade.policy = "manual"
147b37
+scsi0.virtualDev = "pvscsi"
147b37
+scsi0.present = "TRUE"
147b37
+sata0.present = "TRUE"
147b37
+sata0:0.deviceType = "cdrom-image"
147b37
+sata0:0.fileName = "/vmfs/volumes/692eb778-2d4937fe/CentOS-4.7.ServerCD-x86_64.iso"
147b37
+sata0:0.present = "TRUE"
147b37
+scsi0:0.deviceType = "scsi-hardDisk"
147b37
+scsi0:0.fileName = "RHEL7_6.vmdk"
147b37
+sched.scsi0:0.shares = "normal"
147b37
+scsi0:0.present = "TRUE"
147b37
+floppy0.startConnected = "FALSE"
147b37
+floppy0.clientDevice = "TRUE"
147b37
+floppy0.fileName = "vmware-null-remote-floppy"
147b37
+ethernet0.virtualDev = "vmxnet3"
147b37
+ethernet0.networkName = "VM Network"
147b37
+ethernet0.addressType = "static"
147b37
+ethernet0.address = "00:1a:4a:16:01:55"
147b37
+ethernet0.present = "TRUE"
147b37
+displayName = "RHEL7_10_NICs"
147b37
+guestOS = "rhel7-64"
147b37
+toolScripts.afterPowerOn = "TRUE"
147b37
+toolScripts.afterResume = "TRUE"
147b37
+toolScripts.beforeSuspend = "TRUE"
147b37
+toolScripts.beforePowerOff = "TRUE"
147b37
+tools.syncTime = "FALSE"
147b37
+messageBus.tunnelEnabled = "FALSE"
147b37
+uuid.bios = "42 35 94 20 99 dc 42 61-52 64 ba 58 dd ae 20 e4"
147b37
+vc.uuid = "50 35 1d e6 7d 56 29 ab-9d 72 c7 f9 ea 3f cf d0"
147b37
+sched.cpu.latencySensitivity = "normal"
147b37
+tools.guest.desktop.autolock = "FALSE"
147b37
+nvram = "RHEL7_6.nvram"
147b37
+pciBridge0.present = "TRUE"
147b37
+svga.present = "TRUE"
147b37
+pciBridge4.present = "TRUE"
147b37
+pciBridge4.virtualDev = "pcieRootPort"
147b37
+pciBridge4.functions = "8"
147b37
+pciBridge5.present = "TRUE"
147b37
+pciBridge5.virtualDev = "pcieRootPort"
147b37
+pciBridge5.functions = "8"
147b37
+pciBridge6.present = "TRUE"
147b37
+pciBridge6.virtualDev = "pcieRootPort"
147b37
+pciBridge6.functions = "8"
147b37
+pciBridge7.present = "TRUE"
147b37
+pciBridge7.virtualDev = "pcieRootPort"
147b37
+pciBridge7.functions = "8"
147b37
+hpet0.present = "true"
147b37
+sched.scsi0:0.throughputCap = "off"
147b37
+ethernet0.uptCompatibility = "TRUE"
147b37
+ethernet0.pciSlotNumber = "192"
147b37
+monitor.phys_bits_used = "42"
147b37
+pciBridge0.pciSlotNumber = "17"
147b37
+pciBridge4.pciSlotNumber = "21"
147b37
+pciBridge5.pciSlotNumber = "22"
147b37
+pciBridge6.pciSlotNumber = "23"
147b37
+pciBridge7.pciSlotNumber = "24"
147b37
+replay.supported = "false"
147b37
+sata0.pciSlotNumber = "33"
147b37
+scsi0.pciSlotNumber = "160"
147b37
+scsi0.sasWWID = "50 05 05 60 99 dc 42 60"
147b37
+softPowerOff = "FALSE"
147b37
+virtualHW.productCompatibility = "hosted"
147b37
+vmci0.pciSlotNumber = "32"
147b37
+vmotion.checkpointFBSize = "8388608"
147b37
+vmotion.checkpointSVGAPrimarySize = "8388608"
147b37
+tools.remindInstall = "FALSE"
147b37
+toolsInstallManager.lastInstallError = "0"
147b37
+toolsInstallManager.updateCounter = "1"
147b37
+migrate.hostlog = "RHEL7_6-2a23b979.hlog"
147b37
+sched.cpu.min = "0"
147b37
+sched.cpu.shares = "normal"
147b37
+sched.mem.min = "0"
147b37
+sched.mem.minSize = "0"
147b37
+sched.mem.shares = "normal"
147b37
+scsi0:1.deviceType = "scsi-hardDisk"
147b37
+scsi0:1.fileName = "RHEL7_6_1.vmdk"
147b37
+scsi0:1.mode = "independent-nonpersistent"
147b37
+sched.scsi0:1.shares = "normal"
147b37
+sched.scsi0:1.throughputCap = "off"
147b37
+scsi0:1.present = "TRUE"
147b37
+scsi0:2.deviceType = "scsi-hardDisk"
147b37
+scsi0:2.fileName = "/vmfs/volumes/5669422e-699d77db-c144-00e0815e303e/block4/block4.vmdk"
147b37
+sched.scsi0:2.shares = "normal"
147b37
+sched.scsi0:2.throughputCap = "off"
147b37
+scsi0:2.present = "TRUE"
147b37
+numvcpus = "8"
147b37
+cpuid.coresPerSocket = "2"
147b37
+sched.swap.derivedName = "/vmfs/volumes/29dcc8ec-e8d62d3b-0000-000000000000/RHEL7_6/RHEL7_6-05efff7d.vswp"
147b37
+uuid.location = "56 4d d9 db b7 4e df ce-58 6a 77 56 82 53 aa 18"
147b37
+replay.filename = ""
147b37
+scsi0:2.redo = ""
147b37
+scsi0:1.redo = ""
147b37
+scsi0:0.redo = ""
147b37
+vmci0.id = "-575790876"
147b37
+cleanShutdown = "TRUE"
147b37
+ethernet1.virtualDev = "e1000"
147b37
+ethernet1.networkName = "VM Network"
147b37
+ethernet1.addressType = "vpx"
147b37
+ethernet1.generatedAddress = "00:1a:4a:16:21:85"
147b37
+ethernet1.present = "TRUE"
147b37
+ethernet2.virtualDev = "e1000e"
147b37
+ethernet2.networkName = "VM Network"
147b37
+ethernet2.addressType = "vpx"
147b37
+ethernet2.generatedAddress = "00:1a:4a:16:21:82"
147b37
+ethernet2.present = "TRUE"
147b37
+ethernet3.virtualDev = "vmxnet3"
147b37
+ethernet3.networkName = "VM Network"
147b37
+ethernet3.addressType = "vpx"
147b37
+ethernet3.generatedAddress = "00:1a:4a:16:21:69"
147b37
+ethernet3.uptCompatibility = "TRUE"
147b37
+ethernet3.present = "TRUE"
147b37
+ethernet4.virtualDev = "vmxnet3"
147b37
+ethernet4.networkName = "VM Network"
147b37
+ethernet4.addressType = "vpx"
147b37
+ethernet4.generatedAddress = "00:1a:4a:16:21:80"
147b37
+ethernet4.uptCompatibility = "TRUE"
147b37
+ethernet4.present = "TRUE"
147b37
+ethernet5.virtualDev = "vmxnet3"
147b37
+ethernet5.networkName = "VM Network"
147b37
+ethernet5.addressType = "vpx"
147b37
+ethernet5.generatedAddress = "00:1a:4a:16:21:a3"
147b37
+ethernet5.uptCompatibility = "TRUE"
147b37
+ethernet5.present = "TRUE"
147b37
+ethernet6.virtualDev = "vmxnet3"
147b37
+ethernet6.networkName = "VM Network"
147b37
+ethernet6.addressType = "vpx"
147b37
+ethernet6.generatedAddress = "00:1a:4a:16:21:a8"
147b37
+ethernet6.uptCompatibility = "TRUE"
147b37
+ethernet6.present = "TRUE"
147b37
+ethernet7.virtualDev = "vmxnet3"
147b37
+ethernet7.networkName = "VM Network"
147b37
+ethernet7.addressType = "vpx"
147b37
+ethernet7.generatedAddress = "00:1a:4a:16:21:a9"
147b37
+ethernet7.uptCompatibility = "TRUE"
147b37
+ethernet7.present = "TRUE"
147b37
+ethernet8.virtualDev = "vmxnet3"
147b37
+ethernet8.networkName = "VM Network"
147b37
+ethernet8.addressType = "vpx"
147b37
+ethernet8.generatedAddress = "00:1a:4a:16:21:78"
147b37
+ethernet8.uptCompatibility = "TRUE"
147b37
+ethernet8.present = "TRUE"
147b37
+ethernet9.virtualDev = "vmxnet3"
147b37
+ethernet9.networkName = "VM Network"
147b37
+ethernet9.addressType = "vpx"
147b37
+ethernet9.generatedAddress = "00:1a:4a:16:21:81"
147b37
+ethernet9.uptCompatibility = "TRUE"
147b37
+ethernet9.present = "TRUE"
147b37
+ethernet1.pciSlotNumber = "34"
147b37
+ethernet2.pciSlotNumber = "224"
147b37
+ethernet3.pciSlotNumber = "256"
147b37
+ethernet4.pciSlotNumber = "1184"
147b37
+ethernet5.pciSlotNumber = "1216"
147b37
+ethernet6.pciSlotNumber = "1248"
147b37
+ethernet7.pciSlotNumber = "1280"
147b37
+ethernet8.pciSlotNumber = "2208"
147b37
+ethernet9.pciSlotNumber = "2240"
147b37
diff --git a/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml
147b37
new file mode 100644
147b37
index 0000000000..c85ccf3649
147b37
--- /dev/null
147b37
+++ b/tests/vmx2xmldata/vmx2xml-esx-in-the-wild-8.xml
147b37
@@ -0,0 +1,89 @@
147b37
+<domain type='vmware'>
147b37
+  <name>RHEL7_10_NICs</name>
147b37
+  <uuid>42359420-99dc-4261-5264-ba58ddae20e4</uuid>
147b37
+  <memory unit='KiB'>2097152</memory>
147b37
+  <currentMemory unit='KiB'>2097152</currentMemory>
147b37
+  <vcpu placement='static'>8</vcpu>
147b37
+  <cputune>
147b37
+    <shares>8000</shares>
147b37
+  </cputune>
147b37
+  <os>
147b37
+    <type arch='x86_64'>hvm</type>
147b37
+  </os>
147b37
+  <clock offset='utc'/>
147b37
+  <on_poweroff>destroy</on_poweroff>
147b37
+  <on_reboot>restart</on_reboot>
147b37
+  <on_crash>destroy</on_crash>
147b37
+  <devices>
147b37
+    <disk type='file' device='disk'>
147b37
+      <source file='[datastore] directory/RHEL7_6.vmdk'/>
147b37
+      <target dev='sda' bus='scsi'/>
147b37
+      <address type='drive' controller='0' bus='0' target='0' unit='0'/>
147b37
+    </disk>
147b37
+    <disk type='file' device='disk'>
147b37
+      <source file='[datastore] directory/RHEL7_6_1.vmdk'/>
147b37
+      <target dev='sdb' bus='scsi'/>
147b37
+      <transient/>
147b37
+      <address type='drive' controller='0' bus='0' target='0' unit='1'/>
147b37
+    </disk>
147b37
+    <disk type='file' device='disk'>
147b37
+      <source file='[5669422e-699d77db-c144-00e0815e303e] block4/block4.vmdk'/>
147b37
+      <target dev='sdc' bus='scsi'/>
147b37
+      <address type='drive' controller='0' bus='0' target='0' unit='2'/>
147b37
+    </disk>
147b37
+    <controller type='scsi' index='0' model='vmpvscsi'/>
147b37
+    <interface type='bridge'>
147b37
+      <mac address='00:1a:4a:16:01:55'/>
147b37
+      <source bridge='VM Network'/>
147b37
+      <model type='vmxnet3'/>
147b37
+    </interface>
147b37
+    <interface type='bridge'>
147b37
+      <mac address='00:1a:4a:16:21:85'/>
147b37
+      <source bridge='VM Network'/>
147b37
+      <model type='e1000'/>
147b37
+    </interface>
147b37
+    <interface type='bridge'>
147b37
+      <mac address='00:1a:4a:16:21:82'/>
147b37
+      <source bridge='VM Network'/>
147b37
+      <model type='e1000e'/>
147b37
+    </interface>
147b37
+    <interface type='bridge'>
147b37
+      <mac address='00:1a:4a:16:21:69'/>
147b37
+      <source bridge='VM Network'/>
147b37
+      <model type='vmxnet3'/>
147b37
+    </interface>
147b37
+    <interface type='bridge'>
147b37
+      <mac address='00:1a:4a:16:21:80'/>
147b37
+      <source bridge='VM Network'/>
147b37
+      <model type='vmxnet3'/>
147b37
+    </interface>
147b37
+    <interface type='bridge'>
147b37
+      <mac address='00:1a:4a:16:21:a3'/>
147b37
+      <source bridge='VM Network'/>
147b37
+      <model type='vmxnet3'/>
147b37
+    </interface>
147b37
+    <interface type='bridge'>
147b37
+      <mac address='00:1a:4a:16:21:a8'/>
147b37
+      <source bridge='VM Network'/>
147b37
+      <model type='vmxnet3'/>
147b37
+    </interface>
147b37
+    <interface type='bridge'>
147b37
+      <mac address='00:1a:4a:16:21:a9'/>
147b37
+      <source bridge='VM Network'/>
147b37
+      <model type='vmxnet3'/>
147b37
+    </interface>
147b37
+    <interface type='bridge'>
147b37
+      <mac address='00:1a:4a:16:21:78'/>
147b37
+      <source bridge='VM Network'/>
147b37
+      <model type='vmxnet3'/>
147b37
+    </interface>
147b37
+    <interface type='bridge'>
147b37
+      <mac address='00:1a:4a:16:21:81'/>
147b37
+      <source bridge='VM Network'/>
147b37
+      <model type='vmxnet3'/>
147b37
+    </interface>
147b37
+    <video>
147b37
+      <model type='vmvga' vram='8192' primary='yes'/>
147b37
+    </video>
147b37
+  </devices>
147b37
+</domain>
147b37
diff --git a/tests/vmx2xmltest.c b/tests/vmx2xmltest.c
147b37
index 00385dfa71..fd0d9fbea4 100644
147b37
--- a/tests/vmx2xmltest.c
147b37
+++ b/tests/vmx2xmltest.c
147b37
@@ -268,6 +268,7 @@ mymain(void)
147b37
     DO_TEST("esx-in-the-wild-5", "esx-in-the-wild-5");
147b37
     DO_TEST("esx-in-the-wild-6", "esx-in-the-wild-6");
147b37
     DO_TEST("esx-in-the-wild-7", "esx-in-the-wild-7");
147b37
+    DO_TEST("esx-in-the-wild-8", "esx-in-the-wild-8");
147b37
 
147b37
     DO_TEST("gsx-in-the-wild-1", "gsx-in-the-wild-1");
147b37
     DO_TEST("gsx-in-the-wild-2", "gsx-in-the-wild-2");
147b37
-- 
147b37
2.17.0
147b37