render / rpms / libvirt

Forked from rpms/libvirt 11 months ago
Clone
404507
From f39b12fb966c2dfe7841a299f00ff5c6fa68095e Mon Sep 17 00:00:00 2001
404507
Message-Id: <f39b12fb966c2dfe7841a299f00ff5c6fa68095e@dist-git>
404507
From: Andrea Bolognani <abologna@redhat.com>
404507
Date: Wed, 29 Nov 2017 16:23:07 +0100
404507
Subject: [PATCH] conf: Parse and format virDomainChrSerialTargetModel
404507
404507
This information will be used to select, and store in the guest
404507
configuration in order to guarantee ABI stability, the concrete
404507
(hypervisor-specific) model for serial devices.
404507
404507
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
404507
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
404507
(cherry picked from commit 5ad9d9afd4738ea716a6f820bbb53eecf5604a2f)
404507
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1449265
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1511421
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1512929
404507
https://bugzilla.redhat.com/show_bug.cgi?id=1512934
404507
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
404507
---
404507
 docs/formatdomain.html.in     | 16 ++++++++--
404507
 docs/schemas/domaincommon.rng | 15 +++++++++
404507
 src/conf/domain_conf.c        | 72 ++++++++++++++++++++++++++++++++++++++++++-
404507
 src/conf/domain_conf.h        | 12 ++++++++
404507
 4 files changed, 112 insertions(+), 3 deletions(-)
404507
404507
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
404507
index f57a124056..cf1167b9c6 100644
404507
--- a/docs/formatdomain.html.in
404507
+++ b/docs/formatdomain.html.in
404507
@@ -6447,7 +6447,9 @@ qemu-kvm -net nic,model=? /dev/null
404507
 <devices>
404507
   <!-- USB serial port -->
404507
   <serial type='pty'>
404507
-    <target type='usb-serial' port='0'/>
404507
+    <target type='usb-serial' port='0'>
404507
+      <model name='usb-serial'/>
404507
+    </target>
404507
     <address type='usb' bus='0' port='1'/>
404507
   </serial>
404507
 </devices>
404507
@@ -6463,6 +6465,16 @@ qemu-kvm -net nic,model=? /dev/null
404507
       is available).
404507
     

404507
 
404507
+    

404507
+      Since 3.10.0, the target
404507
+      element can have an optional model subelement;
404507
+      valid values for its name attribute are:
404507
+      isa-serial (usable with the isa-serial target
404507
+      type); usb-serial (usable with the usb-serial
404507
+      target type); pci-serial
404507
+      (usable with the pci-serial target type).
404507
+    

404507
+
404507
     

404507
       If any of the attributes is not specified by the user, libvirt will
404507
       choose a value suitable for most users.
404507
@@ -6489,7 +6501,7 @@ qemu-kvm -net nic,model=? /dev/null
404507
   <!-- Serial console -->
404507
   <console type='pty'>
404507
     <source path='/dev/pts/2'/>
404507
-    <target type='serial' port='0'/>
404507
+   <target type='serial' port='0'/>
404507
   </console>
404507
 </devices>
404507
 ...
404507
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
404507
index 367861c1ea..3630e539e6 100644
404507
--- a/docs/schemas/domaincommon.rng
404507
+++ b/docs/schemas/domaincommon.rng
404507
@@ -3575,6 +3575,18 @@
404507
     </attribute>
404507
   </define>
404507
 
404507
+  <define name='qemucdevSerialTgtModel'>
404507
+    <element name='model'>
404507
+      <attribute name='name'>
404507
+        <choice>
404507
+          <value>isa-serial</value>
404507
+          <value>usb-serial</value>
404507
+          <value>pci-serial</value>
404507
+        </choice>
404507
+      </attribute>
404507
+    </element>
404507
+  </define>
404507
+
404507
   <define  name="qemucdevTgtDef">
404507
     <element name="target">
404507
       <interleave>
404507
@@ -3589,6 +3601,9 @@
404507
         <optional>
404507
           <attribute name="port"/>
404507
         </optional>
404507
+        <optional>
404507
+          <ref name="qemucdevSerialTgtModel"/>
404507
+        </optional>
404507
       </interleave>
404507
     </element>
404507
   </define>
404507
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
404507
index 44d9bbe01d..692b9d9414 100644
404507
--- a/src/conf/domain_conf.c
404507
+++ b/src/conf/domain_conf.c
404507
@@ -465,6 +465,14 @@ VIR_ENUM_IMPL(virDomainChrConsoleTarget,
404507
               "sclp",
404507
               "sclplm")
404507
 
404507
+VIR_ENUM_IMPL(virDomainChrSerialTargetModel,
404507
+              VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST,
404507
+              "none",
404507
+              "isa-serial",
404507
+              "usb-serial",
404507
+              "pci-serial",
404507
+);
404507
+
404507
 VIR_ENUM_IMPL(virDomainChrDevice, VIR_DOMAIN_CHR_DEVICE_TYPE_LAST,
404507
               "parallel",
404507
               "serial",
404507
@@ -11530,14 +11538,42 @@ virDomainChrTargetTypeFromString(int devtype,
404507
     return ret;
404507
 }
404507
 
404507
+static int
404507
+virDomainChrTargetModelFromString(int devtype,
404507
+                                  const char *targetModel)
404507
+{
404507
+    int ret = -1;
404507
+
404507
+    if (!targetModel)
404507
+        return 0;
404507
+
404507
+    switch ((virDomainChrDeviceType) devtype) {
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_SERIAL:
404507
+        ret = virDomainChrSerialTargetModelTypeFromString(targetModel);
404507
+        break;
404507
+
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL:
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE:
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
404507
+    case VIR_DOMAIN_CHR_DEVICE_TYPE_LAST:
404507
+        /* Target model not supported yet */
404507
+        ret = 0;
404507
+        break;
404507
+    }
404507
+
404507
+    return ret;
404507
+}
404507
+
404507
 static int
404507
 virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
404507
                               xmlNodePtr cur,
404507
                               unsigned int flags)
404507
 {
404507
     int ret = -1;
404507
+    xmlNodePtr child;
404507
     unsigned int port;
404507
     char *targetType = virXMLPropString(cur, "type");
404507
+    char *targetModel = NULL;
404507
     char *addrStr = NULL;
404507
     char *portStr = NULL;
404507
     char *stateStr = NULL;
404507
@@ -11551,6 +11587,24 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
404507
         goto error;
404507
     }
404507
 
404507
+    child = cur->children;
404507
+    while (child != NULL) {
404507
+        if (child->type == XML_ELEMENT_NODE &&
404507
+            virXMLNodeNameEqual(child, "model")) {
404507
+            targetModel = virXMLPropString(child, "name");
404507
+        }
404507
+        child = child->next;
404507
+    }
404507
+
404507
+    if ((def->targetModel =
404507
+         virDomainChrTargetModelFromString(def->deviceType,
404507
+                                           targetModel)) < 0) {
404507
+        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
404507
+                       _("unknown target model '%s' specified for character device"),
404507
+                       targetModel);
404507
+        goto error;
404507
+    }
404507
+
404507
     switch (def->deviceType) {
404507
     case VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL:
404507
         switch (def->targetType) {
404507
@@ -11639,6 +11693,7 @@ virDomainChrDefParseTargetXML(virDomainChrDefPtr def,
404507
     ret = 0;
404507
  error:
404507
     VIR_FREE(targetType);
404507
+    VIR_FREE(targetModel);
404507
     VIR_FREE(addrStr);
404507
     VIR_FREE(portStr);
404507
     VIR_FREE(stateStr);
404507
@@ -24019,8 +24074,23 @@ virDomainChrTargetDefFormat(virBufferPtr buf,
404507
         }
404507
 
404507
         virBufferAsprintf(buf,
404507
-                          "port='%d'/>\n",
404507
+                          "port='%d'",
404507
                           def->target.port);
404507
+
404507
+        if (def->targetModel != VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE) {
404507
+            virBufferAddLit(buf, ">\n");
404507
+
404507
+            virBufferAdjustIndent(buf, 2);
404507
+            virBufferAsprintf(buf,
404507
+                              "<model name='%s'/>\n",
404507
+                              virDomainChrSerialTargetModelTypeToString(def->targetModel));
404507
+            virBufferAdjustIndent(buf, -2);
404507
+
404507
+            virBufferAddLit(buf, "</target>\n");
404507
+        } else {
404507
+            virBufferAddLit(buf, "/>\n");
404507
+        }
404507
+
404507
         break;
404507
 
404507
     case VIR_DOMAIN_CHR_DEVICE_TYPE_PARALLEL:
404507
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
404507
index bbb056cf21..9dfe9388cd 100644
404507
--- a/src/conf/domain_conf.h
404507
+++ b/src/conf/domain_conf.h
404507
@@ -1104,6 +1104,17 @@ typedef enum {
404507
     VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_LAST
404507
 } virDomainChrConsoleTargetType;
404507
 
404507
+typedef enum {
404507
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_NONE = 0,
404507
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_ISA_SERIAL,
404507
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_USB_SERIAL,
404507
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_PCI_SERIAL,
404507
+
404507
+    VIR_DOMAIN_CHR_SERIAL_TARGET_MODEL_LAST
404507
+} virDomainChrSerialTargetModel;
404507
+
404507
+VIR_ENUM_DECL(virDomainChrSerialTargetModel);
404507
+
404507
 typedef enum {
404507
     VIR_DOMAIN_CHR_TYPE_NULL,
404507
     VIR_DOMAIN_CHR_TYPE_VC,
404507
@@ -1202,6 +1213,7 @@ struct _virDomainChrDef {
404507
     int targetType; /* enum virDomainChrConsoleTargetType ||
404507
                        enum virDomainChrChannelTargetType ||
404507
                        enum virDomainChrSerialTargetType according to deviceType */
404507
+    int targetModel; /* enum virDomainChrSerialTargetModel */
404507
 
404507
     union {
404507
         int port; /* parallel, serial, console */
404507
-- 
404507
2.15.1
404507