john.levon@sun.com
2007-Jun-06 14:09 UTC
[Xen-devel] [PATCH] Fix duplicate random MAC generation
# HG changeset patch # User David Edmondson <dme@sun.com> # Date 1181040295 25200 # Node ID c086f2ec68056e1444a487368b67d2f4eb13576b # Parent d06cf13997038d41eb60ab9055aea94a8e3b7af0 Fix duplicate random MAC generation Ensure that HVMImageHandler and NetifController see the same random MAC address. Signed-off-by: David Edmondson <dme@sun.com> diff --git a/tools/python/xen/xend/XendConfig.py b/tools/python/xen/xend/XendConfig.py --- a/tools/python/xen/xend/XendConfig.py +++ b/tools/python/xen/xend/XendConfig.py @@ -27,6 +27,7 @@ from xen.xend.XendDevices import XendDev from xen.xend.XendDevices import XendDevices from xen.xend.PrettyPrint import prettyprintstring from xen.xend.XendConstants import DOM_STATE_HALTED +from xen.xend.server.netif import randomMAC log = logging.getLogger("xend.XendConfig") log.setLevel(logging.WARN) @@ -993,6 +994,10 @@ class XendConfig(dict): else: dev_info[''driver''] = ''paravirtualised'' + if dev_type == ''vif'': + if not dev_info.get(''mac''): + dev_info[''mac''] = randomMAC() + # create uuid if it doesn''t exist dev_uuid = dev_info.get(''uuid'', None) if not dev_uuid: @@ -1051,8 +1056,9 @@ class XendConfig(dict): dev_info = {} dev_uuid = '''' if dev_type == ''vif'': - if cfg_xenapi.get(''MAC''): # don''t add if blank - dev_info[''mac''] = cfg_xenapi.get(''MAC'') + dev_info[''mac''] = cfg_xenapi.get(''MAC'') + if not dev_info[''mac'']: + dev_info[''mac''] = randomMAC() # vifname is the name on the guest, not dom0 # TODO: we don''t have the ability to find that out or # change it from dom0 diff --git a/tools/python/xen/xend/image.py b/tools/python/xen/xend/image.py --- a/tools/python/xen/xend/image.py +++ b/tools/python/xen/xend/image.py @@ -27,7 +27,6 @@ from xen.xend.XendError import VmError, from xen.xend.XendError import VmError, XendError, HVMRequired from xen.xend.XendLogging import log from xen.xend.XendOptions import instance as xenopts -from xen.xend.server.netif import randomMAC from xen.xend.xenstore.xswatch import xswatch from xen.xend import arch @@ -352,7 +351,7 @@ class HVMImageHandler(ImageHandler): continue mac = devinfo.get(''mac'') if mac is None: - mac = randomMAC() + raise VmError("MAC address not specified or generated.") bridge = devinfo.get(''bridge'', ''xenbr0'') model = devinfo.get(''model'', ''rtl8139'') ret.append("-net") diff --git a/tools/python/xen/xend/server/netif.py b/tools/python/xen/xend/server/netif.py --- a/tools/python/xen/xend/server/netif.py +++ b/tools/python/xen/xend/server/netif.py @@ -112,7 +112,7 @@ class NetifController(DevController): typ = xoptions.netback_type if not mac: - mac = randomMAC() + raise VmError("MAC address not specified or generated.") devid = self.allocateDeviceID() _______________________________________________ Xen-devel mailing list Xen-devel@lists.xensource.com http://lists.xensource.com/xen-devel