[libvirt] [PATCH 12/26] conf: Parse and format <target index='...'/>

Andrea Bolognani posted 26 patches 7 years, 11 months ago
There is a newer version of this series
[libvirt] [PATCH 12/26] conf: Parse and format <target index='...'/>
Posted by Andrea Bolognani 7 years, 11 months ago
---
 src/conf/domain_conf.c | 24 ++++++++++++++++++++++++
 src/conf/domain_conf.h |  1 +
 2 files changed, 25 insertions(+)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index d5dff8e..deb0dce 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -1803,6 +1803,7 @@ virDomainControllerDefNew(virDomainControllerType type)
         def->opts.pciopts.chassis = -1;
         def->opts.pciopts.port = -1;
         def->opts.pciopts.busNr = -1;
+        def->opts.pciopts.idx = -1;
         def->opts.pciopts.numaNode = -1;
         break;
     case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
@@ -8909,6 +8910,7 @@ virDomainControllerDefParseXML(xmlNodePtr node,
             goto error;
         }
         def->idx = idxVal;
+        VIR_FREE(idx);
     }
 
     cur = node->children;
@@ -8940,6 +8942,7 @@ virDomainControllerDefParseXML(xmlNodePtr node,
                 chassis = virXMLPropString(cur, "chassis");
                 port = virXMLPropString(cur, "port");
                 busNr = virXMLPropString(cur, "busNr");
+                idx = virXMLPropString(cur, "index");
                 processedTarget = true;
             }
         }
@@ -9155,6 +9158,23 @@ virDomainControllerDefParseXML(xmlNodePtr node,
                 goto error;
             }
         }
+        if (idx) {
+            if (virStrToLong_i(idx, NULL, 0,
+                               &def->opts.pciopts.idx) < 0) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("Invalid index '%s' in PCI controller"),
+                               idx);
+                goto error;
+            }
+            if (def->opts.pciopts.idx < 0 ||
+                def->opts.pciopts.idx > 31) {
+                virReportError(VIR_ERR_XML_ERROR,
+                               _("PCI controller index '%s' out of range "
+                                 "- must be 0-31"),
+                               idx);
+                goto error;
+            }
+        }
         if (numaNode >= 0)
             def->opts.pciopts.numaNode = numaNode;
         break;
@@ -21413,6 +21433,7 @@ virDomainControllerDefFormat(virBufferPtr buf,
             def->opts.pciopts.chassis != -1 ||
             def->opts.pciopts.port != -1 ||
             def->opts.pciopts.busNr != -1 ||
+            def->opts.pciopts.idx != -1 ||
             def->opts.pciopts.numaNode != -1)
             pciTarget = true;
         break;
@@ -21453,6 +21474,9 @@ virDomainControllerDefFormat(virBufferPtr buf,
             if (def->opts.pciopts.busNr != -1)
                 virBufferAsprintf(buf, " busNr='%d'",
                                   def->opts.pciopts.busNr);
+            if (def->opts.pciopts.idx != -1)
+                virBufferAsprintf(buf, " index='%d'",
+                                  def->opts.pciopts.idx);
             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 83e0672..5a21289 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -780,6 +780,7 @@ struct _virDomainPCIControllerOpts {
     int chassis;
     int port;
     int busNr; /* used by pci-expander-bus, -1 == unspecified */
+    int idx; /* 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.7.5

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 12/26] conf: Parse and format <target index='...'/>
Posted by Laine Stump 7 years, 11 months ago
On 06/02/2017 12:07 PM, Andrea Bolognani wrote:
> ---
>  src/conf/domain_conf.c | 24 ++++++++++++++++++++++++
>  src/conf/domain_conf.h |  1 +
>  2 files changed, 25 insertions(+)
> 
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index d5dff8e..deb0dce 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -1803,6 +1803,7 @@ virDomainControllerDefNew(virDomainControllerType type)
>          def->opts.pciopts.chassis = -1;
>          def->opts.pciopts.port = -1;
>          def->opts.pciopts.busNr = -1;
> +        def->opts.pciopts.idx = -1;
>          def->opts.pciopts.numaNode = -1;
>          break;
>      case VIR_DOMAIN_CONTROLLER_TYPE_IDE:
> @@ -8909,6 +8910,7 @@ virDomainControllerDefParseXML(xmlNodePtr node,
>              goto error;
>          }
>          def->idx = idxVal;
> +        VIR_FREE(idx);
>      }
>  
>      cur = node->children;
> @@ -8940,6 +8942,7 @@ virDomainControllerDefParseXML(xmlNodePtr node,
>                  chassis = virXMLPropString(cur, "chassis");
>                  port = virXMLPropString(cur, "port");
>                  busNr = virXMLPropString(cur, "busNr");
> +                idx = virXMLPropString(cur, "index");
>                  processedTarget = true;
>              }
>          }
> @@ -9155,6 +9158,23 @@ virDomainControllerDefParseXML(xmlNodePtr node,
>                  goto error;
>              }
>          }
> +        if (idx) {
> +            if (virStrToLong_i(idx, NULL, 0,
> +                               &def->opts.pciopts.idx) < 0) {
> +                virReportError(VIR_ERR_XML_ERROR,
> +                               _("Invalid index '%s' in PCI controller"),

You should probably say "target index" to differentiate it from the
toplevel index.

> +                               idx);
> +                goto error;
> +            }
> +            if (def->opts.pciopts.idx < 0 ||
> +                def->opts.pciopts.idx > 31) {
> +                virReportError(VIR_ERR_XML_ERROR,
> +                               _("PCI controller index '%s' out of range "
> +                                 "- must be 0-31"),

Same here.

Other than that, what about an xml2xml test case? (as well as combining
with the previous patch, and adding a sentence to formatdomain.html.in)


> +                               idx);
> +                goto error;
> +            }
> +        }
>          if (numaNode >= 0)
>              def->opts.pciopts.numaNode = numaNode;
>          break;
> @@ -21413,6 +21433,7 @@ virDomainControllerDefFormat(virBufferPtr buf,
>              def->opts.pciopts.chassis != -1 ||
>              def->opts.pciopts.port != -1 ||
>              def->opts.pciopts.busNr != -1 ||
> +            def->opts.pciopts.idx != -1 ||
>              def->opts.pciopts.numaNode != -1)
>              pciTarget = true;
>          break;
> @@ -21453,6 +21474,9 @@ virDomainControllerDefFormat(virBufferPtr buf,
>              if (def->opts.pciopts.busNr != -1)
>                  virBufferAsprintf(buf, " busNr='%d'",
>                                    def->opts.pciopts.busNr);
> +            if (def->opts.pciopts.idx != -1)
> +                virBufferAsprintf(buf, " index='%d'",
> +                                  def->opts.pciopts.idx);
>              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 83e0672..5a21289 100644
> --- a/src/conf/domain_conf.h
> +++ b/src/conf/domain_conf.h
> @@ -780,6 +780,7 @@ struct _virDomainPCIControllerOpts {
>      int chassis;
>      int port;
>      int busNr; /* used by pci-expander-bus, -1 == unspecified */
> +    int idx; /* used by spapr-pci-host-bridge, -1 == unspecified */
>      /* numaNode is a *subelement* of target (to match existing
>       * item in memory target config) -1 == unspecified
>       */
> 

--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
Re: [libvirt] [PATCH 12/26] conf: Parse and format <target index='...'/>
Posted by Andrea Bolognani 7 years, 11 months ago
On Tue, 2017-06-13 at 17:59 -0400, Laine Stump wrote:
> > @@ -9155,6 +9158,23 @@ virDomainControllerDefParseXML(xmlNodePtr node,
> >                  goto error;
> >              }
> >          }
> > +        if (idx) {
> > +            if (virStrToLong_i(idx, NULL, 0,
> > +                               &def->opts.pciopts.idx) < 0) {
> > +                virReportError(VIR_ERR_XML_ERROR,
> > +                               _("Invalid index '%s' in PCI controller"),
> 
> You should probably say "target index" to differentiate it from the
> toplevel index.

I agree and was in fact planning to change it just the way
you suggested, I just forgot O:-)

> Other than that, what about an xml2xml test case? (as well as combining
> with the previous patch, and adding a sentence to formatdomain.html.in)

Test cases (both argv2xml and xml2xml) are added in patch
19/26, that is, after adding the code that fills in the
target index automatically. I'd prefer keeping it that way
so that they excercise the entire functionality at once.

-- 
Andrea Bolognani / Red Hat / Virtualization

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