]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
domain: conf: Use CapabilitiesDomainDataLookup for caps validation
authorCole Robinson <crobinso@redhat.com>
Fri, 17 Apr 2015 23:38:04 +0000 (19:38 -0400)
committerCole Robinson <crobinso@redhat.com>
Mon, 20 Apr 2015 20:43:13 +0000 (16:43 -0400)
The strange logic here is just to duplicate the previous behavior,
which parts of the test suite are currently relying on.

src/conf/capabilities.c
src/conf/capabilities.h
src/conf/domain_conf.c

index 234924b1c467b9e5b993dde65ae7c9a5c9f33624..f817ace986752f078d4423e0f03778b2889a42af 100644 (file)
@@ -729,74 +729,6 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps,
     return ret;
 }
 
-/**
- * virCapabilitiesSupportsGuestArch:
- * @caps: capabilities to query
- * @arch: Architecture to search for
- *
- * Returns non-zero if the capabilities support the
- * requested architecture
- */
-extern int
-virCapabilitiesSupportsGuestArch(virCapsPtr caps,
-                                 virArch arch)
-{
-    size_t i;
-    for (i = 0; i < caps->nguests; i++) {
-        if (caps->guests[i]->arch.id == arch)
-            return 1;
-    }
-    return 0;
-}
-
-
-/**
- * virCapabilitiesSupportsGuestOSType:
- * @caps: capabilities to query
- * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE
- *
- * Returns non-zero if the capabilities support the
- * requested operating system type
- */
-extern int
-virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
-                                   int ostype)
-{
-    size_t i;
-
-    for (i = 0; i < caps->nguests; i++) {
-        if (caps->guests[i]->ostype == ostype)
-            return 1;
-    }
-    return 0;
-}
-
-
-/**
- * virCapabilitiesSupportsGuestOSTypeArch:
- * @caps: capabilities to query
- * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE
- * @arch: Architecture to search for
- *
- * Returns non-zero if the capabilities support the
- * requested operating system type
- */
-extern int
-virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
-                                       int ostype,
-                                       virArch arch)
-{
-    size_t i;
-
-    for (i = 0; i < caps->nguests; i++) {
-        if (caps->guests[i]->ostype == ostype &&
-            caps->guests[i]->arch.id == arch)
-            return 1;
-    }
-    return 0;
-}
-
-
 /**
  * virCapabilitiesDefaultGuestArch:
  * @caps: capabilities to query
index 61cd84a0d6ad08d8dd27047959ce14251d7830d3..40221f4c586593edfdfa0544705e60b757d50fd1 100644 (file)
@@ -280,17 +280,6 @@ virCapabilitiesDomainDataLookup(virCapsPtr caps,
                                 const char *emulator,
                                 const char *machinetype);
 
-extern int
-virCapabilitiesSupportsGuestArch(virCapsPtr caps,
-                                 virArch arch);
-extern int
-virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
-                                   int ostype);
-extern int
-virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
-                                       int ostype,
-                                       virArch arch);
-
 void
 virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu,
                                             size_t ncpus);
index db0079ba0d7917ced14f23a3a482e1bdb2dc6d3c..4d9d4b5c4ac07bd2b2d84f7969a0ea19ab126ed7 100644 (file)
@@ -13729,51 +13729,28 @@ virDomainDefParseXML(xmlDocPtr xml,
     def->emulator = virXPathString("string(./devices/emulator[1])", ctxt);
 
     if (!(flags & VIR_DOMAIN_DEF_PARSE_SKIP_OSTYPE_CHECKS)) {
-        if (!virCapabilitiesSupportsGuestOSType(caps, def->os.type)) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("no support found for os <type> '%s'"),
-                           virDomainOSTypeToString(def->os.type));
-            goto error;
-        }
+        /* If the logic here seems fairly arbitrary, that's because it is :)
+         * This is duplicating how the code worked before
+         * CapabilitiesDomainDataLookup was added. We can simplify this,
+         * but it would take a bit of work because the test suite fails
+         * in numerous minor ways. */
+        bool use_virttype = ((def->os.arch == VIR_ARCH_NONE) ||
+            !def->os.machine);
+        virCapsDomainDataPtr capsdata = NULL;
 
-        if (def->os.arch) {
-            if (!virCapabilitiesSupportsGuestArch(caps, def->os.arch)) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("No guest options available for arch '%s'"),
-                               virArchToString(def->os.arch));
-                goto error;
-            }
-
-            if (!virCapabilitiesSupportsGuestOSTypeArch(caps,
-                                                        def->os.type,
-                                                        def->os.arch)) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("No os type '%s' available for arch '%s'"),
-                               virDomainOSTypeToString(def->os.type),
-                               virArchToString(def->os.arch));
-                goto error;
-            }
-        } else {
-            def->os.arch =
-                virCapabilitiesDefaultGuestArch(caps,
-                                                def->os.type,
-                                                def->virtType);
-            if (!def->os.arch) {
-                virReportError(VIR_ERR_INTERNAL_ERROR,
-                               _("no supported architecture for os type '%s'"),
-                               virDomainOSTypeToString(def->os.type));
-                goto error;
-            }
-        }
+        if (!(capsdata = virCapabilitiesDomainDataLookup(caps, def->os.type,
+                def->os.arch, use_virttype ? def->virtType : -1,
+                NULL, NULL)))
+            goto error;
 
-        if (!def->os.machine) {
-            const char *defaultMachine = virCapabilitiesDefaultGuestMachine(caps,
-                                                                            def->os.type,
-                                                                            def->os.arch,
-                                                                            def->virtType);
-            if (VIR_STRDUP(def->os.machine, defaultMachine) < 0)
-                goto error;
+        if (!def->os.arch)
+            def->os.arch = capsdata->arch;
+        if ((!def->os.machine &&
+             VIR_STRDUP(def->os.machine, capsdata->machinetype) < 0)) {
+            VIR_FREE(capsdata);
+            goto error;
         }
+        VIR_FREE(capsdata);
     }
 
     /* Extract domain name */