The virDomainChrDefParseXML() function uses old style of parsing
XML (virXMLPropString + str2enum conversion). Use
virXMLPropEnumDefault() which encapsulates those steps.

Signed-off-by: Michal Privoznik <mpriv...@redhat.com>
---
 src/ch/ch_monitor.c              |  2 +-
 src/conf/domain_conf.c           | 82 +++++++++++---------------------
 src/conf/domain_conf.h           |  2 +-
 src/conf/domain_validate.c       |  2 +-
 src/conf/virchrdev.c             | 29 +++++++++++
 src/libxl/libxl_conf.c           | 20 ++++++++
 src/libxl/xen_common.c           | 23 ++++++++-
 src/qemu/qemu_command.c          |  6 +--
 src/qemu/qemu_domain.c           | 34 ++++++++++++-
 src/qemu/qemu_monitor_json.c     |  2 +-
 src/qemu/qemu_process.c          |  2 +-
 src/qemu/qemu_validate.c         |  2 +-
 src/security/security_apparmor.c |  4 +-
 src/security/security_dac.c      |  4 +-
 src/security/security_selinux.c  | 24 ++++++++++
 src/vmx/vmx.c                    | 26 ++++++++++
 tests/testutilsqemu.c            |  2 +-
 17 files changed, 197 insertions(+), 69 deletions(-)

diff --git a/src/ch/ch_monitor.c b/src/ch/ch_monitor.c
index 2c6b83a1b5..d6fac642da 100644
--- a/src/ch/ch_monitor.c
+++ b/src/ch/ch_monitor.c
@@ -281,7 +281,7 @@ virCHMonitorBuildNetJson(virJSONValue *nets,
             }
             break;
         case VIR_DOMAIN_NET_TYPE_VHOSTUSER:
-            if ((virDomainChrType)netdef->data.vhostuser->type != 
VIR_DOMAIN_CHR_TYPE_UNIX) {
+            if (netdef->data.vhostuser->type != VIR_DOMAIN_CHR_TYPE_UNIX) {
                 virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                            _("vhost_user type support UNIX socket in this 
CH"));
                 return -1;
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 44b507b74d..b5ce80eb76 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2694,7 +2694,7 @@ virDomainChrSourceDefGetPath(virDomainChrSourceDef *chr)
     if (!chr)
         return NULL;
 
-    switch ((virDomainChrType) chr->type) {
+    switch (chr->type) {
     case VIR_DOMAIN_CHR_TYPE_PTY:
     case VIR_DOMAIN_CHR_TYPE_DEV:
     case VIR_DOMAIN_CHR_TYPE_FILE:
@@ -2761,6 +2761,13 @@ virDomainChrSourceDefClear(virDomainChrSourceDef *def)
     case VIR_DOMAIN_CHR_TYPE_DBUS:
         VIR_FREE(def->data.dbus.channel);
         break;
+    case VIR_DOMAIN_CHR_TYPE_NULL:
+    case VIR_DOMAIN_CHR_TYPE_VC:
+    case VIR_DOMAIN_CHR_TYPE_STDIO:
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
+        break;
     }
 
     VIR_FREE(def->logfile);
@@ -2778,7 +2785,7 @@ virDomainChrSourceDefCopy(virDomainChrSourceDef *dest,
     dest->logfile = g_strdup(src->logfile);
     dest->logappend = src->logappend;
 
-    switch ((virDomainChrType)src->type) {
+    switch (src->type) {
     case VIR_DOMAIN_CHR_TYPE_FILE:
     case VIR_DOMAIN_CHR_TYPE_PTY:
     case VIR_DOMAIN_CHR_TYPE_DEV:
@@ -2875,7 +2882,7 @@ virDomainChrSourceDefIsEqual(const virDomainChrSourceDef 
*src,
     if (tgt->type != src->type)
         return false;
 
-    switch ((virDomainChrType)src->type) {
+    switch (src->type) {
     case VIR_DOMAIN_CHR_TYPE_FILE:
         return src->data.file.append == tgt->data.file.append &&
             STREQ_NULLABLE(src->data.file.path, tgt->data.file.path);
@@ -11270,7 +11277,7 @@ virDomainChrSourceDefParseXML(virDomainChrSourceDef 
*def,
             goto error;
         }
 
-        switch ((virDomainChrType) def->type) {
+        switch (def->type) {
         case VIR_DOMAIN_CHR_TYPE_FILE:
             if (virDomainChrSourceDefParseFile(def, sources[0]) < 0)
                 goto error;
@@ -11477,7 +11484,6 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlopt,
     xmlNodePtr target;
     const char *nodeName;
     virDomainChrDef *def;
-    g_autofree char *type = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
 
     ctxt->node = node;
@@ -11485,15 +11491,12 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlopt,
     if (!(def = virDomainChrDefNew(xmlopt)))
         return NULL;
 
-    type = virXMLPropString(node, "type");
-    if (type == NULL) {
-        def->source->type = VIR_DOMAIN_CHR_TYPE_PTY;
-    } else if ((def->source->type = virDomainChrTypeFromString(type)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown type presented to host for character device: 
%s"),
-                       type);
+    if (virXMLPropEnumDefault(node, "type",
+                              virDomainChrTypeFromString,
+                              VIR_XML_PROP_NONE,
+                              &def->source->type,
+                              VIR_DOMAIN_CHR_TYPE_PTY) < 0)
         goto error;
-    }
 
     nodeName = (const char *) node->name;
     if ((def->deviceType = virDomainChrDeviceTypeFromString(nodeName)) < 0) {
@@ -11551,7 +11554,6 @@ virDomainSmartcardDefParseXML(virDomainXMLOption 
*xmlopt,
                               unsigned int flags)
 {
     g_autoptr(virDomainSmartcardDef) def = NULL;
-    g_autofree char *type = NULL;
     g_autofree xmlNodePtr *certificates = NULL;
     int n = 0;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
@@ -11597,23 +11599,14 @@ virDomainSmartcardDefParseXML(virDomainXMLOption 
*xmlopt,
         break;
 
     case VIR_DOMAIN_SMARTCARD_TYPE_PASSTHROUGH:
-        type = virXMLPropString(node, "type");
-        if (type == NULL) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("passthrough mode requires a character "
-                             "device type attribute"));
-            return NULL;
-        }
-
         if (!(def->data.passthru = virDomainChrSourceDefNew(xmlopt)))
             return NULL;
 
-        if ((def->data.passthru->type = virDomainChrTypeFromString(type)) < 0) 
{
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown type presented to host for "
-                             "character device: %s"), type);
+        if (virXMLPropEnum(node, "type",
+                           virDomainChrTypeFromString,
+                           VIR_XML_PROP_REQUIRED,
+                           &def->data.passthru->type) < 0)
             return NULL;
-        }
 
         if (virDomainChrSourceDefParseXML(def->data.passthru, node, flags,
                                           NULL, ctxt) < 0)
@@ -13349,7 +13342,6 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
     g_autofree xmlNodePtr *backends = NULL;
     g_autofree char *model = NULL;
     g_autofree char *backend = NULL;
-    g_autofree char *type = NULL;
 
     def = g_new0(virDomainRNGDef, 1);
 
@@ -13405,22 +13397,14 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
         break;
 
     case VIR_DOMAIN_RNG_BACKEND_EGD:
-        if (!(type = virXMLPropString(backends[0], "type"))) {
-            virReportError(VIR_ERR_XML_ERROR, "%s",
-                           _("missing EGD backend type"));
-            goto error;
-        }
-
         if (!(def->source.chardev = virDomainChrSourceDefNew(xmlopt)))
             goto error;
 
-        def->source.chardev->type = virDomainChrTypeFromString(type);
-        if (def->source.chardev->type < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown backend type '%s' for egd"),
-                           type);
+        if (virXMLPropEnum(backends[0], "type",
+                           virDomainChrTypeFromString,
+                           VIR_XML_PROP_REQUIRED,
+                           &def->source.chardev->type) < 0)
             goto error;
-        }
 
         if (virDomainChrSourceDefParseXML(def->source.chardev,
                                           backends[0], flags,
@@ -14320,7 +14304,6 @@ virDomainRedirdevDefParseXML(virDomainXMLOption *xmlopt,
 {
     virDomainRedirdevDef *def;
     g_autofree char *bus = NULL;
-    g_autofree char *type = NULL;
 
     def = g_new0(virDomainRedirdevDef, 1);
 
@@ -14338,18 +14321,11 @@ virDomainRedirdevDefParseXML(virDomainXMLOption 
*xmlopt,
         def->bus = VIR_DOMAIN_REDIRDEV_BUS_USB;
     }
 
-    type = virXMLPropString(node, "type");
-    if (type) {
-        if ((def->source->type = virDomainChrTypeFromString(type)) < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown redirdev character device type '%s'"), 
type);
-            goto error;
-        }
-    } else {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("missing type in redirdev"));
+    if (virXMLPropEnum(node, "type",
+                       virDomainChrTypeFromString,
+                       VIR_XML_PROP_REQUIRED,
+                       &def->source->type) < 0)
         goto error;
-    }
 
     /* boot gets parsed in virDomainDeviceInfoParseXML
      * source gets parsed in virDomainChrSourceDefParseXML */
@@ -25070,7 +25046,7 @@ virDomainChrSourceDefFormat(virBuffer *buf,
     g_auto(virBuffer) attrBuf = VIR_BUFFER_INITIALIZER;
     g_auto(virBuffer) childBuf = VIR_BUFFER_INIT_CHILD(buf);
 
-    switch ((virDomainChrType)def->type) {
+    switch (def->type) {
     case VIR_DOMAIN_CHR_TYPE_NULL:
     case VIR_DOMAIN_CHR_TYPE_VC:
     case VIR_DOMAIN_CHR_TYPE_STDIO:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 30aa0ed8d3..a81fb09678 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1281,7 +1281,7 @@ typedef enum {
 /* The host side information for a character device.  */
 struct _virDomainChrSourceDef {
     virObject parent;
-    int type; /* virDomainChrType */
+    virDomainChrType type;
     virObject *privateData;
     union {
         /* no <source> for null, vc, stdio */
diff --git a/src/conf/domain_validate.c b/src/conf/domain_validate.c
index 28234f910d..4fce7059dc 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -932,7 +932,7 @@ virDomainChrSourceDefValidate(const virDomainChrSourceDef 
*src_def,
                               const virDomainChrDef *chr_def,
                               const virDomainDef *def)
 {
-    switch ((virDomainChrType) src_def->type) {
+    switch (src_def->type) {
     case VIR_DOMAIN_CHR_TYPE_NULL:
     case VIR_DOMAIN_CHR_TYPE_PTY:
     case VIR_DOMAIN_CHR_TYPE_VC:
diff --git a/src/conf/virchrdev.c b/src/conf/virchrdev.c
index 8610f0ac5c..730e4e23b4 100644
--- a/src/conf/virchrdev.c
+++ b/src/conf/virchrdev.c
@@ -339,6 +339,21 @@ int virChrdevOpen(virChrdevs *devs,
     case VIR_DOMAIN_CHR_TYPE_UNIX:
         path = source->data.nix.path;
         break;
+    case VIR_DOMAIN_CHR_TYPE_NULL:
+    case VIR_DOMAIN_CHR_TYPE_VC:
+    case VIR_DOMAIN_CHR_TYPE_DEV:
+    case VIR_DOMAIN_CHR_TYPE_FILE:
+    case VIR_DOMAIN_CHR_TYPE_PIPE:
+    case VIR_DOMAIN_CHR_TYPE_STDIO:
+    case VIR_DOMAIN_CHR_TYPE_UDP:
+    case VIR_DOMAIN_CHR_TYPE_TCP:
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+    case VIR_DOMAIN_CHR_TYPE_NMDM:
+    case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+    case VIR_DOMAIN_CHR_TYPE_DBUS:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
+
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Unsupported device type '%s'"),
@@ -404,6 +419,20 @@ int virChrdevOpen(virChrdevs *devs,
         if (virFDStreamConnectUNIX(st, path, false) < 0)
             goto error;
         break;
+    case VIR_DOMAIN_CHR_TYPE_NULL:
+    case VIR_DOMAIN_CHR_TYPE_VC:
+    case VIR_DOMAIN_CHR_TYPE_DEV:
+    case VIR_DOMAIN_CHR_TYPE_FILE:
+    case VIR_DOMAIN_CHR_TYPE_PIPE:
+    case VIR_DOMAIN_CHR_TYPE_STDIO:
+    case VIR_DOMAIN_CHR_TYPE_UDP:
+    case VIR_DOMAIN_CHR_TYPE_TCP:
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+    case VIR_DOMAIN_CHR_TYPE_NMDM:
+    case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+    case VIR_DOMAIN_CHR_TYPE_DBUS:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Unsupported device type '%s'"),
diff --git a/src/libxl/libxl_conf.c b/src/libxl/libxl_conf.c
index 401e47344e..0cfd49ebcf 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -273,6 +273,12 @@ libxlMakeChrdevStr(virDomainChrDef *def, char **buf)
                                srcdef->data.nix.listen ? ",server,nowait" : 
"");
         break;
 
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+    case VIR_DOMAIN_CHR_TYPE_NMDM:
+    case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+    case VIR_DOMAIN_CHR_TYPE_DBUS:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("unsupported chardev '%s'"), type);
@@ -1972,6 +1978,20 @@ libxlMakeChannel(virDomainChrDef *l_channel,
         x_channel->connection = LIBXL_CHANNEL_CONNECTION_SOCKET;
         x_channel->u.socket.path = g_strdup(l_channel->source->data.nix.path);
         break;
+    case VIR_DOMAIN_CHR_TYPE_NULL:
+    case VIR_DOMAIN_CHR_TYPE_VC:
+    case VIR_DOMAIN_CHR_TYPE_DEV:
+    case VIR_DOMAIN_CHR_TYPE_FILE:
+    case VIR_DOMAIN_CHR_TYPE_PIPE:
+    case VIR_DOMAIN_CHR_TYPE_STDIO:
+    case VIR_DOMAIN_CHR_TYPE_UDP:
+    case VIR_DOMAIN_CHR_TYPE_TCP:
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+    case VIR_DOMAIN_CHR_TYPE_NMDM:
+    case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+    case VIR_DOMAIN_CHR_TYPE_DBUS:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
                        _("channel source type not supported"));
diff --git a/src/libxl/xen_common.c b/src/libxl/xen_common.c
index b97ba0a199..6487cb63df 100644
--- a/src/libxl/xen_common.c
+++ b/src/libxl/xen_common.c
@@ -824,11 +824,14 @@ xenParseSxprChar(const char *value,
             def->source->type = VIR_DOMAIN_CHR_TYPE_TCP;
             def->source->data.tcp.protocol = 
VIR_DOMAIN_CHR_TCP_PROTOCOL_TELNET;
         } else {
-            if ((def->source->type = virDomainChrTypeFromString(prefix)) < 0) {
+            int type = virDomainChrTypeFromString(prefix);
+
+            if (type < 0) {
                 virReportError(VIR_ERR_INTERNAL_ERROR,
                                _("unknown chr device type '%s'"), prefix);
                 goto error;
             }
+            def->source->type = type;
         }
     }
 
@@ -920,6 +923,18 @@ xenParseSxprChar(const char *value,
             def->source->data.nix.listen = true;
     }
     break;
+
+    case VIR_DOMAIN_CHR_TYPE_NULL:
+    case VIR_DOMAIN_CHR_TYPE_VC:
+    case VIR_DOMAIN_CHR_TYPE_DEV:
+    case VIR_DOMAIN_CHR_TYPE_STDIO:
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+    case VIR_DOMAIN_CHR_TYPE_NMDM:
+    case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+    case VIR_DOMAIN_CHR_TYPE_DBUS:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
+    break;
     }
 
     return def;
@@ -1525,6 +1540,12 @@ xenFormatSxprChr(virDomainChrDef *def,
             virBufferAddLit(buf, ",server,nowait");
         break;
 
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+    case VIR_DOMAIN_CHR_TYPE_NMDM:
+    case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+    case VIR_DOMAIN_CHR_TYPE_DBUS:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("unsupported chr device type '%s'"), type);
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 5ea88bf239..365b7d8292 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1304,7 +1304,7 @@ qemuBuildChardevStr(const virDomainChrSourceDef *dev,
     const char *path;
     virTristateSwitch append;
 
-    switch ((virDomainChrType) dev->type) {
+    switch (dev->type) {
     case VIR_DOMAIN_CHR_TYPE_NULL:
         virBufferAsprintf(&buf, "null,id=%s", charAlias);
         break;
@@ -1484,7 +1484,7 @@ qemuBuildChardevCommand(virCommand *cmd,
     qemuDomainChrSourcePrivate *chrSourcePriv = 
QEMU_DOMAIN_CHR_SOURCE_PRIVATE(dev);
     g_autofree char *charstr = NULL;
 
-    switch ((virDomainChrType) dev->type) {
+    switch (dev->type) {
     case VIR_DOMAIN_CHR_TYPE_TCP:
         if (dev->data.tcp.haveTLS == VIR_TRISTATE_BOOL_YES) {
             g_autofree char *objalias = NULL;
@@ -8670,7 +8670,7 @@ qemuInterfaceVhostuserConnect(virCommand *cmd,
 {
     g_autofree char *charAlias = qemuAliasChardevFromDevAlias(net->info.alias);
 
-    switch ((virDomainChrType)net->data.vhostuser->type) {
+    switch (net->data.vhostuser->type) {
     case VIR_DOMAIN_CHR_TYPE_UNIX:
         if (qemuBuildChardevCommand(cmd,
                                     net->data.vhostuser,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 30ef5b7550..3432c83153 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2310,10 +2310,28 @@ qemuDomainObjPrivateXMLFormat(virBuffer *buf,
         case VIR_DOMAIN_CHR_TYPE_UNIX:
             monitorpath = priv->monConfig->data.nix.path;
             break;
-        default:
         case VIR_DOMAIN_CHR_TYPE_PTY:
             monitorpath = priv->monConfig->data.file.path;
             break;
+        case VIR_DOMAIN_CHR_TYPE_NULL:
+        case VIR_DOMAIN_CHR_TYPE_VC:
+        case VIR_DOMAIN_CHR_TYPE_DEV:
+        case VIR_DOMAIN_CHR_TYPE_FILE:
+        case VIR_DOMAIN_CHR_TYPE_PIPE:
+        case VIR_DOMAIN_CHR_TYPE_STDIO:
+        case VIR_DOMAIN_CHR_TYPE_UDP:
+        case VIR_DOMAIN_CHR_TYPE_TCP:
+        case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+        case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+        case VIR_DOMAIN_CHR_TYPE_NMDM:
+        case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+        case VIR_DOMAIN_CHR_TYPE_DBUS:
+        case VIR_DOMAIN_CHR_TYPE_LAST:
+        default:
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("unsupported monitor type '%s'"),
+                           virDomainChrTypeToString(priv->monConfig->type));
+            return -1;
         }
 
         virBufferEscapeString(buf, "<monitor path='%s'", monitorpath);
@@ -2963,6 +2981,20 @@ qemuDomainObjPrivateXMLParse(xmlXPathContextPtr ctxt,
     case VIR_DOMAIN_CHR_TYPE_UNIX:
         priv->monConfig->data.nix.path = monitorpath;
         break;
+    case VIR_DOMAIN_CHR_TYPE_NULL:
+    case VIR_DOMAIN_CHR_TYPE_VC:
+    case VIR_DOMAIN_CHR_TYPE_DEV:
+    case VIR_DOMAIN_CHR_TYPE_FILE:
+    case VIR_DOMAIN_CHR_TYPE_PIPE:
+    case VIR_DOMAIN_CHR_TYPE_STDIO:
+    case VIR_DOMAIN_CHR_TYPE_UDP:
+    case VIR_DOMAIN_CHR_TYPE_TCP:
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+    case VIR_DOMAIN_CHR_TYPE_NMDM:
+    case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+    case VIR_DOMAIN_CHR_TYPE_DBUS:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
     default:
         VIR_FREE(monitorpath);
         virReportError(VIR_ERR_INTERNAL_ERROR,
diff --git a/src/qemu/qemu_monitor_json.c b/src/qemu/qemu_monitor_json.c
index afe45c415b..f6294e4ed5 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6651,7 +6651,7 @@ qemuMonitorJSONAttachCharDevGetProps(const char *chrID,
     g_autoptr(virJSONValue) backendData = virJSONValueNewObject();
     const char *backendType = NULL;
 
-    switch ((virDomainChrType)chr->type) {
+    switch (chr->type) {
     case VIR_DOMAIN_CHR_TYPE_NULL:
     case VIR_DOMAIN_CHR_TYPE_VC:
     case VIR_DOMAIN_CHR_TYPE_PTY:
diff --git a/src/qemu/qemu_process.c b/src/qemu/qemu_process.c
index 85bf452a59..f25cc0acf9 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6878,7 +6878,7 @@ 
qemuProcessPrepareHostBackendChardevOne(virDomainDeviceDef *dev,
         devalias = data->fdprefix;
     }
 
-    switch ((virDomainChrType) chardev->type) {
+    switch (chardev->type) {
     case VIR_DOMAIN_CHR_TYPE_NULL:
     case VIR_DOMAIN_CHR_TYPE_VC:
     case VIR_DOMAIN_CHR_TYPE_PTY:
diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c
index e8830c4cd3..4d6355741e 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1968,7 +1968,7 @@ qemuValidateDomainChrSourceDef(const 
virDomainChrSourceDef *def,
                                const virDomainDef *vmdef,
                                virQEMUCaps *qemuCaps)
 {
-    switch ((virDomainChrType)def->type) {
+    switch (def->type) {
     case VIR_DOMAIN_CHR_TYPE_TCP:
         if (qemuValidateDomainChrSourceReconnectDef(&def->data.tcp.reconnect) 
< 0)
             return -1;
diff --git a/src/security/security_apparmor.c b/src/security/security_apparmor.c
index 008384dee8..c05a2fbaac 100644
--- a/src/security/security_apparmor.c
+++ b/src/security/security_apparmor.c
@@ -991,7 +991,7 @@ AppArmorSetChardevLabel(virSecurityManager *mgr,
     if (!secdef)
         return 0;
 
-    switch ((virDomainChrType)dev_source->type) {
+    switch (dev_source->type) {
     case VIR_DOMAIN_CHR_TYPE_DEV:
     case VIR_DOMAIN_CHR_TYPE_FILE:
     case VIR_DOMAIN_CHR_TYPE_UNIX:
@@ -1068,7 +1068,7 @@ AppArmorSetNetdevLabel(virSecurityManager *mgr,
         return 0;
 
     dev_source = net->data.vhostuser;
-    switch ((virDomainChrType)dev_source->type) {
+    switch (dev_source->type) {
     case VIR_DOMAIN_CHR_TYPE_UNIX:
         ret = reload_profile(mgr, def, dev_source->data.file.path, true);
         break;
diff --git a/src/security/security_dac.c b/src/security/security_dac.c
index 69c462de8b..211f5cf9a2 100644
--- a/src/security/security_dac.c
+++ b/src/security/security_dac.c
@@ -1506,7 +1506,7 @@ virSecurityDACSetChardevLabelHelper(virSecurityManager 
*mgr,
             return -1;
     }
 
-    switch ((virDomainChrType)dev_source->type) {
+    switch (dev_source->type) {
     case VIR_DOMAIN_CHR_TYPE_DEV:
     case VIR_DOMAIN_CHR_TYPE_FILE:
         if (virSecurityDACSetOwnership(mgr, NULL,
@@ -1598,7 +1598,7 @@ 
virSecurityDACRestoreChardevLabelHelper(virSecurityManager *mgr,
         chardevStdioLogd)
         return 0;
 
-    switch ((virDomainChrType)dev_source->type) {
+    switch (dev_source->type) {
     case VIR_DOMAIN_CHR_TYPE_DEV:
     case VIR_DOMAIN_CHR_TYPE_FILE:
         if (virSecurityDACRestoreFileLabelInternal(mgr, NULL,
diff --git a/src/security/security_selinux.c b/src/security/security_selinux.c
index 6f02baf2ce..9d9e308a38 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -2570,6 +2570,18 @@ virSecuritySELinuxSetChardevLabel(virSecurityManager 
*mgr,
         ret = 0;
         break;
 
+    case VIR_DOMAIN_CHR_TYPE_NULL:
+    case VIR_DOMAIN_CHR_TYPE_VC:
+    case VIR_DOMAIN_CHR_TYPE_PTY:
+    case VIR_DOMAIN_CHR_TYPE_STDIO:
+    case VIR_DOMAIN_CHR_TYPE_UDP:
+    case VIR_DOMAIN_CHR_TYPE_TCP:
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+    case VIR_DOMAIN_CHR_TYPE_NMDM:
+    case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+    case VIR_DOMAIN_CHR_TYPE_DBUS:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
     default:
         ret = 0;
         break;
@@ -2643,6 +2655,18 @@ virSecuritySELinuxRestoreChardevLabel(virSecurityManager 
*mgr,
         ret = 0;
         break;
 
+    case VIR_DOMAIN_CHR_TYPE_NULL:
+    case VIR_DOMAIN_CHR_TYPE_VC:
+    case VIR_DOMAIN_CHR_TYPE_PTY:
+    case VIR_DOMAIN_CHR_TYPE_STDIO:
+    case VIR_DOMAIN_CHR_TYPE_UDP:
+    case VIR_DOMAIN_CHR_TYPE_TCP:
+    case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+    case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+    case VIR_DOMAIN_CHR_TYPE_NMDM:
+    case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+    case VIR_DOMAIN_CHR_TYPE_DBUS:
+    case VIR_DOMAIN_CHR_TYPE_LAST:
     default:
         ret = 0;
         break;
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index c391caa910..9c63d48c59 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -4117,6 +4117,18 @@ virVMXFormatSerial(virVMXContext *ctx, virDomainChrDef 
*def,
                           def->source->data.tcp.listen ? "server" : "client");
         break;
 
+      case VIR_DOMAIN_CHR_TYPE_NULL:
+      case VIR_DOMAIN_CHR_TYPE_VC:
+      case VIR_DOMAIN_CHR_TYPE_PTY:
+      case VIR_DOMAIN_CHR_TYPE_STDIO:
+      case VIR_DOMAIN_CHR_TYPE_UDP:
+      case VIR_DOMAIN_CHR_TYPE_UNIX:
+      case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+      case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+      case VIR_DOMAIN_CHR_TYPE_NMDM:
+      case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+      case VIR_DOMAIN_CHR_TYPE_DBUS:
+      case VIR_DOMAIN_CHR_TYPE_LAST:
       default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Unsupported character device type '%s'"),
@@ -4174,6 +4186,20 @@ virVMXFormatParallel(virVMXContext *ctx, virDomainChrDef 
*def,
         VIR_FREE(fileName);
         break;
 
+      case VIR_DOMAIN_CHR_TYPE_NULL:
+      case VIR_DOMAIN_CHR_TYPE_VC:
+      case VIR_DOMAIN_CHR_TYPE_PTY:
+      case VIR_DOMAIN_CHR_TYPE_PIPE:
+      case VIR_DOMAIN_CHR_TYPE_STDIO:
+      case VIR_DOMAIN_CHR_TYPE_UDP:
+      case VIR_DOMAIN_CHR_TYPE_TCP:
+      case VIR_DOMAIN_CHR_TYPE_UNIX:
+      case VIR_DOMAIN_CHR_TYPE_SPICEVMC:
+      case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
+      case VIR_DOMAIN_CHR_TYPE_NMDM:
+      case VIR_DOMAIN_CHR_TYPE_LAST:
+      case VIR_DOMAIN_CHR_TYPE_QEMU_VDAGENT:
+      case VIR_DOMAIN_CHR_TYPE_DBUS:
       default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Unsupported character device type '%s'"),
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 004c7cf1d6..7fd3c94f5e 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -1044,7 +1044,7 @@ testQemuPrepareHostBackendChardevOne(virDomainDeviceDef 
*dev,
         devalias = "monitor";
     }
 
-    switch ((virDomainChrType) chardev->type) {
+    switch (chardev->type) {
     case VIR_DOMAIN_CHR_TYPE_NULL:
     case VIR_DOMAIN_CHR_TYPE_VC:
     case VIR_DOMAIN_CHR_TYPE_PTY:
-- 
2.35.1

Reply via email to