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

[libvirt] [PATCH] caps: Improve error if passed an unknown arch



Previously we would have:

"os type 'hvm' & arch 'idontexist' combination is not supported"

Now we get

"No guest options available for arch 'idontexist'"

or if options available but guest OS type not applicable:

"No os type 'xen' available for arch 'x86_64'"
---
 src/conf/capabilities.c |   28 ++++++++++++++++++++++++----
 src/conf/capabilities.h |    9 ++++++---
 src/conf/domain_conf.c  |   13 +++++++++++--
 3 files changed, 41 insertions(+), 9 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index d44ce1b..542bf03 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -497,6 +497,26 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest,
     return NULL;
 }
 
+/**
+ * virCapabilitiesSupportsGuestArch:
+ * @caps: capabilities to query
+ * @arch: Architecture to search for (eg, 'i686', 'x86_64')
+ *
+ * Returns non-zero if the capabilities support the
+ * requested architecture
+ */
+extern int
+virCapabilitiesSupportsGuestArch(virCapsPtr caps,
+                                 const char *arch)
+{
+    int i;
+    for (i = 0 ; i < caps->nguests ; i++) {
+        if (STREQ(caps->guests[i]->arch.name, arch))
+            return 1;
+    }
+    return 0;
+}
+
 
 /**
  * virCapabilitiesSupportsGuestOSType:
@@ -520,7 +540,7 @@ virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
 
 
 /**
- * virCapabilitiesSupportsGuestOSType:
+ * virCapabilitiesSupportsGuestOSTypeArch:
  * @caps: capabilities to query
  * @ostype: OS type to search for (eg 'hvm', 'xen')
  * @arch: Architecture to search for (eg, 'i686', 'x86_64')
@@ -529,9 +549,9 @@ virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
  * requested operating system type
  */
 extern int
-virCapabilitiesSupportsGuestArch(virCapsPtr caps,
-                                 const char *ostype,
-                                 const char *arch)
+virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
+                                       const char *ostype,
+                                       const char *arch)
 {
     int i;
     for (i = 0 ; i < caps->nguests ; i++) {
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 38d07c4..421030d 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -237,12 +237,15 @@ virCapabilitiesAddGuestFeature(virCapsGuestPtr guest,
                                int toggle);
 
 extern int
+virCapabilitiesSupportsGuestArch(virCapsPtr caps,
+                                 const char *arch);
+extern int
 virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
                                    const char *ostype);
 extern int
-virCapabilitiesSupportsGuestArch(virCapsPtr caps,
-                                 const char *ostype,
-                                 const char *arch);
+virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
+                                       const char *ostype,
+                                       const char *arch);
 
 
 extern const char *
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 85a2058..b0c3fa6 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -7581,9 +7581,18 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
     def->os.arch = virXPathString("string(./os/type[1]/@arch)", ctxt);
     if (def->os.arch) {
-        if (!virCapabilitiesSupportsGuestArch(caps, def->os.type, def->os.arch)) {
+        if (!virCapabilitiesSupportsGuestArch(caps, def->os.arch)) {
             virDomainReportError(VIR_ERR_INTERNAL_ERROR,
-                                 _("os type '%s' & arch '%s' combination is not supported"),
+                                 _("No guest options available for arch '%s'"),
+                                 def->os.arch);
+            goto error;
+        }
+
+        if (!virCapabilitiesSupportsGuestOSTypeArch(caps,
+                                                    def->os.type,
+                                                    def->os.arch)) {
+            virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+                                 _("No os type '%s' available for arch '%s'"),
                                  def->os.type, def->os.arch);
             goto error;
         }
-- 
1.7.7.5


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