2
0
mirror of https://github.com/openvswitch/ovs synced 2025-10-21 14:49:41 +00:00

CP-1592: interface-reconfigure: Configure network device MTU from Network.MTU field

With override via other-config:mtu field on specific objects in the datamodel.

Signed-off-by: Ian Campbell <ian.campbell@citrix.com>

# HG changeset patch
# User Ian Campbell <ian.campbell@citrix.com>
# Date 1267008538 0
# Node ID a91df72fd4bf6329831d3efcae45a5ff55e3ba2e
# Parent  219104a041786d7274b15800de5c3efccf0c4f42
This commit is contained in:
Ian Campbell
2010-02-24 10:48:58 +00:00
committed by Ben Pfaff
parent 5c9a0b820c
commit 9a2b117527
5 changed files with 42 additions and 15 deletions

View File

@@ -61,7 +61,8 @@ handle_mtu()
{ {
local mtu=$(xenstore-read "${PRIVATE}/MTU" 2>/dev/null) local mtu=$(xenstore-read "${PRIVATE}/MTU" 2>/dev/null)
if [ $? -eq 0 -a -n "${mtu}" ]; then if [ $? -eq 0 -a -n "${mtu}" ]; then
echo "${mtu}" > /sys/class/net/${dev}/mtu logger -t scripts-vif "Setting ${dev} MTU ${mtu}"
${IP} link set "${dev}" mtu ${mtu} || logger -t scripts-vif "Failed to ip link set ${dev} mtu ${mtu}. Error code $?"
fi fi
} }

View File

@@ -318,6 +318,7 @@ _NETWORK_OTHERCONFIG_ATTRS = [ 'mtu', 'static-routes' ] + _ETHTOOL_OTHERCONFIG_A
_NETWORK_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml), _NETWORK_ATTRS = { 'uuid': (_str_to_xml,_str_from_xml),
'bridge': (_str_to_xml,_str_from_xml), 'bridge': (_str_to_xml,_str_from_xml),
'MTU': (_str_to_xml,_str_from_xml),
'PIFs': (lambda x, p, t, v: _strlist_to_xml(x, p, 'PIFs', 'PIF', v), 'PIFs': (lambda x, p, t, v: _strlist_to_xml(x, p, 'PIFs', 'PIF', v),
lambda n: _strlist_from_xml(n, 'PIFs', 'PIF')), lambda n: _strlist_from_xml(n, 'PIFs', 'PIF')),
'other_config': (lambda x, p, t, v: _otherconfig_to_xml(x, p, v, _NETWORK_OTHERCONFIG_ATTRS), 'other_config': (lambda x, p, t, v: _otherconfig_to_xml(x, p, v, _NETWORK_OTHERCONFIG_ATTRS),
@@ -619,13 +620,33 @@ def ethtool_settings(oc):
log("Invalid value for ethtool-%s = %s. Must be on|true|off|false." % (opt, val)) log("Invalid value for ethtool-%s = %s. Must be on|true|off|false." % (opt, val))
return settings,offload return settings,offload
def mtu_setting(oc): # By default the MTU is taken from the Network.MTU setting for VIF,
# PIF and Bridge. However it is possible to override this by using
# {VIF,PIF,Network}.other-config:mtu.
#
# type parameter is a string describing the object that the oc parameter
# is from. e.g. "PIF", "Network"
def mtu_setting(nw, type, oc):
mtu = None
nwrec = db().get_network_record(nw)
if nwrec.has_key('MTU'):
mtu = nwrec['MTU']
else:
mtu = "1500"
if oc.has_key('mtu'): if oc.has_key('mtu'):
log("Override Network.MTU setting on bridge %s from %s.MTU is %s" % \
(nwrec['bridge'], type, mtu))
mtu = oc['mtu']
if mtu is not None:
try: try:
int(oc['mtu']) # Check that the value is an integer int(mtu) # Check that the value is an integer
return oc['mtu'] return mtu
except ValueError, x: except ValueError, x:
log("Invalid value for mtu = %s" % oc['mtu']) log("Invalid value for mtu = %s" % mtu)
return None return None
# #

View File

@@ -267,6 +267,8 @@ def _configure_physical_interface(pif):
pifrec = db().get_pif_record(pif) pifrec = db().get_pif_record(pif)
log("Configuring physical interface %s" % pifrec['device'])
f = open_pif_ifcfg(pif) f = open_pif_ifcfg(pif)
f.write("TYPE=Ethernet\n") f.write("TYPE=Ethernet\n")
@@ -278,7 +280,7 @@ def _configure_physical_interface(pif):
if len(offload): if len(offload):
f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload)) f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload))
mtu = mtu_setting(pifrec['other_config']) mtu = mtu_setting(pifrec['network'], "PIF", pifrec['other_config'])
if mtu: if mtu:
f.write("MTU=%s\n" % mtu) f.write("MTU=%s\n" % mtu)
@@ -336,7 +338,7 @@ def _configure_bond_interface(pif):
if len(offload): if len(offload):
f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload)) f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload))
mtu = mtu_setting(pifrec['other_config']) mtu = mtu_setting(pifrec['network'], "VLAN-PIF", pifrec['other_config'])
if mtu: if mtu:
f.write("MTU=%s\n" % mtu) f.write("MTU=%s\n" % mtu)
@@ -386,7 +388,7 @@ def _configure_vlan_interface(pif):
if len(offload): if len(offload):
f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload)) f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload))
mtu = mtu_setting(pifrec['other_config']) mtu = mtu_setting(pifrec['network'], "Bond-PIF", pifrec['other_config'])
if mtu: if mtu:
f.write("MTU=%s\n" % mtu) f.write("MTU=%s\n" % mtu)

View File

@@ -366,11 +366,12 @@ class DatapathVswitch(Datapath):
physical_devices = datapath_get_physical_pifs(self._dp) physical_devices = datapath_get_physical_pifs(self._dp)
for p in physical_devices: for p in physical_devices:
oc = db().get_pif_record(p)['other_config'] prec = db().get_pif_record(p)
oc = prec['other_config']
dev = pif_netdev_name(p) dev = pif_netdev_name(p)
mtu = mtu_setting(oc) mtu = mtu_setting(prec['network'], "PIF", oc)
netdev_up(dev, mtu) netdev_up(dev, mtu)

View File

@@ -286,7 +286,8 @@ def ipdev_configure_network(pif, dp):
""" """
pifrec = db().get_pif_record(pif) pifrec = db().get_pif_record(pif)
nwrec = db().get_network_record(pifrec['network']) nw = pifrec['network']
nwrec = db().get_network_record(nw)
ipdev = pif_ipdev_name(pif) ipdev = pif_ipdev_name(pif)
@@ -321,12 +322,13 @@ def ipdev_configure_network(pif, dp):
if len(offload): if len(offload):
f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload)) f.write("ETHTOOL_OFFLOAD_OPTS=\"%s\"\n" % str.join(" ", offload))
mtu = mtu_setting(nwrec['other_config'])
if mtu:
f.write("MTU=%s\n" % mtu)
ipdev_configure_static_routes(ipdev, nwrec['other_config'], f) ipdev_configure_static_routes(ipdev, nwrec['other_config'], f)
mtu = mtu_setting(nw, "Network", nwrec['other_config'])
if mtu:
f.write("MTU=%s\n" % mtu)
if pifrec.has_key('DNS') and pifrec['DNS'] != "": if pifrec.has_key('DNS') and pifrec['DNS'] != "":
ServerList = pifrec['DNS'].split(",") ServerList = pifrec['DNS'].split(",")
for i in range(len(ServerList)): f.write("DNS%d=%s\n" % (i+1, ServerList[i])) for i in range(len(ServerList)): f.write("DNS%d=%s\n" % (i+1, ServerList[i]))