Blob Blame History Raw
From 4c2b1b9cf0bcd8af7a7d011cd758bb6f11e5477b Mon Sep 17 00:00:00 2001
Message-Id: <4c2b1b9cf0bcd8af7a7d011cd758bb6f11e5477b@dist-git>
From: Andrea Bolognani <abologna@redhat.com>
Date: Mon, 17 Jul 2017 12:09:09 +0200
Subject: [PATCH] conf: Parse and format <target index='...'/>

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Reviewed-by: Laine Stump <laine@laine.org>
(cherry picked from commit 47dd6e282ab8b0db662092cf0cc53163d805ac4d)

Conflicts:
  * src/conf/domain_conf.c:

    caused by e146264aaadf5aecf727d8c7b3d85683b55b6c48,
    which significantly refactored
    virDomainControllerDefFormat(), not being in the tree.

Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1431193

Signed-off-by: Andrea Bolognani <abologna@redhat.com>
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
---
 docs/formatdomain.html.in     |  6 ++++++
 docs/schemas/domaincommon.rng |  5 +++++
 src/conf/domain_conf.c        | 32 ++++++++++++++++++++++++++++++++
 src/conf/domain_conf.h        |  1 +
 4 files changed, 44 insertions(+)

diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
index dc8e7d2dc7..bc67a53408 100644
--- a/docs/formatdomain.html.in
+++ b/docs/formatdomain.html.in
@@ -3760,6 +3760,12 @@
         libvirt API to attach host devices to the correct
         pci-expander-bus when assigning them to the domain).
       </dd>
+      <dt><code>index</code></dt>
+      <dd>
+        pci-root controllers for pSeries guests use this attribute to
+        record the order they will show up in the guest.
+        <span class="since">Since 3.6.0</span>
+      </dd>
     </dl>
     <p>
       For machine types which provide an implicit PCI bus, the pci-root
diff --git a/docs/schemas/domaincommon.rng b/docs/schemas/domaincommon.rng
index 964e5c5bd5..b1461d4c61 100644
--- a/docs/schemas/domaincommon.rng
+++ b/docs/schemas/domaincommon.rng
@@ -1945,6 +1945,11 @@
                   </attribute>
                 </optional>
                 <optional>
+                  <attribute name='index'>
+                    <ref name='uint8'/>
+                  </attribute>
+                </optional>
+                <optional>
                   <element name='node'>
                     <ref name='unsignedInt'/>
                   </element>
diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 8a030c9b68..599db5cafe 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1854,6 +1854,7 @@ virDomainControllerDefNew(virDomainControllerType type)
         def->opts.pciopts.chassis = -1;
         def->opts.pciopts.port = -1;
         def->opts.pciopts.busNr = -1;
+        def->opts.pciopts.targetIndex = -1;
         def->opts.pciopts.numaNode = -1;
         break;
     case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
@@ -8964,6 +8965,7 @@ virDomainControllerDefParseXML(xmlNodePtr node,
     char *chassis = NULL;
     char *port = NULL;
     char *busNr = NULL;
+    char *targetIndex = NULL;
     int numaNode = -1;
     char *ioeventfd = NULL;
     char *portsStr = NULL;
@@ -9036,6 +9038,7 @@ virDomainControllerDefParseXML(xmlNodePtr node,
                 chassis = virXMLPropString(cur, "chassis");
                 port = virXMLPropString(cur, "port");
                 busNr = virXMLPropString(cur, "busNr");
+                targetIndex = virXMLPropString(cur, "index");
                 processedTarget = true;
             }
         }
@@ -9254,6 +9257,30 @@ virDomainControllerDefParseXML(xmlNodePtr node,
                 goto error;
             }
         }
+        if (targetIndex) {
+            if (virStrToLong_i(targetIndex, NULL, 0,
+                               &def->opts.pciopts.targetIndex) < 0) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("Invalid target index '%s' in PCI controller"),
+                               targetIndex);
+                goto error;
+            }
+            if (def->opts.pciopts.targetIndex < 0 ||
+                def->opts.pciopts.targetIndex > 31) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("PCI controller target index '%s' out of "
+                                 "range - must be 0-31"),
+                               targetIndex);
+                goto error;
+            }
+            if ((def->idx == 0 && def->opts.pciopts.targetIndex != 0) ||
+                (def->idx != 0 && def->opts.pciopts.targetIndex == 0)) {
+                virReportError(VIR_ERR_XML_ERROR, "%s",
+                               _("Only the PCI controller with index 0 can "
+                                 "have target index 0, and vice versa"));
+                goto error;
+            }
+        }
         if (numaNode >= 0)
             def->opts.pciopts.numaNode = numaNode;
         break;
@@ -9275,6 +9302,7 @@ virDomainControllerDefParseXML(xmlNodePtr node,
     VIR_FREE(chassis);
     VIR_FREE(port);
     VIR_FREE(busNr);
+    VIR_FREE(targetIndex);
     VIR_FREE(ioeventfd);
     VIR_FREE(portsStr);
     VIR_FREE(iothread);
@@ -21615,6 +21643,7 @@ virDomainControllerDefFormat(virBufferPtr buf,
             def->opts.pciopts.chassis != -1 ||
             def->opts.pciopts.port != -1 ||
             def->opts.pciopts.busNr != -1 ||
+            def->opts.pciopts.targetIndex != -1 ||
             def->opts.pciopts.numaNode != -1)
             pciTarget = true;
         break;
@@ -21655,6 +21684,9 @@ virDomainControllerDefFormat(virBufferPtr buf,
             if (def->opts.pciopts.busNr != -1)
                 virBufferAsprintf(buf, " busNr='%d'",
                                   def->opts.pciopts.busNr);
+            if (def->opts.pciopts.targetIndex != -1)
+                virBufferAsprintf(buf, " index='%d'",
+                                  def->opts.pciopts.targetIndex);
             if (def->opts.pciopts.numaNode == -1) {
                 virBufferAddLit(buf, "/>\n");
             } else {
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index e287e6d7f3..50fdc6e2a6 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -786,6 +786,7 @@ struct _virDomainPCIControllerOpts {
     int chassis;
     int port;
     int busNr; /* used by pci-expander-bus, -1 == unspecified */
+    int targetIndex; /* used by spapr-pci-host-bridge, -1 == unspecified */
     /* numaNode is a *subelement* of target (to match existing
      * item in memory target config) -1 == unspecified
      */
-- 
2.13.3