[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

Re: [libvirt] [PATCH] Add domain type checking



2011/7/8 Eric Blake <eblake redhat com>:
> On 07/08/2011 02:13 AM, Matthias Bolte wrote:
>> The drivers were accepting domain configs without checking if those
>> were actually meant for them. For example the LXC driver happily
>> accepts configs with type QEMU.
>>
>> For convenience add an optional check for the domain type for the
>> virDomainDefParse* functions. It's optional because in some places
>> virDomainDefParse* is used to parse a config without caring about
>> it's type. Also the QEMU driver has to accept 4 different types and
>> does this checking own it's own.
>
> Can we factor the 4 QEMU types back into the common method?  Do this by
> treating expectedType as a bitmask:
>
>> +++ b/src/conf/domain_conf.c
>> @@ -1257,7 +1257,7 @@ virDomainObjSetDefTransient(virCapsPtr caps,
>>      if (!(xml = virDomainDefFormat(domain->def, VIR_DOMAIN_XML_WRITE_FLAGS)))
>>          goto out;
>>
>> -    if (!(newDef = virDomainDefParseString(caps, xml,
>> +    if (!(newDef = virDomainDefParseString(caps, xml, -1,
>>                                             VIR_DOMAIN_XML_READ_FLAGS)))
>
> -1 being the bitmask to accept all possible types,
>
>> @@ -5796,6 +5797,14 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
>>      }
>>      VIR_FREE(tmp);
>>
>> +    if (expectedVirtType >= 0 && def->virtType != expectedVirtType) {
>
> here, change the logic to:
>
> if (((1 << def->virtType) & expectedVirtTypes) == 0) {
>
>> +        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
>> +                             _("unexpected domain type %s, should be %s"),
>> +                             virDomainVirtTypeToString(def->virtType),
>> +                             virDomainVirtTypeToString(expectedVirtType));
>> +        goto error;
>> +    }
>> +
>>      /* Extract domain name */
>>      if (!(def->name = virXPathString("string(./name[1])", ctxt))) {
>>          virDomainReportError(VIR_ERR_NO_NAME, NULL);
>> @@ -6704,6 +6713,7 @@ no_memory:
>>  static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
>>                                              xmlDocPtr xml,
>>                                              xmlXPathContextPtr ctxt,
>> +                                            int expectedVirtType,
>
> make this plural expectedVirtTypes, to reflect that it is a bitmask,
>
>> +++ b/src/esx/esx_driver.c
>> @@ -2855,7 +2855,8 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
>>          return NULL;
>>      }
>>
>> -    def = virDomainDefParseString(priv->caps, domainXml, 0);
>> +    def = virDomainDefParseString(priv->caps, domainXml,
>> +                                  VIR_DOMAIN_VIRT_VMWARE, 0);
>
> here, pass (1 << VIR_DOMAIN_VIRT_VMWARE) instead of VIR_DOMAIN_VIRT_VMWARE
>
>> +++ b/src/qemu/qemu_domain.c
>> @@ -700,10 +700,32 @@ void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,
>>      ignore_value(virDomainObjUnref(obj));
>>  }
>>
>> +virDomainDefPtr qemuDomainDefParseXML(struct qemud_driver *driver,
>> +                                      const char *xml,
>> +                                      unsigned int flags)
>> +{
>> +    virDomainDefPtr def;
>> +
>> +    if (!(def = virDomainDefParseString(driver->caps, xml, -1, flags)))
>> +        return NULL;
>> +
>> +    if (def->virtType != VIR_DOMAIN_VIRT_QEMU &&
>> +        def->virtType != VIR_DOMAIN_VIRT_KQEMU &&
>> +        def->virtType != VIR_DOMAIN_VIRT_KVM &&
>> +        def->virtType != VIR_DOMAIN_VIRT_XEN) {
>
> Then here, instead of having qemu parse things, you instead pass:
>
> ((1 << VIR_DOMAIN_VIRT_QEMU) |
>  (1 << VIR_DOMAIN_VIRT_KQEMU) |
>  (1 << VIR_DOMAIN_VIRT_KVM) |
>  (1 << VIR_DOMAIN_VIRT_XEN))
>
> as the expectedVirtTypes.

Good idea, here's a v2 that does this.

-- 
Matthias Bolte
http://photron.blogspot.com
From 59baa7788e743ec65e88e5ac25a2a4bb6732c31b Mon Sep 17 00:00:00 2001
From: Matthias Bolte <matthias bolte googlemail com>
Date: Sat, 9 Jul 2011 15:32:15 +0200
Subject: [PATCH] Add domain type checking

The drivers were accepting domain configs without checking if those
were actually meant for them. For example the LXC driver happily
accepts configs with type QEMU.

Add a check for the expected domain types to the virDomainDefParse*
functions.
---
 src/conf/domain_conf.c        |   50 ++++++++++++++++++++++++++++++++---------
 src/conf/domain_conf.h        |    5 ++++
 src/esx/esx_driver.c          |    5 ++-
 src/libxl/libxl_driver.c      |   15 +++++++++---
 src/lxc/lxc_controller.c      |    1 +
 src/lxc/lxc_driver.c          |   13 +++++++---
 src/openvz/openvz_driver.c    |    2 +
 src/phyp/phyp_driver.c        |    1 +
 src/qemu/qemu_domain.h        |    6 +++++
 src/qemu/qemu_driver.c        |   15 +++++++++---
 src/qemu/qemu_migration.c     |    3 ++
 src/security/virt-aa-helper.c |    2 +-
 src/test/test_driver.c        |   10 ++++++-
 src/uml/uml_driver.c          |    8 +++++-
 src/vbox/vbox_tmpl.c          |    1 +
 src/vmware/vmware_driver.c    |    2 +
 src/xen/xen_driver.c          |    5 +--
 src/xen/xend_internal.c       |    5 ++-
 src/xen/xm_internal.c         |    1 +
 src/xenapi/xenapi_driver.c    |    8 +++++-
 tests/define-dev-segfault     |    2 +-
 tests/qemuxml2argvtest.c      |    2 +
 tests/qemuxml2xmltest.c       |    4 ++-
 tests/xmconfigtest.c          |    2 +-
 tests/xml2sexprtest.c         |    2 +-
 tests/xml2vmxtest.c           |    3 +-
 26 files changed, 131 insertions(+), 42 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index a680b11..86f099f 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -47,9 +47,14 @@
 #include "storage_file.h"
 #include "files.h"
 #include "bitmap.h"
+#include "verify.h"
 
 #define VIR_FROM_THIS VIR_FROM_DOMAIN
 
+/* virDomainVirtType is used to set bits in the expectedVirtTypes bitmask,
+ * verify that it doesn't overflow an unsigned int when shifting */
+verify(VIR_DOMAIN_VIRT_LAST <= 32);
+
 VIR_ENUM_IMPL(virDomainTaint, VIR_DOMAIN_TAINT_LAST,
               "custom-argv",
               "custom-monitor",
@@ -1264,7 +1269,7 @@ virDomainObjSetDefTransient(virCapsPtr caps,
     if (!(xml = virDomainDefFormat(domain->def, VIR_DOMAIN_XML_WRITE_FLAGS)))
         goto out;
 
-    if (!(newDef = virDomainDefParseString(caps, xml,
+    if (!(newDef = virDomainDefParseString(caps, xml, -1,
                                            VIR_DOMAIN_XML_READ_FLAGS)))
         goto out;
 
@@ -5800,6 +5805,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
                                             xmlDocPtr xml,
                                             xmlNodePtr root,
                                             xmlXPathContextPtr ctxt,
+                                            unsigned int expectedVirtTypes,
                                             unsigned int flags)
 {
     xmlNodePtr *nodes = NULL, node = NULL;
@@ -5836,6 +5842,13 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     }
     VIR_FREE(tmp);
 
+    if (((1 << def->virtType) & expectedVirtTypes) == 0) {
+        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+                             _("unexpected domain type %s"),
+                             virDomainVirtTypeToString(def->virtType));
+        goto error;
+    }
+
     /* Extract domain name */
     if (!(def->name = virXPathString("string(./name[1])", ctxt))) {
         virDomainReportError(VIR_ERR_NO_NAME, NULL);
@@ -6744,6 +6757,7 @@ no_memory:
 static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
                                             xmlDocPtr xml,
                                             xmlXPathContextPtr ctxt,
+                                            unsigned int expectedVirtTypes,
                                             unsigned int flags)
 {
     char *tmp = NULL;
@@ -6767,7 +6781,8 @@ static virDomainObjPtr virDomainObjParseXML(virCapsPtr caps,
 
     oldnode = ctxt->node;
     ctxt->node = config;
-    obj->def = virDomainDefParseXML(caps, xml, config, ctxt, flags);
+    obj->def = virDomainDefParseXML(caps, xml, config, ctxt, expectedVirtTypes,
+                                    flags);
     ctxt->node = oldnode;
     if (!obj->def)
         goto error;
@@ -6841,13 +6856,15 @@ static virDomainDefPtr
 virDomainDefParse(const char *xmlStr,
                   const char *filename,
                   virCapsPtr caps,
+                  unsigned int expectedVirtTypes,
                   unsigned int flags)
 {
     xmlDocPtr xml;
     virDomainDefPtr def = NULL;
 
     if ((xml = virXMLParse(filename, xmlStr, "domain.xml"))) {
-        def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml), flags);
+        def = virDomainDefParseNode(caps, xml, xmlDocGetRootElement(xml),
+                                    expectedVirtTypes, flags);
         xmlFreeDoc(xml);
     }
 
@@ -6856,22 +6873,25 @@ virDomainDefParse(const char *xmlStr,
 
 virDomainDefPtr virDomainDefParseString(virCapsPtr caps,
                                         const char *xmlStr,
+                                        unsigned int expectedVirtTypes,
                                         unsigned int flags)
 {
-    return virDomainDefParse(xmlStr, NULL, caps, flags);
+    return virDomainDefParse(xmlStr, NULL, caps, expectedVirtTypes, flags);
 }
 
 virDomainDefPtr virDomainDefParseFile(virCapsPtr caps,
                                       const char *filename,
+                                      unsigned int expectedVirtTypes,
                                       unsigned int flags)
 {
-    return virDomainDefParse(NULL, filename, caps, flags);
+    return virDomainDefParse(NULL, filename, caps, expectedVirtTypes, flags);
 }
 
 
 virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
                                       xmlDocPtr xml,
                                       xmlNodePtr root,
+                                      unsigned int expectedVirtTypes,
                                       unsigned int flags)
 {
     xmlXPathContextPtr ctxt = NULL;
@@ -6890,7 +6910,7 @@ virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
     }
 
     ctxt->node = root;
-    def = virDomainDefParseXML(caps, xml, root, ctxt, flags);
+    def = virDomainDefParseXML(caps, xml, root, ctxt, expectedVirtTypes, flags);
 
 cleanup:
     xmlXPathFreeContext(ctxt);
@@ -6902,6 +6922,7 @@ static virDomainObjPtr
 virDomainObjParseNode(virCapsPtr caps,
                       xmlDocPtr xml,
                       xmlNodePtr root,
+                      unsigned int expectedVirtTypes,
                       unsigned int flags)
 {
     xmlXPathContextPtr ctxt = NULL;
@@ -6920,7 +6941,7 @@ virDomainObjParseNode(virCapsPtr caps,
     }
 
     ctxt->node = root;
-    obj = virDomainObjParseXML(caps, xml, ctxt, flags);
+    obj = virDomainObjParseXML(caps, xml, ctxt, expectedVirtTypes, flags);
 
 cleanup:
     xmlXPathFreeContext(ctxt);
@@ -6930,6 +6951,7 @@ cleanup:
 
 virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
                                       const char *filename,
+                                      unsigned int expectedVirtTypes,
                                       unsigned int flags)
 {
     xmlDocPtr xml;
@@ -6937,7 +6959,8 @@ virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
 
     if ((xml = virXMLParseFile(filename))) {
         obj = virDomainObjParseNode(caps, xml,
-                                    xmlDocGetRootElement(xml), flags);
+                                    xmlDocGetRootElement(xml),
+                                    expectedVirtTypes, flags);
         xmlFreeDoc(xml);
     }
 
@@ -10119,6 +10142,7 @@ static virDomainObjPtr virDomainLoadConfig(virCapsPtr caps,
                                            const char *configDir,
                                            const char *autostartDir,
                                            const char *name,
+                                           unsigned int expectedVirtTypes,
                                            virDomainLoadConfigNotify notify,
                                            void *opaque)
 {
@@ -10130,7 +10154,7 @@ static virDomainObjPtr virDomainLoadConfig(virCapsPtr caps,
 
     if ((configFile = virDomainConfigFile(configDir, name)) == NULL)
         goto error;
-    if (!(def = virDomainDefParseFile(caps, configFile,
+    if (!(def = virDomainDefParseFile(caps, configFile, expectedVirtTypes,
                                       VIR_DOMAIN_XML_INACTIVE)))
         goto error;
 
@@ -10175,6 +10199,7 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr caps,
                                            virDomainObjListPtr doms,
                                            const char *statusDir,
                                            const char *name,
+                                           unsigned int expectedVirtTypes,
                                            virDomainLoadConfigNotify notify,
                                            void *opaque)
 {
@@ -10185,7 +10210,7 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr caps,
     if ((statusFile = virDomainConfigFile(statusDir, name)) == NULL)
         goto error;
 
-    if (!(obj = virDomainObjParseFile(caps, statusFile,
+    if (!(obj = virDomainObjParseFile(caps, statusFile, expectedVirtTypes,
                                       VIR_DOMAIN_XML_INTERNAL_STATUS)))
         goto error;
 
@@ -10220,6 +10245,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
                             const char *configDir,
                             const char *autostartDir,
                             int liveStatus,
+                            unsigned int expectedVirtTypes,
                             virDomainLoadConfigNotify notify,
                             void *opaque)
 {
@@ -10254,6 +10280,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
                                       doms,
                                       configDir,
                                       entry->d_name,
+                                      expectedVirtTypes,
                                       notify,
                                       opaque);
         else
@@ -10262,6 +10289,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
                                       configDir,
                                       autostartDir,
                                       entry->d_name,
+                                      expectedVirtTypes,
                                       notify,
                                       opaque);
         if (dom) {
@@ -11081,7 +11109,7 @@ virDomainObjCopyPersistentDef(virCapsPtr caps, virDomainObjPtr dom)
     if (!xml)
         return NULL;
 
-    ret = virDomainDefParseString(caps, xml, VIR_DOMAIN_XML_READ_FLAGS);
+    ret = virDomainDefParseString(caps, xml, -1, VIR_DOMAIN_XML_READ_FLAGS);
 
     VIR_FREE(xml);
     return ret;
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 15adc70..6ed652b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1391,17 +1391,21 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps,
                                               unsigned int flags);
 virDomainDefPtr virDomainDefParseString(virCapsPtr caps,
                                         const char *xmlStr,
+                                        unsigned int expectedVirtTypes,
                                         unsigned int flags);
 virDomainDefPtr virDomainDefParseFile(virCapsPtr caps,
                                       const char *filename,
+                                      unsigned int expectedVirtTypes,
                                       unsigned int flags);
 virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
                                       xmlDocPtr doc,
                                       xmlNodePtr root,
+                                      unsigned int expectedVirtTypes,
                                       unsigned int flags);
 
 virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
                                       const char *filename,
+                                      unsigned int expectedVirtTypes,
                                       unsigned int flags);
 
 bool virDomainDefCheckABIStability(virDomainDefPtr src,
@@ -1476,6 +1480,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
                             const char *configDir,
                             const char *autostartDir,
                             int liveStatus,
+                            unsigned int expectedVirtTypes,
                             virDomainLoadConfigNotify notify,
                             void *opaque);
 
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index f68ede0..ddb8c23 100644
--- a/src/esx/esx_driver.c
+++ b/src/esx/esx_driver.c
@@ -2856,7 +2856,8 @@ esxDomainXMLToNative(virConnectPtr conn, const char *nativeFormat,
         return NULL;
     }
 
-    def = virDomainDefParseString(priv->caps, domainXml, 0);
+    def = virDomainDefParseString(priv->caps, domainXml,
+                                  1 << VIR_DOMAIN_VIRT_VMWARE, 0);
 
     if (def == NULL) {
         return NULL;
@@ -3069,7 +3070,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml)
     }
 
     /* Parse domain XML */
-    def = virDomainDefParseString(priv->caps, xml,
+    def = virDomainDefParseString(priv->caps, xml, 1 << VIR_DOMAIN_VIRT_VMWARE,
                                   VIR_DOMAIN_XML_INACTIVE);
 
     if (def == NULL) {
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 586d562..21a343e 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -281,6 +281,7 @@ libxlSaveImageOpen(libxlDriverPrivatePtr driver, const char *from,
     }
 
     if (!(def = virDomainDefParseString(driver->caps, xml,
+                                        1 << VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto error;
 
@@ -994,7 +995,8 @@ libxlStartup(int privileged) {
                                 &libxl_driver->domains,
                                 libxl_driver->stateDir,
                                 libxl_driver->autostartDir,
-                                1, NULL, NULL) < 0)
+                                1, 1 << VIR_DOMAIN_VIRT_XEN,
+                                NULL, NULL) < 0)
         goto error;
 
     libxlReconnectDomains(libxl_driver);
@@ -1004,7 +1006,8 @@ libxlStartup(int privileged) {
                                 &libxl_driver->domains,
                                 libxl_driver->configDir,
                                 libxl_driver->autostartDir,
-                                0, NULL, NULL) < 0)
+                                0, 1 << VIR_DOMAIN_VIRT_XEN,
+                                NULL, NULL) < 0)
         goto error;
 
     virHashForEach(libxl_driver->domains.objs, libxlAutostartDomain,
@@ -1037,7 +1040,8 @@ libxlReload(void)
                             &libxl_driver->domains,
                             libxl_driver->configDir,
                             libxl_driver->autostartDir,
-                            1, NULL, libxl_driver);
+                            1, 1 << VIR_DOMAIN_VIRT_XEN,
+                            NULL, libxl_driver);
 
     virHashForEach(libxl_driver->domains.objs, libxlAutostartDomain,
                    libxl_driver);
@@ -1207,6 +1211,7 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
 
     libxlDriverLock(driver);
     if (!(def = virDomainDefParseString(driver->caps, xml,
+                                        1 << VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
@@ -2566,7 +2571,8 @@ libxlDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
         goto cleanup;
     }
 
-    if (!(def = virDomainDefParseString(driver->caps, domainXml, 0)))
+    if (!(def = virDomainDefParseString(driver->caps, domainXml,
+                                        1 << VIR_DOMAIN_VIRT_XEN, 0)))
         goto cleanup;
 
     if (!(conf = xenFormatXM(conn, def, ver_info->xen_version_major)))
@@ -2668,6 +2674,7 @@ libxlDomainDefineXML(virConnectPtr conn, const char *xml)
 
     libxlDriverLock(driver);
     if (!(def = virDomainDefParseString(driver->caps, xml,
+                                        1 << VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
diff --git a/src/lxc/lxc_controller.c b/src/lxc/lxc_controller.c
index 31c7d4f..346edef 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -926,6 +926,7 @@ int main(int argc, char *argv[])
         goto cleanup;
 
     if ((def = virDomainDefParseFile(caps, configFile,
+                                     1 << VIR_DOMAIN_VIRT_LXC,
                                      VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 799a5e7..2ce1fb9 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -409,10 +409,11 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml)
 
     lxcDriverLock(driver);
     if (!(def = virDomainDefParseString(driver->caps, xml,
+                                        1 << VIR_DOMAIN_VIRT_LXC,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
-   if ((dupVM = virDomainObjIsDuplicate(&driver->domains, def, 0)) < 0)
+    if ((dupVM = virDomainObjIsDuplicate(&driver->domains, def, 0)) < 0)
         goto cleanup;
 
     if ((def->nets != NULL) && !(driver->have_netns)) {
@@ -1751,6 +1752,7 @@ lxcDomainCreateAndStart(virConnectPtr conn,
 
     lxcDriverLock(driver);
     if (!(def = virDomainDefParseString(driver->caps, xml,
+                                        1 << VIR_DOMAIN_VIRT_LXC,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
@@ -2138,7 +2140,8 @@ static int lxcStartup(int privileged)
                                 &lxc_driver->domains,
                                 lxc_driver->stateDir,
                                 NULL,
-                                1, NULL, NULL) < 0)
+                                1, 1 << VIR_DOMAIN_VIRT_LXC,
+                                NULL, NULL) < 0)
         goto cleanup;
 
     virHashForEach(lxc_driver->domains.objs, lxcReconnectVM, lxc_driver);
@@ -2148,7 +2151,8 @@ static int lxcStartup(int privileged)
                                 &lxc_driver->domains,
                                 lxc_driver->configDir,
                                 lxc_driver->autostartDir,
-                                0, NULL, NULL) < 0)
+                                0, 1 << VIR_DOMAIN_VIRT_LXC,
+                                NULL, NULL) < 0)
         goto cleanup;
 
     lxcDriverUnlock(lxc_driver);
@@ -2193,7 +2197,8 @@ lxcReload(void) {
                             &lxc_driver->domains,
                             lxc_driver->configDir,
                             lxc_driver->autostartDir,
-                            0, lxcNotifyLoadDomain, lxc_driver);
+                            0, 1 << VIR_DOMAIN_VIRT_LXC,
+                            lxcNotifyLoadDomain, lxc_driver);
     lxcDriverUnlock(lxc_driver);
 
     lxcAutostartConfigs(lxc_driver);
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index 2c6c870..c1d91e4 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -887,6 +887,7 @@ openvzDomainDefineXML(virConnectPtr conn, const char *xml)
 
     openvzDriverLock(driver);
     if ((vmdef = virDomainDefParseString(driver->caps, xml,
+                                         1 << VIR_DOMAIN_VIRT_OPENVZ,
                                          VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
@@ -966,6 +967,7 @@ openvzDomainCreateXML(virConnectPtr conn, const char *xml,
 
     openvzDriverLock(driver);
     if ((vmdef = virDomainDefParseString(driver->caps, xml,
+                                         1 << VIR_DOMAIN_VIRT_OPENVZ,
                                          VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index d1ab5b4..f6f55c4 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -3611,6 +3611,7 @@ phypDomainCreateAndStart(virConnectPtr conn,
     virCheckFlags(0, NULL);
 
     if (!(def = virDomainDefParseString(phyp_driver->caps, xml,
+                                        1 << VIR_DOMAIN_VIRT_PHYP,
                                         VIR_DOMAIN_XML_SECURE)))
         goto err;
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index f282df2..d78c4b4 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -30,6 +30,12 @@
 # include "qemu_conf.h"
 # include "bitmap.h"
 
+# define QEMU_EXPECTED_VIRT_TYPES      \
+    ((1 << VIR_DOMAIN_VIRT_QEMU) |     \
+     (1 << VIR_DOMAIN_VIRT_KQEMU) |    \
+     (1 << VIR_DOMAIN_VIRT_KVM) |      \
+     (1 << VIR_DOMAIN_VIRT_XEN))
+
 /* Only 1 job is allowed at any time
  * A job includes *all* monitor commands, even those just querying
  * information, not merely actions */
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index a05a1ee..970d6be 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -612,7 +612,8 @@ qemudStartup(int privileged) {
                                 &qemu_driver->domains,
                                 qemu_driver->stateDir,
                                 NULL,
-                                1, NULL, NULL) < 0)
+                                1, QEMU_EXPECTED_VIRT_TYPES,
+                                NULL, NULL) < 0)
         goto error;
 
     conn = virConnectOpen(qemu_driver->privileged ?
@@ -626,7 +627,8 @@ qemudStartup(int privileged) {
                                 &qemu_driver->domains,
                                 qemu_driver->configDir,
                                 qemu_driver->autostartDir,
-                                0, NULL, NULL) < 0)
+                                0, QEMU_EXPECTED_VIRT_TYPES,
+                                NULL, NULL) < 0)
         goto error;
 
 
@@ -689,7 +691,8 @@ qemudReload(void) {
                             &qemu_driver->domains,
                             qemu_driver->configDir,
                             qemu_driver->autostartDir,
-                            0, qemudNotifyLoadDomain, qemu_driver);
+                            0, QEMU_EXPECTED_VIRT_TYPES,
+                            qemudNotifyLoadDomain, qemu_driver);
     qemuDriverUnlock(qemu_driver);
 
     qemuAutostartDomains(qemu_driver);
@@ -1253,6 +1256,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
 
     qemuDriverLock(driver);
     if (!(def = virDomainDefParseString(driver->caps, xml,
+                                        QEMU_EXPECTED_VIRT_TYPES,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
@@ -3606,6 +3610,7 @@ qemuDomainSaveImageOpen(struct qemud_driver *driver,
 
     /* Create a domain from this XML */
     if (!(def = virDomainDefParseString(driver->caps, xml,
+                                        QEMU_EXPECTED_VIRT_TYPES,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto error;
 
@@ -3924,7 +3929,8 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
         goto cleanup;
     }
 
-    def = virDomainDefParseString(driver->caps, xmlData, 0);
+    def = virDomainDefParseString(driver->caps, xmlData, 
+                                  QEMU_EXPECTED_VIRT_TYPES, 0);
     if (!def)
         goto cleanup;
 
@@ -4222,6 +4228,7 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) {
 
     qemuDriverLock(driver);
     if (!(def = virDomainDefParseString(driver->caps, xml,
+                                        QEMU_EXPECTED_VIRT_TYPES,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index d7b27a0..e7c1df7 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1019,6 +1019,7 @@ char *qemuMigrationBegin(struct qemud_driver *driver,
 
     if (xmlin) {
         if (!(def = virDomainDefParseString(driver->caps, xmlin,
+                                            QEMU_EXPECTED_VIRT_TYPES,
                                             VIR_DOMAIN_XML_INACTIVE)))
             goto cleanup;
 
@@ -1078,6 +1079,7 @@ qemuMigrationPrepareTunnel(struct qemud_driver *driver,
 
     /* Parse the domain XML. */
     if (!(def = virDomainDefParseString(driver->caps, dom_xml,
+                                        QEMU_EXPECTED_VIRT_TYPES,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
@@ -1313,6 +1315,7 @@ qemuMigrationPrepareDirect(struct qemud_driver *driver,
 
     /* Parse the domain XML. */
     if (!(def = virDomainDefParseString(driver->caps, dom_xml,
+                                        QEMU_EXPECTED_VIRT_TYPES,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
diff --git a/src/security/virt-aa-helper.c b/src/security/virt-aa-helper.c
index afc0d33..fb54dc5 100644
--- a/src/security/virt-aa-helper.c
+++ b/src/security/virt-aa-helper.c
@@ -725,7 +725,7 @@ get_definition(vahControl * ctl, const char *xmlStr)
         goto exit;
     }
 
-    ctl->def = virDomainDefParseString(ctl->caps, xmlStr,
+    ctl->def = virDomainDefParseString(ctl->caps, xmlStr, -1,
                                        VIR_DOMAIN_XML_INACTIVE);
     if (ctl->def == NULL) {
         vah_error(ctl, 0, _("could not parse XML"));
diff --git a/src/test/test_driver.c b/src/test/test_driver.c
index 98daca8..17eb242 100644
--- a/src/test/test_driver.c
+++ b/src/test/test_driver.c
@@ -544,10 +544,11 @@ static int testOpenDefault(virConnectPtr conn) {
 
     privconn->nextDomID = 1;
 
-    if (!(domdef = virDomainDefParseString(privconn->caps,
-                                           defaultDomainXML,
+    if (!(domdef = virDomainDefParseString(privconn->caps, defaultDomainXML,
+                                           1 << VIR_DOMAIN_VIRT_TEST,
                                            VIR_DOMAIN_XML_INACTIVE)))
         goto error;
+
     if (testDomainGenerateIfnames(domdef) < 0)
         goto error;
     if (!(domobj = virDomainAssignDef(privconn->caps,
@@ -889,12 +890,14 @@ static int testOpenFromFile(virConnectPtr conn,
                 goto error;
             }
             def = virDomainDefParseFile(privconn->caps, absFile,
+                                        1 << VIR_DOMAIN_VIRT_TEST,
                                         VIR_DOMAIN_XML_INACTIVE);
             VIR_FREE(absFile);
             if (!def)
                 goto error;
         } else {
             if ((def = virDomainDefParseNode(privconn->caps, xml, domains[i],
+                                             1 << VIR_DOMAIN_VIRT_TEST,
                                              VIR_DOMAIN_XML_INACTIVE)) == NULL)
                 goto error;
         }
@@ -1288,6 +1291,7 @@ testDomainCreateXML(virConnectPtr conn, const char *xml,
 
     testDriverLock(privconn);
     if ((def = virDomainDefParseString(privconn->caps, xml,
+                                       1 << VIR_DOMAIN_VIRT_TEST,
                                        VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
@@ -1868,6 +1872,7 @@ static int testDomainRestore(virConnectPtr conn,
 
     testDriverLock(privconn);
     def = virDomainDefParseString(privconn->caps, xml,
+                                  1 << VIR_DOMAIN_VIRT_TEST,
                                   VIR_DOMAIN_XML_INACTIVE);
     if (!def)
         goto cleanup;
@@ -2416,6 +2421,7 @@ static virDomainPtr testDomainDefineXML(virConnectPtr conn,
 
     testDriverLock(privconn);
     if ((def = virDomainDefParseString(privconn->caps, xml,
+                                       1 << VIR_DOMAIN_VIRT_TEST,
                                        VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 6a396e4..4160ac1 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -443,7 +443,8 @@ umlStartup(int privileged)
                                 &uml_driver->domains,
                                 uml_driver->configDir,
                                 uml_driver->autostartDir,
-                                0, NULL, NULL) < 0)
+                                0, 1 << VIR_DOMAIN_VIRT_UML,
+                                NULL, NULL) < 0)
         goto error;
 
     umlAutostartConfigs(uml_driver);
@@ -480,7 +481,8 @@ umlReload(void) {
                             &uml_driver->domains,
                             uml_driver->configDir,
                             uml_driver->autostartDir,
-                            0, NULL, NULL);
+                            0, 1 << VIR_DOMAIN_VIRT_UML,
+                            NULL, NULL);
 
     umlAutostartConfigs(uml_driver);
     umlDriverUnlock(uml_driver);
@@ -1273,6 +1275,7 @@ static virDomainPtr umlDomainCreate(virConnectPtr conn, const char *xml,
 
     umlDriverLock(driver);
     if (!(def = virDomainDefParseString(driver->caps, xml,
+                                        1 << VIR_DOMAIN_VIRT_UML,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
@@ -1646,6 +1649,7 @@ static virDomainPtr umlDomainDefine(virConnectPtr conn, const char *xml) {
 
     umlDriverLock(driver);
     if (!(def = virDomainDefParseString(driver->caps, xml,
+                                        1 << VIR_DOMAIN_VIRT_UML,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
diff --git a/src/vbox/vbox_tmpl.c b/src/vbox/vbox_tmpl.c
index 4a0858f..a460348 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -4803,6 +4803,7 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
     nsresult rc;
 
     if (!(def = virDomainDefParseString(data->caps, xml,
+                                        1 << VIR_DOMAIN_VIRT_VBOX,
                                         VIR_DOMAIN_XML_INACTIVE))) {
         goto cleanup;
     }
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index 3f0cfae..68afcaf 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -255,6 +255,7 @@ vmwareDomainDefineXML(virConnectPtr conn, const char *xml)
 
     vmwareDriverLock(driver);
     if ((vmdef = virDomainDefParseString(driver->caps, xml,
+                                         1 << VIR_DOMAIN_VIRT_VMWARE,
                                          VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
@@ -508,6 +509,7 @@ vmwareDomainCreateXML(virConnectPtr conn, const char *xml,
     vmwareDriverLock(driver);
 
     if ((vmdef = virDomainDefParseString(driver->caps, xml,
+                                         1 << VIR_DOMAIN_VIRT_VMWARE,
                                          VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 0f66395..1d75da3 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -1325,9 +1325,8 @@ xenUnifiedDomainXMLToNative(virConnectPtr conn,
         goto cleanup;
     }
 
-    if (!(def = virDomainDefParseString(priv->caps,
-                                        xmlData,
-                                        0)))
+    if (!(def = virDomainDefParseString(priv->caps, xmlData,
+                                        1 << VIR_DOMAIN_VIRT_XEN, 0)))
         goto cleanup;
 
     if (STREQ(format, XEN_CONFIG_FORMAT_XM)) {
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 6c2f051..e3f8750 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2596,8 +2596,8 @@ xenDaemonCreateXML(virConnectPtr conn, const char *xmlDesc,
 
     priv = (xenUnifiedPrivatePtr) conn->privateData;
 
-    if (!(def = virDomainDefParseString(priv->caps,
-                                        xmlDesc,
+    if (!(def = virDomainDefParseString(priv->caps, xmlDesc,
+                                        1 << VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
         return (NULL);
 
@@ -3346,6 +3346,7 @@ virDomainPtr xenDaemonDomainDefineXML(virConnectPtr conn, const char *xmlDesc) {
         return(NULL);
 
     if (!(def = virDomainDefParseString(priv->caps, xmlDesc,
+                                        1 << VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE))) {
         virXendError(VIR_ERR_XML_ERROR,
                      "%s", _("failed to parse domain description"));
diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c
index 01b9c4e..68181d2 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -1106,6 +1106,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml)
     }
 
     if (!(def = virDomainDefParseString(priv->caps, xml,
+                                        1 << VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE))) {
         xenUnifiedUnlock(priv);
         return (NULL);
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 1c06f75..4496d4a 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -517,7 +517,9 @@ xenapiDomainCreateXML (virConnectPtr conn,
 
     virCheckFlags(0, NULL);
 
-    virDomainDefPtr defPtr = virDomainDefParseString(caps, xmlDesc, flags);
+    virDomainDefPtr defPtr = virDomainDefParseString(caps, xmlDesc,
+                                                     1 << VIR_DOMAIN_VIRT_XEN,
+                                                     flags);
     createVMRecordFromXml(conn, defPtr, &record, &vm);
     virDomainDefFree(defPtr);
     if (record) {
@@ -1636,9 +1638,11 @@ xenapiDomainDefineXML (virConnectPtr conn, const char *xml)
     virCapsPtr caps = ((struct _xenapiPrivate *)(conn->privateData))->caps;
     if (!caps)
         return NULL;
-    virDomainDefPtr defPtr = virDomainDefParseString(caps, xml, 0);
+    virDomainDefPtr defPtr = virDomainDefParseString(caps, xml,
+                                                     1 << VIR_DOMAIN_VIRT_XEN, 0);
     if (!defPtr)
         return NULL;
+
     if (createVMRecordFromXml(conn, defPtr, &record, &vm) != 0) {
         if (!session->ok)
             xenapiSessionErrorHandler(conn, VIR_ERR_INTERNAL_ERROR, NULL);
diff --git a/tests/define-dev-segfault b/tests/define-dev-segfault
index 19d4e67..3feff46 100755
--- a/tests/define-dev-segfault
+++ b/tests/define-dev-segfault
@@ -17,7 +17,7 @@ fail=0
 
 # Domain definition from Cole Robinson.
 cat <<\EOF > D.xml || fail=1
-<domain type='kvm'>
+<domain type='test'>
   <name>D</name>
   <uuid>aaa3ae22-fed2-bfbd-ac02-3bea3bcfad82</uuid>
   <memory>262144</memory>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index f12d815..5689367 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -14,6 +14,7 @@
 # include "testutils.h"
 # include "qemu/qemu_capabilities.h"
 # include "qemu/qemu_command.h"
+# include "qemu/qemu_domain.h"
 # include "datatypes.h"
 # include "cpu/cpu_map.h"
 
@@ -51,6 +52,7 @@ static int testCompareXMLToArgvFiles(const char *xml,
         expectargv[len - 1] = '\0';
 
     if (!(vmdef = virDomainDefParseFile(driver.caps, xml,
+                                        QEMU_EXPECTED_VIRT_TYPES,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto fail;
 
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 2a3e75a..f22872f 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -13,6 +13,7 @@
 # include "internal.h"
 # include "testutils.h"
 # include "qemu/qemu_conf.h"
+# include "qemu/qemu_domain.h"
 # include "testutilsqemu.h"
 
 static struct qemud_driver driver;
@@ -32,7 +33,8 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
         goto fail;
 
     if (!(def = virDomainDefParseString(driver.caps, inXmlData,
-                                          VIR_DOMAIN_XML_INACTIVE)))
+                                        QEMU_EXPECTED_VIRT_TYPES,
+                                        VIR_DOMAIN_XML_INACTIVE)))
         goto fail;
 
     if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE)))
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index a15a7ff..c184b8d 100644
--- a/tests/xmconfigtest.c
+++ b/tests/xmconfigtest.c
@@ -68,7 +68,7 @@ testCompareParseXML(const char *xmcfg, const char *xml, int xendConfigVersion)
     priv.caps = caps;
     conn->privateData = &priv;
 
-    if (!(def = virDomainDefParseString(caps, xmlData,
+    if (!(def = virDomainDefParseString(caps, xmlData, 1 << VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto fail;
 
diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
index d8cdcbb..b27ec1d 100644
--- a/tests/xml2sexprtest.c
+++ b/tests/xml2sexprtest.c
@@ -31,7 +31,7 @@ testCompareFiles(const char *xml, const char *sexpr, int xendConfigVersion)
   if (virtTestLoadFile(sexpr, &sexprData) < 0)
       goto fail;
 
-  if (!(def = virDomainDefParseString(caps, xmlData,
+  if (!(def = virDomainDefParseString(caps, xmlData, 1 << VIR_DOMAIN_VIRT_XEN,
                                       VIR_DOMAIN_XML_INACTIVE)))
       goto fail;
 
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index f1e1b95..439ddc8 100644
--- a/tests/xml2vmxtest.c
+++ b/tests/xml2vmxtest.c
@@ -80,7 +80,8 @@ testCompareFiles(const char *xml, const char *vmx, int virtualHW_version)
         goto failure;
     }
 
-    def = virDomainDefParseString(caps, xmlData, VIR_DOMAIN_XML_INACTIVE);
+    def = virDomainDefParseString(caps, xmlData, 1 << VIR_DOMAIN_VIRT_VMWARE,
+                                  VIR_DOMAIN_XML_INACTIVE);
 
     if (def == NULL) {
         goto failure;
-- 
1.7.4.1


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]