Mark Wu has uploaded a new change for review. Change subject: Simplify setNewMtu() ......................................................................
Simplify setNewMtu() It will update the interface's MTU only if its user being removed has the maximum MTU. Change-Id: I32e8e0d45b7887af8fd1b003fd4c358826b77289 Signed-off-by: Mark Wu <wu...@linux.vnet.ibm.com> --- M vdsm/configNetwork.py M vdsm/netconf/ifcfg.py 2 files changed, 32 insertions(+), 57 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/55/15355/1 diff --git a/vdsm/configNetwork.py b/vdsm/configNetwork.py index 6809e98..525996c 100755 --- a/vdsm/configNetwork.py +++ b/vdsm/configNetwork.py @@ -303,7 +303,6 @@ if not utils.tobool(force): _validateDelNetwork(network, vlan, bonding, nics, bridged, _netinfo) - configWriter.setNewMtu(network=network, bridged=bridged, _netinfo=_netinfo) configurator.removeLibvirtNetwork(network) # We need to gather NetInfo again to refresh networks info from libvirt. diff --git a/vdsm/netconf/ifcfg.py b/vdsm/netconf/ifcfg.py index e023e99..02ee20e 100644 --- a/vdsm/netconf/ifcfg.py +++ b/vdsm/netconf/ifcfg.py @@ -36,7 +36,7 @@ from vdsm import libvirtconnection from vdsm import netinfo from vdsm import utils -from netmodels import Bridge +from netmodels import Bond, Vlan, Bridge import neterrors as ne @@ -167,6 +167,7 @@ bridge.port.remove() def removeVlan(self, vlan): + vlan.mtu = netinfo.getMtu(vlan.name) ifdown(vlan.name) self.configWriter.removeVlan(vlan.name) vlan.device.remove() @@ -177,8 +178,10 @@ ifdown(iface.name) multiple_usage = _netinfo.ifaceHasMultiUsers(iface.name) yield not multiple_usage - if multiple_usage and iface.master is None: - self.configWriter.removeIpConfig(iface.name) + if multiple_usage: + self._setNewMtu(iface, _netinfo=_netinfo) + if iface.master is None: + self.configWriter.removeIpConfig(iface.name) if not hasattr(iface, 'destroy'): ifup(iface.name) @@ -196,6 +199,32 @@ with self.removeIface(nic) as to_be_removed: if to_be_removed: self.configWriter.removeNic(nic.name) + + def _setNewMtu(self, iface, _netinfo=None): + """ + Update an interface's MTU when one of its users is removed. + + :param iface: interface object (bond or nic device) + :type iface: NetDevice instance + + """ + ifaceMtu = netinfo.getMtu(iface.name) + if isinstance(iface.master, Vlan): + if iface.master.mtu < ifaceMtu: + return + + vlans = _netinfo.getVlansForIface(iface.name) + try: + maxMtu = max(int(netinfo.getMtu(iface.name + '.' + vlan)) + for vlan in vlans) + except ValueError: + maxMtu = None + + if maxMtu and maxMtu < ifaceMtu: + if isinstance(iface, Bond): + self.configWriter.setBondingMtu(iface.name, maxMtu) + else: + self.configWriter.setIfaceMtu(iface.name, maxMtu) class ConfigWriter(object): @@ -704,59 +733,6 @@ slaves = netinfo.slaves(bonding) for slave in slaves: self.setIfaceMtu(slave, newmtu) - - def setNewMtu(self, network, bridged, _netinfo=None): - """ - Set new MTU value to network and its interfaces - - :param network: network name - :type network: string - :param bridged: network type (bridged or bridgeless) - :type bridged: bool - - Update MTU to devices (vlans, bonds and nics) - or added a new value - """ - if _netinfo is None: - _netinfo = netinfo.NetInfo() - currmtu = None - if bridged: - try: - currmtu = int(netinfo.getMtu(network)) - except IOError as e: - if e.errno != os.errno.ENOENT: - raise - - nics, delvlan, bonding = \ - _netinfo.getNicsVlanAndBondingForNetwork(network) - if delvlan is None: - return - - iface = bonding if bonding else nics[0] - vlans = _netinfo.getVlansForIface(iface) - - newmtu = None - for vlan in vlans: - cf = netinfo.NET_CONF_PREF + iface + '.' + vlan - mtu = self._getConfigValue(cf, 'MTU') - if mtu: - mtu = int(mtu) - - if vlan == delvlan: - # For VLANed bridgeless networks use MTU of delvlan - # as current MTU - if not bridged and mtu: - currmtu = mtu - continue - - newmtu = max(newmtu, mtu) - - # Optimization: if network hasn't custom MTU (currmtu), do nothing - if currmtu and newmtu != currmtu: - if bonding: - self.setBondingMtu(bonding, newmtu) - else: - self.setIfaceMtu(nics[0], newmtu) def ifdown(iface): -- To view, visit http://gerrit.ovirt.org/15355 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I32e8e0d45b7887af8fd1b003fd4c358826b77289 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Mark Wu <wu...@linux.vnet.ibm.com> _______________________________________________ vdsm-patches mailing list vdsm-patches@lists.fedorahosted.org https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches