[libvirt] [PATCH 05/11] domain: Convert os.type to VIR_DOMAIN_OSTYPE enum

Cole Robinson crobinso at redhat.com
Sat Apr 18 01:45:15 UTC 2015


---
 src/conf/capabilities.c          |  55 ++++---------------
 src/conf/capabilities.h          |  10 ++--
 src/conf/domain_audit.c          |   2 +-
 src/conf/domain_conf.c           | 115 +++++++++++++++++++--------------------
 src/conf/domain_conf.h           |   2 +-
 src/hyperv/hyperv_driver.c       |   4 +-
 src/libvirt_private.syms         |   2 +
 src/libxl/libxl_conf.c           |  10 ++--
 src/libxl/libxl_domain.c         |   6 +-
 src/libxl/libxl_driver.c         |   2 +-
 src/lxc/lxc_driver.c             |   2 +-
 src/lxc/lxc_native.c             |   4 +-
 src/openvz/openvz_conf.c         |   3 +-
 src/openvz/openvz_driver.c       |   4 +-
 src/parallels/parallels_driver.c |   8 +--
 src/parallels/parallels_sdk.c    |   6 +-
 src/parallels/parallels_utils.h  |   2 +-
 src/phyp/phyp_driver.c           |   3 +-
 src/qemu/qemu_capabilities.c     |   2 +-
 src/qemu/qemu_command.c          |  10 ++--
 src/qemu/qemu_driver.c           |   2 +-
 src/uml/uml_driver.c             |   2 +-
 src/vbox/vbox_common.c           |  15 ++---
 src/vmware/vmware_driver.c       |   2 +-
 src/vmx/vmx.c                    |   3 +-
 src/xen/xen_driver.c             |   2 +-
 src/xen/xend_internal.c          |   6 +-
 src/xenapi/xenapi_driver.c       |  12 +---
 src/xenapi/xenapi_utils.c        |   4 +-
 src/xenconfig/xen_common.c       |  29 +++++-----
 src/xenconfig/xen_sxpr.c         |   5 +-
 src/xenconfig/xen_xl.c           |  15 ++---
 src/xenconfig/xen_xm.c           |  12 ++--
 tests/openvzutilstest.c          |   2 +-
 34 files changed, 152 insertions(+), 211 deletions(-)

diff --git a/src/conf/capabilities.c b/src/conf/capabilities.c
index a8b098a..deae472 100644
--- a/src/conf/capabilities.c
+++ b/src/conf/capabilities.c
@@ -593,23 +593,16 @@ virCapabilitiesSupportsGuestArch(virCapsPtr caps,
 /**
  * virCapabilitiesSupportsGuestOSType:
  * @caps: capabilities to query
- * @ostype: OS type to search for (eg 'hvm', 'xen')
+ * @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,
-                                   const char *ostypestr)
+                                   int ostype)
 {
     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 (caps->guests[i]->ostype == ostype)
@@ -622,7 +615,7 @@ virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
 /**
  * virCapabilitiesSupportsGuestOSTypeArch:
  * @caps: capabilities to query
- * @ostype: OS type to search for (eg 'hvm', 'xen')
+ * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE
  * @arch: Architecture to search for
  *
  * Returns non-zero if the capabilities support the
@@ -630,17 +623,10 @@ virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
  */
 extern int
 virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
-                                       const char *ostypestr,
+                                       int ostype,
                                        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 (caps->guests[i]->ostype == ostype &&
@@ -654,24 +640,17 @@ virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
 /**
  * virCapabilitiesDefaultGuestArch:
  * @caps: capabilities to query
- * @ostype: OS type to search for
+ * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE
  *
  * Returns the first architecture able to run the
  * requested operating system type
  */
 extern virArch
 virCapabilitiesDefaultGuestArch(virCapsPtr caps,
-                                const char *ostypestr,
+                                int ostype,
                                 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++) {
@@ -700,7 +679,7 @@ virCapabilitiesDefaultGuestArch(virCapsPtr caps,
 /**
  * virCapabilitiesDefaultGuestMachine:
  * @caps: capabilities to query
- * @ostype: OS type to search for
+ * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE
  * @arch: architecture to search for
  * @domain: domain type to search for
  *
@@ -710,18 +689,11 @@ virCapabilitiesDefaultGuestArch(virCapsPtr caps,
  */
 extern const char *
 virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
-                                   const char *ostypestr,
+                                   int ostype,
                                    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];
@@ -753,7 +725,7 @@ virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
 /**
  * virCapabilitiesDefaultGuestEmulator:
  * @caps: capabilities to query
- * @ostype: OS type to search for ('xen', 'hvm')
+ * @ostype: guest operating system type, of enum VIR_DOMAIN_OSTYPE
  * @arch: architecture to search for
  * @domain: domain type ('xen', 'qemu', 'kvm')
  *
@@ -763,18 +735,11 @@ virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
  */
 extern const char *
 virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
-                                    const char *ostypestr,
+                                    int ostype,
                                     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;
diff --git a/src/conf/capabilities.h b/src/conf/capabilities.h
index 9312cc2..8969a97 100644
--- a/src/conf/capabilities.h
+++ b/src/conf/capabilities.h
@@ -267,10 +267,10 @@ virCapabilitiesSupportsGuestArch(virCapsPtr caps,
                                  virArch arch);
 extern int
 virCapabilitiesSupportsGuestOSType(virCapsPtr caps,
-                                   const char *ostype);
+                                   int ostype);
 extern int
 virCapabilitiesSupportsGuestOSTypeArch(virCapsPtr caps,
-                                       const char *ostype,
+                                       int ostype,
                                        virArch arch);
 
 void
@@ -279,16 +279,16 @@ virCapabilitiesClearHostNUMACellCPUTopology(virCapsHostNUMACellCPUPtr cpu,
 
 extern virArch
 virCapabilitiesDefaultGuestArch(virCapsPtr caps,
-                                const char *ostype,
+                                int ostype,
                                 const char *domain);
 extern const char *
 virCapabilitiesDefaultGuestMachine(virCapsPtr caps,
-                                   const char *ostype,
+                                   int ostype,
                                    virArch arch,
                                    const char *domain);
 extern const char *
 virCapabilitiesDefaultGuestEmulator(virCapsPtr caps,
-                                    const char *ostype,
+                                    int ostype,
                                     virArch arch,
                                     const char *domain);
 
diff --git a/src/conf/domain_audit.c b/src/conf/domain_audit.c
index 159ebf5..3e93d97 100644
--- a/src/conf/domain_audit.c
+++ b/src/conf/domain_audit.c
@@ -859,7 +859,7 @@ virDomainAuditStart(virDomainObjPtr vm, const char *reason, bool success)
         if (i == 0 &&
             (vm->def->consoles[i]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ||
              vm->def->consoles[i]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) &&
-             STREQ_NULLABLE(vm->def->os.type, "hvm"))
+             vm->def->os.type == VIR_DOMAIN_OSTYPE_HVM)
             continue;
 
         virDomainAuditChardev(vm, NULL, vm->def->consoles[i], "start", true);
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8731fc1..727d060 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2276,7 +2276,6 @@ void virDomainDefFree(virDomainDefPtr def)
     VIR_FREE(def->idmap.uidmap);
     VIR_FREE(def->idmap.gidmap);
 
-    VIR_FREE(def->os.type);
     VIR_FREE(def->os.machine);
     VIR_FREE(def->os.init);
     for (i = 0; def->os.initargv && def->os.initargv[i]; i++)
@@ -3065,7 +3064,7 @@ virDomainDeviceInfoIterateInternal(virDomainDefPtr def,
             i == 0 &&
             (def->consoles[i]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ||
              def->consoles[i]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) &&
-             STREQ_NULLABLE(def->os.type, "hvm"))
+             def->os.type == VIR_DOMAIN_OSTYPE_HVM)
             continue;
         device.data.chr = def->consoles[i];
         if (cb(def, &device, &def->consoles[i]->info, opaque) < 0)
@@ -3299,14 +3298,8 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
 {
     size_t i;
 
-    if (!def->os.type) {
-        virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
-                       _("hypervisor type must be specified"));
-        return -1;
-    }
-
     /* verify init path for container based domains */
-    if (STREQ(def->os.type, "exe") && !def->os.init) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_EXE && !def->os.init) {
         virReportError(VIR_ERR_XML_ERROR, "%s",
                        _("init binary must be specified"));
         return -1;
@@ -3384,7 +3377,7 @@ virDomainDefPostParseInternal(virDomainDefPtr def,
             return -1;
         }
     }
-    if (def->nconsoles > 0 && STREQ(def->os.type, "hvm") &&
+    if (def->nconsoles > 0 && def->os.type == VIR_DOMAIN_OSTYPE_HVM &&
         (def->consoles[0]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ||
          def->consoles[0]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE)) {
 
@@ -9451,7 +9444,7 @@ virDomainInputDefParseXML(const virDomainDef *dom,
             goto error;
         }
 
-        if (STREQ(dom->os.type, "hvm")) {
+        if (dom->os.type == VIR_DOMAIN_OSTYPE_HVM) {
             if (def->bus == VIR_DOMAIN_INPUT_BUS_PS2 &&
                 def->type != VIR_DOMAIN_INPUT_TYPE_MOUSE &&
                 def->type != VIR_DOMAIN_INPUT_TYPE_KBD) {
@@ -9466,7 +9459,7 @@ virDomainInputDefParseXML(const virDomainDef *dom,
                                bus);
                 goto error;
             }
-        } else if (STREQ(dom->os.type, "xen")) {
+        } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN) {
             if (def->bus != VIR_DOMAIN_INPUT_BUS_XEN) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("unsupported input bus %s"),
@@ -9506,7 +9499,7 @@ virDomainInputDefParseXML(const virDomainDef *dom,
             }
         }
     } else {
-        if (STREQ(dom->os.type, "hvm")) {
+        if (dom->os.type == VIR_DOMAIN_OSTYPE_HVM) {
             if ((def->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
                 def->type == VIR_DOMAIN_INPUT_TYPE_KBD) &&
                 (ARCH_IS_X86(dom->os.arch) || dom->os.arch == VIR_ARCH_NONE)) {
@@ -9514,7 +9507,7 @@ virDomainInputDefParseXML(const virDomainDef *dom,
             } else {
                 def->bus = VIR_DOMAIN_INPUT_BUS_USB;
             }
-        } else if (STREQ(dom->os.type, "xen")) {
+        } else if (dom->os.type == VIR_DOMAIN_OSTYPE_XEN) {
             def->bus = VIR_DOMAIN_INPUT_BUS_XEN;
         } else {
             if ((dom->virtType == VIR_DOMAIN_VIRT_PARALLELS))
@@ -10989,9 +10982,8 @@ virDomainVideoDefaultType(const virDomainDef *def)
     case VIR_DOMAIN_VIRT_KQEMU:
     case VIR_DOMAIN_VIRT_KVM:
     case VIR_DOMAIN_VIRT_XEN:
-        if (def->os.type &&
-            (STREQ(def->os.type, "xen") ||
-             STREQ(def->os.type, "linux")))
+        if (def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+            def->os.type == VIR_DOMAIN_OSTYPE_LINUX)
             return VIR_DOMAIN_VIDEO_TYPE_XEN;
         else if ARCH_IS_PPC64(def->os.arch)
             return VIR_DOMAIN_VIDEO_TYPE_VGA;
@@ -11005,15 +10997,10 @@ virDomainVideoDefaultType(const virDomainDef *def)
         return VIR_DOMAIN_VIDEO_TYPE_VMVGA;
 
     case VIR_DOMAIN_VIRT_PARALLELS:
-        if (def->os.type) {
-            if (STREQ(def->os.type, "hvm"))
-                return VIR_DOMAIN_VIDEO_TYPE_VGA;
-            else
-                return VIR_DOMAIN_VIDEO_TYPE_PARALLELS;
-        } else {
+        if (def->os.type == VIR_DOMAIN_OSTYPE_HVM)
             return VIR_DOMAIN_VIDEO_TYPE_VGA;
-        }
-
+        else
+            return VIR_DOMAIN_VIDEO_TYPE_PARALLELS;
     default:
         return -1;
     }
@@ -12992,7 +12979,8 @@ virDomainDefGetDefaultEmulator(virDomainDefPtr def,
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("no emulator for domain %s os type %s "
                          "on architecture %s"),
-                       type, def->os.type, virArchToString(def->os.arch));
+                       type, virDomainOSTypeToString(def->os.type),
+                       virArchToString(def->os.arch));
         return NULL;
     }
 
@@ -14640,27 +14628,32 @@ virDomainDefParseXML(xmlDocPtr xml,
     def->os.bootloader = virXPathString("string(./bootloader)", ctxt);
     def->os.bootloaderArgs = virXPathString("string(./bootloader_args)", ctxt);
 
-    def->os.type = virXPathString("string(./os/type[1])", ctxt);
-    if (!def->os.type) {
+    tmp = virXPathString("string(./os/type[1])", ctxt);
+    if (!tmp) {
         if (def->os.bootloader) {
-            if (VIR_STRDUP(def->os.type, "xen") < 0)
-                goto error;
+            def->os.type = VIR_DOMAIN_OSTYPE_XEN;
         } else {
             virReportError(VIR_ERR_XML_ERROR, "%s",
                            _("an os <type> must be specified"));
             goto error;
         }
+    } else {
+        if ((def->os.type = virDomainOSTypeFromString(tmp)) < 0) {
+            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                           _("unknown OS type '%s'"), tmp);
+            goto error;
+        }
+        VIR_FREE(tmp);
     }
+
     /*
      * HACK: For xen driver we previously used bogus 'linux' as the
      * os type for paravirt, whereas capabilities declare it to
      * be 'xen'. So we accept the former and convert
      */
-    if (STREQ(def->os.type, "linux") &&
+    if (def->os.type == VIR_DOMAIN_OSTYPE_LINUX &&
         def->virtType == VIR_DOMAIN_VIRT_XEN) {
-        VIR_FREE(def->os.type);
-        if (VIR_STRDUP(def->os.type, "xen") < 0)
-            goto error;
+        def->os.type = VIR_DOMAIN_OSTYPE_XEN;
     }
 
     tmp = virXPathString("string(./os/type[1]/@arch)", ctxt);
@@ -14678,7 +14671,7 @@ virDomainDefParseXML(xmlDocPtr xml,
         if (!virCapabilitiesSupportsGuestOSType(caps, def->os.type)) {
             virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                            _("no support found for os <type> '%s'"),
-                           def->os.type);
+                           virDomainOSTypeToString(def->os.type));
             goto error;
         }
 
@@ -14695,7 +14688,8 @@ virDomainDefParseXML(xmlDocPtr xml,
                                                         def->os.arch)) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("No os type '%s' available for arch '%s'"),
-                               def->os.type, virArchToString(def->os.arch));
+                               virDomainOSTypeToString(def->os.type),
+                               virArchToString(def->os.arch));
                 goto error;
             }
         } else {
@@ -14706,7 +14700,7 @@ virDomainDefParseXML(xmlDocPtr xml,
             if (!def->os.arch) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("no supported architecture for os type '%s'"),
-                               def->os.type);
+                               virDomainOSTypeToString(def->os.type));
                 goto error;
             }
         }
@@ -14731,7 +14725,7 @@ virDomainDefParseXML(xmlDocPtr xml,
      *   - An init script                             (exe)
      */
 
-    if (STREQ(def->os.type, "exe")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) {
         def->os.init = virXPathString("string(./os/init[1])", ctxt);
         def->os.cmdline = virXPathString("string(./os/cmdline[1])", ctxt);
 
@@ -14755,9 +14749,9 @@ virDomainDefParseXML(xmlDocPtr xml,
         VIR_FREE(nodes);
     }
 
-    if (STREQ(def->os.type, "xen") ||
-        STREQ(def->os.type, "hvm") ||
-        STREQ(def->os.type, "uml")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+        def->os.type == VIR_DOMAIN_OSTYPE_HVM ||
+        def->os.type == VIR_DOMAIN_OSTYPE_UML) {
         xmlNodePtr loader_node;
 
         def->os.kernel = virXPathString("string(./os/kernel[1])", ctxt);
@@ -14777,7 +14771,7 @@ virDomainDefParseXML(xmlDocPtr xml,
         }
     }
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (virDomainDefParseBootXML(ctxt, def) < 0)
             goto error;
         if (!(bootHash = virHashCreate(5, NULL)))
@@ -15055,15 +15049,15 @@ virDomainDefParseXML(xmlDocPtr xml,
         /* With QEMU / KVM / Xen graphics, mouse + PS/2 is implicit
          * with graphics, so don't store it.
          * XXX will this be true for other virt types ? */
-        if ((STREQ(def->os.type, "hvm") &&
+        if ((def->os.type == VIR_DOMAIN_OSTYPE_HVM &&
              input->bus == VIR_DOMAIN_INPUT_BUS_PS2 &&
              (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
               input->type == VIR_DOMAIN_INPUT_TYPE_KBD)) ||
-            (STREQ(def->os.type, "xen") &&
+            (def->os.type == VIR_DOMAIN_OSTYPE_XEN &&
              input->bus == VIR_DOMAIN_INPUT_BUS_XEN &&
              (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
               input->type == VIR_DOMAIN_INPUT_TYPE_KBD)) ||
-            (STREQ(def->os.type, "exe") &&
+            (def->os.type == VIR_DOMAIN_OSTYPE_EXE &&
              def->virtType == VIR_DOMAIN_VIRT_PARALLELS &&
              input->bus == VIR_DOMAIN_INPUT_BUS_PARALLELS &&
              (input->type == VIR_DOMAIN_INPUT_TYPE_MOUSE ||
@@ -15097,9 +15091,9 @@ virDomainDefParseXML(xmlDocPtr xml,
         (ARCH_IS_X86(def->os.arch) || def->os.arch == VIR_ARCH_NONE)) {
         int input_bus = VIR_DOMAIN_INPUT_BUS_XEN;
 
-        if (STREQ(def->os.type, "hvm"))
+        if (def->os.type == VIR_DOMAIN_OSTYPE_HVM)
             input_bus = VIR_DOMAIN_INPUT_BUS_PS2;
-        if (STREQ(def->os.type, "exe") &&
+        if (def->os.type == VIR_DOMAIN_OSTYPE_EXE &&
             def->virtType == VIR_DOMAIN_VIRT_PARALLELS)
             input_bus = VIR_DOMAIN_INPUT_BUS_PARALLELS;
 
@@ -16795,10 +16789,11 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
         goto error;
     }
 
-    if (STRNEQ(src->os.type, dst->os.type)) {
+    if (src->os.type != dst->os.type) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Target domain OS type %s does not match source %s"),
-                       dst->os.type, src->os.type);
+                       virDomainOSTypeToString(dst->os.type),
+                       virDomainOSTypeToString(src->os.type));
         goto error;
     }
     if (src->os.arch != dst->os.arch) {
@@ -16810,8 +16805,8 @@ virDomainDefCheckABIStability(virDomainDefPtr src,
     }
     if (STRNEQ_NULLABLE(src->os.machine, dst->os.machine)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("Target domain OS type %s does not match source %s"),
-                       dst->os.machine, src->os.machine);
+                    _("Target domain machine type %s does not match source %s"),
+                    dst->os.machine, src->os.machine);
         goto error;
     }
 
@@ -20819,10 +20814,12 @@ virDomainDefFormatInternal(virDomainDefPtr def,
      * be 'xen'. So we convert to the former for backcompat
      */
     if (def->virtType == VIR_DOMAIN_VIRT_XEN &&
-        STREQ(def->os.type, "xen"))
-        virBufferAsprintf(buf, ">%s</type>\n", "linux");
+        def->os.type == VIR_DOMAIN_OSTYPE_XEN)
+        virBufferAsprintf(buf, ">%s</type>\n",
+                          virDomainOSTypeToString(VIR_DOMAIN_OSTYPE_LINUX));
     else
-        virBufferAsprintf(buf, ">%s</type>\n", def->os.type);
+        virBufferAsprintf(buf, ">%s</type>\n",
+                          virDomainOSTypeToString(def->os.type));
 
     virBufferEscapeString(buf, "<init>%s</init>\n",
                           def->os.init);
@@ -21194,7 +21191,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         /* Back compat, ignore the console element for hvm guests
          * if it is type == serial
          */
-        if (STREQ(def->os.type, "hvm") &&
+        if (def->os.type == VIR_DOMAIN_OSTYPE_HVM &&
             (def->consoles[n]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_SERIAL ||
              def->consoles[n]->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE) &&
             (n < def->nserials)) {
@@ -21207,7 +21204,7 @@ virDomainDefFormatInternal(virDomainDefPtr def,
         if (virDomainChrDefFormat(buf, &console, flags) < 0)
             goto error;
     }
-    if (STREQ(def->os.type, "hvm") &&
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM &&
         def->nconsoles == 0 &&
         def->nserials > 0) {
         virDomainChrDef console;
@@ -21240,9 +21237,9 @@ virDomainDefFormatInternal(virDomainDefPtr def,
                 .info = { .alias = NULL },
             };
 
-            if (STREQ(def->os.type, "hvm"))
+            if (def->os.type == VIR_DOMAIN_OSTYPE_HVM)
                 autoInput.bus = VIR_DOMAIN_INPUT_BUS_PS2;
-            else if (STREQ(def->os.type, "exe") &&
+            else if (def->os.type == VIR_DOMAIN_OSTYPE_EXE &&
                      def->virtType == VIR_DOMAIN_VIRT_PARALLELS)
                 autoInput.bus = VIR_DOMAIN_INPUT_BUS_PARALLELS;
             else
@@ -21479,7 +21476,7 @@ virDomainDefCompatibleDevice(virDomainDefPtr def,
         return 0;
 
     if (!virDomainDefHasUSB(def) &&
-        STRNEQ(def->os.type, "exe") &&
+        def->os.type != VIR_DOMAIN_OSTYPE_EXE &&
         virDomainDeviceIsUSB(dev)) {
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("Device configuration is not compatible: "
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 6dc9918..3c99019 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1783,7 +1783,7 @@ void virDomainLoaderDefFree(virDomainLoaderDefPtr loader);
 typedef struct _virDomainOSDef virDomainOSDef;
 typedef virDomainOSDef *virDomainOSDefPtr;
 struct _virDomainOSDef {
-    char *type;
+    int type;
     virArch arch;
     char *machine;
     size_t nBootDevs;
diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c
index 00169c7..b539541 100644
--- a/src/hyperv/hyperv_driver.c
+++ b/src/hyperv/hyperv_driver.c
@@ -875,9 +875,7 @@ hypervDomainGetXMLDesc(virDomainPtr domain, unsigned int flags)
 
     def->vcpus = processorSettingData->data->VirtualQuantity;
     def->maxvcpus = processorSettingData->data->VirtualQuantity;
-
-    if (VIR_STRDUP(def->os.type, "hvm") < 0)
-        goto cleanup;
+    def->os.type = VIR_DOMAIN_OSTYPE_HVM;
 
     /* FIXME: devices section is totally missing */
 
diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
index 8c37303..a587597 100644
--- a/src/libvirt_private.syms
+++ b/src/libvirt_private.syms
@@ -400,6 +400,8 @@ virDomainObjSetDefTransient;
 virDomainObjSetMetadata;
 virDomainObjSetState;
 virDomainObjTaint;
+virDomainOSTypeFromString;
+virDomainOSTypeToString;
 virDomainParseMemory;
 virDomainPausedReasonTypeFromString;
 virDomainPausedReasonTypeToString;
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 0609fdd..322dd56 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -499,7 +499,7 @@ libxlMakeDomCreateInfo(libxl_ctx *ctx,
 
     libxl_domain_create_info_init(c_info);
 
-    if (STREQ(def->os.type, "hvm"))
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM)
         c_info->type = LIBXL_DOMAIN_TYPE_HVM;
     else
         c_info->type = LIBXL_DOMAIN_TYPE_PV;
@@ -625,7 +625,7 @@ libxlMakeDomBuildInfo(virDomainDefPtr def,
                       libxl_domain_config *d_config)
 {
     libxl_domain_build_info *b_info = &d_config->b_info;
-    int hvm = STREQ(def->os.type, "hvm");
+    int hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
     size_t i;
 
     libxl_domain_build_info_init(b_info);
@@ -875,7 +875,7 @@ libxlDomainGetEmulatorType(const virDomainDef *def)
     virCommandPtr cmd = NULL;
     char *output = NULL;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (def->emulator) {
             cmd = virCommandNew(def->emulator);
 
@@ -1070,7 +1070,7 @@ libxlMakeNic(virDomainDefPtr def,
              virDomainNetDefPtr l_nic,
              libxl_device_nic *x_nic)
 {
-    bool ioemu_nic = STREQ(def->os.type, "hvm");
+    bool ioemu_nic = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
     virDomainNetType actual_type = virDomainNetGetActualType(l_nic);
 
     /* TODO: Where is mtu stored?
@@ -1309,7 +1309,7 @@ libxlMakeVfbList(virPortAllocatorPtr graphicsports,
      * VNC or SDL info must also be set in libxl_domain_build_info
      * for HVM domains.  Use the first vfb device.
      */
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         libxl_domain_build_info *b_info = &d_config->b_info;
         libxl_device_vfb vfb = d_config->vfbs[0];
 
diff --git a/src/libxl/libxl_domain.c b/src/libxl/libxl_domain.c
index 77d46d0..f33df42 100644
--- a/src/libxl/libxl_domain.c
+++ b/src/libxl/libxl_domain.c
@@ -235,7 +235,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
     if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
         dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
         dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE &&
-        STRNEQ(def->os.type, "hvm"))
+        def->os.type != VIR_DOMAIN_OSTYPE_HVM)
         dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
 
     if (dev->type == VIR_DOMAIN_DEVICE_NET &&
@@ -278,7 +278,7 @@ libxlDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
             pcisrc->backend = VIR_DOMAIN_HOSTDEV_PCI_BACKEND_XEN;
     }
 
-    if (dev->type == VIR_DOMAIN_DEVICE_VIDEO && STREQ(def->os.type, "hvm")) {
+    if (dev->type == VIR_DOMAIN_DEVICE_VIDEO && def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         int dm_type = libxlDomainGetEmulatorType(def);
 
         switch (dev->data.video->type) {
@@ -315,7 +315,7 @@ libxlDomainDefPostParse(virDomainDefPtr def,
 {
     /* Xen PV domains always have a PV console, so add one to the domain config
      * via post-parse callback if not explicitly specified in the XML. */
-    if (STRNEQ(def->os.type, "hvm") && def->nconsoles == 0) {
+    if (def->os.type != VIR_DOMAIN_OSTYPE_HVM && def->nconsoles == 0) {
         virDomainChrDefPtr chrdef;
 
         if (!(chrdef = virDomainChrDefNew()))
diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c
index 9eb071e..1271149 100644
--- a/src/libxl/libxl_driver.c
+++ b/src/libxl/libxl_driver.c
@@ -1295,7 +1295,7 @@ libxlDomainGetOSType(virDomainPtr dom)
     if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    if (VIR_STRDUP(type, vm->def->os.type) < 0)
+    if (VIR_STRDUP(type, virDomainOSTypeToString(vm->def->os.type)) < 0)
         goto cleanup;
 
  cleanup:
diff --git a/src/lxc/lxc_driver.c b/src/lxc/lxc_driver.c
index 8dfa686..b491f34 100644
--- a/src/lxc/lxc_driver.c
+++ b/src/lxc/lxc_driver.c
@@ -665,7 +665,7 @@ static char *lxcDomainGetOSType(virDomainPtr dom)
     if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    if (VIR_STRDUP(ret, vm->def->os.type) < 0)
+    if (VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)) < 0)
         goto cleanup;
 
  cleanup:
diff --git a/src/lxc/lxc_native.c b/src/lxc/lxc_native.c
index c15eb19..25d5383 100644
--- a/src/lxc/lxc_native.c
+++ b/src/lxc/lxc_native.c
@@ -1025,9 +1025,7 @@ lxcParseConfigString(const char *config)
     vmdef->vcpus = 1;
 
     vmdef->nfss = 0;
-
-    if (VIR_STRDUP(vmdef->os.type, "exe") < 0)
-        goto error;
+    vmdef->os.type = VIR_DOMAIN_OSTYPE_EXE;
 
     if ((value = virConfGetValue(properties, "lxc.arch")) && value->str) {
         virArch arch = virArchFromString(value->str);
diff --git a/src/openvz/openvz_conf.c b/src/openvz/openvz_conf.c
index 80df15a..a2d2da7 100644
--- a/src/openvz/openvz_conf.c
+++ b/src/openvz/openvz_conf.c
@@ -564,8 +564,7 @@ int openvzLoadDomains(struct openvz_driver *driver)
             goto cleanup;
         }
 
-        if (VIR_STRDUP(def->os.type, "exe") < 0)
-            goto cleanup;
+        def->os.type = VIR_DOMAIN_OSTYPE_EXE;
         if (VIR_STRDUP(def->os.init, "/sbin/init") < 0)
             goto cleanup;
 
diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c
index f9f924f..f07337a 100644
--- a/src/openvz/openvz_driver.c
+++ b/src/openvz/openvz_driver.c
@@ -92,7 +92,7 @@ openvzDomainDefPostParse(virDomainDefPtr def,
                          void *opaque ATTRIBUTE_UNUSED)
 {
     /* fill the init path */
-    if (STREQ(def->os.type, "exe") && !def->os.init) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_EXE && !def->os.init) {
         if (VIR_STRDUP(def->os.init, "/sbin/init") < 0)
             return -1;
     }
@@ -371,7 +371,7 @@ static char *openvzDomainGetOSType(virDomainPtr dom)
         goto cleanup;
     }
 
-    ignore_value(VIR_STRDUP(ret, vm->def->os.type));
+    ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)));
 
  cleanup:
     if (vm)
diff --git a/src/parallels/parallels_driver.c b/src/parallels/parallels_driver.c
index d80fe24..f7a75e0 100644
--- a/src/parallels/parallels_driver.c
+++ b/src/parallels/parallels_driver.c
@@ -184,7 +184,7 @@ parallelsDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
         (dev->data.net->type == VIR_DOMAIN_NET_TYPE_NETWORK ||
          dev->data.net->type == VIR_DOMAIN_NET_TYPE_BRIDGE) &&
         !dev->data.net->model &&
-        STREQ(def->os.type, "hvm") &&
+        def->os.type == VIR_DOMAIN_OSTYPE_HVM &&
         VIR_STRDUP(dev->data.net->model, "e1000") < 0)
         goto cleanup;
 
@@ -575,7 +575,7 @@ parallelsDomainGetOSType(virDomainPtr domain)
         goto cleanup;
     }
 
-    ignore_value(VIR_STRDUP(ret, privdom->def->os.type));
+    ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(privdom->def->os.type)));
 
  cleanup:
     if (privdom)
@@ -712,10 +712,10 @@ parallelsDomainDefineXMLFlags(virConnectPtr conn, const char *xml, unsigned int
     olddom = virDomainObjListFindByUUID(privconn->domains, def->uuid);
     if (olddom == NULL) {
         virResetLastError();
-        if (STREQ(def->os.type, "hvm")) {
+        if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
             if (prlsdkCreateVm(conn, def))
                 goto cleanup;
-        } else if (STREQ(def->os.type, "exe")) {
+        } else if (def->os.type == VIR_DOMAIN_OSTYPE_EXE) {
             if (prlsdkCreateCt(conn, def))
                 goto cleanup;
         } else {
diff --git a/src/parallels/parallels_sdk.c b/src/parallels/parallels_sdk.c
index dcc0bec..2915d80 100644
--- a/src/parallels/parallels_sdk.c
+++ b/src/parallels/parallels_sdk.c
@@ -1164,12 +1164,10 @@ prlsdkConvertDomainType(PRL_HANDLE sdkdom, virDomainDefPtr def)
 
     switch (domainType) {
     case PVT_VM:
-        if (VIR_STRDUP(def->os.type, "hvm") < 0)
-            return -1;
+        def->os.type = VIR_DOMAIN_OSTYPE_HVM;
         break;
     case PVT_CT:
-        if (VIR_STRDUP(def->os.type, "exe") < 0)
-            return -1;
+        def->os.type = VIR_DOMAIN_OSTYPE_EXE;
         if (VIR_STRDUP(def->os.init, "/sbin/init") < 0)
             return -1;
         break;
diff --git a/src/parallels/parallels_utils.h b/src/parallels/parallels_utils.h
index 0f29374..5731381 100644
--- a/src/parallels/parallels_utils.h
+++ b/src/parallels/parallels_utils.h
@@ -37,7 +37,7 @@
     virReportErrorHelper(VIR_FROM_TEST, VIR_ERR_OPERATION_FAILED, __FILE__,    \
                      __FUNCTION__, __LINE__, _("Can't parse prlctl output"))
 
-# define IS_CT(def)  (STREQ_NULLABLE(def->os.type, "exe"))
+# define IS_CT(def)  (def->os.type == VIR_DOMAIN_OSTYPE_HVM)
 
 # define parallelsDomNotFoundError(domain)                               \
     do {                                                                 \
diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c
index a6b96de..6e177b0 100644
--- a/src/phyp/phyp_driver.c
+++ b/src/phyp/phyp_driver.c
@@ -1720,8 +1720,7 @@ phypDomainAttachDevice(virDomainPtr domain, const char *xml)
     if (domain_name == NULL)
         goto cleanup;
 
-    if (VIR_STRDUP(def->os.type, "aix") < 0)
-        goto cleanup;
+    def->os.type = VIR_DOMAIN_OSTYPE_AIX;
 
     dev = virDomainDeviceDefParse(xml, def, phyp_driver->caps, NULL,
                                   VIR_DOMAIN_DEF_PARSE_INACTIVE);
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 9606459..afeeddf 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -1897,7 +1897,7 @@ int virQEMUCapsGetDefaultVersion(virCapsPtr caps,
 
     hostarch = virArchFromHost();
     if ((binary = virCapabilitiesDefaultGuestEmulator(caps,
-                                                      "hvm",
+                                                      VIR_DOMAIN_OSTYPE_HVM,
                                                       hostarch,
                                                       "qemu")) == NULL) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index e7e0937..886bba4 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -8834,8 +8834,8 @@ qemuBuildCommandLine(virConnectPtr conn,
     if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_UUID))
         virCommandAddArgList(cmd, "-uuid", uuid, NULL);
     if (def->virtType == VIR_DOMAIN_VIRT_XEN ||
-        STREQ(def->os.type, "xen") ||
-        STREQ(def->os.type, "linux")) {
+        def->os.type == VIR_DOMAIN_OSTYPE_XEN ||
+        def->os.type == VIR_DOMAIN_OSTYPE_LINUX) {
         if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_XEN_DOMID)) {
             virCommandAddArg(cmd, "-xen-attach");
             virCommandAddArg(cmd, "-xen-domid");
@@ -12315,11 +12315,9 @@ qemuParseCommandLine(virCapsPtr qemuCaps,
 
     if (strstr(path, "xenner")) {
         def->virtType = VIR_DOMAIN_VIRT_KVM;
-        if (VIR_STRDUP(def->os.type, "xen") < 0)
-            goto error;
+        def->os.type = VIR_DOMAIN_OSTYPE_XEN;
     } else {
-        if (VIR_STRDUP(def->os.type, "hvm") < 0)
-            goto error;
+        def->os.type = VIR_DOMAIN_OSTYPE_HVM;
         if (strstr(path, "kvm")) {
             def->virtType = VIR_DOMAIN_VIRT_KVM;
             def->features[VIR_DOMAIN_FEATURE_PAE] = VIR_TRISTATE_SWITCH_ON;
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index b3816ee..0f16678 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2241,7 +2241,7 @@ static char *qemuDomainGetOSType(virDomainPtr dom) {
     if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    ignore_value(VIR_STRDUP(type, vm->def->os.type));
+    ignore_value(VIR_STRDUP(type, virDomainOSTypeToString(vm->def->os.type)));
 
  cleanup:
     qemuDomObjEndAPI(&vm);
diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c
index 6b4f655..6744702 100644
--- a/src/uml/uml_driver.c
+++ b/src/uml/uml_driver.c
@@ -1773,7 +1773,7 @@ static char *umlDomainGetOSType(virDomainPtr dom) {
     if (virDomainGetOSTypeEnsureACL(dom->conn, vm->def) < 0)
         goto cleanup;
 
-    if (VIR_STRDUP(type, vm->def->os.type) < 0)
+    if (VIR_STRDUP(type, virDomainOSTypeToString(vm->def->os.type)) < 0)
         goto cleanup;
 
  cleanup:
diff --git a/src/vbox/vbox_common.c b/src/vbox/vbox_common.c
index 710c50f..b419ddc 100644
--- a/src/vbox/vbox_common.c
+++ b/src/vbox/vbox_common.c
@@ -930,7 +930,7 @@ vboxSetBootDeviceOrder(virDomainDefPtr def, vboxGlobalData *data,
     PRUint32 maxBootPosition            = 0;
     size_t i = 0;
 
-    VIR_DEBUG("def->os.type             %s", def->os.type);
+    VIR_DEBUG("def->os.type             %s", virDomainOSTypeToString(def->os.type));
     VIR_DEBUG("def->os.arch             %s", virArchToString(def->os.arch));
     VIR_DEBUG("def->os.machine          %s", def->os.machine);
     VIR_DEBUG("def->os.nBootDevs        %zu", def->os.nBootDevs);
@@ -3906,9 +3906,7 @@ static char *vboxDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
 
     /* Skip cpumasklen, cpumask, onReboot, onPoweroff, onCrash */
 
-    if (VIR_STRDUP(def->os.type, "hvm") < 0)
-        goto cleanup;
-
+    def->os.type = VIR_DOMAIN_OSTYPE_HVM;
     def->os.arch = virArchFromHost();
 
     def->os.nBootDevs = 0;
@@ -4122,8 +4120,7 @@ static int vboxDomainAttachDeviceImpl(virDomainPtr dom,
     if (!(def = virDomainDefNew()))
         return ret;
 
-    if (VIR_STRDUP(def->os.type, "hvm") < 0)
-        goto cleanup;
+    def->os.type = VIR_DOMAIN_OSTYPE_HVM;
 
     dev = virDomainDeviceDefParse(xml, def, data->caps, data->xmlopt,
                                   VIR_DOMAIN_DEF_PARSE_INACTIVE);
@@ -4254,8 +4251,7 @@ static int vboxDomainDetachDevice(virDomainPtr dom, const char *xml)
     if (!(def = virDomainDefNew()))
         return ret;
 
-    if (VIR_STRDUP(def->os.type, "hvm") < 0)
-        goto cleanup;
+    def->os.type = VIR_DOMAIN_OSTYPE_HVM;
 
     dev = virDomainDeviceDefParse(xml, def, data->caps, data->xmlopt,
                                   VIR_DOMAIN_DEF_PARSE_INACTIVE);
@@ -6061,8 +6057,7 @@ static char *vboxDomainSnapshotGetXMLDesc(virDomainSnapshotPtr snapshot,
          * reading and while dumping xml
          */
         virDomainDefSetMemoryInitial(def->dom, memorySize * 1024);
-        if (VIR_STRDUP(def->dom->os.type, "hvm") < 0)
-            goto cleanup;
+        def->dom->os.type = VIR_DOMAIN_OSTYPE_HVM;
         def->dom->os.arch = virArchFromHost();
         gVBoxAPI.UIMachine.GetCPUCount(machine, &CPUCount);
         def->dom->maxvcpus = def->dom->vcpus = CPUCount;
diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c
index 3382994..6967dbc 100644
--- a/src/vmware/vmware_driver.c
+++ b/src/vmware/vmware_driver.c
@@ -870,7 +870,7 @@ vmwareDomainGetOSType(virDomainPtr dom)
         goto cleanup;
     }
 
-    ignore_value(VIR_STRDUP(ret, vm->def->os.type));
+    ignore_value(VIR_STRDUP(ret, virDomainOSTypeToString(vm->def->os.type)));
 
  cleanup:
     if (vm)
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 8b81436..cacc951 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -1522,8 +1522,7 @@ virVMXParseConfig(virVMXContext *ctx,
     def->onCrash = VIR_DOMAIN_LIFECYCLE_DESTROY;
 
     /* def:os */
-    if (VIR_STRDUP(def->os.type, "hvm") < 0)
-        goto cleanup;
+    def->os.type = VIR_DOMAIN_OSTYPE_HVM;
 
     /* vmx:guestOS -> def:os.arch */
     if (virVMXGetConfigString(conf, "guestOS", &guestOS, true) < 0)
diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c
index 3b11e9a..6cd3b76 100644
--- a/src/xen/xen_driver.c
+++ b/src/xen/xen_driver.c
@@ -338,7 +338,7 @@ xenDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
     if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
         dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
         dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE &&
-        STRNEQ(def->os.type, "hvm"))
+        def->os.type != VIR_DOMAIN_OSTYPE_HVM)
         dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
 
     /* forbid capabilities mode hostdev in this kind of hypervisor */
diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c
index 3813900..99dfdcb 100644
--- a/src/xen/xend_internal.c
+++ b/src/xen/xend_internal.c
@@ -2261,7 +2261,7 @@ xenDaemonAttachDeviceFlags(virConnectPtr conn,
     case VIR_DOMAIN_DEVICE_DISK:
         if (xenFormatSxprDisk(dev->data.disk,
                               &buf,
-                              STREQ(def->os.type, "hvm") ? 1 : 0,
+                              def->os.type == VIR_DOMAIN_OSTYPE_HVM ? 1 : 0,
                               priv->xendConfigVersion, 1) < 0)
             goto cleanup;
 
@@ -2274,7 +2274,7 @@ xenDaemonAttachDeviceFlags(virConnectPtr conn,
         if (xenFormatSxprNet(conn,
                              dev->data.net,
                              &buf,
-                             STREQ(def->os.type, "hvm") ? 1 : 0,
+                             def->os.type == VIR_DOMAIN_OSTYPE_HVM ? 1 : 0,
                              priv->xendConfigVersion, 1) < 0)
             goto cleanup;
 
@@ -2409,7 +2409,7 @@ xenDaemonUpdateDeviceFlags(virConnectPtr conn,
     case VIR_DOMAIN_DEVICE_DISK:
         if (xenFormatSxprDisk(dev->data.disk,
                               &buf,
-                              STREQ(def->os.type, "hvm") ? 1 : 0,
+                              def->os.type == VIR_DOMAIN_OSTYPE_HVM ? 1 : 0,
                               priv->xendConfigVersion, 1) < 0)
             goto cleanup;
         break;
diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c
index 2ec0b65..6b2e5ee 100644
--- a/src/xenapi/xenapi_driver.c
+++ b/src/xenapi/xenapi_driver.c
@@ -52,7 +52,7 @@ xenapiDomainDeviceDefPostParse(virDomainDeviceDefPtr dev,
     if (dev->type == VIR_DOMAIN_DEVICE_CHR &&
         dev->data.chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
         dev->data.chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_NONE &&
-        STRNEQ(def->os.type, "hvm"))
+        def->os.type != VIR_DOMAIN_OSTYPE_HVM)
         dev->data.chr->targetType = VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_XEN;
 
     /* forbid capabilities mode hostdev in this kind of hypervisor */
@@ -1427,10 +1427,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
         goto error;
     xen_vm_get_hvm_boot_policy(session, &boot_policy, vm);
     if (STREQ(boot_policy, "BIOS order")) {
-        if (VIR_STRDUP(defPtr->os.type, "hvm") < 0) {
-            VIR_FREE(boot_policy);
-            goto error;
-        }
+        defPtr->os.type = VIR_DOMAIN_OSTYPE_HVM;
         xen_vm_get_hvm_boot_params(session, &result, vm);
         if (result != NULL) {
             size_t i;
@@ -1450,10 +1447,7 @@ xenapiDomainGetXMLDesc(virDomainPtr dom, unsigned int flags)
         VIR_FREE(boot_policy);
     } else {
         char *value = NULL;
-        if (VIR_STRDUP(defPtr->os.type, "xen") < 0) {
-            VIR_FREE(boot_policy);
-            goto error;
-        }
+        defPtr->os.type = VIR_DOMAIN_OSTYPE_XEN;
         if (VIR_ALLOC(defPtr->os.loader) < 0 ||
             VIR_STRDUP(defPtr->os.loader->path, "pygrub") < 0) {
             VIR_FREE(boot_policy);
diff --git a/src/xenapi/xenapi_utils.c b/src/xenapi/xenapi_utils.c
index ce95260..a80e084 100644
--- a/src/xenapi/xenapi_utils.c
+++ b/src/xenapi/xenapi_utils.c
@@ -464,7 +464,7 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,
     virUUIDFormat(def->uuid, uuidStr);
     if (VIR_STRDUP((*record)->uuid, uuidStr) < 0)
         goto error;
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         char *boot_order = NULL;
         if (VIR_STRDUP((*record)->hvm_boot_policy, "BIOS order") < 0)
             goto error;
@@ -476,7 +476,7 @@ createVMRecordFromXml(virConnectPtr conn, virDomainDefPtr def,
             (*record)->hvm_boot_params = hvm_boot_params;
             VIR_FREE(boot_order);
         }
-    } else if (STREQ(def->os.type, "xen")) {
+    } else if (def->os.type == VIR_DOMAIN_OSTYPE_XEN) {
         if (VIR_STRDUP((*record)->pv_bootloader, "pygrub") < 0)
             goto error;
         if (def->os.kernel) {
diff --git a/src/xenconfig/xen_common.c b/src/xenconfig/xen_common.c
index 7ae2d4a..48484d6 100644
--- a/src/xenconfig/xen_common.c
+++ b/src/xenconfig/xen_common.c
@@ -331,7 +331,7 @@ xenParseTimeOffset(virConfPtr conf, virDomainDefPtr def,
     if (xenConfigGetBool(conf, "localtime", &vmlocaltime, 0) < 0)
         return -1;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         /* only managed HVM domains since 3.1.0 have persistent rtc_timeoffset */
         if (xendConfigVersion < XEND_CONFIG_VERSION_3_1_0) {
             if (vmlocaltime)
@@ -513,7 +513,7 @@ xenParseCPUFeatures(virConfPtr conf, virDomainDefPtr def)
     if (str && (virBitmapParse(str, 0, &def->cpumask, 4096) < 0))
         return -1;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (xenConfigGetBool(conf, "pae", &val, 1) < 0)
             return -1;
 
@@ -570,7 +570,7 @@ xenParseVfb(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
 {
     int val;
     char *listenAddr = NULL;
-    int hvm = STREQ(def->os.type, "hvm");
+    int hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
     virConfValuePtr list;
     virDomainGraphicsDefPtr graphics = NULL;
 
@@ -724,7 +724,7 @@ xenParseCharDev(virConfPtr conf, virDomainDefPtr def)
     virConfValuePtr value = NULL;
     virDomainChrDefPtr chr = NULL;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (xenConfigGetString(conf, "parallel", &str, NULL) < 0)
             goto cleanup;
         if (str && STRNEQ(str, "none") &&
@@ -967,7 +967,7 @@ xenParseEmulatedDevices(virConfPtr conf, virDomainDefPtr def)
 {
     const char *str;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (xenConfigGetString(conf, "soundhw", &str, NULL) < 0)
             return -1;
 
@@ -997,8 +997,7 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
         STREQ(str, "hvm"))
         hvm = 1;
 
-    if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "xen") < 0)
-        return -1;
+    def->os.type = (hvm ? VIR_DOMAIN_OSTYPE_HVM : VIR_DOMAIN_OSTYPE_XEN);
 
     def->os.arch =
         virCapabilitiesDefaultGuestArch(caps,
@@ -1007,7 +1006,7 @@ xenParseGeneralMeta(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
     if (!def->os.arch) {
         virReportError(VIR_ERR_INTERNAL_ERROR,
                        _("no supported architecture for os type '%s'"),
-                       def->os.type);
+                       virDomainOSTypeToString(def->os.type));
         return -1;
     }
 
@@ -1346,7 +1345,7 @@ xenFormatTimeOffset(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
         }
 
     } else {
-        if (STREQ(def->os.type, "hvm")) {
+        if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
             /* >=3.1 HV: VARIABLE */
             int rtc_timeoffset;
 
@@ -1447,7 +1446,7 @@ xenFormatCharDev(virConfPtr conf, virDomainDefPtr def)
 {
     size_t i;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (def->nparallels) {
             virBuffer buf = VIR_BUFFER_INITIALIZER;
             char *str;
@@ -1565,7 +1564,7 @@ xenFormatCPUFeatures(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion
 {
     size_t i;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (xenConfigSetInt(conf, "pae",
                             (def->features[VIR_DOMAIN_FEATURE_PAE] ==
                             VIR_TRISTATE_SWITCH_ON) ? 1 : 0) < 0)
@@ -1621,7 +1620,7 @@ xenFormatCDROM(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
 {
     size_t i;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (xendConfigVersion == XEND_CONFIG_VERSION_3_0_2) {
             for (i = 0; i < def->ndisks; i++) {
                 if (def->disks[i]->device == VIR_DOMAIN_DISK_DEVICE_CDROM &&
@@ -1644,7 +1643,7 @@ xenFormatCDROM(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
 static int
 xenFormatVfb(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
 {
-    int hvm = STREQ(def->os.type, "hvm") ? 1 : 0;
+    int hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM ? 1 : 0;
 
     if (def->ngraphics == 1 &&
         def->graphics[0]->type != VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
@@ -1763,7 +1762,7 @@ xenFormatVfb(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
 static int
 xenFormatSound(virConfPtr conf, virDomainDefPtr def)
 {
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (def->sounds) {
             virBuffer buf = VIR_BUFFER_INITIALIZER;
             char *str = NULL;
@@ -1792,7 +1791,7 @@ xenFormatVif(virConfPtr conf,
 {
    virConfValuePtr netVal = NULL;
    size_t i;
-   int hvm = STREQ(def->os.type, "hvm");
+   int hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
 
    if (VIR_ALLOC(netVal) < 0)
         goto cleanup;
diff --git a/src/xenconfig/xen_sxpr.c b/src/xenconfig/xen_sxpr.c
index d77abf3..5f58fd8 100644
--- a/src/xenconfig/xen_sxpr.c
+++ b/src/xenconfig/xen_sxpr.c
@@ -1145,8 +1145,7 @@ xenParseSxpr(const struct sexpr *root,
             goto error;
     }
 
-    if (VIR_STRDUP(def->os.type, hvm ? "hvm" : "linux") < 0)
-        goto error;
+    def->os.type = (hvm ? VIR_DOMAIN_OSTYPE_HVM : VIR_DOMAIN_OSTYPE_LINUX);
 
     if (def->id != 0) {
         if (sexpr_lookup(root, "domain/image")) {
@@ -2273,7 +2272,7 @@ xenFormatSxpr(virConnectPtr conn,
     }
     virBufferAsprintf(&buf, "(on_crash '%s')", tmp);
 
-    if (STREQ(def->os.type, "hvm"))
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM)
         hvm = 1;
 
     if (!def->os.bootloader) {
diff --git a/src/xenconfig/xen_xl.c b/src/xenconfig/xen_xl.c
index 62284f7..db554b2 100644
--- a/src/xenconfig/xen_xl.c
+++ b/src/xenconfig/xen_xl.c
@@ -64,7 +64,7 @@ xenParseXLOS(virConfPtr conf, virDomainDefPtr def, virCapsPtr caps)
     size_t i;
     const char *extra, *root;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         const char *boot;
 
         for (i = 0; i < caps->nguests; i++) {
@@ -159,7 +159,7 @@ xenParseXLSpice(virConfPtr conf, virDomainDefPtr def)
     char *listenAddr = NULL;
     int val;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (xenConfigGetBool(conf, "spice", &val, 0) < 0)
             return -1;
 
@@ -353,7 +353,8 @@ xenParseXLDisk(virConfPtr conf, virDomainDefPtr def)
                 }
             }
 
-            if (STRPREFIX(libxldisk->vdev, "xvd") || !STREQ(def->os.type, "hvm"))
+            if (STRPREFIX(libxldisk->vdev, "xvd") ||
+                def->os.type != VIR_DOMAIN_OSTYPE_HVM)
                 disk->bus = VIR_DOMAIN_DISK_BUS_XEN;
             else if (STRPREFIX(libxldisk->vdev, "sd"))
                 disk->bus = VIR_DOMAIN_DISK_BUS_SCSI;
@@ -388,7 +389,7 @@ xenParseXLInputDevs(virConfPtr conf, virDomainDefPtr def)
     const char *str;
     virConfValuePtr val;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         val = virConfGetValue(conf, "usbdevice");
         /* usbdevice can be defined as either a single string or a list */
         if (val && val->type == VIR_CONF_LIST) {
@@ -475,7 +476,7 @@ xenFormatXLOS(virConfPtr conf, virDomainDefPtr def)
 {
     size_t i;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         char boot[VIR_DOMAIN_BOOT_LAST+1];
         if (xenConfigSetString(conf, "builder", "hvm") < 0)
             return -1;
@@ -667,7 +668,7 @@ xenFormatXLSpice(virConfPtr conf, virDomainDefPtr def)
 {
     const char *listenAddr = NULL;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (def->graphics[0]->type == VIR_DOMAIN_GRAPHICS_TYPE_SPICE) {
             /* set others to false but may not be necessary */
             if (xenConfigSetInt(conf, "sdl", 0) < 0)
@@ -726,7 +727,7 @@ xenFormatXLInputDevs(virConfPtr conf, virDomainDefPtr def)
     const char *devtype;
     virConfValuePtr usbdevices = NULL, lastdev;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (VIR_ALLOC(usbdevices) < 0)
             goto error;
 
diff --git a/src/xenconfig/xen_xm.c b/src/xenconfig/xen_xm.c
index ba10fb9..fafe662 100644
--- a/src/xenconfig/xen_xm.c
+++ b/src/xenconfig/xen_xm.c
@@ -42,7 +42,7 @@ xenParseXMOS(virConfPtr conf, virDomainDefPtr def)
 {
     size_t i;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         const char *boot;
 
         if (VIR_ALLOC(def->os.loader) < 0 ||
@@ -108,7 +108,7 @@ xenParseXMDisk(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
 {
     const char *str = NULL;
     virDomainDiskDefPtr disk = NULL;
-    int hvm = STREQ(def->os.type, "hvm");
+    int hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
     virConfValuePtr list = virConfGetValue(conf, "disk");
 
     if (list && list->type == VIR_CONF_LIST) {
@@ -391,7 +391,7 @@ xenFormatXMDisks(virConfPtr conf, virDomainDefPtr def, int xendConfigVersion)
 {
     virConfValuePtr diskVal = NULL;
     size_t i = 0;
-    int hvm = STREQ(def->os.type, "hvm");
+    int hvm = def->os.type == VIR_DOMAIN_OSTYPE_HVM;
 
     if (VIR_ALLOC(diskVal) < 0)
         goto cleanup;
@@ -436,7 +436,7 @@ xenParseXMInputDevs(virConfPtr conf, virDomainDefPtr def)
 {
     const char *str;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         if (xenConfigGetString(conf, "usbdevice", &str, NULL) < 0)
             return -1;
         if (str &&
@@ -503,7 +503,7 @@ xenFormatXMOS(virConfPtr conf, virDomainDefPtr def)
 {
     size_t i;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         char boot[VIR_DOMAIN_BOOT_LAST+1];
         if (xenConfigSetString(conf, "builder", "hvm") < 0)
             return -1;
@@ -573,7 +573,7 @@ xenFormatXMInputDevs(virConfPtr conf, virDomainDefPtr def)
     size_t i;
     const char *devtype;
 
-    if (STREQ(def->os.type, "hvm")) {
+    if (def->os.type == VIR_DOMAIN_OSTYPE_HVM) {
         for (i = 0; i < def->ninputs; i++) {
             if (def->inputs[i]->bus == VIR_DOMAIN_INPUT_BUS_USB) {
                 if (xenConfigSetInt(conf, "usb", 1) < 0)
diff --git a/tests/openvzutilstest.c b/tests/openvzutilstest.c
index f9d1002..1414d70 100644
--- a/tests/openvzutilstest.c
+++ b/tests/openvzutilstest.c
@@ -103,11 +103,11 @@ testReadNetworkConf(const void *data ATTRIBUTE_UNUSED)
         "</domain>\n";
 
     if (!(def = virDomainDefNew()) ||
-        VIR_STRDUP(def->os.type, "exe") < 0 ||
         VIR_STRDUP(def->os.init, "/sbin/init") < 0)
         goto cleanup;
 
     def->virtType = VIR_DOMAIN_VIRT_OPENVZ;
+    def->os.type = VIR_DOMAIN_OSTYPE_EXE;
 
     if (openvzReadNetworkConf(def, 1) < 0) {
         err = virGetLastError();
-- 
2.3.5




More information about the libvir-list mailing list