]> xenbits.xensource.com Git - people/liuw/libxenctrl-split/libvirt.git/commitdiff
caps: Use an enum internally for ostype value
authorCole Robinson <crobinso@redhat.com>
Thu, 16 Apr 2015 23:18:32 +0000 (19:18 -0400)
committerCole Robinson <crobinso@redhat.com>
Mon, 20 Apr 2015 20:37:25 +0000 (16:37 -0400)
But the internal API stays the same, and we just convert the value as
needed. Not useful yet, but this is the beginning step of using an enum
for ostype throughout the code.

src/conf/capabilities.c
src/conf/capabilities.h
src/conf/domain_conf.c
src/conf/domain_conf.h
src/libvirt_private.syms
src/xenconfig/xen_xl.c

index b66c6ddbf51b633165f131a75c34d47157235d0f..acae41a8de1f2d072bb86486c01f5350680ceb4d 100644 (file)
@@ -32,6 +32,7 @@
 #include "cpu_conf.h"
 #include "virerror.h"
 #include "virstring.h"
+#include "domain_conf.h"
 
 #define VIR_FROM_THIS VIR_FROM_CAPABILITIES
 
@@ -155,8 +156,6 @@ virCapabilitiesFreeGuest(virCapsGuestPtr guest)
     if (guest == NULL)
         return;
 
-    VIR_FREE(guest->ostype);
-
     VIR_FREE(guest->arch.defaultInfo.emulator);
     VIR_FREE(guest->arch.defaultInfo.loader);
     for (i = 0; i < guest->arch.defaultInfo.nmachines; i++)
@@ -408,7 +407,7 @@ virCapabilitiesFreeMachines(virCapsGuestMachinePtr *machines,
  */
 virCapsGuestPtr
 virCapabilitiesAddGuest(virCapsPtr caps,
-                        const char *ostype,
+                        const char *ostypestr,
                         virArch arch,
                         const char *emulator,
                         const char *loader,
@@ -416,13 +415,18 @@ virCapabilitiesAddGuest(virCapsPtr caps,
                         virCapsGuestMachinePtr *machines)
 {
     virCapsGuestPtr guest;
+    int ostype;
 
     if (VIR_ALLOC(guest) < 0)
         goto error;
 
-    if (VIR_STRDUP(guest->ostype, ostype) < 0)
+    if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown OS type '%s'"), ostypestr);
         goto error;
+    }
 
+    guest->ostype = ostype;
     guest->arch.id = arch;
     guest->arch.wordsize = virArchGetWordSize(arch);
 
@@ -603,11 +607,19 @@ virCapabilitiesSupportsGuestArch(virCapsPtr caps,
  */
 extern int
 virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
-                                   const char *ostype)
+                                   const char *ostypestr)
 {
     size_t i;
+    int ostype;
+
+    if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown OS type '%s'"), ostypestr);
+        return 0;
+    }
+
     for (i = 0; i < caps->nguests; i++) {
-        if (STREQ(caps->guests[i]->ostype, ostype))
+        if (caps->guests[i]->ostype == ostype)
             return 1;
     }
     return 0;
@@ -625,12 +637,20 @@ virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
  */
 extern int
 virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
-                                       const char *ostype,
+                                       const char *ostypestr,
                                        virArch arch)
 {
     size_t i;
+    int ostype;
+
+    if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown OS type '%s'"), ostypestr);
+        return 0;
+    }
+
     for (i = 0; i < caps->nguests; i++) {
-        if (STREQ(caps->guests[i]->ostype, ostype) &&
+        if (caps->guests[i]->ostype == ostype &&
             caps->guests[i]->arch.id == arch)
             return 1;
     }
@@ -648,14 +668,21 @@ virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
  */
 extern virArch
 virCapabilitiesDefaultGuestArch(virCapsPtr caps,
-                                const char *ostype,
+                                const char *ostypestr,
                                 const char *domain)
 {
     size_t i, j;
+    int ostype;
+
+    if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown OS type '%s'"), ostypestr);
+        return VIR_ARCH_NONE;
+    }
 
     /* First try to find one matching host arch */
     for (i = 0; i < caps->nguests; i++) {
-        if (STREQ(caps->guests[i]->ostype, ostype)) {
+        if (caps->guests[i]->ostype == ostype) {
             for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
                 if (STREQ(caps->guests[i]->arch.domains[j]->type, domain) &&
                     caps->guests[i]->arch.id == caps->host.arch)
@@ -666,7 +693,7 @@ virCapabilitiesDefaultGuestArch(virCapsPtr caps,
 
     /* Otherwise find the first match */
     for (i = 0; i < caps->nguests; i++) {
-        if (STREQ(caps->guests[i]->ostype, ostype)) {
+        if (caps->guests[i]->ostype == ostype) {
             for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
                 if (STREQ(caps->guests[i]->arch.domains[j]->type, domain))
                     return caps->guests[i]->arch.id;
@@ -690,17 +717,24 @@ virCapabilitiesDefaultGuestArch(virCapsPtr caps,
  */
 extern const char *
 virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
-                                   const char *ostype,
+                                   const char *ostypestr,
                                    virArch arch,
                                    const char *domain)
 {
     size_t i;
+    int ostype;
+
+    if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown OS type '%s'"), ostypestr);
+        return NULL;
+    }
 
     for (i = 0; i < caps->nguests; i++) {
         virCapsGuestPtr guest = caps->guests[i];
         size_t j;
 
-        if (!STREQ(guest->ostype, ostype) ||
+        if (guest->ostype != ostype ||
             guest->arch.id != arch)
             continue;
 
@@ -736,14 +770,22 @@ virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
  */
 extern const char *
 virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
-                                    const char *ostype,
+                                    const char *ostypestr,
                                     virArch arch,
                                     const char *domain)
 {
     size_t i, j;
+    int ostype;
+
+    if ((ostype = virDomainOSTypeFromString(ostypestr)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown OS type '%s'"), ostypestr);
+        return NULL;
+    }
+
     for (i = 0; i < caps->nguests; i++) {
         char *emulator;
-        if (STREQ(caps->guests[i]->ostype, ostype) &&
+        if (caps->guests[i]->ostype == ostype &&
             caps->guests[i]->arch.id == arch) {
             emulator = caps->guests[i]->arch.defaultInfo.emulator;
             for (j = 0; j < caps->guests[i]->arch.ndomains; j++) {
@@ -944,7 +986,7 @@ virCapabilitiesFormatXML(virCapsPtr caps)
         virBufferAddLit(&buf, "<guest>\n");
         virBufferAdjustIndent(&buf, 2);
         virBufferAsprintf(&buf, "<os_type>%s</os_type>\n",
-                          caps->guests[i]->ostype);
+                          virDomainOSTypeToString(caps->guests[i]->ostype));
         if (caps->guests[i]->arch.id)
             virBufferAsprintf(&buf, "<arch name='%s'>\n",
                               virArchToString(caps->guests[i]->arch.id));
index 476debaa0f7614e4323c2bd0739f0fce84eb36ae..fc852ac9b663f109105d953f3938bab343fe5d8d 100644 (file)
@@ -79,7 +79,7 @@ struct _virCapsGuestArch {
 typedef struct _virCapsGuest virCapsGuest;
 typedef virCapsGuest *virCapsGuestPtr;
 struct _virCapsGuest {
-    char *ostype;
+    int ostype;
     virCapsGuestArch arch;
     size_t nfeatures;
     size_t nfeatures_max;
index 860c9501ca60e0b436aece84bafebdf4e178a17c..8731fc1f9cd1ba875590d7b533f1102bb204d991 100644 (file)
@@ -122,6 +122,14 @@ VIR_ENUM_IMPL(virDomainVirt, VIR_DOMAIN_VIRT_LAST,
               "parallels",
               "bhyve")
 
+VIR_ENUM_IMPL(virDomainOS, VIR_DOMAIN_OSTYPE_LAST,
+              "hvm",
+              "xen",
+              "linux",
+              "exe",
+              "uml",
+              "aix")
+
 VIR_ENUM_IMPL(virDomainBoot, VIR_DOMAIN_BOOT_LAST,
               "fd",
               "cdrom",
index 30456524bba69256f345b6a52a8c89a1ed9d7175..6dc9918f97ddb50df448af4df194d95dfe21a6f9 100644 (file)
@@ -227,6 +227,19 @@ typedef enum {
     VIR_DOMAIN_VIRT_LAST
 } virDomainVirtType;
 
+typedef enum {
+    VIR_DOMAIN_OSTYPE_HVM,
+    VIR_DOMAIN_OSTYPE_XEN,
+    VIR_DOMAIN_OSTYPE_LINUX,
+    VIR_DOMAIN_OSTYPE_EXE,
+    VIR_DOMAIN_OSTYPE_UML,
+    VIR_DOMAIN_OSTYPE_AIX,
+
+    VIR_DOMAIN_OSTYPE_LAST
+} virDomainOSType;
+VIR_ENUM_DECL(virDomainOS)
+
+
 typedef enum {
     VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE,
     VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI,
index 8c3730399b995dfcdb67bb2e2c64f4fcc885a1da..a587597fbb00db4a696462df9a789dcb6dd3aeed 100644 (file)
@@ -400,6 +400,8 @@ virDomainObjSetDefTransient;
 virDomainObjSetMetadata;
 virDomainObjSetState;
 virDomainObjTaint;
+virDomainOSTypeFromString;
+virDomainOSTypeToString;
 virDomainParseMemory;
 virDomainPausedReasonTypeFromString;
 virDomainPausedReasonTypeToString;
index b5725875ca2f2fc29088942fe03deb6e0b929120..62284f79212f862a1598ccd7a77087582deac290 100644 (file)
@@ -68,7 +68,7 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
         const char *boot;
 
         for (i = 0; i < caps->nguests; i++) {
-            if (STREQ(caps->guests[i]->ostype, "hvm") &&
+            if (caps->guests[i]->ostype == VIR_DOMAIN_OSTYPE_HVM &&
                 caps->guests[i]->arch.id == def->os.arch) {
                 if (VIR_ALLOC(def->os.loader) < 0 ||
                     VIR_STRDUP(def->os.loader->path,