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

[libvirt] [PATCH 3/5] domain conf: char: Add an explicit targetType field



targetType only tracks the actual <target> format we are parsing.
TYPE_DEFAULT is the typical serial/parallel format, NONE is for the
<monitor> device which prints nothing.

Signed-off-by: Cole Robinson <crobinso redhat com>
---
 src/conf/domain_conf.c |  108 ++++++++++++++++++++++++-----------------------
 src/conf/domain_conf.h |   19 ++++++--
 src/qemu/qemu_conf.c   |    6 +-
 3 files changed, 72 insertions(+), 61 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index c9140fe..e4d52ff 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -161,14 +161,18 @@ VIR_ENUM_IMPL(virDomainNet, VIR_DOMAIN_NET_TYPE_LAST,
               "internal",
               "direct")
 
+VIR_ENUM_IMPL(virDomainChrTarget, VIR_DOMAIN_CHR_TARGET_TYPE_LAST,
+              "none",
+              "default",
+              "guestfwd",
+              "virtio")
+
 VIR_ENUM_IMPL(virDomainChrDevice, VIR_DOMAIN_CHR_DEVICE_TYPE_LAST,
-              "null",
               "monitor",
               "parallel",
               "serial",
               "console",
-              "guestfwd",
-              "virtio")
+              "channel")
 
 VIR_ENUM_IMPL(virDomainChr, VIR_DOMAIN_CHR_TYPE_LAST,
               "null",
@@ -516,12 +520,12 @@ void virDomainChrDefFree(virDomainChrDefPtr def)
     if (!def)
         return;
 
-    switch (def->deviceType) {
-    case VIR_DOMAIN_CHR_DEVICE_TYPE_GUESTFWD:
+    switch (def->targetType) {
+    case VIR_DOMAIN_CHR_TARGET_TYPE_GUESTFWD:
         VIR_FREE(def->target.addr);
         break;
 
-    case VIR_DOMAIN_CHR_DEVICE_TYPE_VIRTIO:
+    case VIR_DOMAIN_CHR_TARGET_TYPE_VIRTIO:
         VIR_FREE(def->target.name);
         break;
     }
@@ -2379,7 +2383,7 @@ virDomainChrDefParseXML(xmlNodePtr node,
     char *mode = NULL;
     char *protocol = NULL;
     const char *nodeName;
-    const char *deviceType = NULL;
+    const char *targetType = NULL;
     const char *addrStr = NULL;
     const char *portStr = NULL;
     virDomainChrDefPtr def;
@@ -2397,15 +2401,9 @@ virDomainChrDefParseXML(xmlNodePtr node,
 
     nodeName = (const char *) node->name;
     if ((def->deviceType = virDomainChrDeviceTypeFromString(nodeName)) < 0) {
-        /* channel is handled below */
-        if (STRNEQ(nodeName, "channel")) {
-            virDomainReportError(VIR_ERR_XML_ERROR,
-                              _("unknown target type for character device: %s"),
-                                 nodeName);
-            VIR_FREE(def);
-            return NULL;
-        }
-        def->deviceType = VIR_DOMAIN_CHR_DEVICE_TYPE_NULL;
+        virDomainReportError(VIR_ERR_XML_ERROR,
+                             _("unknown character device type: %s"),
+                             nodeName);
     }
 
     cur = node->children;
@@ -2454,31 +2452,36 @@ virDomainChrDefParseXML(xmlNodePtr node,
                 if (protocol == NULL)
                     protocol = virXMLPropString(cur, "type");
             } else if (xmlStrEqual(cur->name, BAD_CAST "target")) {
-                /* If target type isn't set yet, expect it to be set here */
-                if (def->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_NULL) {
-                    deviceType = virXMLPropString(cur, "type");
-                    if (deviceType == NULL) {
+                def->targetType = VIR_DOMAIN_CHR_TARGET_TYPE_DEFAULT;
+
+                if (def->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_MONITOR) {
+                    /* Don't target <target> info for monitor device */
+                    def->targetType = VIR_DOMAIN_CHR_TARGET_TYPE_NONE;
+
+                } else if (def->deviceType ==
+                            VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL) {
+                    targetType = virXMLPropString(cur, "type");
+                    if (targetType == NULL) {
                         virDomainReportError(VIR_ERR_XML_ERROR, "%s",
                                              _("character device target does "
                                                "not define a type"));
                         goto error;
                     }
-                    if ((def->deviceType =
-                        virDomainChrDeviceTypeFromString(deviceType)) < 0)
+
+                    if ((def->targetType =
+                        virDomainChrTargetTypeFromString(targetType)) < 0)
                     {
                         virDomainReportError(VIR_ERR_XML_ERROR,
                                              _("unknown target type for "
                                                "character device: %s"),
-                                             deviceType);
+                                             targetType);
                         goto error;
                     }
                 }
 
                 unsigned int port;
-                switch (def->deviceType) {
-                case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
-                case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
-                case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
+                switch (def->targetType) {
+                case VIR_DOMAIN_CHR_TARGET_TYPE_DEFAULT:
                     portStr = virXMLPropString(cur, "port");
                     if (portStr == NULL) {
                         /* Not required. It will be assigned automatically
@@ -2494,7 +2497,7 @@ virDomainChrDefParseXML(xmlNodePtr node,
                     }
                     break;
 
-                case VIR_DOMAIN_CHR_DEVICE_TYPE_GUESTFWD:
+                case VIR_DOMAIN_CHR_TARGET_TYPE_GUESTFWD:
                     addrStr = virXMLPropString(cur, "address");
                     portStr = virXMLPropString(cur, "port");
 
@@ -2538,14 +2541,17 @@ virDomainChrDefParseXML(xmlNodePtr node,
                     virSocketSetPort(def->target.addr, port);
                     break;
 
-                case VIR_DOMAIN_CHR_DEVICE_TYPE_VIRTIO:
+                case VIR_DOMAIN_CHR_TARGET_TYPE_VIRTIO:
                     def->target.name = virXMLPropString(cur, "name");
                     break;
 
+                case VIR_DOMAIN_CHR_TARGET_TYPE_NONE:
+                    break;
+
                 default:
                     virDomainReportError(VIR_ERR_XML_ERROR,
-                                         _("unexpected target type type %u"),
-                                         def->deviceType);
+                                         _("unexpected target type %u"),
+                                         def->targetType);
                 }
             }
         }
@@ -2678,7 +2684,7 @@ cleanup:
     VIR_FREE(connectHost);
     VIR_FREE(connectService);
     VIR_FREE(path);
-    VIR_FREE(deviceType);
+    VIR_FREE(targetType);
     VIR_FREE(addrStr);
     VIR_FREE(portStr);
 
@@ -4422,7 +4428,7 @@ static virDomainDefPtr virDomainDefParseXML(virCapsPtr caps,
 
         def->channels[def->nchannels++] = chr;
 
-        if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_VIRTIO &&
+        if (chr->targetType == VIR_DOMAIN_CHR_TARGET_TYPE_VIRTIO &&
             chr->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
             chr->info.type = VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL;
 
@@ -4891,7 +4897,7 @@ static int virDomainDefMaybeAddVirtioSerialController(virDomainDefPtr def)
     for (i = 0 ; i < def->nchannels ; i++) {
         virDomainChrDefPtr channel = def->channels[i];
 
-        if (channel->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_VIRTIO) {
+        if (channel->targetType == VIR_DOMAIN_CHR_TARGET_TYPE_VIRTIO) {
             int idx = 0;
             if (channel->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_VIRTIO_SERIAL)
                 idx = channel->info.addr.vioserial.controller;
@@ -5473,28 +5479,23 @@ virDomainChrDefFormat(virBufferPtr buf,
                       int flags)
 {
     const char *type = virDomainChrTypeToString(def->type);
-    const char *targetName = virDomainChrDeviceTypeToString(def->deviceType);
-    const char *elementName;
+    const char *elementName = virDomainChrDeviceTypeToString(def->deviceType);
 
     int ret = 0;
 
-    switch (def->deviceType) {
-    /* channel types are in a common channel element */
-    case VIR_DOMAIN_CHR_DEVICE_TYPE_GUESTFWD:
-    case VIR_DOMAIN_CHR_DEVICE_TYPE_VIRTIO:
-        elementName = "channel";
-        break;
-
-    default:
-        elementName = targetName;
-    }
-
     if (!type) {
         virDomainReportError(VIR_ERR_INTERNAL_ERROR,
                              _("unexpected char type %d"), def->type);
         return -1;
     }
 
+    if (!elementName) {
+        virDomainReportError(VIR_ERR_INTERNAL_ERROR,
+                             _("unexpected char device type %d"),
+                             def->deviceType);
+        return -1;
+    }
+
     /* Compat with legacy  <console tty='/dev/pts/5'/> syntax */
     virBufferVSprintf(buf, "    <%s type='%s'",
                       elementName, type);
@@ -5573,8 +5574,8 @@ virDomainChrDefFormat(virBufferPtr buf,
         break;
     }
 
-    switch (def->deviceType) {
-    case VIR_DOMAIN_CHR_DEVICE_TYPE_GUESTFWD:
+    switch (def->targetType) {
+    case VIR_DOMAIN_CHR_TARGET_TYPE_GUESTFWD:
         {
             int port = virSocketGetPort(def->target.addr);
             if (port < 0) {
@@ -5595,7 +5596,7 @@ virDomainChrDefFormat(virBufferPtr buf,
             break;
         }
 
-    case VIR_DOMAIN_CHR_DEVICE_TYPE_VIRTIO:
+    case VIR_DOMAIN_CHR_TARGET_TYPE_VIRTIO:
         virBufferAddLit(buf, "      <target type='virtio'");
         if (def->target.name) {
             virBufferEscapeString(buf, " name='%s'", def->target.name);
@@ -5603,12 +5604,13 @@ virDomainChrDefFormat(virBufferPtr buf,
         virBufferAddLit(buf, "/>\n");
         break;
 
-    case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
-    case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
-    case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
+    case VIR_DOMAIN_CHR_TARGET_TYPE_DEFAULT:
         virBufferVSprintf(buf, "      <target port='%d'/>\n", def->target.port);
         break;
 
+    case VIR_DOMAIN_CHR_TARGET_TYPE_NONE:
+        break;
+
     default:
         virDomainReportError(VIR_ERR_INTERNAL_ERROR,
                              _("unexpected character destination type %d"),
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index b4e756a..75dc29a 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -312,15 +312,22 @@ struct _virDomainNetDef {
 };
 
 enum virDomainChrDeviceType {
-    VIR_DOMAIN_CHR_DEVICE_TYPE_NULL = 0,
-    VIR_DOMAIN_CHR_DEVICE_TYPE_MONITOR,
+    VIR_DOMAIN_CHR_DEVICE_TYPE_MONITOR = 0,
     VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL,
     VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL,
     VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE,
-    VIR_DOMAIN_CHR_DEVICE_TYPE_GUESTFWD,
-    VIR_DOMAIN_CHR_DEVICE_TYPE_VIRTIO,
+    VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL,
 
-    VIR_DOMAIN_CHR_DEVICE_TYPE_LAST
+    VIR_DOMAIN_CHR_DEVICE_TYPE_LAST,
+};
+
+enum virDomainChrTargetType {
+    VIR_DOMAIN_CHR_TARGET_TYPE_DEFAULT = 0,
+    VIR_DOMAIN_CHR_TARGET_TYPE_NONE,
+    VIR_DOMAIN_CHR_TARGET_TYPE_GUESTFWD,
+    VIR_DOMAIN_CHR_TARGET_TYPE_VIRTIO,
+
+    VIR_DOMAIN_CHR_TARGET_TYPE_LAST,
 };
 
 enum virDomainChrType {
@@ -349,6 +356,7 @@ typedef struct _virDomainChrDef virDomainChrDef;
 typedef virDomainChrDef *virDomainChrDefPtr;
 struct _virDomainChrDef {
     int deviceType;
+    int targetType;
     union {
         int port; /* parallel, serial, console */
         virSocketAddrPtr addr; /* guestfwd */
@@ -1096,6 +1104,7 @@ VIR_ENUM_DECL(virDomainControllerModel)
 VIR_ENUM_DECL(virDomainFS)
 VIR_ENUM_DECL(virDomainNet)
 VIR_ENUM_DECL(virDomainChrDevice)
+VIR_ENUM_DECL(virDomainChrTarget)
 VIR_ENUM_DECL(virDomainChr)
 VIR_ENUM_DECL(virDomainSoundModel)
 VIR_ENUM_DECL(virDomainWatchdogModel)
diff --git a/src/qemu/qemu_conf.c b/src/qemu/qemu_conf.c
index 1c4e934..62b4fb7 100644
--- a/src/qemu/qemu_conf.c
+++ b/src/qemu/qemu_conf.c
@@ -4382,8 +4382,8 @@ int qemudBuildCommandLine(virConnectPtr conn,
         virDomainChrDefPtr channel = def->channels[i];
         char *devstr;
 
-        switch(channel->deviceType) {
-        case VIR_DOMAIN_CHR_DEVICE_TYPE_GUESTFWD:
+        switch(channel->targetType) {
+        case VIR_DOMAIN_CHR_TARGET_TYPE_GUESTFWD:
             if (!(qemuCmdFlags & QEMUD_CMD_FLAG_CHARDEV) ||
                 !(qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE)) {
                 qemuReportError(VIR_ERR_NO_SUPPORT,
@@ -4409,7 +4409,7 @@ int qemudBuildCommandLine(virConnectPtr conn,
             ADD_ARG(devstr);
             break;
 
-        case VIR_DOMAIN_CHR_DEVICE_TYPE_VIRTIO:
+        case VIR_DOMAIN_CHR_TARGET_TYPE_VIRTIO:
             if (!(qemuCmdFlags & QEMUD_CMD_FLAG_DEVICE)) {
                 qemuReportError(VIR_ERR_NO_SUPPORT, "%s",
                     _("virtio channel requires QEMU to support -device"));
-- 
1.6.6.1


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