]> git.proxmox.com Git - mirror_corosync.git/commitdiff
config: Allow generated nodeis for UDP & UDPU
authorChristine Caulfield <ccaulfie@redhat.com>
Thu, 25 Oct 2018 10:29:33 +0000 (11:29 +0100)
committerJan Friesse <jfriesse@redhat.com>
Thu, 25 Oct 2018 16:21:02 +0000 (18:21 +0200)
The conversion to the new srp_addr format broke the feature where
UDP/UDPU nodes could get their nodeids generated from the IP address.

A big part of this was the removal of mandatory ring0_addr - it was used
as a placeholder when reading down the nodelist. I replaced this with
nodeid thinking that nodeid was now mandatory, forgetting this use case.
So the compare on "ring0_addr" or "nodeid" is now replaced with a more
robust check that we're only reading keys from the same node_pos once,
this was needed in votequorum.c as well as totemconfig.c

Another tidying side-effect of this patch is that the nodeid generation
is now all in a single routine in totemconfig.c and not shared between
it and totemip.c.

Signed-off-by: Christine Caulfield <ccaulfie@redhat.com>
Reviewed-by: Jan Friesse <jfriesse@redhat.com>
exec/totemconfig.c
exec/totemip.c
exec/votequorum.c

index a92978d2793a7a65d602f73aaa95729951e9f098..1d44940dffef78e4416dd479f4d37c0ef48b6bce 100644 (file)
@@ -850,7 +850,7 @@ static int get_cluster_mcast_addr (
        return (err);
 }
 
-static unsigned int generate_nodeid_for_duplicate_test(
+static unsigned int generate_nodeid(
        struct totem_config *totem_config,
        char *addr)
 {
@@ -888,6 +888,7 @@ static int check_for_duplicate_nodeids(
        char *ring0_addr1=NULL;
        unsigned int node_pos;
        unsigned int node_pos1;
+       unsigned int last_node_pos = -1;
        unsigned int nodeid;
        unsigned int nodeid1;
        int autogenerated;
@@ -899,9 +900,15 @@ static int check_for_duplicate_nodeids(
                        continue;
                }
 
-               if (strcmp(tmp_key, "nodeid") != 0) {
+               /*
+                * This relies on the fact the icmap keys are always returned in order
+                * so all of the keys for a node will be grouped together. We're basically
+                * just running the code below once for each node.
+                */
+               if (last_node_pos == node_pos) {
                        continue;
                }
+               last_node_pos = node_pos;
 
                snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
                autogenerated = 0;
@@ -915,7 +922,7 @@ static int check_for_duplicate_nodeids(
                        }
 
                        /* Generate nodeid so we can check that auto-generated nodeids don't clash either */
-                       nodeid = generate_nodeid_for_duplicate_test(totem_config, ring0_addr);
+                       nodeid = generate_nodeid(totem_config, ring0_addr);
                        if (nodeid == -1) {
                                continue;
                        }
@@ -941,7 +948,7 @@ static int check_for_duplicate_nodeids(
                                if (icmap_get_string(tmp_key, &ring0_addr1) != CS_OK) {
                                        continue;
                                }
-                               nodeid1 = generate_nodeid_for_duplicate_test(totem_config, ring0_addr1);
+                               nodeid1 = generate_nodeid(totem_config, ring0_addr1);
                                if (nodeid1 == -1) {
                                        continue;
                                }
@@ -1170,6 +1177,7 @@ static void put_nodelist_members_to_config(struct totem_config *totem_config, in
        int member_count;
        unsigned int linknumber = 0;
        int i, j;
+       int last_node_pos = -1;
        struct totem_interface *new_interfaces = NULL;
 
        if (reload) {
@@ -1196,17 +1204,21 @@ static void put_nodelist_members_to_config(struct totem_config *totem_config, in
                if (res != 2) {
                        continue;
                }
-               if (strcmp(tmp_key, "nodeid") != 0) {
+               /* If it's the same as the last node_pos then skip it */
+               if (node_pos == last_node_pos) {
                        continue;
                }
+               last_node_pos = node_pos;
 
                snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.", node_pos);
                iter2 = icmap_iter_init(tmp_key);
                while ((iter_key2 = icmap_iter_next(iter2, NULL, NULL)) != NULL) {
                        unsigned int nodeid;
+                       char *str;
 
                        snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.nodeid", node_pos);
                        if (icmap_get_uint32(tmp_key, &nodeid) != CS_OK) {
+                               nodeid = 0;
                        }
 
                        res = sscanf(iter_key2, "nodelist.node.%u.ring%u%s", &node_pos, &linknumber, tmp_key2);
@@ -1218,6 +1230,19 @@ static void put_nodelist_members_to_config(struct totem_config *totem_config, in
                                continue;
                        }
 
+                       /* Generate nodeids if they are not provided and transport is UDP/U */
+                       if (!nodeid &&
+                           (totem_config->transport_number == TOTEM_TRANSPORT_UDP ||
+                            totem_config->transport_number == TOTEM_TRANSPORT_UDPU)) {
+                               snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", node_pos);
+                               if (icmap_get_string(tmp_key, &str) == CS_OK) {
+                                       nodeid = generate_nodeid(totem_config, str);
+                                       free(str);
+                                       log_printf(LOGSYS_LEVEL_DEBUG,
+                                                  "Generated nodeid = 0x%x for %s\n", nodeid, str);
+                               }
+                       }
+
                        member_count = totem_config->interfaces[linknumber].member_count;
                        res = totemip_parse(&totem_config->interfaces[linknumber].member_list[member_count],
                                                node_addr_str, totem_config->ip_version);
@@ -1689,6 +1714,18 @@ extern int totem_config_read (
                                return -1;
                        }
 
+                       if ((totem_config->transport_number == TOTEM_TRANSPORT_UDP ||
+                            totem_config->transport_number == TOTEM_TRANSPORT_UDPU) && (!totem_config->node_id)) {
+
+                               snprintf(tmp_key, ICMAP_KEYNAME_MAXLEN, "nodelist.node.%u.ring0_addr", local_node_pos);
+                               icmap_get_string(tmp_key, &str);
+
+                               totem_config->node_id = generate_nodeid(totem_config, str);
+                               totem_config->interfaces[0].member_list[local_node_pos].nodeid = totem_config->node_id;
+
+                               free(str);
+                       }
+
                        /* Users must not change this */
                        icmap_set_ro_access("nodelist.local_node_pos", 0, 1);
                }
index 1eb0889c0a3730f887f896dbcfb6a37084f1c22f..c0f753d1a1b98f65f3a8225ca03e1fbbec52664e 100644 (file)
@@ -484,18 +484,6 @@ int totemip_iface_check(struct totem_ip_address *bindnet,
                        *interface_up = if_addr->interface_up;
                        *interface_num = if_addr->interface_num;
 
-                       if (boundto->family == AF_INET && boundto->nodeid == 0) {
-                               unsigned int nodeid = 0;
-                               memcpy (&nodeid, boundto->addr, sizeof (int));
-#if __BYTE_ORDER == __LITTLE_ENDIAN
-                                nodeid = swab32 (nodeid);
-#endif
-                               if (mask_high_bit) {
-                                       nodeid &= 0x7FFFFFFF;
-                               }
-                               boundto->nodeid = nodeid;
-                       }
-
                        net_match_found = 1;
                        res = 0;
 
index 246c5e0fdd744735afbbae624311e439b8793211..b105e7cca2aef0fbb99290898380b83186b7eb0c 100644 (file)
@@ -1149,7 +1149,7 @@ static int votequorum_read_nodelist_configuration(uint32_t *votes,
        icmap_iter_t iter;
        const char *iter_key;
        char tmp_key[ICMAP_KEYNAME_MAXLEN];
-       uint32_t our_pos, node_pos;
+       uint32_t our_pos, node_pos, last_node_pos=-1;
        uint32_t nodecount = 0;
        uint32_t nodelist_expected_votes = 0;
        uint32_t node_votes = 0;
@@ -1172,9 +1172,15 @@ static int votequorum_read_nodelist_configuration(uint32_t *votes,
                        continue;
                }
 
-               if (strcmp(tmp_key, "nodeid") != 0) {
+               /*
+                * If current node_pos is the same as the last_node_pos then skip it
+                * so we only do the code below once per node.
+                * (icmap keys are always in order)
+                */
+               if (last_node_pos == node_pos) {
                        continue;
                }
+               last_node_pos = node_pos;
 
                nodecount++;