diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index ec461a85e21..5ffec7e43b0 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -843,30 +843,26 @@ int ctdb_ctrl_setrecmode(struct ctdb_context *ctdb, uint32_t destnode, uint32_t /* get a list of databases off a remote node */ -int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_dbid_map *dbmap) +int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap) { int ret; TDB_DATA data, outdata; - int32_t i, res; + int32_t res; ZERO_STRUCT(data); ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_GET_DBMAP, 0, data, ctdb, &outdata, &res); if (ret != 0 || res != 0) { - DEBUG(0,(__location__ " ctdb_control for getvnnmap failed\n")); + DEBUG(0,(__location__ " ctdb_control for getdbmap failed\n")); return -1; } - dbmap->num = ((uint32_t *)outdata.dptr)[0]; - dbmap->dbids=talloc_array(mem_ctx, uint32_t, dbmap->num); - if (!dbmap->dbids) { - DEBUG(0,(__location__ " failed to talloc dbmap\n")); - return -1; - } - for (i=0;inum;i++) { - dbmap->dbids[i] = ((uint32_t *)outdata.dptr)[i+1]; + if (*dbmap) { + talloc_free(*dbmap); + *dbmap = NULL; } + *dbmap = (struct ctdb_dbid_map *)talloc_memdup(mem_ctx, outdata.dptr, outdata.dsize); return 0; } diff --git a/ctdb/common/ctdb_control.c b/ctdb/common/ctdb_control.c index f2eabf38e20..b132533724c 100644 --- a/ctdb/common/ctdb_control.c +++ b/ctdb/common/ctdb_control.c @@ -174,30 +174,8 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb, case CTDB_CONTROL_GETVNNMAP: return ctdb_control_getvnnmap(ctdb, opcode, indata, outdata); - case CTDB_CONTROL_GET_DBMAP: { - uint32_t i, len; - struct ctdb_db_context *ctdb_db; - - CHECK_CONTROL_DATA_SIZE(0); - len = 0; - for(ctdb_db=ctdb->db_list;ctdb_db;ctdb_db=ctdb_db->next){ - len++; - } - - outdata->dsize = (len+1)*sizeof(uint32_t); - outdata->dptr = (unsigned char *)talloc_array(outdata, uint32_t, len+1); - if (!outdata->dptr) { - DEBUG(0, (__location__ "Failed to allocate dbmap array\n")); - exit(1); - } - - ((uint32_t *)outdata->dptr)[0] = len; - for(i=0,ctdb_db=ctdb->db_list;ctdb_db;i++,ctdb_db=ctdb_db->next){ - ((uint32_t *)outdata->dptr)[i+1] = ctdb_db->db_id; - } - - return 0; - } + case CTDB_CONTROL_GET_DBMAP: + return ctdb_control_getdbmap(ctdb, opcode, indata, outdata); case CTDB_CONTROL_GET_NODEMAP: { uint32_t num_nodes, i, len; diff --git a/ctdb/common/ctdb_recover.c b/ctdb/common/ctdb_recover.c index 6d07a52884c..b368cc147d1 100644 --- a/ctdb/common/ctdb_recover.c +++ b/ctdb/common/ctdb_recover.c @@ -52,3 +52,33 @@ ctdb_control_setvnnmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA inda return 0; } +int +ctdb_control_getdbmap(struct ctdb_context *ctdb, uint32_t opcode, TDB_DATA indata, TDB_DATA *outdata) +{ + uint32_t i, len; + struct ctdb_db_context *ctdb_db; + struct ctdb_dbid_map *dbid_map; + + CHECK_CONTROL_DATA_SIZE(0); + + len = 0; + for(ctdb_db=ctdb->db_list;ctdb_db;ctdb_db=ctdb_db->next){ + len++; + } + + + outdata->dsize = offsetof(struct ctdb_dbid_map, dbids) + 4*len; + outdata->dptr = (unsigned char *)talloc_zero_size(outdata, outdata->dsize); + if (!outdata->dptr) { + DEBUG(0, (__location__ "Failed to allocate dbmap array\n")); + exit(1); + } + + dbid_map = (struct ctdb_dbid_map *)outdata->dptr; + dbid_map->num = len; + for(i=0,ctdb_db=ctdb->db_list;ctdb_db;i++,ctdb_db=ctdb_db->next){ + dbid_map->dbids[i] = ctdb_db->db_id; + } + + return 0; +} diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index fff58c1f65a..6dda475aed5 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -208,9 +208,9 @@ int ctdb_ctrl_setvnnmap(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX */ struct ctdb_dbid_map { uint32_t num; - uint32_t *dbids; + uint32_t dbids[1]; }; -int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_dbid_map *dbmap); +int ctdb_ctrl_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, TALLOC_CTX *mem_ctx, struct ctdb_dbid_map **dbmap); /* table that contains a list of all nodes a ctdb knows about and their diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index d14ce336861..d1028933955 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -642,5 +642,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); #endif diff --git a/ctdb/tools/ctdb_control.c b/ctdb/tools/ctdb_control.c index dee21528a59..68f77c9e2de 100644 --- a/ctdb/tools/ctdb_control.c +++ b/ctdb/tools/ctdb_control.c @@ -246,7 +246,7 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg struct ctdb_vnn_map *vnnmap; struct ctdb_node_map nodemap; int i, j, ret; - struct ctdb_dbid_map dbmap; + struct ctdb_dbid_map *dbmap=NULL; if (argc < 1) { usage(); @@ -298,19 +298,19 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg printf("Unable to get dbids from node %u\n", vnn); return ret; } - for (i=0;inum;i++) { const char *path; - ctdb_ctrl_getdbpath(ctdb, dbmap.dbids[i], ctdb, &path); - printf("dbid:0x%08x path:%s\n", dbmap.dbids[i], path); + ctdb_ctrl_getdbpath(ctdb, dbmap->dbids[i], ctdb, &path); + printf("dbid:0x%08x path:%s\n", dbmap->dbids[i], path); } /* 5: pull all records from all other nodes across to this node (this merges based on rsn internally) */ 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; jdbids[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); return ret; @@ -334,17 +334,17 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg printf("\n6: repoint dmaster to the recovery node\n"); dmaster = vnn; printf("new dmaster is %d\n", dmaster); - for (i=0;inum;i++) { for (j=0; jdbids[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; } } @@ -352,8 +352,8 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg /* 7: push all records out to the nodes again */ 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; jdbids[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); return ret; @@ -583,7 +583,7 @@ static int control_getdbmap(struct ctdb_context *ctdb, int argc, const char **ar { uint32_t vnn; int i, ret; - struct ctdb_dbid_map dbmap; + struct ctdb_dbid_map *dbmap=NULL; if (argc < 1) { usage(); @@ -597,12 +597,12 @@ static int control_getdbmap(struct ctdb_context *ctdb, int argc, const char **ar return ret; } - printf("Number of databases:%d\n", dbmap.num); - for(i=0;inum); + for(i=0;inum;i++){ const char *path; - ctdb_ctrl_getdbpath(ctdb, dbmap.dbids[i], ctdb, &path); - printf("dbid:0x%08x path:%s\n", dbmap.dbids[i], path); + ctdb_ctrl_getdbpath(ctdb, dbmap->dbids[i], ctdb, &path); + printf("dbid:0x%08x path:%s\n", dbmap->dbids[i], path); } return 0;