Commit afa1386e authored by Guido Trotter's avatar Guido Trotter

ConfigWriter: simplify GenerateDRBDSecret

We can do this by adding a new TemporaryReservationManager
Signed-off-by: default avatarGuido Trotter <ultrotter@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 36b66e6e
......@@ -5323,7 +5323,7 @@ def _GenerateDRBD8Branch(lu, primary, secondary, size, names, iv_name,
"""
port = lu.cfg.AllocatePort()
vgname = lu.cfg.GetVGName()
shared_secret = lu.cfg.GenerateDRBDSecret()
shared_secret = lu.cfg.GenerateDRBDSecret(lu.proc.GetECId())
dev_data = objects.Disk(dev_type=constants.LD_LV, size=size,
logical_id=(vgname, names[0]))
dev_meta = objects.Disk(dev_type=constants.LD_LV, size=128,
......
......@@ -138,6 +138,7 @@ class ConfigWriter:
self._temporary_ids = TemporaryReservationManager()
self._temporary_drbds = {}
self._temporary_macs = TemporaryReservationManager()
self._temporary_secrets = TemporaryReservationManager()
# Note: in order to prevent errors when resolving our name in
# _DistributeConfig, we compute it here once and reuse it; it's
# better to raise an error before starting to modify the config
......@@ -190,23 +191,15 @@ class ConfigWriter:
self._temporary_macs.Reserve(mac, ec_id)
@locking.ssynchronized(_config_lock, shared=1)
def GenerateDRBDSecret(self):
def GenerateDRBDSecret(self, ec_id):
"""Generate a DRBD secret.
This checks the current disks for duplicates.
"""
all_secrets = self._AllDRBDSecrets()
retries = 64
while retries > 0:
secret = utils.GenerateSecret()
if secret not in all_secrets:
break
retries -= 1
else:
raise errors.ConfigurationError("Can't generate unique DRBD secret")
return secret
return self._temporary_secrets.Generate(self._AllDRBDSecrets(),
utils.GenerateSecret,
ec_id)
def _AllLVs(self):
"""Compute the list of all LVs.
......@@ -1429,4 +1422,5 @@ class ConfigWriter:
"""
self._temporary_ids.DropECReservations(ec_id)
self._temporary_macs.DropECReservations(ec_id)
self._temporary_secrets.DropECReservations(ec_id)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment