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

ctdb-common: Move ctdb_node_list_to_map() to utilities

Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
Martin Schwenke 2015-02-20 12:34:25 +11:00 committed by Amitay Isaacs
parent dd52d82c73
commit 1ef1cfdc4d
3 changed files with 30 additions and 27 deletions

View File

@ -579,6 +579,33 @@ struct ctdb_node_map *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
return ret;
}
struct ctdb_node_map *
ctdb_node_list_to_map(struct ctdb_node **nodes, uint32_t num_nodes,
TALLOC_CTX *mem_ctx)
{
uint32_t i;
size_t size;
struct ctdb_node_map *node_map;
size = offsetof(struct ctdb_node_map, nodes) +
num_nodes * sizeof(struct ctdb_node_and_flags);
node_map = (struct ctdb_node_map *)talloc_zero_size(mem_ctx, size);
if (node_map == NULL) {
DEBUG(DEBUG_ERR,
(__location__ " Failed to allocate nodemap array\n"));
return NULL;
}
node_map->num = num_nodes;
for (i=0; i<num_nodes; i++) {
node_map->nodes[i].addr = nodes[i]->address;
node_map->nodes[i].pnn = nodes[i]->pnn;
node_map->nodes[i].flags = nodes[i]->flags;
}
return node_map;
}
const char *ctdb_eventscript_call_names[] = {
"init",
"setup",

View File

@ -1388,6 +1388,9 @@ int ctdb_client_async_control(struct ctdb_context *ctdb,
client_async_callback fail_callback,
void *callback_data);
struct ctdb_node_map *
ctdb_node_list_to_map(struct ctdb_node **nodes, uint32_t num_nodes,
TALLOC_CTX *mem_ctx);
struct ctdb_node_map *ctdb_read_nodes_file(TALLOC_CTX *mem_ctx,
const char *nlist);
void ctdb_load_nodes_file(struct ctdb_context *ctdb);

View File

@ -118,33 +118,6 @@ ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indat
return 0;
}
static struct ctdb_node_map *
ctdb_node_list_to_map(struct ctdb_node **nodes, uint32_t num_nodes,
TALLOC_CTX *mem_ctx)
{
uint32_t i;
size_t size;
struct ctdb_node_map *node_map;
size = offsetof(struct ctdb_node_map, nodes) + num_nodes*sizeof(struct ctdb_node_and_flags);
node_map = (struct ctdb_node_map *)talloc_zero_size(mem_ctx, size);
if (node_map == NULL) {
DEBUG(DEBUG_ERR, (__location__ " Failed to allocate nodemap array\n"));
return NULL;
}
node_map->num = num_nodes;
for (i=0; i<num_nodes; i++) {
node_map->nodes[i].addr = nodes[i]->address;
node_map->nodes[i].pnn = nodes[i]->pnn;
node_map->nodes[i].flags = nodes[i]->flags;
}
return node_map;
}
int
ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata)
{