<div dir="ltr">I'm sorry that I didn't configure the 'git send-email' well.<br>The 2 issues can be consider separate.<br>Issue 1(move the 'i++'):<br>Yes, I do mean that we shouldn't update the 'i' value for the reason you said. I was thinking to minimize the change. But while loop is also a good choose.<br><br>Issue 2:<br>Steps to reproduce the bug :<br>1. Domain A and B xml contain the same SRIOV net hostdev(same pci address).<br>'    <interface type='hostdev' managed='yes'><br>      <source><br>        <address type='pci' domain='0x0000' bus='0x00' slot='0x07' function='0x0'/><br>      </source><br>      <mac address='52:11:11:22:22:22'/><br>    </interface>'<br>2. virsh start A (Successfully, and configure the SRIOV net mac witch custom one )<br>3. virsh start B (Fail because the hostdev is used by domain A or other reason.)<br>The failure in step 3 makes the mac/vlan of the net in Doamin A change. <br>Because when we call 'virHostdevReAttachPCIDevices' for domain B in step 3, we do 'virHostdevNetConfigRestore' for all net hostdev, even the one is being used by Domain A. The mac/vlan of the SRIOV net back to the value before step 2.<br><br>In my fix, as the pci used by other domain have been removed from 'pcidevs' in loop 1, <br> we only need do 'virHostdevNetConfigRestore' for the hostdev still in 'pcidevs'(used by current domain).<br><br>I will resend a patch. Thanks for your suggestion.<br><br></div><div class="gmail_extra"><br><div class="gmail_quote">2015-03-24 20:47 GMT+08:00 John Ferlan <span dir="ltr"><<a href="mailto:jferlan@redhat.com" target="_blank">jferlan@redhat.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
<br>
On 03/22/2015 09:59 AM, Huanle Han wrote:<br>
><br>
> Bug 1: The the next element in the pcidevs is skipped after we<br>
> virPCIDeviceListDel the previous element.<br>
><br>
> Bug 2: virHostdevNetConfigRestore is called for store the hostdevs<br>
> which may be used by other domain.<br>
><br>
</span>> Signed-off-by: Huanle Han <<a href="mailto:hanxueluo@gmail.com">hanxueluo@gmail.com</a> <mailto:<a href="mailto:hanxueluo@gmail.com">hanxueluo@gmail.com</a>>><br>
<span class="">> ---<br>
>  src/util/virhostdev.c | 25 +++++++++++++++++++++----<br>
>  1 file changed, 21 insertions(+), 4 deletions(-)<br>
><br>
</span>Should this be two separate patches? IOW: Are you fixing two separate<br>
issues or essentially the same issue? Makes it easier to cherry-pick and<br>
choose what may need to be backported elsewhere...<br>
<br>
If there's a bug associated that would have been "good" to list as well<br>
as perhaps an example or two...  That is - what XML and command(s)<br>
sequence(s) prompted you to write the patch(es)...<br>
<br>
Also, my attempt to git am -3 your patch fails - perhaps it's your<br>
mailer configuration.  Did you use git send-email?  or something else...<br>
I'm seeing html format... So I'm only reviewing based on what I read.<br>
<span class=""><br>
> diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c<br>
> index 9678e2b..ecbe5d8 100644<br>
> --- a/src/util/virhostdev.c<br>
> +++ b/src/util/virhostdev.c<br>
> @@ -785,7 +785,7 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr<br>
> hostdev_mgr,<br>
>       * them and reset all the devices before re-attach.<br>
>       * Attach mac and port profile parameters to devices<br>
>       */<br>
<br>
</span>^^^<br>
I think the comment here could be updated to make it clear what's being<br>
done. To just say "Again 4 loops;..." is a bit misleading since the only<br>
loops I found in the code were in virHostdevPreparePCIDevices where<br>
there are (currently) 9 such loops!<br>
<span class=""><br>
> -    for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {<br>
> +    for (i = 0; i < virPCIDeviceListCount(pcidevs);) {<br>
>          virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);<br>
>          virPCIDevicePtr activeDev = NULL;<br>
><br>
> @@ -806,6 +806,7 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr<br>
> hostdev_mgr,<br>
>          }<br>
><br>
>          virPCIDeviceListDel(hostdev_mgr->activePCIHostdevs, dev);<br>
> +        i++;<br>
>      }<br>
<br>
<br>
</span>Not sure I'm seeing why your fix works... Are you claiming that the<br>
remove from other domain check (e.g. where the code "continue;"'s)<br>
shouldn't be updating the 'i' value?  All it seems you did was move the<br>
i++ from the for line to after the second virPCIDeviceListDel in the<br>
block... Which yes, does reduce the count of devices and I would think<br>
should be the case that doesn't increment i...<br>
<br>
If we have 4 devices [0, 1, 2, 3] and we remove [1], then there are 3<br>
devices left and i would be 2, but the new array would be [0, 2, 3] and<br>
thus we don't check [2].<br>
<br>
Perhaps this would work/read better as a while loop.<br>
<span class=""><br>
><br>
>      /* At this point, any device that had been used by the guest is in<br>
> @@ -816,9 +817,25 @@ virHostdevReAttachPCIDevices(virHostdevManagerPtr<br>
> hostdev_mgr,<br>
>       * For SRIOV net host devices, unset mac and port profile before<br>
>       * reset and reattach device<br>
>       */<br>
> -    for (i = 0; i < nhostdevs; i++)<br>
> -        virHostdevNetConfigRestore(hostdevs[i], hostdev_mgr->stateDir,<br>
> -                                   oldStateDir);<br>
> +    for (i = 0; i < nhostdevs; i++) {<br>
> +        virPCIDevicePtr dev;<br>
> +        virDomainHostdevDefPtr hostdev = hostdevs[i];<br>
> +        virDomainHostdevSubsysPCIPtr pcisrc =<br>
> &hostdev->source.subsys.u.pci;<br>
> +<br>
> +        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS ||<br>
> +            hostdev->source.subsys.type !=<br>
> VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI ||<br>
> +            hostdev->parent.type != VIR_DOMAIN_DEVICE_NET ||<br>
</span>> +            !hostdev-><a href="http://parent.data.net" target="_blank">parent.data.net</a> <<a href="http://parent.data.net" target="_blank">http://parent.data.net</a>>)<br>
                                         ^^^^^^^^^^^^^^^^^^^^^^^^<br>
This is what makes me believe you sent in html format<br>
<br>
It's also directly taken from virHostdevNetConfigRestore... and could be<br>
considered partially from virHostdevPreparePCIDevices<br>
<br>
Suggestion - create a patch that has a new static bool function<br>
("isHostdevPCINetDevice") that does the same check passing "hostdev"...<br>
Then adjust the (currently) two places that make that check in order to<br>
use the bool function to decide to continue or not. Then this patch<br>
would use that function here instead.<br>
<span class=""><br>
> +                continue;<br>
> +<br>
> +        dev = virPCIDeviceNew(pcisrc->addr.domain, pcisrc->addr.bus,<br>
> +                              pcisrc->addr.slot, pcisrc->addr.function);<br>
> +        if (virPCIDeviceListFind(pcidevs, dev)) {<br>
> +            virHostdevNetConfigRestore(hostdev, hostdev_mgr->stateDir,<br>
> +                                       oldStateDir);<br>
> +        }<br>
> +        virPCIDeviceFree(dev);<br>
> +   }<br>
<br>
</span>It's still not quite clear to me from your description why we have to<br>
search the pcidevs for our device before calling the Restore function.<br>
Does it matter if it's in or not in the activePCIHostdevs list (the<br>
comment just before this section).  I think this is one of those cases<br>
where the code perhaps isn't self documenting and that by adding a few<br>
more comments along the way we can better describe what we're trying to<br>
do and why it has to be done.<br>
<br>
<br>
John<br>
<div class="HOEnZb"><div class="h5">><br>
>      for (i = 0; i < virPCIDeviceListCount(pcidevs); i++) {<br>
>          virPCIDevicePtr dev = virPCIDeviceListGet(pcidevs, i);<br>
> --<br>
> 2.1.0<br>
><br>
><br>
><br>
><br>
</div></div><span class="HOEnZb"><font color="#888888">> --<br>
> libvir-list mailing list<br>
> <a href="mailto:libvir-list@redhat.com">libvir-list@redhat.com</a><br>
> <a href="https://www.redhat.com/mailman/listinfo/libvir-list" target="_blank">https://www.redhat.com/mailman/listinfo/libvir-list</a><br>
><br>
</font></span></blockquote></div><br></div>