Mark Wu has uploaded a new change for review.
Change subject: netinfo: Simplify the check if an interface still has any other users. ......................................................................
netinfo: Simplify the check if an interface still has any other users.
In current oVirt network models, a nic device has four kinds of usages: * bonding's slave * vlan's slave * bridge's port * bridgeless network's interface A bond device has the same usages as nic except the first one.
And an interface(nic or bonding) could be multiplexed by different usages. But bonding and bridge need use the interface exclusively. So only two combinations are valid: * multiple vlan users * multiple vlan users with one bridgeless network user
When we remove one user of an interface, we need check if the interface still has by other users except the user being removed currently. According to that, we decide if restore the interface to initial state or destroy it (for bonding).
The old implementation of this check is getting a set of all users(bonding, vlan, bridge and bridgeless network) and drop the user removed from the set. So it needs get the information of the user being removed. Actually, it's not neccessary. We could make a snapshot of the netinfo after the user is removed. The new snapshot shouldn't include the interface already removed, because we delete the network entities from top to bottom. We just need to check if it still has one or more vlan or bridgeless network users because bridge and bond can't coexist with any type of users. The conflict is validated when a new network is added.
In the old implementation, the checks for nic and bonding are handled differently because it also checks the bond users if a nic is a slave of bond. Actually, it's not neccessary either. If the bond has other users, we will not remove its slave. That means the check will not be invoked. So for the check of nic, it doesn't need care about the usage of its bond master, because it's done in bond level.
Change-Id: Ie70cbfcc4c561c98f2e90685329900796517f933 Signed-off-by: Mark Wu wudxw@linux.vnet.ibm.com --- M lib/vdsm/netinfo.py M vdsm/configNetwork.py 2 files changed, 21 insertions(+), 29 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/16/15416/1
diff --git a/lib/vdsm/netinfo.py b/lib/vdsm/netinfo.py index 564859e..8bf7078 100644 --- a/lib/vdsm/netinfo.py +++ b/lib/vdsm/netinfo.py @@ -605,32 +605,23 @@ users.add(v) return users
- def nicOtherUsers(self, bridge, vlan, bonding, nic): + def ifaceHasOtherUsers(self, iface): """ - Returns a list of interfaces using a nic, - other than the specified one. - """ - if bonding: - owner = bonding - elif vlan: - owner = nic + '.' + vlan - else: - owner = bridge - users = self.ifaceUsers(nic) - if bonding: - users.update(self.bondingOtherUsers(bridge, vlan, bonding)) - users.discard(owner) - return users + It's used to check if an interface has other direct users when one of + its user is removed. It could only happen in the following two cases:
- def bondingOtherUsers(self, bridge, vlan, bonding): + --> vlan1 --> network1 (bridged or bridgeless) + / + interface(nic or bond) ---> vlan2 --> network2 (bridged or bridgeless) + \ + --> vlan3 --> network3 (bridged or bridgeless) + + --> vlan1 --> network1 (bridged or bridgeless) + / + interface(nic or bond) ---> vlan2 --> network2 (bridged or bridgeless) + \ + --> network3 (bridgeless) + """ - Return a list of nics/interfaces using a bonding, - other than the specified one. - """ - if vlan: - owner = bonding + '.' + vlan - else: - owner = bridge - users = self.ifaceUsers(bonding) - users.discard(owner) - return users + return (list(self.getVlansForIface(iface)) or + self.getBridgelessNetworkForIface(iface)) diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py index 22d3699..fee985a 100755 --- a/vdsm/configNetwork.py +++ b/vdsm/configNetwork.py @@ -251,7 +251,7 @@ def _removeUnusedNics(network, vlan, bonding, nics, configWriter): _netinfo = netinfo.NetInfo() for nic in nics: - if not _netinfo.nicOtherUsers(network, vlan, bonding, nic): + if not _netinfo.ifaceHasOtherUsers(nic): ifdown(nic) configWriter.removeNic(nic) ifup(nic) @@ -345,15 +345,16 @@
# The (relatively) new setupNetwork verb allows to remove a network # defined on top of an bonding device without break the bond itself. + _netinfo = netinfo.NetInfo() if implicitBonding: - if bonding and not _netinfo.bondingOtherUsers(network, vlan, bonding): + if bonding and not _netinfo.ifaceHasOtherUsers(bonding): ifdown(bonding) configWriter.removeBonding(bonding)
_removeUnusedNics(network, vlan, bonding, nics, configWriter) elif not bonding: _removeUnusedNics(network, vlan, bonding, nics, configWriter) - elif not _netinfo.bondingOtherUsers(network, vlan, bonding): + elif not _netinfo.ifaceHasOtherUsers(bonding): ifdown(bonding) configWriter.setBondingMtu(bonding, DEFAULT_MTU) ifup(bonding)
-- To view, visit http://gerrit.ovirt.org/15416 To unsubscribe, visit http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange Gerrit-Change-Id: Ie70cbfcc4c561c98f2e90685329900796517f933 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu wudxw@linux.vnet.ibm.com