mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
ctdb-daemon: Factor out new function ctdb_node_list_to_map()
Change ctdb_control_getnodemap() to use this. Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
This commit is contained in:
parent
ffbe0a6def
commit
dd52d82c73
@ -118,31 +118,47 @@ ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indat
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata)
|
||||
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, num_nodes;
|
||||
uint32_t i;
|
||||
size_t size;
|
||||
struct ctdb_node_map *node_map;
|
||||
|
||||
CHECK_CONTROL_DATA_SIZE(0);
|
||||
|
||||
num_nodes = ctdb->num_nodes;
|
||||
|
||||
outdata->dsize = offsetof(struct ctdb_node_map, nodes) + num_nodes*sizeof(struct ctdb_node_and_flags);
|
||||
outdata->dptr = (unsigned char *)talloc_zero_size(outdata, outdata->dsize);
|
||||
if (!outdata->dptr) {
|
||||
DEBUG(DEBUG_ALERT, (__location__ " Failed to allocate nodemap array\n"));
|
||||
exit(1);
|
||||
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 = (struct ctdb_node_map *)outdata->dptr;
|
||||
node_map->num = num_nodes;
|
||||
for (i=0; i<num_nodes; i++) {
|
||||
node_map->nodes[i].addr = ctdb->nodes[i]->address;
|
||||
node_map->nodes[i].pnn = ctdb->nodes[i]->pnn;
|
||||
node_map->nodes[i].flags = ctdb->nodes[i]->flags;
|
||||
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)
|
||||
{
|
||||
CHECK_CONTROL_DATA_SIZE(0);
|
||||
|
||||
outdata->dptr = (unsigned char *)ctdb_node_list_to_map(ctdb->nodes,
|
||||
ctdb->num_nodes,
|
||||
outdata);
|
||||
if (outdata->dptr == NULL) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
outdata->dsize = talloc_get_size(outdata->dptr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user