]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
add a control to pull the database list from a remote node
authorRonnie Sahlberg <sahlberg@ronnie>
Sat, 28 Apr 2007 10:00:50 +0000 (20:00 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Sat, 28 Apr 2007 10:00:50 +0000 (20:00 +1000)
(This used to be ctdb commit d130e02936ea4bdcd3a6f02c53be4b7771993138)

ctdb/common/ctdb_client.c
ctdb/common/ctdb_control.c
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/tests/ctdb_test.c
ctdb/tools/ctdb_control.c

index 529420d158d7089a61b3b8d6b950e257b766078b..21c991cb09f3ba4a179f7a8c05b5e1b54fb4502f 100644 (file)
@@ -793,6 +793,41 @@ int ctdb_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn
        return 0;
 }
 
+/*
+  get a list of databases off a remote node
+ */
+int ctdb_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_dbid_map *dbmap)
+{
+       int ret;
+       TDB_DATA data, outdata;
+       int32_t i, res;
+
+       ZERO_STRUCT(data);
+       ret = ctdb_control(ctdb, destnode, 0, 
+                          CTDB_CONTROL_GET_DBMAP, data, 
+                          ctdb, &outdata, &res);
+       if (ret != 0 || res != 0) {
+               DEBUG(0,(__location__ " ctdb_control for getvnnmap failed\n"));
+               return -1;
+       }
+
+       dbmap->num = ((uint32_t *)outdata.dptr)[0];
+       if (dbmap->dbids) {
+               talloc_free(dbmap->dbids);
+               dbmap->dbids=NULL;
+       }
+       dbmap->dbids=talloc_array(dbmap, 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];
+       }
+                   
+       return 0;
+}
+
 
 /*
   set vnn map on a node
@@ -877,19 +912,19 @@ int ctdb_get_config(struct ctdb_context *ctdb)
 /*
   find the real path to a ltdb 
  */
-int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, 
+int ctdb_getdbpath(struct ctdb_context *ctdb, uint32_t dbid, TALLOC_CTX *mem_ctx, 
                   const char **path)
 {
        int ret;
        int32_t res;
        TDB_DATA data;
 
-       data.dptr = (uint8_t *)&ctdb_db->db_id;
-       data.dsize = sizeof(ctdb_db->db_id);
+       data.dptr = (uint8_t *)&dbid;
+       data.dsize = sizeof(dbid);
 
-       ret = ctdb_control(ctdb_db->ctdb, CTDB_CURRENT_NODE, 0, 
+       ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, 
                           CTDB_CONTROL_GETDBPATH, data, 
-                          ctdb_db, &data, &res);
+                          mem_ctx, &data, &res);
        if (ret != 0 || res != 0) {
                return -1;
        }
index eac8b5170b5d2e21eb0636572ba294d3ca3c6137..bec24206ca0b002d7d6deb0c8b0110c6f8ccad5e 100644 (file)
@@ -96,6 +96,31 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return 0;
        }
 
+       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_SETVNNMAP: {
                uint32_t *ptr, i;
                
index 9c5d2399d6c7871b36391dd537f7c124eb6b58b8..b9ad7c1ced50a7b69b9379e222abc7d8dde85fff 100644 (file)
@@ -218,8 +218,10 @@ int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status
 struct ctdb_vnn_map;
 int ctdb_getvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap);
 int ctdb_setvnnmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_vnn_map *vnnmap);
+struct ctdb_dbid_map;
+int ctdb_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_dbid_map *dbmap);
 
-int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, const char **path);
+int ctdb_getdbpath(struct ctdb_context *ctdb, uint32_t dbid, TALLOC_CTX *mem_ctx, const char **path);
 
 int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
 
index 20efc5bd7ebaa8774fb14f45f003eda9a4e0c119..e0e51b8d4a50f46769975a7a035a2d7b296c7ca2 100644 (file)
@@ -160,6 +160,13 @@ struct ctdb_status {
        double max_lockwait_latency;
 };
 
+/* table that contains a list of all dbids on a node
+ */
+struct ctdb_dbid_map {
+       uint32_t num;
+       uint32_t *dbids;
+};
+
 /* table that contains the mapping between a hash value and lmaster
  */
 struct ctdb_vnn_map {
@@ -250,7 +257,8 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS,
                    CTDB_CONTROL_GETVNNMAP,
                    CTDB_CONTROL_SETVNNMAP,
                    CTDB_CONTROL_GET_DEBUG,
-                   CTDB_CONTROL_SET_DEBUG};
+                   CTDB_CONTROL_SET_DEBUG,
+                   CTDB_CONTROL_GET_DBMAP};
 
 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
 
index 82555607a47ec08ec60ef1bfda555f0c13664bfb..5e86041b744b95c7c6d3f84e736714f1982bc468 100644 (file)
@@ -23,6 +23,7 @@
 #include "system/filesys.h"
 #include "popt.h"
 #include "cmdline.h"
+#include "ctdb_private.h"
 
 enum my_functions {FUNC_SORT=1, FUNC_FETCH=2};
 
@@ -137,7 +138,7 @@ int main(int argc, const char *argv[])
        ctdb_connect_wait(ctdb);
 
        /* find the full path to the database file */
-       ctdb_getdbpath(ctdb_db, ctdb_db, &path);
+       ctdb_getdbpath(ctdb, ctdb_db->db_id, ctdb_db, &path);
        printf("path to database:[%s]\n",path);
 
        ZERO_STRUCT(call);
index c3ad212f97b1794ef7776851196e10fbf99ad50d..909054b397867958af973d5fb7e8afc4fe07ff16 100644 (file)
@@ -40,6 +40,7 @@ static void usage(void)
        printf("  debuglevel                         display ctdb debug levels\n");
        printf("  getvnnmap <vnn>                    display ctdb vnnmap\n");
        printf("  setvnnmap <vnn> <generation> <numslots> <lmaster>*\n");
+       printf("  getdbmap <vnn>                     lists databases on a node\n");
        exit(1);
 }
 
@@ -154,6 +155,40 @@ static int control_getvnnmap(struct ctdb_context *ctdb, int argc, const char **a
        return 0;
 }
 
+/*
+  display a list of the databases on a remote ctdb
+ */
+static int control_getdbmap(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       uint32_t vnn;
+       int i, ret;
+       struct ctdb_dbid_map *dbmap;
+
+       if (argc < 1) {
+               usage();
+       }
+
+       vnn = strtoul(argv[0], NULL, 0);
+
+       dbmap = talloc_zero(ctdb, struct ctdb_dbid_map);
+       ret = ctdb_getdbmap(ctdb, vnn, dbmap);
+       if (ret != 0) {
+               printf("Unable to get dbids from node %u\n", vnn);
+               talloc_free(dbmap);
+               return ret;
+       }
+
+       printf("Number of databases:%d\n", dbmap->num);
+       for(i=0;i<dbmap->num;i++){
+               const char *path;
+
+               ctdb_getdbpath(ctdb, dbmap->dbids[i], dbmap, &path);
+               printf("dbid:0x%08x path:%s\n", dbmap->dbids[i], path);
+       }
+       talloc_free(dbmap);
+       return 0;
+}
+
 /*
   set remote ctdb vnn map
  */
@@ -304,6 +339,8 @@ int main(int argc, const char *argv[])
                ret = control_status(ctdb, extra_argc-1, extra_argv+1);
        } else if (strcmp(control, "getvnnmap") == 0) {
                ret = control_getvnnmap(ctdb, extra_argc-1, extra_argv+1);
+       } else if (strcmp(control, "getdbmap") == 0) {
+               ret = control_getdbmap(ctdb, extra_argc-1, extra_argv+1);
        } else if (strcmp(control, "setvnnmap") == 0) {
                ret = control_setvnnmap(ctdb, extra_argc-1, extra_argv+1);
        } else if (strcmp(control, "ping") == 0) {