1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +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) {
return parm;
}
if (this_ip->pnn == -1) {
if (this_ip->pnn == CTDB_UNKNOWN_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) {
tmp_ip->pnn = public_ips->ip[j].pnn;
} else {
tmp_ip->pnn = -1;
tmp_ip->pnn = CTDB_UNKNOWN_PNN;
}
tmp_ip->addr = public_ips->ip[j].addr;
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
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);

View File

@ -87,7 +87,7 @@ int find_takeover_node(struct ipalloc_state *ipalloc_state,
unsigned int i, numnodes;
numnodes = ipalloc_state->num;
pnn = -1;
pnn = CTDB_UNKNOWN_PNN;
for (i=0; i<numnodes; i++) {
/* verify that this node can serve this 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);
/* was this the first node we checked ? */
if (pnn == -1) {
if (pnn == CTDB_UNKNOWN_PNN) {
pnn = i;
min = num;
} 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",
ctdb_sock_addr_to_string(ipalloc_state,
&ip->addr,
@ -157,7 +157,7 @@ void basic_allocate_unassigned(struct ipalloc_state *ipalloc_state)
each unassigned ip.
*/
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)) {
DEBUG(DEBUG_WARNING,
("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;
/* 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) {
if (t->pnn == -1) {
if (t->pnn == CTDB_UNKNOWN_PNN) {
continue;
}
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,
&t->addr, false),
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.
*/
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;
}
}
@ -217,13 +217,13 @@ static void lcp2_allocate_unassigned(struct ipalloc_state *ipalloc_state,
DEBUG(DEBUG_DEBUG,(" ----------------------------------------\n"));
DEBUG(DEBUG_DEBUG,(" CONSIDERING MOVES (UNASSIGNED)\n"));
minnode = -1;
minnode = CTDB_UNKNOWN_PNN;
mindsum = 0;
minip = NULL;
/* loop over each unassigned ip. */
for (t = ipalloc_state->all_ips; t != NULL ; t = t->next) {
if (t->pnn != -1) {
if (t->pnn != CTDB_UNKNOWN_PNN) {
continue;
}
@ -249,7 +249,8 @@ static void lcp2_allocate_unassigned(struct ipalloc_state *ipalloc_state,
dstimbl - lcp2_imbalances[dstnode]));
if ((minnode == -1) || (dstdsum < mindsum)) {
if (minnode == CTDB_UNKNOWN_PNN ||
dstdsum < mindsum) {
minnode = dstnode;
minimbl = dstimbl;
mindsum = dstdsum;
@ -262,7 +263,7 @@ static void lcp2_allocate_unassigned(struct ipalloc_state *ipalloc_state,
DEBUG(DEBUG_DEBUG,(" ----------------------------------------\n"));
/* If we found one then assign it to the given node. */
if (minnode != -1) {
if (minnode != CTDB_UNKNOWN_PNN) {
minip->pnn = minnode;
lcp2_imbalances[minnode] = minimbl;
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. */
have_unassigned = false;
for (t = ipalloc_state->all_ips; t != NULL; t = t->next) {
if (t->pnn == -1) {
if (t->pnn == CTDB_UNKNOWN_PNN) {
have_unassigned = true;
}
}
@ -287,7 +288,7 @@ static void lcp2_allocate_unassigned(struct ipalloc_state *ipalloc_state,
*/
if (have_unassigned) {
for (t = ipalloc_state->all_ips; t != NULL; t = t->next) {
if (t->pnn == -1) {
if (t->pnn == CTDB_UNKNOWN_PNN) {
DEBUG(DEBUG_WARNING,
("Failed to find node to cover ip %s\n",
ctdb_sock_addr_to_string(ipalloc_state,
@ -317,7 +318,7 @@ static bool lcp2_failback_candidate(struct ipalloc_state *ipalloc_state,
srcimbl = 0;
minip = NULL;
minsrcimbl = 0;
mindstnode = -1;
mindstnode = CTDB_UNKNOWN_PNN;
mindstimbl = 0;
numnodes = ipalloc_state->num;
@ -369,7 +370,7 @@ static bool lcp2_failback_candidate(struct ipalloc_state *ipalloc_state,
if ((dstimbl < lcp2_imbalances[srcnode]) &&
(dstdsum < srcdsum) && \
((mindstnode == -1) || \
((mindstnode == CTDB_UNKNOWN_PNN) || \
((srcimbl + dstimbl) < (minsrcimbl + mindstimbl)))) {
minip = t;
@ -381,7 +382,7 @@ static bool lcp2_failback_candidate(struct ipalloc_state *ipalloc_state,
}
DEBUG(DEBUG_DEBUG,(" ----------------------------------------\n"));
if (mindstnode != -1) {
if (mindstnode != CTDB_UNKNOWN_PNN) {
/* We found a move that makes things better... */
DEBUG(DEBUG_INFO,
("%d [%d] -> %s -> %d [+%d]\n",

View File

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