From: Ronnie Sahlberg Date: Thu, 3 May 2007 03:30:38 +0000 (+1000) Subject: cleanup getnodemap X-Git-Tag: tevent-0.9.20~348^2~2789^2 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d88154b24a495d4804aa9399952821bc3eeb80df;p=thirdparty%2Fsamba.git cleanup getnodemap (This used to be ctdb commit 3867ccf71a167fb82dbc5a3f03f968a325a0c70b) --- diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index 5ffec7e43b0..520a7a143f7 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -872,14 +872,13 @@ int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX get a list of nodes (vnn and flags ) from a remote node */ int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, - TALLOC_CTX *mem_ctx, struct ctdb_node_map *nodemap) + TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap) { int ret; TDB_DATA data, outdata; - int32_t i, res; + int32_t res; ZERO_STRUCT(data); - ZERO_STRUCT(*nodemap); ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_NODEMAP, 0, data, ctdb, &outdata, &res); @@ -888,14 +887,11 @@ int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, return -1; } - nodemap->num = ((uint32_t *)outdata.dptr)[0]; - nodemap->nodes=talloc_array(mem_ctx, struct ctdb_node_and_flags, nodemap->num); - CTDB_NO_MEMORY(ctdb, nodemap->nodes); - - for (i=0;inum;i++) { - nodemap->nodes[i].vnn = ((uint32_t *)outdata.dptr)[2*i+1]; - nodemap->nodes[i].flags = ((uint32_t *)outdata.dptr)[2*i+2]; + if (*nodemap) { + talloc_free(*nodemap); + *nodemap = NULL; } + *nodemap = (struct ctdb_node_map *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize); return 0; } @@ -1248,24 +1244,19 @@ int ctdb_ctrl_set_debuglevel(struct ctdb_context *ctdb, uint32_t destnode, uint3 uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, TALLOC_CTX *mem_ctx, uint32_t *num_nodes) { - struct ctdb_node_map *map; + struct ctdb_node_map *map=NULL; int ret, i; uint32_t *nodes; *num_nodes = 0; - map = talloc(mem_ctx, struct ctdb_node_map); - CTDB_NO_MEMORY_VOID(ctdb, map); - - ret = ctdb_ctrl_getnodemap(ctdb, CTDB_CURRENT_NODE, map, map); + ret = ctdb_ctrl_getnodemap(ctdb, CTDB_CURRENT_NODE, mem_ctx, &map); if (ret != 0) { - talloc_free(map); return NULL; } nodes = talloc_array(mem_ctx, uint32_t, map->num); if (nodes == NULL) { - talloc_free(map); return NULL; } @@ -1276,7 +1267,6 @@ uint32_t *ctdb_get_connected_nodes(struct ctdb_context *ctdb, TALLOC_CTX *mem_ct } } - talloc_free(map); return nodes; } diff --git a/ctdb/common/ctdb_control.c b/ctdb/common/ctdb_control.c index b132533724c..ef6ba6f0b14 100644 --- a/ctdb/common/ctdb_control.c +++ b/ctdb/common/ctdb_control.c @@ -177,30 +177,8 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, case CTDB_CONTROL_GET_DBMAP: return ctdb_control_getdbmap(ctdb, opcode, indata, outdata); - case CTDB_CONTROL_GET_NODEMAP: { - uint32_t num_nodes, i, len; - struct ctdb_node *node; - - num_nodes = ctdb_get_num_nodes(ctdb); - len = 2*num_nodes + 1; - - outdata->dsize = len*sizeof(uint32_t); - outdata->dptr = (unsigned char *)talloc_array(outdata, uint32_t, len); - if (!outdata->dptr) { - DEBUG(0, (__location__ "Failed to allocate node array\n")); - exit(1); - } - - - ((uint32_t *)outdata->dptr)[0] = num_nodes; - for (i=0; inodes[i]; - ((uint32_t *)outdata->dptr)[i*2+1]=node->vnn; - ((uint32_t *)outdata->dptr)[i*2+2]=node->flags; - } - - return 0; - } + case CTDB_CONTROL_GET_NODEMAP: + return ctdb_control_getnodemap(ctdb, opcode, indata, outdata); case CTDB_CONTROL_SETVNNMAP: return ctdb_control_setvnnmap(ctdb, opcode, indata, outdata); diff --git a/ctdb/common/ctdb_recover.c b/ctdb/common/ctdb_recover.c index b368cc147d1..2dcba26a858 100644 --- a/ctdb/common/ctdb_recover.c +++ b/ctdb/common/ctdb_recover.c @@ -82,3 +82,30 @@ 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) +{ + uint32_t i, num_nodes; + struct ctdb_node_map *node_map; + + CHECK_CONTROL_DATA_SIZE(0); + + num_nodes = ctdb_get_num_nodes(ctdb); + + 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(0, (__location__ "Failed to allocate nodemap array\n")); + exit(1); + } + + node_map = (struct ctdb_node_map *)outdata->dptr; + node_map->num = num_nodes; + for (i=0; inodes[i].vnn = ctdb->nodes[i]->vnn; + node_map->nodes[i].flags = ctdb->nodes[i]->flags; + } + + return 0; +} diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index 6dda475aed5..42e6d1c9d2c 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -222,10 +222,10 @@ struct ctdb_node_and_flags { }; struct ctdb_node_map { uint32_t num; - struct ctdb_node_and_flags *nodes; + struct ctdb_node_and_flags nodes[1]; }; int ctdb_ctrl_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, - TALLOC_CTX *mem_ctx, struct ctdb_node_map *nodemap); + TALLOC_CTX *mem_ctx, struct ctdb_node_map **nodemap); struct ctdb_key_list { uint32_t dbid; diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index d1028933955..7c679284947 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -643,5 +643,6 @@ int ctdb_control(struct ctdb_context *ctdb, uint32_t destnode, uint64_t srvid, int ctdb_control_getvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata); int ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata); int ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata); +int ctdb_control_getnodemap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata); #endif diff --git a/ctdb/tools/ctdb_control.c b/ctdb/tools/ctdb_control.c index 68f77c9e2de..800a42efc15 100644 --- a/ctdb/tools/ctdb_control.c +++ b/ctdb/tools/ctdb_control.c @@ -244,7 +244,7 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg { uint32_t vnn, num_nodes, generation, dmaster; struct ctdb_vnn_map *vnnmap; - struct ctdb_node_map nodemap; + struct ctdb_node_map *nodemap=NULL; int i, j, ret; struct ctdb_dbid_map *dbmap=NULL; @@ -268,8 +268,8 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg /* 2: count the active nodes */ printf("\n2: count number of active nodes\n"); num_nodes = 0; - for (i=0; inum; i++) { + if (nodemap->nodes[i].flags&NODE_FLAGS_CONNECTED) { num_nodes++; } } @@ -277,16 +277,16 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg /* 3: go to all active nodes and activate recovery mode */ printf("\n3: set recovery mode for all active nodes\n"); - for (j=0; jnum; j++) { /* dont change it for nodes that are unavailable */ - if (!(nodemap.nodes[j].flags&NODE_FLAGS_CONNECTED)) { + if (!(nodemap->nodes[j].flags&NODE_FLAGS_CONNECTED)) { continue; } - printf("setting node %d to recovery mode\n",nodemap.nodes[j].vnn); - ret = ctdb_ctrl_setrecmode(ctdb, nodemap.nodes[j].vnn, CTDB_RECOVERY_ACTIVE); + printf("setting node %d to recovery mode\n",nodemap->nodes[j].vnn); + ret = ctdb_ctrl_setrecmode(ctdb, nodemap->nodes[j].vnn, CTDB_RECOVERY_ACTIVE); if (ret != 0) { - printf("Unable to set recmode on node %u\n", nodemap.nodes[j].vnn); + printf("Unable to set recmode on node %u\n", nodemap->nodes[j].vnn); return ret; } } @@ -311,20 +311,20 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg printf("\n5: merge all records from remote nodes\n"); for (i=0;inum;i++) { printf("recovering database 0x%08x\n",dbmap->dbids[i]); - for (j=0; jnum; j++) { /* we dont need to merge with ourselves */ - if (nodemap.nodes[j].vnn == vnn) { + if (nodemap->nodes[j].vnn == vnn) { continue; } /* dont merge from nodes that are unavailable */ - if (!(nodemap.nodes[j].flags&NODE_FLAGS_CONNECTED)) { + if (!(nodemap->nodes[j].flags&NODE_FLAGS_CONNECTED)) { continue; } - printf("merging all records from node %d for database 0x%08x\n", nodemap.nodes[j].vnn, dbmap->dbids[i]); - ret = ctdb_ctrl_copydb(ctdb, nodemap.nodes[j].vnn, vnn, dbmap->dbids[i], CTDB_LMASTER_ANY, ctdb); + printf("merging all records from node %d for database 0x%08x\n", nodemap->nodes[j].vnn, dbmap->dbids[i]); + ret = ctdb_ctrl_copydb(ctdb, nodemap->nodes[j].vnn, vnn, dbmap->dbids[i], CTDB_LMASTER_ANY, ctdb); if (ret != 0) { - printf("Unable to copy db from node %u to node %u\n", nodemap.nodes[j].vnn, vnn); + printf("Unable to copy db from node %u to node %u\n", nodemap->nodes[j].vnn, vnn); return ret; } } @@ -335,16 +335,16 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg dmaster = vnn; printf("new dmaster is %d\n", dmaster); for (i=0;inum;i++) { - for (j=0; jnum; j++) { /* dont repoint nodes that are unavailable */ - if (!(nodemap.nodes[j].flags&NODE_FLAGS_CONNECTED)) { + if (!(nodemap->nodes[j].flags&NODE_FLAGS_CONNECTED)) { continue; } - printf("setting dmaster to %d for node %d db 0x%08x\n",dmaster,nodemap.nodes[j].vnn,dbmap->dbids[i]); - ret = ctdb_ctrl_setdmaster(ctdb, nodemap.nodes[j].vnn, ctdb, dbmap->dbids[i], dmaster); + printf("setting dmaster to %d for node %d db 0x%08x\n",dmaster,nodemap->nodes[j].vnn,dbmap->dbids[i]); + ret = ctdb_ctrl_setdmaster(ctdb, nodemap->nodes[j].vnn, ctdb, dbmap->dbids[i], dmaster); if (ret != 0) { - printf("Unable to set dmaster for node %u db:0x%08x\n", nodemap.nodes[j].vnn, dbmap->dbids[i]); + printf("Unable to set dmaster for node %u db:0x%08x\n", nodemap->nodes[j].vnn, dbmap->dbids[i]); return ret; } } @@ -354,20 +354,20 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg printf("\n7: push all records to remote nodes\n"); for (i=0;inum;i++) { printf("distributing new database 0x%08x\n",dbmap->dbids[i]); - for (j=0; jnum; j++) { /* we dont need to push to ourselves */ - if (nodemap.nodes[j].vnn == vnn) { + if (nodemap->nodes[j].vnn == vnn) { continue; } /* dont push to nodes that are unavailable */ - if (!(nodemap.nodes[j].flags&NODE_FLAGS_CONNECTED)) { + if (!(nodemap->nodes[j].flags&NODE_FLAGS_CONNECTED)) { continue; } - printf("pushing all records to node %d for database 0x%08x\n", nodemap.nodes[j].vnn, dbmap->dbids[i]); - ret = ctdb_ctrl_copydb(ctdb, vnn, nodemap.nodes[j].vnn, dbmap->dbids[i], CTDB_LMASTER_ANY, ctdb); + printf("pushing all records to node %d for database 0x%08x\n", nodemap->nodes[j].vnn, dbmap->dbids[i]); + ret = ctdb_ctrl_copydb(ctdb, vnn, nodemap->nodes[j].vnn, dbmap->dbids[i], CTDB_LMASTER_ANY, ctdb); if (ret != 0) { - printf("Unable to copy db from node %u to node %u\n", vnn, nodemap.nodes[j].vnn); + printf("Unable to copy db from node %u to node %u\n", vnn, nodemap->nodes[j].vnn); return ret; } } @@ -384,9 +384,9 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg generation = random(); vnnmap->generation = generation; vnnmap->size = num_nodes; - for (i=j=0;imap[j++]=nodemap.nodes[i].vnn; + for (i=j=0;inum;i++) { + if (nodemap->nodes[i].flags&NODE_FLAGS_CONNECTED) { + vnnmap->map[j++]=nodemap->nodes[i].vnn; } } printf("Generation:%d\n",vnnmap->generation); @@ -397,14 +397,14 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg /* 9: push the new vnn map out to all the nodes */ printf("\n9: distribute the new vnn map\n"); - for (j=0; jnum; j++) { /* dont push to nodes that are unavailable */ - if (!(nodemap.nodes[j].flags&NODE_FLAGS_CONNECTED)) { + if (!(nodemap->nodes[j].flags&NODE_FLAGS_CONNECTED)) { continue; } - printf("setting new vnn map on node %d\n",nodemap.nodes[j].vnn); - ret = ctdb_ctrl_setvnnmap(ctdb, nodemap.nodes[j].vnn, ctdb, vnnmap); + printf("setting new vnn map on node %d\n",nodemap->nodes[j].vnn); + ret = ctdb_ctrl_setvnnmap(ctdb, nodemap->nodes[j].vnn, ctdb, vnnmap); if (ret != 0) { printf("Unable to set vnnmap for node %u\n", vnn); return ret; @@ -413,16 +413,16 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg /* 10: disable recovery mode */ printf("\n10: restore recovery mode back to normal\n"); - for (j=0; jnum; j++) { /* dont push to nodes that are unavailable */ - if (!(nodemap.nodes[j].flags&NODE_FLAGS_CONNECTED)) { + if (!(nodemap->nodes[j].flags&NODE_FLAGS_CONNECTED)) { continue; } - printf("changing recovery mode back to normal for node %d\n",nodemap.nodes[j].vnn); - ret = ctdb_ctrl_setrecmode(ctdb, nodemap.nodes[j].vnn, CTDB_RECOVERY_NORMAL); + printf("changing recovery mode back to normal for node %d\n",nodemap->nodes[j].vnn); + ret = ctdb_ctrl_setrecmode(ctdb, nodemap->nodes[j].vnn, CTDB_RECOVERY_NORMAL); if (ret != 0) { - printf("Unable to set recmode on node %u\n", nodemap.nodes[j].vnn); + printf("Unable to set recmode on node %u\n", nodemap->nodes[j].vnn); return ret; } } @@ -615,7 +615,7 @@ static int control_getnodemap(struct ctdb_context *ctdb, int argc, const char ** { uint32_t vnn; int i, ret; - struct ctdb_node_map *nodemap; + struct ctdb_node_map *nodemap=NULL; if (argc < 1) { usage(); @@ -623,11 +623,9 @@ static int control_getnodemap(struct ctdb_context *ctdb, int argc, const char ** vnn = strtoul(argv[0], NULL, 0); - nodemap = talloc_zero(ctdb, struct ctdb_node_map); - ret = ctdb_ctrl_getnodemap(ctdb, vnn, nodemap, nodemap); + ret = ctdb_ctrl_getnodemap(ctdb, vnn, ctdb, &nodemap); if (ret != 0) { printf("Unable to get nodemap from node %u\n", vnn); - talloc_free(nodemap); return ret; } @@ -638,7 +636,7 @@ static int control_getnodemap(struct ctdb_context *ctdb, int argc, const char ** "CONNECTED":"UNAVAILABLE", nodemap->nodes[i].vnn==vnn?" (THIS NODE)":""); } - talloc_free(nodemap); + return 0; }