[PATCH 12/17] virDomainChrDefParseXML: Switch to virXMLPropEnumDefault()

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

 



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

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 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             | 24 ++++++++++
 src/libxl/libxl_conf.c           | 16 +++++++
 src/libxl/xen_common.c           | 19 +++++++-
 src/qemu/qemu_command.c          |  6 +--
 src/qemu/qemu_domain.c           | 30 +++++++++++-
 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  | 20 ++++++++
 src/vmx/vmx.c                    | 22 +++++++++
 tests/testutilsqemu.c            |  2 +-
 17 files changed, 172 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 97cf4f20eb..84a65076b9 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -2684,7 +2684,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:
@@ -2745,6 +2745,13 @@ virDomainChrSourceDefClear(virDomainChrSourceDef *def)
     case VIR_DOMAIN_CHR_TYPE_SPICEPORT:
         VIR_FREE(def->data.spiceport.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_LAST:
+        break;
     }
 
     VIR_FREE(def->logfile);
@@ -2762,7 +2769,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:
@@ -2850,7 +2857,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);
@@ -11247,7 +11254,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;
@@ -11444,7 +11451,6 @@ virDomainChrDefParseXML(virDomainXMLOption *xmlopt,
     xmlNodePtr target;
     const char *nodeName;
     virDomainChrDef *def;
-    g_autofree char *type = NULL;
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
 
     ctxt->node = node;
@@ -11452,15 +11458,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) {
@@ -11518,7 +11521,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)
@@ -11564,23 +11566,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)
@@ -13268,7 +13261,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);
 
@@ -13324,22 +13316,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,
@@ -14239,7 +14223,6 @@ virDomainRedirdevDefParseXML(virDomainXMLOption *xmlopt,
 {
     virDomainRedirdevDef *def;
     g_autofree char *bus = NULL;
-    g_autofree char *type = NULL;
 
     def = g_new0(virDomainRedirdevDef, 1);
 
@@ -14257,18 +14240,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 */
@@ -24975,7 +24951,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 f23444d768..c500a78680 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1272,7 +1272,7 @@ struct _virDomainChrSourceReconnectDef {
 /* 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 2aab8e8b40..9e64a96eb9 100644
--- a/src/conf/domain_validate.c
+++ b/src/conf/domain_validate.c
@@ -843,7 +843,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..7123229ede 100644
--- a/src/conf/virchrdev.c
+++ b/src/conf/virchrdev.c
@@ -339,6 +339,18 @@ 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_LAST:
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Unsupported device type '%s'"),
@@ -404,6 +416,18 @@ 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_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 a6a110e548..7a733cf30d 100644
--- a/src/libxl/libxl_conf.c
+++ b/src/libxl/libxl_conf.c
@@ -273,6 +273,10 @@ 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_LAST:
     default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("unsupported chardev '%s'"), type);
@@ -1970,6 +1974,18 @@ 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_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..1b22bc2787 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,16 @@ 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_LAST:
+    break;
     }
 
     return def;
@@ -1525,6 +1538,10 @@ 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_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 8eda740571..3ef062f2e5 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -1303,7 +1303,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;
@@ -1458,7 +1458,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;
@@ -8628,7 +8628,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 15f753b0fc..f8e67e5479 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -2309,10 +2309,26 @@ 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_LAST:
+        default:
+            virReportError(VIR_ERR_INTERNAL_ERROR,
+                           _("unsupported monitor type '%s'"),
+                           virDomainChrTypeToString(priv->monConfig->type));
+            return -1;
         }
 
         virBufferEscapeString(buf, "<monitor path='%s'", monitorpath);
@@ -2954,6 +2970,18 @@ 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_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 bf3245f7e2..3cfd1cc161 100644
--- a/src/qemu/qemu_monitor_json.c
+++ b/src/qemu/qemu_monitor_json.c
@@ -6681,7 +6681,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 bb754ff8d6..5f70bd3115 100644
--- a/src/qemu/qemu_process.c
+++ b/src/qemu/qemu_process.c
@@ -6820,7 +6820,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 37844c1874..097e35a430 100644
--- a/src/qemu/qemu_validate.c
+++ b/src/qemu/qemu_validate.c
@@ -1975,7 +1975,7 @@ static int
 qemuValidateDomainChrSourceDef(const virDomainChrSourceDef *def,
                                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 8f7acba980..957c1a6357 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:
@@ -1066,7 +1066,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 e9e316551e..183f291cc6 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,
@@ -1596,7 +1596,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..099306b522 100644
--- a/src/security/security_selinux.c
+++ b/src/security/security_selinux.c
@@ -2570,6 +2570,16 @@ 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_LAST:
     default:
         ret = 0;
         break;
@@ -2643,6 +2653,16 @@ 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_LAST:
     default:
         ret = 0;
         break;
diff --git a/src/vmx/vmx.c b/src/vmx/vmx.c
index 8150bbfaa9..8f519e9302 100644
--- a/src/vmx/vmx.c
+++ b/src/vmx/vmx.c
@@ -4116,6 +4116,16 @@ 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_LAST:
       default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Unsupported character device type '%s'"),
@@ -4173,6 +4183,18 @@ 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:
       default:
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
                        _("Unsupported character device type '%s'"),
diff --git a/tests/testutilsqemu.c b/tests/testutilsqemu.c
index 105b41cbeb..c0c829fbd1 100644
--- a/tests/testutilsqemu.c
+++ b/tests/testutilsqemu.c
@@ -1031,7 +1031,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




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux