From e46402147df5702872534f3c312f8f60c05fc175 Mon Sep 17 00:00:00 2001 From: Guido Trotter <ultrotter@google.com> Date: Thu, 12 Feb 2009 17:35:28 +0000 Subject: [PATCH] ConfigWriter.AddInstance check instance mac There is a race condition in CreateInstance, since the mac address is generated early and only added to the config (and thus really assured to be unique) only at this point. Since it's possible that another instance gets the same mac address in the meantime with this check we'll make the instance creation fail before modifying the config data and thus having a wrong in-memory config (which is bad!!). Note that the same race condition exists, for example, in SetInstanceParams, and should be fully addressed by a way to revert config changes if writing them fails! Reviewed-by: iustin --- lib/config.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/config.py b/lib/config.py index a4134f551..e41014ff3 100644 --- a/lib/config.py +++ b/lib/config.py @@ -687,6 +687,12 @@ class ConfigWriter: all_lvs = instance.MapLVsByNode() logging.info("Instance '%s' DISK_LAYOUT: %s", instance.name, all_lvs) + all_macs = self._AllMACs() + for nic in instance.nics: + if nic.mac in all_macs: + raise errors.ConfigurationError("Cannot add instance %s:" + " MAC address '%s' already in use." % (instance.name, nic.mac)) + instance.serial_no = 1 self._config_data.instances[instance.name] = instance self._config_data.cluster.serial_no += 1 -- GitLab