1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-11 05:18:09 +03:00

ctdb-ipalloc: Avoid -1 as a PNN, use CTDB_UNKNOWN_PNN instead

This fixes warnings about signed versus unsigned comparisons.

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2019-05-30 15:40:42 +10:00 committed by Amitay Isaacs
parent 86666d6570
commit 7df15b246a
4 changed files with 27 additions and 26 deletions

View File

@ -67,7 +67,7 @@ static void *add_ip_callback(void *parm, void *data)
if (prev_ip == NULL) { if (prev_ip == NULL) {
return parm; return parm;
} }
if (this_ip->pnn == -1) { if (this_ip->pnn == CTDB_UNKNOWN_PNN) {
this_ip->pnn = prev_ip->pnn; this_ip->pnn = prev_ip->pnn;
} }
@ -125,7 +125,7 @@ create_merged_ip_list(struct ipalloc_state *ipalloc_state)
if (public_ips->ip[j].pnn == i) { if (public_ips->ip[j].pnn == i) {
tmp_ip->pnn = public_ips->ip[j].pnn; tmp_ip->pnn = public_ips->ip[j].pnn;
} else { } else {
tmp_ip->pnn = -1; tmp_ip->pnn = CTDB_UNKNOWN_PNN;
} }
tmp_ip->addr = public_ips->ip[j].addr; tmp_ip->addr = public_ips->ip[j].addr;
tmp_ip->next = NULL; tmp_ip->next = NULL;
@ -272,7 +272,7 @@ struct public_ip_list *ipalloc(struct ipalloc_state *ipalloc_state)
} }
/* at this point ->pnn is the node which will own each IP /* at this point ->pnn is the node which will own each IP
or -1 if there is no node that can cover this ip or CTDB_UNKNOWN_PNN if there is no node that can cover this ip
*/ */
return (ret ? ipalloc_state->all_ips : NULL); return (ret ? ipalloc_state->all_ips : NULL);

View File

@ -87,7 +87,7 @@ int find_takeover_node(struct ipalloc_state *ipalloc_state,
unsigned int i, numnodes; unsigned int i, numnodes;
numnodes = ipalloc_state->num; numnodes = ipalloc_state->num;
pnn = -1; pnn = CTDB_UNKNOWN_PNN;
for (i=0; i<numnodes; i++) { for (i=0; i<numnodes; i++) {
/* verify that this node can serve this ip */ /* verify that this node can serve this ip */
if (!can_node_takeover_ip(ipalloc_state, i, ip)) { if (!can_node_takeover_ip(ipalloc_state, i, ip)) {
@ -97,7 +97,7 @@ int find_takeover_node(struct ipalloc_state *ipalloc_state,
num = node_ip_coverage(i, ipalloc_state->all_ips); num = node_ip_coverage(i, ipalloc_state->all_ips);
/* was this the first node we checked ? */ /* was this the first node we checked ? */
if (pnn == -1) { if (pnn == CTDB_UNKNOWN_PNN) {
pnn = i; pnn = i;
min = num; min = num;
} else { } else {
@ -107,7 +107,7 @@ int find_takeover_node(struct ipalloc_state *ipalloc_state,
} }
} }
} }
if (pnn == -1) { if (pnn == CTDB_UNKNOWN_PNN) {
DEBUG(DEBUG_WARNING,(__location__ " Could not find node to take over public address '%s'\n", DEBUG(DEBUG_WARNING,(__location__ " Could not find node to take over public address '%s'\n",
ctdb_sock_addr_to_string(ipalloc_state, ctdb_sock_addr_to_string(ipalloc_state,
&ip->addr, &ip->addr,
@ -157,7 +157,7 @@ void basic_allocate_unassigned(struct ipalloc_state *ipalloc_state)
each unassigned ip. each unassigned ip.
*/ */
for (t = ipalloc_state->all_ips; t != NULL; t = t->next) { for (t = ipalloc_state->all_ips; t != NULL; t = t->next) {
if (t->pnn == -1) { if (t->pnn == CTDB_UNKNOWN_PNN) {
if (find_takeover_node(ipalloc_state, t)) { if (find_takeover_node(ipalloc_state, t)) {
DEBUG(DEBUG_WARNING, DEBUG(DEBUG_WARNING,
("Failed to find node to cover ip %s\n", ("Failed to find node to cover ip %s\n",
@ -174,10 +174,10 @@ void unassign_unsuitable_ips(struct ipalloc_state *ipalloc_state)
struct public_ip_list *t; struct public_ip_list *t;
/* verify that the assigned nodes can serve that public ip /* verify that the assigned nodes can serve that public ip
and set it to -1 if not and set it to CTDB_UNKNOWN_PNN if not
*/ */
for (t = ipalloc_state->all_ips; t != NULL; t = t->next) { for (t = ipalloc_state->all_ips; t != NULL; t = t->next) {
if (t->pnn == -1) { if (t->pnn == CTDB_UNKNOWN_PNN) {
continue; continue;
} }
if (!can_node_host_ip(ipalloc_state, t->pnn, t) != 0) { if (!can_node_host_ip(ipalloc_state, t->pnn, t) != 0) {
@ -187,7 +187,7 @@ void unassign_unsuitable_ips(struct ipalloc_state *ipalloc_state)
ipalloc_state, ipalloc_state,
&t->addr, false), &t->addr, false),
t->pnn)); t->pnn));
t->pnn = -1; t->pnn = CTDB_UNKNOWN_PNN;
} }
} }
} }

View File

@ -164,7 +164,7 @@ static bool lcp2_init(struct ipalloc_state *ipalloc_state,
* changes. * changes.
*/ */
for (t = ipalloc_state->all_ips; t != NULL; t = t->next) { for (t = ipalloc_state->all_ips; t != NULL; t = t->next) {
if (t->pnn != -1) { if (t->pnn != CTDB_UNKNOWN_PNN) {
(*rebalance_candidates)[t->pnn] = false; (*rebalance_candidates)[t->pnn] = false;
} }
} }
@ -217,13 +217,13 @@ static void lcp2_allocate_unassigned(struct ipalloc_state *ipalloc_state,
DEBUG(DEBUG_DEBUG,(" ----------------------------------------\n")); DEBUG(DEBUG_DEBUG,(" ----------------------------------------\n"));
DEBUG(DEBUG_DEBUG,(" CONSIDERING MOVES (UNASSIGNED)\n")); DEBUG(DEBUG_DEBUG,(" CONSIDERING MOVES (UNASSIGNED)\n"));
minnode = -1; minnode = CTDB_UNKNOWN_PNN;
mindsum = 0; mindsum = 0;
minip = NULL; minip = NULL;
/* loop over each unassigned ip. */ /* loop over each unassigned ip. */
for (t = ipalloc_state->all_ips; t != NULL ; t = t->next) { for (t = ipalloc_state->all_ips; t != NULL ; t = t->next) {
if (t->pnn != -1) { if (t->pnn != CTDB_UNKNOWN_PNN) {
continue; continue;
} }
@ -249,7 +249,8 @@ static void lcp2_allocate_unassigned(struct ipalloc_state *ipalloc_state,
dstimbl - lcp2_imbalances[dstnode])); dstimbl - lcp2_imbalances[dstnode]));
if ((minnode == -1) || (dstdsum < mindsum)) { if (minnode == CTDB_UNKNOWN_PNN ||
dstdsum < mindsum) {
minnode = dstnode; minnode = dstnode;
minimbl = dstimbl; minimbl = dstimbl;
mindsum = dstdsum; mindsum = dstdsum;
@ -262,7 +263,7 @@ static void lcp2_allocate_unassigned(struct ipalloc_state *ipalloc_state,
DEBUG(DEBUG_DEBUG,(" ----------------------------------------\n")); DEBUG(DEBUG_DEBUG,(" ----------------------------------------\n"));
/* If we found one then assign it to the given node. */ /* If we found one then assign it to the given node. */
if (minnode != -1) { if (minnode != CTDB_UNKNOWN_PNN) {
minip->pnn = minnode; minip->pnn = minnode;
lcp2_imbalances[minnode] = minimbl; lcp2_imbalances[minnode] = minimbl;
DEBUG(DEBUG_INFO,(" %s -> %d [+%d]\n", DEBUG(DEBUG_INFO,(" %s -> %d [+%d]\n",
@ -276,7 +277,7 @@ static void lcp2_allocate_unassigned(struct ipalloc_state *ipalloc_state,
/* There might be a better way but at least this is clear. */ /* There might be a better way but at least this is clear. */
have_unassigned = false; have_unassigned = false;
for (t = ipalloc_state->all_ips; t != NULL; t = t->next) { for (t = ipalloc_state->all_ips; t != NULL; t = t->next) {
if (t->pnn == -1) { if (t->pnn == CTDB_UNKNOWN_PNN) {
have_unassigned = true; have_unassigned = true;
} }
} }
@ -287,7 +288,7 @@ static void lcp2_allocate_unassigned(struct ipalloc_state *ipalloc_state,
*/ */
if (have_unassigned) { if (have_unassigned) {
for (t = ipalloc_state->all_ips; t != NULL; t = t->next) { for (t = ipalloc_state->all_ips; t != NULL; t = t->next) {
if (t->pnn == -1) { if (t->pnn == CTDB_UNKNOWN_PNN) {
DEBUG(DEBUG_WARNING, DEBUG(DEBUG_WARNING,
("Failed to find node to cover ip %s\n", ("Failed to find node to cover ip %s\n",
ctdb_sock_addr_to_string(ipalloc_state, ctdb_sock_addr_to_string(ipalloc_state,
@ -317,7 +318,7 @@ static bool lcp2_failback_candidate(struct ipalloc_state *ipalloc_state,
srcimbl = 0; srcimbl = 0;
minip = NULL; minip = NULL;
minsrcimbl = 0; minsrcimbl = 0;
mindstnode = -1; mindstnode = CTDB_UNKNOWN_PNN;
mindstimbl = 0; mindstimbl = 0;
numnodes = ipalloc_state->num; numnodes = ipalloc_state->num;
@ -369,7 +370,7 @@ static bool lcp2_failback_candidate(struct ipalloc_state *ipalloc_state,
if ((dstimbl < lcp2_imbalances[srcnode]) && if ((dstimbl < lcp2_imbalances[srcnode]) &&
(dstdsum < srcdsum) && \ (dstdsum < srcdsum) && \
((mindstnode == -1) || \ ((mindstnode == CTDB_UNKNOWN_PNN) || \
((srcimbl + dstimbl) < (minsrcimbl + mindstimbl)))) { ((srcimbl + dstimbl) < (minsrcimbl + mindstimbl)))) {
minip = t; minip = t;
@ -381,7 +382,7 @@ static bool lcp2_failback_candidate(struct ipalloc_state *ipalloc_state,
} }
DEBUG(DEBUG_DEBUG,(" ----------------------------------------\n")); DEBUG(DEBUG_DEBUG,(" ----------------------------------------\n"));
if (mindstnode != -1) { if (mindstnode != CTDB_UNKNOWN_PNN) {
/* We found a move that makes things better... */ /* We found a move that makes things better... */
DEBUG(DEBUG_INFO, DEBUG(DEBUG_INFO,
("%d [%d] -> %s -> %d [+%d]\n", ("%d [%d] -> %s -> %d [+%d]\n",

View File

@ -54,15 +54,15 @@ try_again:
not greater than 1. not greater than 1.
*/ */
for (t = ipalloc_state->all_ips; t != NULL; t = t->next) { for (t = ipalloc_state->all_ips; t != NULL; t = t->next) {
if (t->pnn == -1) { if (t->pnn == CTDB_UNKNOWN_PNN) {
continue; continue;
} }
/* Get the highest and lowest number of ips's served by any /* Get the highest and lowest number of ips's served by any
valid node which can serve this ip. valid node which can serve this ip.
*/ */
maxnode = -1; maxnode = CTDB_UNKNOWN_PNN;
minnode = -1; minnode = CTDB_UNKNOWN_PNN;
for (i=0; i<numnodes; i++) { for (i=0; i<numnodes; i++) {
/* only check nodes that can actually serve this ip */ /* only check nodes that can actually serve this ip */
if (!can_node_takeover_ip(ipalloc_state, i, if (!can_node_takeover_ip(ipalloc_state, i,
@ -72,7 +72,7 @@ try_again:
} }
num = node_ip_coverage(i, ipalloc_state->all_ips); num = node_ip_coverage(i, ipalloc_state->all_ips);
if (maxnode == -1) { if (maxnode == CTDB_UNKNOWN_PNN) {
maxnode = i; maxnode = i;
maxnum = num; maxnum = num;
} else { } else {
@ -81,7 +81,7 @@ try_again:
maxnum = num; maxnum = num;
} }
} }
if (minnode == -1) { if (minnode == CTDB_UNKNOWN_PNN) {
minnode = i; minnode = i;
minnum = num; minnum = num;
} else { } else {
@ -91,7 +91,7 @@ try_again:
} }
} }
} }
if (maxnode == -1) { if (maxnode == CTDB_UNKNOWN_PNN) {
DEBUG(DEBUG_WARNING, DEBUG(DEBUG_WARNING,
(__location__ " Could not find maxnode. May not be able to serve ip '%s'\n", (__location__ " Could not find maxnode. May not be able to serve ip '%s'\n",
ctdb_sock_addr_to_string(ipalloc_state, ctdb_sock_addr_to_string(ipalloc_state,