[PATCH v2 10/21] conf: Parse and format virDomainChrSerialTargetModel

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

 



This information will be used to select, and store in the guest
configuration in order to guarantee ABI stability, the concrete
(hypervisor-specific) model for serial devices.

Signed-off-by: Andrea Bolognani <abologna@xxxxxxxxxx>
---
 docs/schemas/domaincommon.rng | 15 +++++++++
 src/conf/domain_conf.c        | 72 ++++++++++++++++++++++++++++++++++++++++++-
 src/conf/domain_conf.h        | 12 ++++++++
 3 files changed, 98 insertions(+), 1 deletion(-)

diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index f1808065b..fbba092d1 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -3589,6 +3589,18 @@
     </attribute>
   </define>
 
+  <define name='qemucdevSerialTgtModel'>
+    <element name='model'>
+      <attribute name='name'>
+        <choice>
+          <value>isa-serial</value>
+          <value>usb-serial</value>
+          <value>pci-serial</value>
+        </choice>
+      </attribute>
+    </element>
+  </define>
+
   <define  name="qemucdevTgtDef">
     <element name="target">
       <interleave>
@@ -3603,6 +3615,9 @@
         <optional>
           <attribute name="port"/>
         </optional>
+        <optional>
+          <ref name="qemucdevSerialTgtModel"/>
+        </optional>
       </interleave>
     </element>
   </define>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 9d6e06025..140f478b0 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -472,6 +472,14 @@ VIR_ENUM_IMPL(virDomainChrConsoleTarget,
               "sclp",
               "sclplm")
 
+VIR_ENUM_IMPL(virDomainChrSerialTargetModel,
+              VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST,
+              "none",
+              "isa-serial",
+              "usb-serial",
+              "pci-serial",
+);
+
 VIR_ENUM_IMPL(virDomainChrDevice, VIR_DOMAIN_CHR_DEVICE_TYPE_LAST,
               "parallel",
               "serial",
@@ -11526,14 +11534,42 @@ virDomainChrTargetTypeFromString(int devtype,
     return ret;
 }
 
+static int
+virDomainChrTargetModelFromString(int devtype,
+                                  const char *targetModel)
+{
+    int ret = -1;
+
+    if (!targetModel)
+        return 0;
+
+    switch ((virDomainChrDeviceType) devtype) {
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
+        ret = virDomainChrSerialTargetModelTypeFromString(targetModel);
+        break;
+
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL:
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
+        /* Target model not supported yet */
+        ret = 0;
+        break;
+    }
+
+    return ret;
+}
+
 static int
 virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
                               xmlNodePtr cur,
                               unsigned int flags)
 {
     int ret = -1;
+    xmlNodePtr child;
     unsigned int port;
     char *targetType = virXMLPropString(cur, "type");
+    char *targetModel = NULL;
     char *addrStr = NULL;
     char *portStr = NULL;
     char *stateStr = NULL;
@@ -11547,6 +11583,24 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
         goto error;
     }
 
+    child = cur->children;
+    while (child != NULL) {
+        if (child->type == XML_ELEMENT_NODE &&
+            virXMLNodeNameEqual(child, "model")) {
+            targetModel = virXMLPropString(child, "name");
+        }
+        child = child->next;
+    }
+
+    if ((def->targetModel =
+         virDomainChrTargetModelFromString(def->deviceType,
+                                           targetModel)) < 0) {
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+                       _("unknown target model '%s' specified for character device"),
+                       targetModel);
+        goto error;
+    }
+
     switch (def->deviceType) {
     case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL:
         switch (def->targetType) {
@@ -11635,6 +11689,7 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
     ret = 0;
  error:
     VIR_FREE(targetType);
+    VIR_FREE(targetModel);
     VIR_FREE(addrStr);
     VIR_FREE(portStr);
     VIR_FREE(stateStr);
@@ -24016,8 +24071,23 @@ virDomainChrTargetDefFormat(virBufferPtr buf,
         }
 
         virBufferAsprintf(buf,
-                          "port='%d'/>\n",
+                          "port='%d'",
                           def->target.port);
+
+        if (def->targetModel != VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE) {
+            virBufferAddLit(buf, ">\n");
+
+            virBufferAdjustIndent(buf, 2);
+            virBufferAsprintf(buf,
+                              "<model name='%s'/>\n",
+                              virDomainChrSerialTargetModelTypeToString(def->targetModel));
+            virBufferAdjustIndent(buf, -2);
+
+            virBufferAddLit(buf, "</target>\n");
+        } else {
+            virBufferAddLit(buf, "/>\n");
+        }
+
         break;
 
     case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index 5d4d17ed6..3e74c635b 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -1112,6 +1112,17 @@ typedef enum {
     VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LAST
 } virDomainChrConsoleTargetType;
 
+typedef enum {
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE = 0,
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL,
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL,
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL,
+
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST
+} virDomainChrSerialTargetModel;
+
+VIR_ENUM_DECL(virDomainChrSerialTargetModel);
+
 typedef enum {
     VIR_DOMAIN_CHR_TYPE_NULL,
     VIR_DOMAIN_CHR_TYPE_VC,
@@ -1210,6 +1221,7 @@ struct _virDomainChrDef {
     int targetType; /* enum virDomainChrConsoleTargetType ||
                        enum virDomainChrChannelTargetType ||
                        enum virDomainChrSerialTargetType according to deviceType */
+    int targetModel; /* enum virDomainChrSerialTargetModel */
 
     union {
         int port; /* parallel, serial, console */
-- 
2.14.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[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