If a non-persistent tap device that is attached to an OVS is
closed, does OVS not notice this and automatically detach it?
You may want to experiment with that; possibly nothing is
needed.
(it would be much better if not, because otherwise there will
need to be special care taken to prevent dangling tap devices
(or dangling references to deleted tap devices))
The difference between OVS and
Linux Bridge is that OVS will need a hook that removes all
ports on
VM shutdown event (and maybe also for some other events?).
Not just when a guest is shutdown, but also if a network
device is detached from a running domain.
If it's necessary to explicitly detach the tap from the OVS,
whatever hook is added in to do that can hopefully just as
well be identical for a Linux bridge (i.e., the only
OVS-specific code should be in the lowest level function that
does that bridge detach).
Another point - since a shutdown initiated by the guest would
likely end up destroying the tap device, we can't just add in
a hook to detach it from the bridge - too early and the guest
won't be done with it yet, too late and it will already not
exist. I'm thinking that instead we may need to create the tap
as persistent, then explicitly detach it from the bridge and
delete it after the domain is finished with it.
It wouldn't be too late. It's ok If actual tap device is
not alive anymore.
Well, as long as there are no negative consequences to the port
being assigned past the time when the tap device is deleted.
As I mentioned before, you should modify virNetDevBridgeRemovePort
to do this removal (and do it appropriately depending on the type of
bridge), but change it so that it should return success if it would
fail simply because the tap device already is not on the bridge.
(This way we can leave the tap device as non-persistent, and it will
be an effective NOP for tap devices on linux bridges.
Also, for consistency we should be just always calling the function
to detach from the bridge if virDomainNetGetActualType(net) ==
VIR_DOMAIN_NET_TYPE_BRIDGE, regardless of whether it's a linux
bridge or ovs.
As far as where to put the calls to this - look for where there are
calls to networkReleaseActualDevice(), and do it up above that (for
example, you can see in qemuDomainDetachNetDevice() how there is an
"if virDomainNetGetActualType(detach) ==
VIR_DOMAIN_NET_TYPE_DIRECT)" - you can change that to a
switch(actualtype), and add a case for VIR_DOMAIN_NET_TYPE_BRIDGE
that calls virNetDevBridgeRemovePort().