<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Nov 14, 2016 at 11:21 PM, Pino Toscano <span dir="ltr"><<a href="mailto:ptoscano@redhat.com" target="_blank">ptoscano@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">On Monday, 14 November 2016 22:43:55 CET Nitesh Konkar wrote:<br>
> In the current scenario the controller parsing fails<br>
> when no index is specified .As the docs point out<br>
> that specifying index is optional, libvirt is expected<br>
> to fill the index without erroring out.<br>
><br>
> Signed-off-by: Nitesh Konkar <<a href="mailto:nitkon12@linux.vnet.ibm.com">nitkon12@linux.vnet.ibm.com</a>><br>
> ---<br>
<br>
</span>There's something I don't understand -- it looks to me there's a<br>
mismatch between the test case you provide (and its output), and what<br>
the code part for it actually does.<br>
<span class="gmail-"><br>
> Before the Patch:<br>
> cat controller.xml<br>
> <controller model="virtio-scsi" type="scsi" /><br>
<br>
</span>Your XML has no index="" attribute.<br></blockquote><div>As documented here <a href="https://libvirt.org/formatdomain.html#elementsControllers">https://libvirt.org/formatdomain.html#elementsControllers</a> , 
      <span class="gmail-since">Since 1.3.5</span> the index is optional; if
      not specified, it will be auto-assigned to be the lowest unused
      index for the given controller type.<br> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<span class="gmail-"><br>
> virsh attach-device vm1 controller.xml  --persistent<br>
> error: Failed to attach device from controller.xml<br>
> error: internal error: Cannot parse controller index -1<br></span></blockquote><div><span class="gmail-"> virsh attach-device vm1 controller.xml  --live and  </span><span class="gmail-">virsh attach-device vm1 controller.xml  --config work fine.<br></span></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><span class="gmail-">
></span><br><span class="gmail-"><span class="gmail-"></span>> After the patch:</span><br><span class="gmail-"><span class="gmail-"></span>> virsh attach-device vm1 controller.xml  --persistent<br>
> Device attached successfully<br>
> ---<br>
>  src/conf/domain_conf.c | 2 +-<br>
>  1 file changed, 1 insertion(+), 1 deletion(-)<br>
><br>
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c<br>
> index 6e008e2..c52e67f 100644<br>
> --- a/src/conf/domain_conf.c<br>
> +++ b/src/conf/domain_conf.c<br>
> @@ -8374,7 +8374,7 @@ virDomainControllerDefParseXML<wbr>(xmlNodePtr node,<br>
>      if (idx) {<br>
<br>
</span>Here "idx" is non-null only if the attribute is actually found, which<br>
does not seem the case in the XML snippet above.<br>
<span class="gmail-"><br>
>          unsigned int idxVal;<br>
>          if (virStrToLong_ui(idx, NULL, 10, &idxVal) < 0 ||<br>
> -            idxVal > INT_MAX) {<br>
> +            idxVal > UINT_MAX) {<br>
<br>
</span>This looks wrong to me: UINT_MAX is the maximum value that is going to<br>
fit into a 'unsigned int', so 'idxVal' will never be (even on error)<br>
greater than that.<br></blockquote><div>Incase of <span class="gmail-"> "virsh attach-device vm1 controller.xml  --persistent" , the index value<br></span></div><div><span class="gmail-">is -1 , as assigned by def->idx = -1; in virDomainControllerDefNew. <br></span><span class="gmail-">The function virStrToLong_ui(idx, NULL, 10, &idxVal), returns the value<br></span><span class="gmail-"> UINT_MAX for idx = -1. </span><span class="gmail-"></span> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
<br>
If the index must be non-negative, it looks like using virStrToLong_uip<br>
instead of virStrToLong_ui could work fine in rejecting negative values<br>
outright.<br>
<span class="gmail-"><br>
>              virReportError(VIR_ERR_<wbr>INTERNAL_ERROR,<br>
>                             _("Cannot parse controller index %s"), idx);<br>
<br>
</span>Considering this, I think the XML you used in your testsmost probably<br>
has index="-1" as attribute -- can you please confirm?<br>
<br>
Thanks,<br>
<span class="gmail-HOEnZb"><font color="#888888">--<br>
Pino Toscano</font></span></blockquote></div><br></div></div>