[libvirt] [PATCH] vmx: Fix a VMX parsing problem.

Geoff Hickey ghickey at datagravity.com
Wed Jan 7 23:45:42 UTC 2015


VMware ESX does not always set the "serialX.fileType" tag in VMX files. The
default value for this tag is "device", and when adding a new serial port
of this type VMware will omit the fileType tag. This caused libvirt to
fail to parse the VMX file. Fixed by making this tag optional and using
"device" as a default value. Also updated vmx2xmltest to test for this
case.

Conflicts:
	src/vmx/vmx.c
---
 src/vmx/vmx.c                               | 10 +++++++---
 tests/vmx2xmldata/vmx2xml-serial-device.vmx |  2 ++
 tests/vmx2xmldata/vmx2xml-serial-device.xml |  4 ++++
 3 files changed, 13 insertions(+), 3 deletions(-)

diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index e6bf5c3..2a794c7 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -2697,7 +2697,7 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port,
         goto ignore;
 
     /* vmx:fileType -> def:type */
-    if (virVMXGetConfigString(conf, fileType_name, &fileType, false) < 0)
+    if (virVMXGetConfigString(conf, fileType_name, &fileType, true) < 0)
         goto cleanup;
 
     /* vmx:fileName -> def:data.file.path */
@@ -2710,8 +2710,12 @@ virVMXParseSerial(virVMXContext *ctx, virConfPtr conf, int port,
         goto cleanup;
     }
 
-    /* Setup virDomainChrDef */
-    if (STRCASEEQ(fileType, "device")) {
+    /*
+     * Setup virDomainChrDef. The default fileType is "device", and vmware
+     * will sometimes omit this tag when adding a new serial port of this
+     * type.
+     */
+    if (!fileType || STRCASEEQ(fileType, "device")) {
         (*def)->target.port = port;
         (*def)->source.type = VIR_DOMAIN_CHR_TYPE_DEV;
         (*def)->source.data.file.path = fileName;
diff --git a/tests/vmx2xmldata/vmx2xml-serial-device.vmx b/tests/vmx2xmldata/vmx2xml-serial-device.vmx
index 8c101e3..927f408 100644
--- a/tests/vmx2xmldata/vmx2xml-serial-device.vmx
+++ b/tests/vmx2xmldata/vmx2xml-serial-device.vmx
@@ -3,3 +3,5 @@ virtualHW.version = "4"
 serial0.present = "true"
 serial0.fileType = "device"
 serial0.fileName = "/dev/ttyS0"
+serial1.present = "true"
+serial1.fileName = "/dev/ttyS1"
diff --git a/tests/vmx2xmldata/vmx2xml-serial-device.xml b/tests/vmx2xmldata/vmx2xml-serial-device.xml
index 9ecd867..cc45c07 100644
--- a/tests/vmx2xmldata/vmx2xml-serial-device.xml
+++ b/tests/vmx2xmldata/vmx2xml-serial-device.xml
@@ -15,6 +15,10 @@
       <source path='/dev/ttyS0'/>
       <target port='0'/>
     </serial>
+    <serial type='dev'>
+      <source path='/dev/ttyS1'/>
+      <target port='1'/>
+    </serial>
     <console type='dev'>
       <source path='/dev/ttyS0'/>
       <target type='serial' port='0'/>
-- 
1.9.1




More information about the libvir-list mailing list