From 48ce9fd9ed51b9bb6b24751fd535e6cb858d994e Mon Sep 17 00:00:00 2001 From: Iustin Pop <iustin@google.com> Date: Sat, 27 Sep 2008 20:45:01 +0000 Subject: [PATCH] Add checks for tcp/udp port collisions MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case the config file is manually modified, or in case of bugs, the tcp/udp ports could be reused, which will create various problems (instances not able to start, or drbd disks not able to communicate). This patch extends the ConfigWriter.VerifyConfig() method (which is used in cluster verify) to check for duplicates between: - the ports used for DRBD disks - the ports used for network console - the ports marked as free in the config file Also, if the cluster parameter βhighest_used_portβ is actually lower than the computed highest used port, this is also flagged as an error. The output from gnt-cluster verify will show (output manually wrapped): node1 # gnt-cluster verify * Verifying global settings - ERROR: tcp/udp port 11006 has duplicates: instance3.example.com/network port, instance2.example.com/drbd disk sda - ERROR: tcp/udp port 11017 has duplicates: instance3.example.com/drbd disk sda, instance3.example.com/drbd disk sdb, cluster/port marked as free - ERROR: Highest used port mismatch, saved 11010, computed 11017 * Gathering data (2 nodes) ... Reviewed-by: ultrotter --- lib/config.py | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/lib/config.py b/lib/config.py index 53dc9bd54..b8adc8402 100644 --- a/lib/config.py +++ b/lib/config.py @@ -193,6 +193,7 @@ class ConfigWriter: result = [] seen_macs = [] + ports = {} data = self._config_data for instance_name in data.instances: instance = data.instances[instance_name] @@ -209,6 +210,43 @@ class ConfigWriter: (instance_name, idx, nic.mac)) else: seen_macs.append(nic.mac) + + # gather the drbd ports for duplicate checks + for dsk in instance.disks: + if dsk.dev_type in constants.LDS_DRBD: + tcp_port = dsk.logical_id[2] + if tcp_port not in ports: + ports[tcp_port] = [] + ports[tcp_port].append((instance.name, "drbd disk %s" % dsk.iv_name)) + # gather network port reservation + net_port = getattr(instance, "network_port", None) + if net_port is not None: + if net_port not in ports: + ports[net_port] = [] + ports[net_port].append((instance.name, "network port")) + + # cluster-wide pool of free ports + for free_port in self._config_data.cluster.tcpudp_port_pool: + if free_port not in ports: + ports[free_port] = [] + ports[free_port].append(("cluster", "port marked as free")) + + # compute tcp/udp duplicate ports + keys = ports.keys() + keys.sort() + for pnum in keys: + pdata = ports[pnum] + if len(pdata) > 1: + txt = ", ".join(["%s/%s" % val for val in pdata]) + result.append("tcp/udp port %s has duplicates: %s" % (pnum, txt)) + + # highest used tcp port check + if keys: + if keys[-1] > self._config_data.cluster.highest_used_port: + result.append("Highest used port mismatch, saved %s, computed %s" % + (self._config_data.cluster.highest_used_port, + keys[-1])) + return result def _UnlockedSetDiskID(self, disk, node_name): -- GitLab