mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
ctdb-ipalloc: Remove most uses of struct ctdb_public_ip_list_old
Where possible, this should no longer be used. struct ctdb_public_ip_list is a fixed size structure and introduces an extra level of indirection. This means one level of indirection can be dropped for known_public_ips and available_public_ips. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Autobuild-User(master): Amitay Isaacs <amitay@samba.org> Autobuild-Date(master): Fri Feb 12 08:40:21 CET 2016 on sn-devel-144
This commit is contained in:
parent
53752bcf29
commit
2deba05c58
@ -1254,7 +1254,7 @@ static int getips_count_callback(void *param, void *data)
|
||||
}
|
||||
|
||||
static int verify_remote_ip_allocation(struct ctdb_context *ctdb,
|
||||
struct ctdb_public_ip_list_old *ips,
|
||||
struct ctdb_public_ip_list *ips,
|
||||
uint32_t pnn);
|
||||
|
||||
static int ctdb_reload_remote_public_ips(struct ctdb_context *ctdb,
|
||||
@ -1263,6 +1263,7 @@ static int ctdb_reload_remote_public_ips(struct ctdb_context *ctdb,
|
||||
{
|
||||
int j;
|
||||
int ret;
|
||||
struct ctdb_public_ip_list_old *ip_list;
|
||||
|
||||
if (ipalloc_state->num != nodemap->num) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
@ -1283,18 +1284,25 @@ static int ctdb_reload_remote_public_ips(struct ctdb_context *ctdb,
|
||||
j,
|
||||
ipalloc_state->known_public_ips,
|
||||
0,
|
||||
&ipalloc_state->known_public_ips[j]);
|
||||
&ip_list);
|
||||
if (ret != 0) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Failed to read known public IPs from node: %u\n",
|
||||
j));
|
||||
return -1;
|
||||
}
|
||||
ipalloc_state->known_public_ips[j].num = ip_list->num;
|
||||
/* This could be copied and freed. However, ip_list
|
||||
* is allocated off ipalloc_state->known_public_ips,
|
||||
* so this is a safe hack. This will go away in a
|
||||
* while anyway... */
|
||||
ipalloc_state->known_public_ips[j].ip = &ip_list->ips[0];
|
||||
|
||||
if (ctdb->do_checkpublicip) {
|
||||
verify_remote_ip_allocation(ctdb,
|
||||
ipalloc_state->known_public_ips[j],
|
||||
j);
|
||||
verify_remote_ip_allocation(
|
||||
ctdb,
|
||||
&ipalloc_state->known_public_ips[j],
|
||||
j);
|
||||
}
|
||||
|
||||
/* Retrieve the list of available public IPs from the node */
|
||||
@ -1303,13 +1311,19 @@ static int ctdb_reload_remote_public_ips(struct ctdb_context *ctdb,
|
||||
j,
|
||||
ipalloc_state->available_public_ips,
|
||||
CTDB_PUBLIC_IP_FLAGS_ONLY_AVAILABLE,
|
||||
&ipalloc_state->available_public_ips[j]);
|
||||
&ip_list);
|
||||
if (ret != 0) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Failed to read available public IPs from node: %u\n",
|
||||
j));
|
||||
return -1;
|
||||
}
|
||||
ipalloc_state->available_public_ips[j].num = ip_list->num;
|
||||
/* This could be copied and freed. However, ip_list
|
||||
* is allocated off ipalloc_state->available_public_ips,
|
||||
* so this is a safe hack. This will go away in a
|
||||
* while anyway... */
|
||||
ipalloc_state->available_public_ips[j].ip = &ip_list->ips[0];
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -1320,13 +1334,13 @@ create_merged_ip_list(struct ctdb_context *ctdb, struct ipalloc_state *ipalloc_s
|
||||
{
|
||||
int i, j;
|
||||
struct public_ip_list *ip_list;
|
||||
struct ctdb_public_ip_list_old *public_ips;
|
||||
struct ctdb_public_ip_list *public_ips;
|
||||
|
||||
TALLOC_FREE(ctdb->ip_tree);
|
||||
ctdb->ip_tree = trbt_create(ctdb, 0);
|
||||
|
||||
for (i=0; i < ctdb->num_nodes; i++) {
|
||||
public_ips = ipalloc_state->known_public_ips[i];
|
||||
public_ips = &ipalloc_state->known_public_ips[i];
|
||||
|
||||
if (ctdb->nodes[i]->flags & NODE_FLAGS_DELETED) {
|
||||
continue;
|
||||
@ -1344,16 +1358,16 @@ create_merged_ip_list(struct ctdb_context *ctdb, struct ipalloc_state *ipalloc_s
|
||||
CTDB_NO_MEMORY_NULL(ctdb, tmp_ip);
|
||||
/* Do not use information about IP addresses hosted
|
||||
* on other nodes, it may not be accurate */
|
||||
if (public_ips->ips[j].pnn == ctdb->nodes[i]->pnn) {
|
||||
tmp_ip->pnn = public_ips->ips[j].pnn;
|
||||
if (public_ips->ip[j].pnn == ctdb->nodes[i]->pnn) {
|
||||
tmp_ip->pnn = public_ips->ip[j].pnn;
|
||||
} else {
|
||||
tmp_ip->pnn = -1;
|
||||
}
|
||||
tmp_ip->addr = public_ips->ips[j].addr;
|
||||
tmp_ip->addr = public_ips->ip[j].addr;
|
||||
tmp_ip->next = NULL;
|
||||
|
||||
trbt_insertarray32_callback(ctdb->ip_tree,
|
||||
IP_KEYLEN, ip_key(&public_ips->ips[j].addr),
|
||||
IP_KEYLEN, ip_key(&public_ips->ip[j].addr),
|
||||
add_ip_callback,
|
||||
tmp_ip);
|
||||
}
|
||||
@ -1582,17 +1596,19 @@ static struct ipalloc_state * ipalloc_state_init(struct ctdb_context *ctdb,
|
||||
}
|
||||
|
||||
ipalloc_state->num = ctdb->num_nodes;
|
||||
|
||||
ipalloc_state->known_public_ips =
|
||||
talloc_zero_array(ipalloc_state,
|
||||
struct ctdb_public_ip_list_old *,
|
||||
struct ctdb_public_ip_list,
|
||||
ipalloc_state->num);
|
||||
if (ipalloc_state->known_public_ips == NULL) {
|
||||
DEBUG(DEBUG_ERR, (__location__ " Out of memory\n"));
|
||||
goto fail;
|
||||
}
|
||||
|
||||
ipalloc_state->available_public_ips =
|
||||
talloc_zero_array(ipalloc_state,
|
||||
struct ctdb_public_ip_list_old *,
|
||||
struct ctdb_public_ip_list,
|
||||
ipalloc_state->num);
|
||||
if (ipalloc_state->available_public_ips == NULL) {
|
||||
DEBUG(DEBUG_ERR, (__location__ " Out of memory\n"));
|
||||
@ -1804,7 +1820,7 @@ int ctdb_takeover_run(struct ctdb_context *ctdb, struct ctdb_node_map_old *nodem
|
||||
/* Short-circuit IP allocation if no node has available IPs */
|
||||
can_host_ips = false;
|
||||
for (i=0; i < ipalloc_state->num; i++) {
|
||||
if (ipalloc_state->available_public_ips[i] != NULL) {
|
||||
if (ipalloc_state->available_public_ips[i].num != 0) {
|
||||
can_host_ips = true;
|
||||
}
|
||||
}
|
||||
@ -3459,7 +3475,7 @@ int32_t ctdb_control_ipreallocated(struct ctdb_context *ctdb,
|
||||
This is verified against ctdb->ip_tree
|
||||
*/
|
||||
static int verify_remote_ip_allocation(struct ctdb_context *ctdb,
|
||||
struct ctdb_public_ip_list_old *ips,
|
||||
struct ctdb_public_ip_list *ips,
|
||||
uint32_t pnn)
|
||||
{
|
||||
struct public_ip_list *tmp_ip;
|
||||
@ -3476,22 +3492,22 @@ static int verify_remote_ip_allocation(struct ctdb_context *ctdb,
|
||||
}
|
||||
|
||||
for (i=0; i<ips->num; i++) {
|
||||
tmp_ip = trbt_lookuparray32(ctdb->ip_tree, IP_KEYLEN, ip_key(&ips->ips[i].addr));
|
||||
tmp_ip = trbt_lookuparray32(ctdb->ip_tree, IP_KEYLEN, ip_key(&ips->ip[i].addr));
|
||||
if (tmp_ip == NULL) {
|
||||
DEBUG(DEBUG_ERR,("Node %u has new or unknown public IP %s\n", pnn, ctdb_addr_to_str(&ips->ips[i].addr)));
|
||||
DEBUG(DEBUG_ERR,("Node %u has new or unknown public IP %s\n", pnn, ctdb_addr_to_str(&ips->ip[i].addr)));
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tmp_ip->pnn == -1 || ips->ips[i].pnn == -1) {
|
||||
if (tmp_ip->pnn == -1 || ips->ip[i].pnn == -1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tmp_ip->pnn != ips->ips[i].pnn) {
|
||||
if (tmp_ip->pnn != ips->ip[i].pnn) {
|
||||
DEBUG(DEBUG_ERR,
|
||||
("Inconsistent IP allocation - node %u thinks %s is held by node %u while it is assigned to node %u\n",
|
||||
pnn,
|
||||
ctdb_addr_to_str(&ips->ips[i].addr),
|
||||
ips->ips[i].pnn, tmp_ip->pnn));
|
||||
ctdb_addr_to_str(&ips->ip[i].addr),
|
||||
ips->ip[i].pnn, tmp_ip->pnn));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
@ -25,8 +25,6 @@
|
||||
#include "replace.h"
|
||||
#include "system/network.h"
|
||||
|
||||
#include "include/ctdb_protocol.h"
|
||||
|
||||
struct public_ip_list {
|
||||
struct public_ip_list *next;
|
||||
uint32_t pnn;
|
||||
@ -47,8 +45,8 @@ struct ipalloc_state {
|
||||
uint32_t num;
|
||||
|
||||
/* Arrays with data for each node */
|
||||
struct ctdb_public_ip_list_old **known_public_ips;
|
||||
struct ctdb_public_ip_list_old **available_public_ips;
|
||||
struct ctdb_public_ip_list *known_public_ips;
|
||||
struct ctdb_public_ip_list *available_public_ips;
|
||||
bool *noiptakeover;
|
||||
bool *noiphost;
|
||||
|
||||
|
@ -32,8 +32,6 @@
|
||||
#include "common/common.h"
|
||||
#include "common/rb_tree.h"
|
||||
|
||||
#include "include/ctdb_protocol.h"
|
||||
|
||||
#include "server/ipalloc_private.h"
|
||||
|
||||
#define TAKEOVER_TIMEOUT() timeval_current_ofs(ctdb->tunable.takeover_timeout,0)
|
||||
@ -61,21 +59,21 @@ static bool can_node_host_ip(struct ipalloc_state *ipalloc_state,
|
||||
int32_t pnn,
|
||||
struct public_ip_list *ip)
|
||||
{
|
||||
struct ctdb_public_ip_list_old *public_ips;
|
||||
struct ctdb_public_ip_list *public_ips;
|
||||
int i;
|
||||
|
||||
if (ipalloc_state->noiphost[pnn]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public_ips = ipalloc_state->available_public_ips[pnn];
|
||||
public_ips = &ipalloc_state->available_public_ips[pnn];
|
||||
|
||||
if (public_ips == NULL) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (i=0; i<public_ips->num; i++) {
|
||||
if (ctdb_same_ip(&ip->addr, &public_ips->ips[i].addr)) {
|
||||
if (ctdb_same_ip(&ip->addr, &public_ips->ip[i].addr)) {
|
||||
/* yes, this node can serve this public ip */
|
||||
return true;
|
||||
}
|
||||
|
@ -109,29 +109,25 @@ static bool
|
||||
read_ctdb_public_ip_info(TALLOC_CTX *ctx ,
|
||||
int numnodes,
|
||||
struct public_ip_list ** all_ips,
|
||||
struct ctdb_public_ip_list_old *** known,
|
||||
struct ctdb_public_ip_list_old *** avail)
|
||||
struct ctdb_public_ip_list ** known,
|
||||
struct ctdb_public_ip_list ** avail)
|
||||
{
|
||||
char line[1024];
|
||||
ctdb_sock_addr addr;
|
||||
char *t, *tok;
|
||||
struct public_ip_list * ta;
|
||||
int pnn, numips, curr, n, i;
|
||||
struct ctdb_public_ip_list_old * a;
|
||||
struct ctdb_public_ip_list * a;
|
||||
|
||||
struct public_ip_list *last = NULL;
|
||||
enum ctdb_runstate *runstate;
|
||||
|
||||
runstate = get_runstate(ctx, numnodes);
|
||||
|
||||
*known = talloc_array_size(ctx, sizeof(struct ctdb_public_ip_list_old *), CTDB_TEST_MAX_NODES);
|
||||
memset(*known, 0,
|
||||
sizeof(struct ctdb_public_ip_list_old *) * CTDB_TEST_MAX_NODES);
|
||||
|
||||
*avail = talloc_array_size(ctx, sizeof(struct ctdb_public_ip_list_old *),
|
||||
*known = talloc_zero_array(ctx, struct ctdb_public_ip_list,
|
||||
CTDB_TEST_MAX_NODES);
|
||||
*avail = talloc_zero_array(ctx, struct ctdb_public_ip_list,
|
||||
CTDB_TEST_MAX_NODES);
|
||||
memset(*avail, 0,
|
||||
sizeof(struct ctdb_public_ip_list_old *) * CTDB_TEST_MAX_NODES);
|
||||
|
||||
numips = 0;
|
||||
*all_ips = NULL;
|
||||
@ -195,39 +191,36 @@ read_ctdb_public_ip_info(TALLOC_CTX *ctx ,
|
||||
t = strtok(tok, ",");
|
||||
while (t != NULL) {
|
||||
n = (int) strtol(t, (char **) NULL, 10);
|
||||
if ((*known)[n] == NULL) {
|
||||
if ((*known)[n].num == 0) {
|
||||
/* Array size here has to be
|
||||
* CTDB_TEST_MAX_IPS because total
|
||||
* number of IPs isn't yet known */
|
||||
(*known)[n] = talloc_size(ctx,
|
||||
offsetof(struct ctdb_public_ip_list_old, ips) +
|
||||
CTDB_TEST_MAX_IPS * sizeof(struct ctdb_public_ip));
|
||||
(*known)[n]->num = 0;
|
||||
(*known)[n].ip = talloc_zero_array(
|
||||
*known, struct ctdb_public_ip, CTDB_TEST_MAX_IPS);
|
||||
}
|
||||
curr = (*known)[n]->num;
|
||||
(*known)[n]->ips[curr].pnn = pnn;
|
||||
memcpy(&((*known)[n]->ips[curr].addr),
|
||||
curr = (*known)[n].num;
|
||||
(*known)[n].ip[curr].pnn = pnn;
|
||||
memcpy(&((*known)[n].ip[curr].addr),
|
||||
&addr, sizeof(addr));
|
||||
(*known)[n]->num++;
|
||||
(*known)[n].num++;
|
||||
t = strtok(NULL, ",");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Build list of all allowed IPs */
|
||||
a = talloc_size(ctx,
|
||||
offsetof(struct ctdb_public_ip_list_old, ips) +
|
||||
numips * sizeof(struct ctdb_public_ip));
|
||||
a = talloc(ctx, struct ctdb_public_ip_list);
|
||||
a->ip = talloc_zero_array(a, struct ctdb_public_ip, numips);
|
||||
a->num = numips;
|
||||
for (ta = *all_ips, i=0; ta != NULL && i < numips ; ta = ta->next, i++) {
|
||||
a->ips[i].pnn = ta->pnn;
|
||||
memcpy(&(a->ips[i].addr), &(ta->addr), sizeof(ta->addr));
|
||||
a->ip[i].pnn = ta->pnn;
|
||||
memcpy(&(a->ip[i].addr), &(ta->addr), sizeof(ta->addr));
|
||||
}
|
||||
|
||||
/* Assign it to any nodes that don't have a list assigned */
|
||||
for (n = 0; n < numnodes; n++) {
|
||||
if ((*known)[n] == NULL) {
|
||||
(*known)[n] = a;
|
||||
if ((*known)[n].num == 0) {
|
||||
(*known)[n] = *a;
|
||||
}
|
||||
if (runstate[n] == CTDB_RUNSTATE_RUNNING) {
|
||||
(*avail)[n] = (*known)[n];
|
||||
@ -238,17 +231,17 @@ read_ctdb_public_ip_info(TALLOC_CTX *ctx ,
|
||||
}
|
||||
|
||||
static void print_ctdb_available_ips(int numnodes,
|
||||
struct ctdb_public_ip_list_old **avail)
|
||||
struct ctdb_public_ip_list *avail)
|
||||
{
|
||||
int n, i;
|
||||
|
||||
for (n = 0; n < numnodes; n++) {
|
||||
if ((avail[n] != NULL) && (avail[n]->num > 0)) {
|
||||
if (avail[n].num > 0) {
|
||||
printf("%d:", n);
|
||||
for (i = 0; i < avail[n]->num; i++) {
|
||||
for (i = 0; i < avail[n].num; i++) {
|
||||
printf("%s%s",
|
||||
(i == 0) ? " " : ", ",
|
||||
ctdb_addr_to_str(&(avail[n]->ips[i].addr)));
|
||||
ctdb_addr_to_str(&(avail[n].ip[i].addr)));
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
@ -259,8 +252,8 @@ static void ctdb_test_read_ctdb_public_ip_info(const char nodestates[])
|
||||
{
|
||||
int numnodes;
|
||||
struct public_ip_list *l;
|
||||
struct ctdb_public_ip_list_old **known;
|
||||
struct ctdb_public_ip_list_old **avail;
|
||||
struct ctdb_public_ip_list *known;
|
||||
struct ctdb_public_ip_list *avail;
|
||||
char *tok, *ns;
|
||||
|
||||
TALLOC_CTX *tmp_ctx = talloc_new(NULL);
|
||||
@ -437,8 +430,8 @@ static void ctdb_test_init(const char nodestates[],
|
||||
struct ipalloc_state **ipalloc_state,
|
||||
bool read_ips_for_multiple_nodes)
|
||||
{
|
||||
struct ctdb_public_ip_list_old **known;
|
||||
struct ctdb_public_ip_list_old **avail;
|
||||
struct ctdb_public_ip_list *known;
|
||||
struct ctdb_public_ip_list *avail;
|
||||
int i, numnodes;
|
||||
uint32_t nodeflags[CTDB_TEST_MAX_NODES];
|
||||
char *tok, *ns, *t;
|
||||
|
Loading…
Reference in New Issue
Block a user