Commit f396ad8c authored by Vangelis Koukis's avatar Vangelis Koukis Committed by Iustin Pop
Browse files

Ensure unused ports return to the free port pool



Ensure ports previously allocated by calling ConfigWriter's AllocatePort() are
returned to the pool of free ports when no longer needed:

 * Return the network_port of an instance when it is removed
 * Return the port used by a DRBD-based disk when it is removed
Signed-off-by: default avatarVangelis Koukis <vkoukis@grnet.gr>
Signed-off-by: default avatarIustin Pop <iustin@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent ca8f5622
......@@ -6896,6 +6896,11 @@ def _RemoveDisks(lu, instance, target_node=None):
" continuing anyway: %s", device.iv_name, node, msg)
all_result = False
# if this is a DRBD disk, return its port to the pool
if device.dev_type in constants.LDS_DRBD:
tcp_port = device.logical_id[2]
lu.cfg.AddTcpUdpPort(tcp_port)
if instance.disk_template == constants.DT_FILE:
file_storage_dir = os.path.dirname(instance.disks[0].logical_id[1])
if target_node:
......@@ -9682,6 +9687,11 @@ class LUInstanceSetParams(LogicalUnit):
self.LogWarning("Could not remove metadata for disk %d on node %s,"
" continuing anyway: %s", idx, pnode, msg)
# this is a DRBD disk, return its port to the pool
for disk in old_disks:
tcp_port = disk.logical_id[2]
self.cfg.AddTcpUdpPort(tcp_port)
def Exec(self, feedback_fn):
"""Modifies an instance.
......@@ -9708,6 +9718,11 @@ class LUInstanceSetParams(LogicalUnit):
self.LogWarning("Could not remove disk/%d on node %s: %s,"
" continuing anyway", device_idx, node, msg)
result.append(("disk/%d" % device_idx, "remove"))
# if this is a DRBD disk, return its port to the pool
if device.dev_type in constants.LDS_DRBD:
tcp_port = device.logical_id[2]
self.cfg.AddTcpUdpPort(tcp_port)
elif disk_op == constants.DDM_ADD:
# add a new disk
if instance.disk_template == constants.DT_FILE:
......
......@@ -1134,6 +1134,14 @@ class ConfigWriter:
"""
if instance_name not in self._config_data.instances:
raise errors.ConfigurationError("Unknown instance '%s'" % instance_name)
# If a network port has been allocated to the instance,
# return it to the pool of free ports.
inst = self._config_data.instances[instance_name]
network_port = getattr(inst, "network_port", None)
if network_port is not None:
self._config_data.cluster.tcpudp_port_pool.add(network_port)
del self._config_data.instances[instance_name]
self._config_data.cluster.serial_no += 1
self._WriteConfig()
......
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