1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-26 10:04:02 +03:00

ctdb-ipalloc: Switch set_ipflags_internal() to use a new-style node map

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2016-06-22 11:37:52 +10:00 committed by Amitay Isaacs
parent ee7fc252c8
commit 2eb0b9e98a
2 changed files with 43 additions and 16 deletions

View File

@ -1185,12 +1185,13 @@ ctdb_fetch_remote_public_ips(struct ctdb_context *ctdb,
return public_ips;
}
static bool all_nodes_are_disabled(struct ctdb_node_map_old *nodemap)
static bool all_nodes_are_disabled(struct ctdb_node_map *nodemap)
{
int i;
for (i=0;i<nodemap->num;i++) {
if (!(nodemap->nodes[i].flags & (NODE_FLAGS_INACTIVE|NODE_FLAGS_DISABLED))) {
if (!(nodemap->node[i].flags &
(NODE_FLAGS_INACTIVE|NODE_FLAGS_DISABLED))) {
/* Found one completely healthy node */
return false;
}
@ -1321,7 +1322,7 @@ static uint32_t *get_tunable_from_nodes(struct ctdb_context *ctdb,
* Set NOIPHOST ip flags for disabled nodes
*/
static void set_ipflags_internal(struct ipalloc_state *ipalloc_state,
struct ctdb_node_map_old *nodemap,
struct ctdb_node_map *nodemap,
uint32_t *tval_noiptakeover,
uint32_t *tval_noiphostonalldisabled)
{
@ -1334,7 +1335,7 @@ static void set_ipflags_internal(struct ipalloc_state *ipalloc_state,
}
/* Can not host IPs on INACTIVE node */
if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) {
if (nodemap->node[i].flags & NODE_FLAGS_INACTIVE) {
ipalloc_state->noiphost[i] = true;
}
}
@ -1353,19 +1354,41 @@ static void set_ipflags_internal(struct ipalloc_state *ipalloc_state,
* IPs on DISABLED node
*/
for (i=0;i<nodemap->num;i++) {
if (nodemap->nodes[i].flags & NODE_FLAGS_DISABLED) {
if (nodemap->node[i].flags & NODE_FLAGS_DISABLED) {
ipalloc_state->noiphost[i] = true;
}
}
}
}
static struct ctdb_node_map *
ctdb_node_map_old_to_new(TALLOC_CTX *mem_ctx,
const struct ctdb_node_map_old *old)
{
struct ctdb_node_map *new;
new = talloc(mem_ctx, struct ctdb_node_map);
if (new == NULL) {
DEBUG(DEBUG_ERR, (__location__ " out of memory\n"));
return NULL;
}
new->num = old->num;
new->node = talloc_zero_array(new,
struct ctdb_node_and_flags, new->num);
memcpy(new->node, &old->nodes[0],
sizeof(struct ctdb_node_and_flags) * new->num);
return new;
}
static bool set_ipflags(struct ctdb_context *ctdb,
struct ipalloc_state *ipalloc_state,
struct ctdb_node_map_old *nodemap)
{
uint32_t *tval_noiptakeover;
uint32_t *tval_noiphostonalldisabled;
struct ctdb_node_map *new;
tval_noiptakeover = get_tunable_from_nodes(ctdb, ipalloc_state, nodemap,
"NoIPTakeover", 0);
@ -1381,12 +1404,18 @@ static bool set_ipflags(struct ctdb_context *ctdb,
return false;
}
set_ipflags_internal(ipalloc_state, nodemap,
new = ctdb_node_map_old_to_new(ipalloc_state, nodemap);
if (new == NULL) {
return false;
}
set_ipflags_internal(ipalloc_state, new,
tval_noiptakeover,
tval_noiphostonalldisabled);
talloc_free(tval_noiptakeover);
talloc_free(tval_noiphostonalldisabled);
talloc_free(new);
return true;
}

View File

@ -239,7 +239,7 @@ static void ctdb_test_init(const char nodestates[],
struct ctdb_public_ip_list *avail;
int i;
char *tok, *ns, *t;
struct ctdb_node_map_old *nodemap;
struct ctdb_node_map *nodemap;
uint32_t *tval_noiptakeover;
uint32_t *tval_noiptakeoverondisabled;
ctdb_sock_addr sa_zero = { .ip = { 0 } };
@ -249,19 +249,17 @@ static void ctdb_test_init(const char nodestates[],
/* Avoid that const */
ns = talloc_strdup(*ctdb, nodestates);
nodemap = talloc_zero(*ctdb, struct ctdb_node_map_old);
nodemap = talloc_zero(*ctdb, struct ctdb_node_map);
assert(nodemap != NULL);
nodemap->num = 0;
tok = strtok(ns, ",");
while (tok != NULL) {
uint32_t n = nodemap->num;
size_t size =
offsetof(struct ctdb_node_map_old, nodes) +
(n + 1) * sizeof(struct ctdb_node_and_flags);
nodemap = talloc_realloc_size(*ctdb, nodemap, size);
nodemap->nodes[n].pnn = n;
nodemap->nodes[n].flags = (uint32_t) strtol(tok, NULL, 0);
nodemap->nodes[n].addr = sa_zero;
nodemap->node = talloc_realloc(nodemap, nodemap->node,
struct ctdb_node_and_flags, n+1);
nodemap->node[n].pnn = n;
nodemap->node[n].flags = (uint32_t) strtol(tok, NULL, 0);
nodemap->node[n].addr = sa_zero;
nodemap->num++;
tok = strtok(NULL, ",");
}
@ -307,7 +305,7 @@ static void ctdb_test_init(const char nodestates[],
for (i=0; i < nodemap->num; i++) {
(*ctdb)->nodes[i] = talloc(*ctdb, struct ctdb_node);
(*ctdb)->nodes[i]->pnn = i;
(*ctdb)->nodes[i]->flags = nodemap->nodes[i].flags;
(*ctdb)->nodes[i]->flags = nodemap->node[i].flags;
}
if (! ipalloc_set_public_ips(*ipalloc_state, known, avail)) {