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
/*
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;
}
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;
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);
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 {
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};
#include "system/filesys.h"
#include "popt.h"
#include "cmdline.h"
+#include "ctdb_private.h"
enum my_functions {FUNC_SORT=1, FUNC_FETCH=2};
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);
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);
}
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
*/
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) {