[PATCH] Add domain type checking

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

 



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.
---
 src/conf/domain_conf.c        |   48 ++++++++++++++++++++++++++++++----------
 src/conf/domain_conf.h        |    5 ++++
 src/esx/esx_driver.c          |    5 ++-
 src/libxl/libxl_driver.c      |   14 ++++++-----
 src/lxc/lxc_controller.c      |    2 +-
 src/lxc/lxc_driver.c          |   13 ++++++-----
 src/openvz/openvz_driver.c    |    2 +
 src/phyp/phyp_driver.c        |    1 +
 src/qemu/qemu_domain.c        |   26 ++++++++++++++++++++-
 src/qemu/qemu_domain.h        |    8 +++++-
 src/qemu/qemu_driver.c        |   34 ++++++++++++++++++++--------
 src/qemu/qemu_migration.c     |   12 +++++-----
 src/security/virt-aa-helper.c |    2 +-
 src/test/test_driver.c        |   11 ++++++--
 src/uml/uml_driver.c          |    8 +++---
 src/vbox/vbox_tmpl.c          |    2 +-
 src/vmware/vmware_driver.c    |    2 +
 src/xen/xen_driver.c          |    5 +--
 src/xen/xend_internal.c       |    5 ++-
 src/xen/xm_internal.c         |    2 +-
 src/xenapi/xenapi_driver.c    |    7 ++++-
 tests/define-dev-segfault     |    2 +-
 tests/qemuxml2argvtest.c      |   11 ++++++++-
 tests/qemuxml2xmltest.c       |   13 +++++++++-
 tests/xmconfigtest.c          |    2 +-
 tests/xml2sexprtest.c         |    2 +-
 tests/xml2vmxtest.c           |    3 +-
 27 files changed, 176 insertions(+), 71 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7bcdcaf..69200ee 100644
--- a/src/conf/domain_conf.c
+++ 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)))
         goto out;
 
@@ -5760,7 +5760,8 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
                                             xmlDocPtr xml,
                                             xmlNodePtr root,
                                             xmlXPathContextPtr ctxt,
-                                            int flags)
+                                            int expectedVirtType,
+                                            unsigned int flags)
 {
     xmlNodePtr *nodes = NULL, node = NULL;
     char *tmp = NULL;
@@ -5796,6 +5797,14 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
     }
     VIR_FREE(tmp);
 
+    if (expectedVirtType >= 0 && def->virtType != expectedVirtType) {
+        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,
                                             unsigned int flags)
 {
     char *tmp = NULL;
@@ -6727,7 +6737,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, expectedVirtType,
+                                    flags);
     ctxt->node = oldnode;
     if (!obj->def)
         goto error;
@@ -6801,13 +6812,15 @@ static virDomainDefPtr
 virDomainDefParse(const char *xmlStr,
                   const char *filename,
                   virCapsPtr caps,
+                  int expectedVirtType,
                   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),
+                                    expectedVirtType, flags);
         xmlFreeDoc(xml);
     }
 
@@ -6816,22 +6829,25 @@ virDomainDefParse(const char *xmlStr,
 
 virDomainDefPtr virDomainDefParseString(virCapsPtr caps,
                                         const char *xmlStr,
+                                        int expectedVirtType,
                                         unsigned int flags)
 {
-    return virDomainDefParse(xmlStr, NULL, caps, flags);
+    return virDomainDefParse(xmlStr, NULL, caps, expectedVirtType, flags);
 }
 
 virDomainDefPtr virDomainDefParseFile(virCapsPtr caps,
                                       const char *filename,
+                                      int expectedVirtType,
                                       unsigned int flags)
 {
-    return virDomainDefParse(NULL, filename, caps, flags);
+    return virDomainDefParse(NULL, filename, caps, expectedVirtType, flags);
 }
 
 
 virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
                                       xmlDocPtr xml,
                                       xmlNodePtr root,
+                                      int expectedVirtType,
                                       unsigned int flags)
 {
     xmlXPathContextPtr ctxt = NULL;
@@ -6850,7 +6866,7 @@ virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
     }
 
     ctxt->node = root;
-    def = virDomainDefParseXML(caps, xml, root, ctxt, flags);
+    def = virDomainDefParseXML(caps, xml, root, ctxt, expectedVirtType, flags);
 
 cleanup:
     xmlXPathFreeContext(ctxt);
@@ -6862,6 +6878,7 @@ static virDomainObjPtr
 virDomainObjParseNode(virCapsPtr caps,
                       xmlDocPtr xml,
                       xmlNodePtr root,
+                      int expectedVirtType,
                       unsigned int flags)
 {
     xmlXPathContextPtr ctxt = NULL;
@@ -6880,7 +6897,7 @@ virDomainObjParseNode(virCapsPtr caps,
     }
 
     ctxt->node = root;
-    obj = virDomainObjParseXML(caps, xml, ctxt, flags);
+    obj = virDomainObjParseXML(caps, xml, ctxt, expectedVirtType, flags);
 
 cleanup:
     xmlXPathFreeContext(ctxt);
@@ -6890,6 +6907,7 @@ cleanup:
 
 virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
                                       const char *filename,
+                                      int expectedVirtType,
                                       unsigned int flags)
 {
     xmlDocPtr xml;
@@ -6897,7 +6915,8 @@ virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
 
     if ((xml = virXMLParseFile(filename))) {
         obj = virDomainObjParseNode(caps, xml,
-                                    xmlDocGetRootElement(xml), flags);
+                                    xmlDocGetRootElement(xml),
+                                    expectedVirtType, flags);
         xmlFreeDoc(xml);
     }
 
@@ -10075,6 +10094,7 @@ static virDomainObjPtr virDomainLoadConfig(virCapsPtr caps,
                                            const char *configDir,
                                            const char *autostartDir,
                                            const char *name,
+                                           int expectedVirtType,
                                            virDomainLoadConfigNotify notify,
                                            void *opaque)
 {
@@ -10086,7 +10106,7 @@ static virDomainObjPtr virDomainLoadConfig(virCapsPtr caps,
 
     if ((configFile = virDomainConfigFile(configDir, name)) == NULL)
         goto error;
-    if (!(def = virDomainDefParseFile(caps, configFile,
+    if (!(def = virDomainDefParseFile(caps, configFile, expectedVirtType,
                                       VIR_DOMAIN_XML_INACTIVE)))
         goto error;
 
@@ -10131,6 +10151,7 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr caps,
                                            virDomainObjListPtr doms,
                                            const char *statusDir,
                                            const char *name,
+                                           int expectedVirtType,
                                            virDomainLoadConfigNotify notify,
                                            void *opaque)
 {
@@ -10141,7 +10162,7 @@ static virDomainObjPtr virDomainLoadStatus(virCapsPtr caps,
     if ((statusFile = virDomainConfigFile(statusDir, name)) == NULL)
         goto error;
 
-    if (!(obj = virDomainObjParseFile(caps, statusFile,
+    if (!(obj = virDomainObjParseFile(caps, statusFile, expectedVirtType,
                                       VIR_DOMAIN_XML_INTERNAL_STATUS)))
         goto error;
 
@@ -10176,6 +10197,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
                             const char *configDir,
                             const char *autostartDir,
                             int liveStatus,
+                            int expectedVirtType,
                             virDomainLoadConfigNotify notify,
                             void *opaque)
 {
@@ -10210,6 +10232,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
                                       doms,
                                       configDir,
                                       entry->d_name,
+                                      expectedVirtType,
                                       notify,
                                       opaque);
         else
@@ -10218,6 +10241,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
                                       configDir,
                                       autostartDir,
                                       entry->d_name,
+                                      expectedVirtType,
                                       notify,
                                       opaque);
         if (dom) {
@@ -11037,7 +11061,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 ddfe18e..26656f4 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1381,17 +1381,21 @@ virDomainDeviceDefPtr virDomainDeviceDefParse(virCapsPtr caps,
                                               unsigned int flags);
 virDomainDefPtr virDomainDefParseString(virCapsPtr caps,
                                         const char *xmlStr,
+                                        int expectedVirtType,
                                         unsigned int flags);
 virDomainDefPtr virDomainDefParseFile(virCapsPtr caps,
                                       const char *filename,
+                                      int expectedVirtType,
                                       unsigned int flags);
 virDomainDefPtr virDomainDefParseNode(virCapsPtr caps,
                                       xmlDocPtr doc,
                                       xmlNodePtr root,
+                                      int expectedVirtType,
                                       unsigned int flags);
 
 virDomainObjPtr virDomainObjParseFile(virCapsPtr caps,
                                       const char *filename,
+                                      int expectedVirtType,
                                       unsigned int flags);
 
 bool virDomainDefCheckABIStability(virDomainDefPtr src,
@@ -1466,6 +1470,7 @@ int virDomainLoadAllConfigs(virCapsPtr caps,
                             const char *configDir,
                             const char *autostartDir,
                             int liveStatus,
+                            int expectedVirtType,
                             virDomainLoadConfigNotify notify,
                             void *opaque);
 
diff --git a/src/esx/esx_driver.c b/src/esx/esx_driver.c
index a6e47a4..85da3ff 100644
--- a/src/esx/esx_driver.c
+++ 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);
 
     if (def == NULL) {
         return NULL;
@@ -3068,7 +3069,7 @@ esxDomainDefineXML(virConnectPtr conn, const char *xml)
     }
 
     /* Parse domain XML */
-    def = virDomainDefParseString(priv->caps, xml,
+    def = virDomainDefParseString(priv->caps, xml, 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 ade69d8..4f3b8ec 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,
+                                        VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto error;
 
@@ -994,7 +995,7 @@ libxlStartup(int privileged) {
                                 &libxl_driver->domains,
                                 libxl_driver->stateDir,
                                 libxl_driver->autostartDir,
-                                1, NULL, NULL) < 0)
+                                1, VIR_DOMAIN_VIRT_XEN, NULL, NULL) < 0)
         goto error;
 
     libxlReconnectDomains(libxl_driver);
@@ -1004,7 +1005,7 @@ libxlStartup(int privileged) {
                                 &libxl_driver->domains,
                                 libxl_driver->configDir,
                                 libxl_driver->autostartDir,
-                                0, NULL, NULL) < 0)
+                                0, VIR_DOMAIN_VIRT_XEN, NULL, NULL) < 0)
         goto error;
 
     virHashForEach(libxl_driver->domains.objs, libxlAutostartDomain,
@@ -1037,7 +1038,7 @@ libxlReload(void)
                             &libxl_driver->domains,
                             libxl_driver->configDir,
                             libxl_driver->autostartDir,
-                            1, NULL, libxl_driver);
+                            1, VIR_DOMAIN_VIRT_XEN, NULL, libxl_driver);
 
     virHashForEach(libxl_driver->domains.objs, libxlAutostartDomain,
                    libxl_driver);
@@ -1206,7 +1207,7 @@ libxlDomainCreateXML(virConnectPtr conn, const char *xml,
     virCheckFlags(VIR_DOMAIN_START_PAUSED, NULL);
 
     libxlDriverLock(driver);
-    if (!(def = virDomainDefParseString(driver->caps, xml,
+    if (!(def = virDomainDefParseString(driver->caps, xml, VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
@@ -2566,7 +2567,8 @@ libxlDomainXMLToNative(virConnectPtr conn, const char * nativeFormat,
         goto cleanup;
     }
 
-    if (!(def = virDomainDefParseString(driver->caps, domainXml, 0)))
+    if (!(def = virDomainDefParseString(driver->caps, domainXml,
+                                        VIR_DOMAIN_VIRT_XEN, 0)))
         goto cleanup;
 
     if (!(conf = xenFormatXM(conn, def, ver_info->xen_version_major)))
@@ -2667,7 +2669,7 @@ libxlDomainDefineXML(virConnectPtr conn, const char *xml)
     int dupVM;
 
     libxlDriverLock(driver);
-    if (!(def = virDomainDefParseString(driver->caps, xml,
+    if (!(def = virDomainDefParseString(driver->caps, xml, 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..e9f709e 100644
--- a/src/lxc/lxc_controller.c
+++ b/src/lxc/lxc_controller.c
@@ -925,7 +925,7 @@ int main(int argc, char *argv[])
                                           name)) == NULL)
         goto cleanup;
 
-    if ((def = virDomainDefParseFile(caps, configFile,
+    if ((def = virDomainDefParseFile(caps, configFile, 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 ffcfe4d..e16cfc8 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -408,11 +408,11 @@ static virDomainPtr lxcDomainDefine(virConnectPtr conn, const char *xml)
     int dupVM;
 
     lxcDriverLock(driver);
-    if (!(def = virDomainDefParseString(driver->caps, xml,
+    if (!(def = virDomainDefParseString(driver->caps, xml, 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)) {
@@ -1750,7 +1750,7 @@ lxcDomainCreateAndStart(virConnectPtr conn,
     virCheckFlags(0, NULL);
 
     lxcDriverLock(driver);
-    if (!(def = virDomainDefParseString(driver->caps, xml,
+    if (!(def = virDomainDefParseString(driver->caps, xml, VIR_DOMAIN_VIRT_LXC,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
@@ -2138,7 +2138,7 @@ static int lxcStartup(int privileged)
                                 &lxc_driver->domains,
                                 lxc_driver->stateDir,
                                 NULL,
-                                1, NULL, NULL) < 0)
+                                1, VIR_DOMAIN_VIRT_LXC, NULL, NULL) < 0)
         goto cleanup;
 
     virHashForEach(lxc_driver->domains.objs, lxcReconnectVM, lxc_driver);
@@ -2148,7 +2148,7 @@ static int lxcStartup(int privileged)
                                 &lxc_driver->domains,
                                 lxc_driver->configDir,
                                 lxc_driver->autostartDir,
-                                0, NULL, NULL) < 0)
+                                0, VIR_DOMAIN_VIRT_LXC, NULL, NULL) < 0)
         goto cleanup;
 
     lxcDriverUnlock(lxc_driver);
@@ -2193,7 +2193,8 @@ lxcReload(void) {
                             &lxc_driver->domains,
                             lxc_driver->configDir,
                             lxc_driver->autostartDir,
-                            0, lxcNotifyLoadDomain, lxc_driver);
+                            0, 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 c13f346..82f4428 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,
+                                         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,
+                                         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 a9a9a21..b057b55 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,
+                                        VIR_DOMAIN_VIRT_PHYP,
                                         VIR_DOMAIN_XML_SECURE)))
         goto err;
 
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 4b65d87..0af26ab 100644
--- a/src/qemu/qemu_domain.c
+++ 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) {
+        qemuReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                        _("unexpected domain type %s"),
+                        virDomainVirtTypeToString(def->virtType));
+        virDomainDefFree(def);
+        def = NULL;
+    }
+
+    return def;
+}
 
 char *qemuDomainDefFormatXML(struct qemud_driver *driver,
                              virDomainDefPtr def,
-                             int flags)
+                             unsigned int flags)
 {
     char *ret = NULL;
     virCPUDefPtr cpu = NULL;
@@ -735,7 +757,7 @@ cleanup:
 
 char *qemuDomainFormatXML(struct qemud_driver *driver,
                           virDomainObjPtr vm,
-                          int flags)
+                          unsigned int flags)
 {
     virDomainDefPtr def;
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index f282df2..ca57ee8 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -125,13 +125,17 @@ void qemuDomainObjEnterRemoteWithDriver(struct qemud_driver *driver,
 void qemuDomainObjExitRemoteWithDriver(struct qemud_driver *driver,
                                        virDomainObjPtr obj);
 
+virDomainDefPtr qemuDomainDefParseXML(struct qemud_driver *driver,
+                                      const char *xml,
+                                      unsigned int flags);
+
 char *qemuDomainDefFormatXML(struct qemud_driver *driver,
                              virDomainDefPtr vm,
-                             int flags);
+                             unsigned int flags);
 
 char *qemuDomainFormatXML(struct qemud_driver *driver,
                           virDomainObjPtr vm,
-                          int flags);
+                          unsigned int flags);
 
 void qemuDomainObjTaint(struct qemud_driver *driver,
                         virDomainObjPtr obj,
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 52b7dfd..55bad8a 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -363,6 +363,19 @@ cleanup:
     virDomainObjUnlock(vm);
 }
 
+static void qemudNotifyLoadDomainCheckVirtType(virDomainObjPtr vm,
+                                               int newVM ATTRIBUTE_UNUSED,
+                                               void *opaque ATTRIBUTE_UNUSED)
+{
+    if (vm->def->virtType != VIR_DOMAIN_VIRT_QEMU &&
+        vm->def->virtType != VIR_DOMAIN_VIRT_KQEMU &&
+        vm->def->virtType != VIR_DOMAIN_VIRT_KVM &&
+        vm->def->virtType != VIR_DOMAIN_VIRT_XEN) {
+        VIR_ERROR(_("unexpected domain type %s"),
+                  virDomainVirtTypeToString(vm->def->virtType));
+    }
+}
+
 /**
  * qemudStartup:
  *
@@ -612,7 +625,8 @@ qemudStartup(int privileged) {
                                 &qemu_driver->domains,
                                 qemu_driver->stateDir,
                                 NULL,
-                                1, NULL, NULL) < 0)
+                                1, -1, qemudNotifyLoadDomainCheckVirtType,
+                                qemu_driver) < 0)
         goto error;
 
     conn = virConnectOpen(qemu_driver->privileged ?
@@ -626,7 +640,8 @@ qemudStartup(int privileged) {
                                 &qemu_driver->domains,
                                 qemu_driver->configDir,
                                 qemu_driver->autostartDir,
-                                0, NULL, NULL) < 0)
+                                0, -1, qemudNotifyLoadDomainCheckVirtType,
+                                qemu_driver) < 0)
         goto error;
 
 
@@ -663,6 +678,8 @@ static void qemudNotifyLoadDomain(virDomainObjPtr vm, int newVM, void *opaque)
 {
     struct qemud_driver *driver = opaque;
 
+    qemudNotifyLoadDomainCheckVirtType(vm, newVM, opaque);
+
     if (newVM) {
         virDomainEventPtr event =
             virDomainEventNewFromObj(vm,
@@ -689,7 +706,7 @@ qemudReload(void) {
                             &qemu_driver->domains,
                             qemu_driver->configDir,
                             qemu_driver->autostartDir,
-                            0, qemudNotifyLoadDomain, qemu_driver);
+                            0, -1, qemudNotifyLoadDomain, qemu_driver);
     qemuDriverUnlock(qemu_driver);
 
     qemuAutostartDomains(qemu_driver);
@@ -1251,8 +1268,7 @@ static virDomainPtr qemudDomainCreate(virConnectPtr conn, const char *xml,
                   VIR_DOMAIN_START_AUTODESTROY, NULL);
 
     qemuDriverLock(driver);
-    if (!(def = virDomainDefParseString(driver->caps, xml,
-                                        VIR_DOMAIN_XML_INACTIVE)))
+    if (!(def = qemuDomainDefParseXML(driver, xml, VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
     if (virSecurityManagerVerify(driver->securityManager, def) < 0)
@@ -3605,8 +3621,7 @@ qemuDomainSaveImageOpen(struct qemud_driver *driver,
     }
 
     /* Create a domain from this XML */
-    if (!(def = virDomainDefParseString(driver->caps, xml,
-                                        VIR_DOMAIN_XML_INACTIVE)))
+    if (!(def = qemuDomainDefParseXML(driver, xml, VIR_DOMAIN_XML_INACTIVE)))
         goto error;
 
     VIR_FREE(xml);
@@ -3923,7 +3938,7 @@ static char *qemuDomainXMLToNative(virConnectPtr conn,
         goto cleanup;
     }
 
-    def = virDomainDefParseString(driver->caps, xmlData, 0);
+    def = qemuDomainDefParseXML(driver, xmlData, 0);
     if (!def)
         goto cleanup;
 
@@ -4220,8 +4235,7 @@ static virDomainPtr qemudDomainDefine(virConnectPtr conn, const char *xml) {
     int dupVM;
 
     qemuDriverLock(driver);
-    if (!(def = virDomainDefParseString(driver->caps, xml,
-                                        VIR_DOMAIN_XML_INACTIVE)))
+    if (!(def = qemuDomainDefParseXML(driver, xml, VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
     if (virSecurityManagerVerify(driver->securityManager, def) < 0)
diff --git a/src/qemu/qemu_migration.c b/src/qemu/qemu_migration.c
index d7b27a0..1770a10 100644
--- a/src/qemu/qemu_migration.c
+++ b/src/qemu/qemu_migration.c
@@ -1018,8 +1018,8 @@ char *qemuMigrationBegin(struct qemud_driver *driver,
         goto cleanup;
 
     if (xmlin) {
-        if (!(def = virDomainDefParseString(driver->caps, xmlin,
-                                            VIR_DOMAIN_XML_INACTIVE)))
+        if (!(def = qemuDomainDefParseXML(driver, xmlin,
+                                          VIR_DOMAIN_XML_INACTIVE)))
             goto cleanup;
 
         if (!virDomainDefCheckABIStability(def, vm->def))
@@ -1077,8 +1077,8 @@ qemuMigrationPrepareTunnel(struct qemud_driver *driver,
         return -1;
 
     /* Parse the domain XML. */
-    if (!(def = virDomainDefParseString(driver->caps, dom_xml,
-                                        VIR_DOMAIN_XML_INACTIVE)))
+    if (!(def = qemuDomainDefParseXML(driver, dom_xml,
+                                      VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
     if (!qemuMigrationIsAllowed(def))
@@ -1312,8 +1312,8 @@ qemuMigrationPrepareDirect(struct qemud_driver *driver,
         VIR_DEBUG("Generated uri_out=%s", *uri_out);
 
     /* Parse the domain XML. */
-    if (!(def = virDomainDefParseString(driver->caps, dom_xml,
-                                        VIR_DOMAIN_XML_INACTIVE)))
+    if (!(def = qemuDomainDefParseXML(driver, dom_xml,
+                                      VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
     if (!qemuMigrationIsAllowed(def))
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 18f6a52..d228c99 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,
+                                           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,
+                                        VIR_DOMAIN_VIRT_TEST,
                                         VIR_DOMAIN_XML_INACTIVE);
             VIR_FREE(absFile);
             if (!def)
                 goto error;
         } else {
             if ((def = virDomainDefParseNode(privconn->caps, xml, domains[i],
+                                             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,
+                                       VIR_DOMAIN_VIRT_TEST,
                                        VIR_DOMAIN_XML_INACTIVE)) == NULL)
         goto cleanup;
 
@@ -1867,7 +1871,7 @@ static int testDomainRestore(virConnectPtr conn,
     xml[len] = '\0';
 
     testDriverLock(privconn);
-    def = virDomainDefParseString(privconn->caps, xml,
+    def = virDomainDefParseString(privconn->caps, xml, VIR_DOMAIN_VIRT_TEST,
                                   VIR_DOMAIN_XML_INACTIVE);
     if (!def)
         goto cleanup;
@@ -2416,6 +2420,7 @@ static virDomainPtr testDomainDefineXML(virConnectPtr conn,
 
     testDriverLock(privconn);
     if ((def = virDomainDefParseString(privconn->caps, xml,
+                                       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 f0f053b..43bd101 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -443,7 +443,7 @@ umlStartup(int privileged)
                                 &uml_driver->domains,
                                 uml_driver->configDir,
                                 uml_driver->autostartDir,
-                                0, NULL, NULL) < 0)
+                                0, VIR_DOMAIN_VIRT_UML, NULL, NULL) < 0)
         goto error;
 
     umlAutostartConfigs(uml_driver);
@@ -480,7 +480,7 @@ umlReload(void) {
                             &uml_driver->domains,
                             uml_driver->configDir,
                             uml_driver->autostartDir,
-                            0, NULL, NULL);
+                            0, VIR_DOMAIN_VIRT_UML, NULL, NULL);
 
     umlAutostartConfigs(uml_driver);
     umlDriverUnlock(uml_driver);
@@ -1272,7 +1272,7 @@ static virDomainPtr umlDomainCreate(virConnectPtr conn, const char *xml,
     virCheckFlags(0, NULL);
 
     umlDriverLock(driver);
-    if (!(def = virDomainDefParseString(driver->caps, xml,
+    if (!(def = virDomainDefParseString(driver->caps, xml, VIR_DOMAIN_VIRT_UML,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto cleanup;
 
@@ -1645,7 +1645,7 @@ static virDomainPtr umlDomainDefine(virConnectPtr conn, const char *xml) {
     virDomainPtr dom = NULL;
 
     umlDriverLock(driver);
-    if (!(def = virDomainDefParseString(driver->caps, xml,
+    if (!(def = virDomainDefParseString(driver->caps, xml, 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 37fe248..2cf08af 100644
--- a/src/vbox/vbox_tmpl.c
+++ b/src/vbox/vbox_tmpl.c
@@ -4802,7 +4802,7 @@ static virDomainPtr vboxDomainDefineXML(virConnectPtr conn, const char *xml) {
 #endif
     nsresult rc;
 
-    if (!(def = virDomainDefParseString(data->caps, xml,
+    if (!(def = virDomainDefParseString(data->caps, xml, 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 52582d6..faf0086 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,
+                                         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,
+                                         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 88febba..4886070 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,
+                                        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 d0eb32a0..71b64be 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,
+                                        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,
+                                        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 530b0d4..7d5af65 100644
--- a/src/xen/xm_internal.c
+++ b/src/xen/xm_internal.c
@@ -1105,7 +1105,7 @@ virDomainPtr xenXMDomainDefineXML(virConnectPtr conn, const char *xml)
         return (NULL);
     }
 
-    if (!(def = virDomainDefParseString(priv->caps, xml,
+    if (!(def = virDomainDefParseString(priv->caps, xml, 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 0a618ab..fed999b 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -516,7 +516,8 @@ xenapiDomainCreateXML (virConnectPtr conn,
 
     virCheckFlags(0, NULL);
 
-    virDomainDefPtr defPtr = virDomainDefParseString(caps, xmlDesc, flags);
+    virDomainDefPtr defPtr = virDomainDefParseString(caps, xmlDesc,
+                                                     VIR_DOMAIN_VIRT_XEN, flags);
     createVMRecordFromXml(conn, defPtr, &record, &vm);
     virDomainDefFree(defPtr);
     if (record) {
@@ -1635,9 +1636,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,
+                                                     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 ec1f4b5..1607387 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -50,10 +50,19 @@ static int testCompareXMLToArgvFiles(const char *xml,
     if (len && expectargv[len - 1] == '\n')
         expectargv[len - 1] = '\0';
 
-    if (!(vmdef = virDomainDefParseFile(driver.caps, xml,
+    if (!(vmdef = virDomainDefParseFile(driver.caps, xml, -1,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto fail;
 
+    if (vmdef->virtType != VIR_DOMAIN_VIRT_QEMU &&
+        vmdef->virtType != VIR_DOMAIN_VIRT_KQEMU &&
+        vmdef->virtType != VIR_DOMAIN_VIRT_KVM &&
+        vmdef->virtType != VIR_DOMAIN_VIRT_XEN) {
+        fprintf(stderr, "unexpected domain type %s",
+                virDomainVirtTypeToString(vmdef->virtType));
+        goto fail;
+    }
+
     /*
      * For test purposes, we may want to fake emulator's output by providing
      * our own script instead of a real emulator. For this to work we need to
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 2a3e75a..499796b 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -31,10 +31,19 @@ testCompareXMLToXMLFiles(const char *inxml, const char *outxml)
     if (virtTestLoadFile(outxml, &outXmlData) < 0)
         goto fail;
 
-    if (!(def = virDomainDefParseString(driver.caps, inXmlData,
-                                          VIR_DOMAIN_XML_INACTIVE)))
+    if (!(def = virDomainDefParseString(driver.caps, inXmlData, -1,
+                                        VIR_DOMAIN_XML_INACTIVE)))
         goto fail;
 
+    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) {
+        fprintf(stderr, "unexpected domain type %s",
+                virDomainVirtTypeToString(def->virtType));
+        goto fail;
+    }
+
     if (!(actual = virDomainDefFormat(def, VIR_DOMAIN_XML_SECURE)))
         goto fail;
 
diff --git a/tests/xmconfigtest.c b/tests/xmconfigtest.c
index a15a7ff..4bbce24 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, VIR_DOMAIN_VIRT_XEN,
                                         VIR_DOMAIN_XML_INACTIVE)))
         goto fail;
 
diff --git a/tests/xml2sexprtest.c b/tests/xml2sexprtest.c
index d8cdcbb..203e951 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, VIR_DOMAIN_VIRT_XEN,
                                       VIR_DOMAIN_XML_INACTIVE)))
       goto fail;
 
diff --git a/tests/xml2vmxtest.c b/tests/xml2vmxtest.c
index 66ed53d..5d0b899 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, VIR_DOMAIN_VIRT_VMWARE,
+                                  VIR_DOMAIN_XML_INACTIVE);
 
     if (def == NULL) {
         goto failure;
-- 
1.7.4.1

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list


[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]