[libvirt] [PATCH 3/4] vmx: allow version safety bypass with allowUnsafe

Martin Kletzander mkletzan at redhat.com
Mon May 5 09:47:04 UTC 2014


We were (almost) blindly adding new virtualHW versions to the check
that was supposed to catch unsupported ones.  Accepting such changes
renders the check completely useless.  In order to avoid that, new
parameter, 'allowUnsafe', was added to the function.  This parameter
controls whether we error out with unsupported virtualHW version or
not.  Until there's somebody testing the code or an autotest setup for
that, we should not be adding new versions to the mix and instead
caller applications (like virt-v2v) should make use of this parameter.

Signed-off-by: Martin Kletzander <mkletzan at redhat.com>
---
 src/esx/esx_driver.c       |  6 ++++--
 src/vmware/vmware_conf.c   |  4 ++--
 src/vmware/vmware_driver.c |  3 ++-
 src/vmx/vmx.c              | 24 ++++++++++++++++++------
 src/vmx/vmx.h              |  4 +++-
 5 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index d082927..f7d40b2 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -2735,7 +2735,8 @@ esxDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
     ctx.formatFileName = NULL;
     ctx.autodetectSCSIControllerModel = NULL;

-    def = virVMXParseConfig(&ctx, priv->xmlopt, vmx);
+    def = virVMXParseConfig(&ctx, priv->xmlopt, vmx,
+                            priv->parsedUri->allowUnsafe);

     if (def) {
         if (powerState != esxVI_VirtualMachinePowerState_PoweredOff) {
@@ -2794,7 +2795,8 @@ esxConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,
     ctx.formatFileName = NULL;
     ctx.autodetectSCSIControllerModel = NULL;

-    def = virVMXParseConfig(&ctx, priv->xmlopt, nativeConfig);
+    def = virVMXParseConfig(&ctx, priv->xmlopt, nativeConfig,
+                            priv->parsedUri->allowUnsafe);

     if (def) {
         xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE);
diff --git a/src/vmware/vmware_conf.c b/src/vmware/vmware_conf.c
index 29ca322..5a435e4 100644
--- a/src/vmware/vmware_conf.c
+++ b/src/vmware/vmware_conf.c
@@ -162,8 +162,8 @@ vmwareLoadDomains(struct vmware_driver *driver)
         if (virFileReadAll(vmxPath, 10000, &vmx) < 0)
             goto cleanup;

-        if ((vmdef =
-             virVMXParseConfig(&ctx, driver->xmlopt, vmx)) == NULL) {
+        if ((vmdef = virVMXParseConfig(&ctx, driver->xmlopt, vmx,
+                                       driver->allowUnsafe)) == NULL) {
             goto cleanup;
         }

diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index b0a3279..ff5c2de 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -999,7 +999,8 @@ vmwareConnectDomainXMLFromNative(virConnectPtr conn, const char *nativeFormat,

     ctx.parseFileName = vmwareCopyVMXFileName;

-    def = virVMXParseConfig(&ctx, driver->xmlopt, nativeConfig);
+    def = virVMXParseConfig(&ctx, driver->xmlopt, nativeConfig,
+                            driver->allowUnsafe);

     if (def != NULL)
         xml = virDomainDefFormat(def, VIR_DOMAIN_XML_INACTIVE);
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 169440c..194fda8 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1225,7 +1225,8 @@ virVMXGatherSCSIControllers(virVMXContext *ctx, virDomainDefPtr def,
 virDomainDefPtr
 virVMXParseConfig(virVMXContext *ctx,
                   virDomainXMLOptionPtr xmlopt,
-                  const char *vmx)
+                  const char *vmx,
+                  bool allowUnsafe)
 {
     bool success = false;
     virConfPtr conf = NULL;
@@ -1316,14 +1317,25 @@ virVMXParseConfig(virVMXContext *ctx,
         goto cleanup;
     }

+    /* If you need to add another version in here, please consider
+     * using allow_unsafe = 1 in URI in the upper layer.  We currently
+     * say we support these versions, but actually, we were just
+     * adding these versions with no sense of the related hypervisor
+     * changes whatsoever. */
     if (virtualHW_version != 4 && virtualHW_version != 7 &&
         virtualHW_version != 8 && virtualHW_version != 9 &&
         virtualHW_version != 10) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       _("Expecting VMX entry 'virtualHW.version' to be "
-                         "4, 7, 8, 9 or 10 but found %lld"),
-                       virtualHW_version);
-        goto cleanup;
+        if (allowUnsafe) {
+            VIR_DEBUG("Value %lld of VMX entry 'virtualHW.version' is not "
+                      "supported, but explicitly allowed",
+                      virtualHW_version);
+        } else {
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("Expecting VMX entry 'virtualHW.version' to be "
+                             "4, 7, 8, 9 or 10 but found %lld"),
+                           virtualHW_version);
+            goto cleanup;
+        }
     }

     /* vmx:uuid.bios -> def:uuid */
diff --git a/src/vmx/vmx.h b/src/vmx/vmx.h
index 6a68c8b..0525d0a 100644
--- a/src/vmx/vmx.h
+++ b/src/vmx/vmx.h
@@ -1,6 +1,7 @@
 /*
  * vmx.h: VMware VMX parsing/formatting functions
  *
+ * Copyright (C) 2014 Red Hat, Inc.
  * Copyright (C) 2009-2010 Matthias Bolte <matthias.bolte at googlemail.com>
  *
  * This library is free software; you can redistribute it and/or
@@ -80,7 +81,8 @@ char *virVMXConvertToUTF8(const char *encoding, const char *string);

 virDomainDefPtr virVMXParseConfig(virVMXContext *ctx,
                                   virDomainXMLOptionPtr xmlopt,
-                                  const char *vmx);
+                                  const char *vmx,
+                                  bool allowUnsafe);

 int virVMXParseVNC(virConfPtr conf, virDomainGraphicsDefPtr *def);

-- 
1.9.2




More information about the libvir-list mailing list