1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-02 09:47:23 +03:00

fixup getdbmap control so it looks a bit nicer

(This used to be ctdb commit 78a4d61cb78da20af5210488e685c91bc3023e90)
This commit is contained in:
Ronnie Sahlberg 2007-05-03 13:07:34 +10:00
commit 633ae7f346
6 changed files with 63 additions and 58 deletions

View File

@ -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;i<dbmap->num;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;
}

View File

@ -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;

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -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;i<dbmap.num;i++) {
for (i=0;i<dbmap->num;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;i<dbmap.num;i++) {
printf("recovering database 0x%08x\n",dbmap.dbids[i]);
for (i=0;i<dbmap->num;i++) {
printf("recovering database 0x%08x\n",dbmap->dbids[i]);
for (j=0; j<nodemap.num; j++) {
/* we dont need to merge with ourselves */
if (nodemap.nodes[j].vnn == vnn) {
@ -321,8 +321,8 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg
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);
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;i<dbmap.num;i++) {
for (i=0;i<dbmap->num;i++) {
for (j=0; j<nodemap.num; j++) {
/* dont repoint nodes that are unavailable */
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;
}
}
@ -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;i<dbmap.num;i++) {
printf("distributing new database 0x%08x\n",dbmap.dbids[i]);
for (i=0;i<dbmap->num;i++) {
printf("distributing new database 0x%08x\n",dbmap->dbids[i]);
for (j=0; j<nodemap.num; j++) {
/* we dont need to push to ourselves */
if (nodemap.nodes[j].vnn == vnn) {
@ -364,8 +364,8 @@ static int control_recover(struct ctdb_context *ctdb, int argc, const char **arg
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);
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;i<dbmap.num;i++){
printf("Number of databases:%d\n", dbmap->num);
for(i=0;i<dbmap->num;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;