]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
fixup getdbmap control so it looks a bit nicer
authorRonnie Sahlberg <sahlberg@ronnie>
Thu, 3 May 2007 03:07:34 +0000 (13:07 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Thu, 3 May 2007 03:07:34 +0000 (13:07 +1000)
(This used to be ctdb commit 78a4d61cb78da20af5210488e685c91bc3023e90)

1  2 
ctdb/common/ctdb_client.c
ctdb/common/ctdb_control.c
ctdb/common/ctdb_recover.c
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/tools/ctdb_control.c

index ec461a85e2126121bfddc8b4e6536d3d42058039,ec461a85e2126121bfddc8b4e6536d3d42058039..5ffec7e43b0f315df493e7020900265f6b769424
@@@ -843,30 -843,30 +843,26 @@@ int ctdb_ctrl_setrecmode(struct ctdb_co
  /*
    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;
  }
index f2eabf38e2052f246f9592ceecce11ea2d434a25,f2eabf38e2052f246f9592ceecce11ea2d434a25..b132533724c08dfdcb0bf3f12687c9625822fe8a
@@@ -174,30 -174,30 +174,8 @@@ static int32_t ctdb_control_dispatch(st
        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;
index 6d07a52884c775191acc2fd4a37b4d151e4bb97d,6d07a52884c775191acc2fd4a37b4d151e4bb97d..b368cc147d19db549cf9acf9991168c4cbd4db3f
@@@ -52,3 -52,3 +52,33 @@@ ctdb_control_setvnnmap(struct ctdb_cont
        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;
++}
index fff58c1f65a3fcb3b2070596158d954b56d377a8,fff58c1f65a3fcb3b2070596158d954b56d377a8..6dda475aed58f1f4e8d32a69a02a982ca598e494
@@@ -208,9 -208,9 +208,9 @@@ int ctdb_ctrl_setvnnmap(struct ctdb_con
   */
  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 
index d14ce336861ffbf0deb38b123ed903ef9b1dc278,d14ce336861ffbf0deb38b123ed903ef9b1dc278..d1028933955c0736d66e3f213d1caab4e2fc9f64
@@@ -642,5 -642,5 +642,6 @@@ int ctdb_control(struct ctdb_context *c
  
  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
index dee21528a59cfb3ac2f4cb9e488a2cd5642cbab7,dee21528a59cfb3ac2f4cb9e488a2cd5642cbab7..68f77c9e2deefdbcae14ffe84b31dc08d51af871
@@@ -246,7 -246,7 +246,7 @@@ static int control_recover(struct ctdb_
        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();
                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) {
                                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;
        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;
                        }
                }
  
        /* 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) {
                                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 +583,7 @@@ static int control_getdbmap(struct ctdb
  {
        uint32_t vnn;
        int i, ret;
--      struct ctdb_dbid_map dbmap;
++      struct ctdb_dbid_map *dbmap=NULL;
  
        if (argc < 1) {
                usage();
                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;