<div dir="ltr"><div><div><div>Hello Michal,<br><br></div>Thanks for the feedback. I have sent a follow up v3 version of my patch. <br><br></div>Warm Regards,<br></div>Nitesh Konkar.<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Feb 22, 2016 at 6:02 PM, Michal Privoznik <span dir="ltr"><<a href="mailto:mprivozn@redhat.com" target="_blank">mprivozn@redhat.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On 19.02.2016 12:53, Nitesh Konkar wrote:<br>
> The virsh attach virsh detach interface command fails  when both live and config<br>
> are set and when the  interface gets attached to different pci slots<br>
> on live and config xml respectively.<br>
><br>
> When we attach an interface with both --live and --config,<br>
> the first time they get the same PCI slots, but the second time<br>
> onwards it differs and hence the virsh detach-interface --live<br>
> --config command fails. This patch makes sure that when both<br>
> --live --config are set , qemuDomainDetachDeviceFlags is called<br>
> twice, once with config xml and once with live xml.<br>
><br>
> Steps to see the issue:<br>
> virsh attach-interface --domain DomainName --type network --source default --mac 52:54:00:4b:76:5f --live --config<br>
> virsh  detach-interface --domain DomainName --type network --mac 52:54:00:4b:76:5f --live --config<br>
> virsh attach-interface --domain DomainName --type network --source default --mac 52:54:00:4b:76:5f --live --config<br>
> virsh  detach-interface --domain DomainName --type network --mac 52:54:00:4b:76:5f --live --config<br>
><br>
<br>
</span>Okay, I can see the problem but I find the solution a bit hackish.<br>
<span class=""><br>
> <a href="mailto:Signed-off-by%3Anitkon12@linux.vnet.ibm.com">Signed-off-by:nitkon12@linux.vnet.ibm.com</a><br>
> ---<br>
>  tools/virsh-domain.c | 14 ++++++++++++--<br>
>  1 file changed, 12 insertions(+), 2 deletions(-)<br>
><br>
> diff --git a/tools/virsh-domain.c b/tools/virsh-domain.c<br>
> index 62acecb..43c8436 100644<br>
> --- a/tools/virsh-domain.c<br>
> +++ b/tools/virsh-domain.c<br>
> @@ -10815,7 +10815,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)<br>
>      char buf[64];<br>
>      int diff_mac;<br>
>      size_t i;<br>
> -    int ret;<br>
> +    int ret, flag_live_config_both = 0;<br>
<br>
</span>This new flag makes me confused. I know what you're trying to achieve<br>
with it, but the name could be better. How about configDetached?<br>
Moreover, it's a boolean not an int.<br>
<span class=""><br>
>      bool functionReturn = false;<br>
>      unsigned int flags = VIR_DOMAIN_AFFECT_CURRENT;<br>
>      bool current = vshCommandOptBool(cmd, "current");<br>
> @@ -10830,7 +10830,7 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)<br>
><br>
>      if (config || persistent)<br>
>          flags |= VIR_DOMAIN_AFFECT_CONFIG;<br>
> -    if (live)<br>
> +    if (!(config || persistent) && live) // Only Live<br>
>          flags |= VIR_DOMAIN_AFFECT_LIVE;<br>
<br>
</span>I don't think I follow. But maybe I'm misguided by --persistent.<br>
Historically it just an alias for --config. But not in this case. I<br>
wonder why.<br>
<span class=""><br>
><br>
>      if (!(dom = virshCommandOptDomain(ctl, cmd, NULL)))<br>
> @@ -10851,6 +10851,8 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)<br>
>      else<br>
>          doc = virDomainGetXMLDesc(dom, 0);<br>
><br>
> +    forlivexml:<br>
> +<br>
<br>
</span>I'd rather avoid introducing this kind of label. How about putting the<br>
important code (interface lookup in domain XML) into a separate function<br>
and call it twice if needed? That way you can also avoid using<br>
@flag_live_config_both.<br>
<span class=""><br>
>      if (!doc)<br>
>          goto cleanup;<br>
><br>
> @@ -10921,6 +10923,14 @@ cmdDetachInterface(vshControl *ctl, const vshCmd *cmd)<br>
>      if (ret != 0) {<br>
>          vshError(ctl, "%s", _("Failed to detach interface"));<br>
>      } else {<br>
> +        if ((config || persistent) && live && flag_live_config_both == 0) {//executed only when live config both in cmd.<br>
> +             doc = virDomainGetXMLDesc(dom, 0);<br>
> +             flag_live_config_both=1; //Need to execute this code only once<br>
> +             flags |= VIR_DOMAIN_AFFECT_LIVE; //set live flag<br>
> +             flags &= (~VIR_DOMAIN_AFFECT_CONFIG ); // need to unset config flag as config xml detach is already done.<br>
> +             mac=NULL;<br>
> +             goto forlivexml;<br>
> +             }<br>
>          vshPrint(ctl, "%s", _("Interface detached successfully\n"));<br>
>          functionReturn = true;<br>
>      }<br>
><br>
<br>
</span>Then, this patch does not comply with our formatting rules. Run 'make<br>
syntax-check' to see all the problems.<br>
<br>
Looking forward to v3.<br>
<span class="HOEnZb"><font color="#888888"><br>
Michal<br>
<br>
</font></span></blockquote></div><br></div>