From: Martin Schwenke Date: Tue, 3 Nov 2015 05:30:23 +0000 (+1100) Subject: ctdb-ipalloc: Have set_ipflags_internal() set ipalloc_state->ipflags X-Git-Url: http://git.samba.org/?a=commitdiff_plain;h=47c5e5aa14328a4cbe147dd1ef77f6fd9c69fd5c;p=obnox%2Fsamba%2Fsamba-obnox.git ctdb-ipalloc: Have set_ipflags_internal() set ipalloc_state->ipflags This is cleaner than returning ipflags and assigning them into ipalloc_state afterwards. Signed-off-by: Martin Schwenke Reviewed-by: Amitay Isaacs --- diff --git a/ctdb/server/ctdb_takeover.c b/ctdb/server/ctdb_takeover.c index 4145e3d024e..4391151db7b 100644 --- a/ctdb/server/ctdb_takeover.c +++ b/ctdb/server/ctdb_takeover.c @@ -2360,31 +2360,30 @@ static uint32_t *get_tunable_from_nodes(struct ctdb_context *ctdb, * else * Set NOIPHOST ip flags for disabled nodes */ -static struct ctdb_ipflags * -set_ipflags_internal(struct ipalloc_state *ipalloc_state, - struct ctdb_node_map_old *nodemap, - uint32_t *tval_noiptakeover, - uint32_t *tval_noiphostonalldisabled) +static bool set_ipflags_internal(struct ipalloc_state *ipalloc_state, + struct ctdb_node_map_old *nodemap, + uint32_t *tval_noiptakeover, + uint32_t *tval_noiphostonalldisabled) { int i; - struct ctdb_ipflags *ipflags; /* Clear IP flags - implicit due to talloc_zero */ - ipflags = talloc_zero_array(ipalloc_state, struct ctdb_ipflags, nodemap->num); - if (ipflags == NULL) { + ipalloc_state->ipflags = + talloc_zero_array(ipalloc_state, struct ctdb_ipflags, nodemap->num); + if (ipalloc_state->ipflags == NULL) { DEBUG(DEBUG_ERR, (__location__ " out of memory\n")); - return NULL; + return false; } for (i=0;inum;i++) { /* Can not take IPs on node with NoIPTakeover set */ if (tval_noiptakeover[i] != 0) { - ipflags[i].noiptakeover = true; + ipalloc_state->ipflags[i].noiptakeover = true; } /* Can not host IPs on INACTIVE node */ if (nodemap->nodes[i].flags & NODE_FLAGS_INACTIVE) { - ipflags[i].noiphost = true; + ipalloc_state->ipflags[i].noiphost = true; } } @@ -2394,7 +2393,7 @@ set_ipflags_internal(struct ipalloc_state *ipalloc_state, */ for (i=0;inum;i++) { if (tval_noiphostonalldisabled[i] != 0) { - ipflags[i].noiphost = true; + ipalloc_state->ipflags[i].noiphost = true; } } } else { @@ -2403,27 +2402,26 @@ set_ipflags_internal(struct ipalloc_state *ipalloc_state, */ for (i=0;inum;i++) { if (nodemap->nodes[i].flags & NODE_FLAGS_DISABLED) { - ipflags[i].noiphost = true; + ipalloc_state->ipflags[i].noiphost = true; } } } - return ipflags; + return true; } -static struct ctdb_ipflags *set_ipflags(struct ctdb_context *ctdb, - struct ipalloc_state *ipalloc_state, - struct ctdb_node_map_old *nodemap) +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_ipflags *ipflags; - + bool ret; tval_noiptakeover = get_tunable_from_nodes(ctdb, ipalloc_state, nodemap, "NoIPTakeover", 0); if (tval_noiptakeover == NULL) { - return NULL; + return false; } tval_noiphostonalldisabled = @@ -2431,17 +2429,17 @@ static struct ctdb_ipflags *set_ipflags(struct ctdb_context *ctdb, "NoIPHostOnAllDisabled", 0); if (tval_noiphostonalldisabled == NULL) { /* Caller frees tmp_ctx */ - return NULL; + return false; } - ipflags = set_ipflags_internal(ipalloc_state, nodemap, - tval_noiptakeover, - tval_noiphostonalldisabled); + ret = set_ipflags_internal(ipalloc_state, nodemap, + tval_noiptakeover, + tval_noiphostonalldisabled); talloc_free(tval_noiptakeover); talloc_free(tval_noiphostonalldisabled); - return ipflags; + return ret; } static struct ipalloc_state * ipalloc_state_init(struct ctdb_context *ctdb, @@ -2599,7 +2597,6 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodem struct client_async_data *async_data; struct ctdb_client_control_state *state; TALLOC_CTX *tmp_ctx = talloc_new(ctdb); - struct ctdb_ipflags *ipflags; struct ipalloc_state *ipalloc_state; struct takeover_callback_data *takeover_data; struct iprealloc_callback_data iprealloc_data; @@ -2620,13 +2617,11 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodem return -1; } - ipflags = set_ipflags(ctdb, ipalloc_state, nodemap); - if (ipflags == NULL) { + if (!set_ipflags(ctdb, ipalloc_state, nodemap)) { DEBUG(DEBUG_ERR,("Failed to set IP flags - aborting takeover run\n")); talloc_free(tmp_ctx); return -1; } - ipalloc_state->ipflags= ipflags; /* Fetch known/available public IPs from each active node */ ret = ctdb_reload_remote_public_ips(ctdb, ipalloc_state, nodemap); diff --git a/ctdb/tests/src/ctdb_takeover_tests.c b/ctdb/tests/src/ctdb_takeover_tests.c index 0902f625ad4..20fe6285c7f 100644 --- a/ctdb/tests/src/ctdb_takeover_tests.c +++ b/ctdb/tests/src/ctdb_takeover_tests.c @@ -516,10 +516,9 @@ static void ctdb_test_init(const char nodestates[], (*ipalloc_state)->known_public_ips[i] = known[i]; } - (*ipalloc_state)->ipflags = - set_ipflags_internal(*ipalloc_state, nodemap, - tval_noiptakeover, - tval_noiptakeoverondisabled); + set_ipflags_internal(*ipalloc_state, nodemap, + tval_noiptakeover, + tval_noiptakeoverondisabled); } /* IP layout is read from stdin. */