6d3351
From 4c2b1b9cf0bcd8af7a7d011cd758bb6f11e5477b Mon Sep 17 00:00:00 2001
6d3351
Message-Id: <4c2b1b9cf0bcd8af7a7d011cd758bb6f11e5477b@dist-git>
6d3351
From: Andrea Bolognani <abologna@redhat.com>
6d3351
Date: Mon, 17 Jul 2017 12:09:09 +0200
6d3351
Subject: [PATCH] conf: Parse and format <target index='...'/>
6d3351
6d3351
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
6d3351
Reviewed-by: Laine Stump <laine@laine.org>
6d3351
(cherry picked from commit 47dd6e282ab8b0db662092cf0cc53163d805ac4d)
6d3351
6d3351
Conflicts:
6d3351
  * src/conf/domain_conf.c:
6d3351
6d3351
    caused by e146264aaadf5aecf727d8c7b3d85683b55b6c48,
6d3351
    which significantly refactored
6d3351
    virDomainControllerDefFormat(), not being in the tree.
6d3351
6d3351
Bug: https://bugzilla.redhat.com/show_bug.cgi?id=1431193
6d3351
6d3351
Signed-off-by: Andrea Bolognani <abologna@redhat.com>
6d3351
Signed-off-by: Jiri Denemark <jdenemar@redhat.com>
6d3351
---
6d3351
 docs/formatdomain.html.in     |  6 ++++++
6d3351
 docs/schemas/domaincommon.rng |  5 +++++
6d3351
 src/conf/domain_conf.c        | 32 ++++++++++++++++++++++++++++++++
6d3351
 src/conf/domain_conf.h        |  1 +
6d3351
 4 files changed, 44 insertions(+)
6d3351
6d3351
diff --git a/docs/formatdomain.html.in b/docs/formatdomain.html.in
6d3351
index dc8e7d2dc7..bc67a53408 100644
6d3351
--- a/docs/formatdomain.html.in
6d3351
+++ b/docs/formatdomain.html.in
6d3351
@@ -3760,6 +3760,12 @@
6d3351
         libvirt API to attach host devices to the correct
6d3351
         pci-expander-bus when assigning them to the domain).
6d3351
       
6d3351
+      
index
6d3351
+      
6d3351
+        pci-root controllers for pSeries guests use this attribute to
6d3351
+        record the order they will show up in the guest.
6d3351
+        Since 3.6.0
6d3351
+      
6d3351
     
6d3351
     

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