]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
add a few more controls that are useful for debugging a cluster
authorRonnie Sahlberg <sahlberg@ronnie>
Sat, 28 Apr 2007 10:40:26 +0000 (20:40 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Sat, 28 Apr 2007 10:40:26 +0000 (20:40 +1000)
(This used to be ctdb commit 751c1365ab55a217ff33d985d52bd26581578617)

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

index 4b47a6e2a1d7d78ace344466f06e6eed515c2e5a..63e5b6543848b5588bcdeb0836834012e1fa2f79 100644 (file)
@@ -326,6 +326,7 @@ void ctdb_recv_raw_pkt(void *p, uint8_t *data, uint32_t length)
 static void ctdb_node_dead(struct ctdb_node *node)
 {
        node->ctdb->num_connected--;
+       node->flags &= ~NODE_FLAGS_CONNECTED;
        DEBUG(1,("%s: node %s is dead: %d connected\n", 
                 node->ctdb->name, node->name, node->ctdb->num_connected));
 }
@@ -336,6 +337,7 @@ static void ctdb_node_dead(struct ctdb_node *node)
 static void ctdb_node_connected(struct ctdb_node *node)
 {
        node->ctdb->num_connected++;
+       node->flags |= NODE_FLAGS_CONNECTED;
        DEBUG(1,("%s: connected to %s - %d connected\n", 
                 node->ctdb->name, node->name, node->ctdb->num_connected));
 }
index 21c991cb09f3ba4a179f7a8c05b5e1b54fb4502f..d43a9f6de9163d473903b00c1fdaca7f710666c8 100644 (file)
@@ -829,6 +829,42 @@ int ctdb_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_dbid
 }
 
 
+/*
+  get a list of nodes (vnn and flags ) from a remote node
+ */
+int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_node_map *nodemap)
+{
+       int ret;
+       TDB_DATA data, outdata;
+       int32_t i, res;
+
+       ZERO_STRUCT(data);
+       ret = ctdb_control(ctdb, destnode, 0, 
+                          CTDB_CONTROL_GET_NODEMAP, data, 
+                          ctdb, &outdata, &res);
+       if (ret != 0 || res != 0) {
+               DEBUG(0,(__location__ " ctdb_control for getnodes failed\n"));
+               return -1;
+       }
+
+       nodemap->num = ((uint32_t *)outdata.dptr)[0];
+       if (nodemap->nodes) {
+               talloc_free(nodemap->nodes);
+               nodemap->nodes=NULL;
+       }
+       nodemap->nodes=talloc_array(nodemap, struct ctdb_node_and_flags, nodemap->num);
+       if (!nodemap->nodes) {
+               DEBUG(0,(__location__ " failed to talloc nodemap\n"));
+               return -1;
+       }
+       for (i=0;i<nodemap->num;i++) {
+               nodemap->nodes[i].vnn = ((uint32_t *)outdata.dptr)[2*i+1];
+               nodemap->nodes[i].flags = ((uint32_t *)outdata.dptr)[2*i+2];
+       }
+                   
+       return 0;
+}
+
 /*
   set vnn map on a node
  */
index bec24206ca0b002d7d6deb0c8b0110c6f8ccad5e..83bac958e06ff9d0cab2696cc79219db99ea121f 100644 (file)
@@ -121,6 +121,31 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                return 0;
        }
 
+       case CTDB_CONTROL_GET_NODEMAP: {
+               uint32_t num_nodes, i, len;
+               struct ctdb_node *node;
+
+               num_nodes = ctdb_get_num_nodes(ctdb);
+               len = 2*num_nodes + 1;
+
+               outdata->dsize = len*sizeof(uint32_t);
+               outdata->dptr = (unsigned char *)talloc_array(outdata, uint32_t, len);
+               if (!outdata->dptr) {
+                       DEBUG(0, (__location__ "Failed to allocate node array\n"));
+                       exit(1);
+               }
+
+               
+               ((uint32_t *)outdata->dptr)[0] = num_nodes;
+               for (i=0; i<num_nodes; i++) {
+                       node=ctdb->nodes[i];
+                       ((uint32_t *)outdata->dptr)[i*2+1]=node->vnn;
+                       ((uint32_t *)outdata->dptr)[i*2+2]=node->flags;
+               }
+
+               return 0;
+       }
+
        case CTDB_CONTROL_SETVNNMAP: {
                uint32_t *ptr, i;
                
index b9ad7c1ced50a7b69b9379e222abc7d8dde85fff..7dba352a46ffb374277c7c56b3ba6a857a4c7b79 100644 (file)
@@ -218,9 +218,29 @@ 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;
+
+/* table that contains a list of all dbids on a node
+ */
+struct ctdb_dbid_map {
+       uint32_t num;
+       uint32_t *dbids;
+};
 int ctdb_getdbmap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_dbid_map *dbmap);
 
+
+/* table that contains a list of all nodes a ctdb knows about and their 
+   status
+ */
+struct ctdb_node_and_flags {
+       uint32_t vnn;
+       uint32_t flags;
+};
+struct ctdb_node_map {
+       uint32_t num;
+       struct ctdb_node_and_flags *nodes;
+};
+int ctdb_getnodemap(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_node_map *nodemap);
+
 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 e0e51b8d4a50f46769975a7a035a2d7b296c7ca2..dbbce30a447d82b39b8ef68d47dda5df2a90ed33 100644 (file)
@@ -79,6 +79,8 @@ struct ctdb_node {
        const char *name; /* for debug messages */
        void *private_data; /* private to transport */
        uint32_t vnn;
+#define NODE_FLAGS_CONNECTED 0x00000001
+       uint32_t flags;
 };
 
 /*
@@ -160,13 +162,6 @@ 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 {
@@ -258,7 +253,8 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS,
                    CTDB_CONTROL_SETVNNMAP,
                    CTDB_CONTROL_GET_DEBUG,
                    CTDB_CONTROL_SET_DEBUG,
-                   CTDB_CONTROL_GET_DBMAP};
+                   CTDB_CONTROL_GET_DBMAP,
+                   CTDB_CONTROL_GET_NODEMAP};
 
 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
 
index 909054b397867958af973d5fb7e8afc4fe07ff16..59b0be11f954f223d8caf75782d7b66012b86a27 100644 (file)
@@ -41,6 +41,7 @@ static void usage(void)
        printf("  getvnnmap <vnn>                    display ctdb vnnmap\n");
        printf("  setvnnmap <vnn> <generation> <numslots> <lmaster>*\n");
        printf("  getdbmap <vnn>                     lists databases on a node\n");
+       printf("  getnodemap <vnn>                   lists nodes known to a ctdb daemon\n");
        exit(1);
 }
 
@@ -189,6 +190,37 @@ static int control_getdbmap(struct ctdb_context *ctdb, int argc, const char **ar
        return 0;
 }
 
+/*
+  display a list nodes known to a remote ctdb
+ */
+static int control_getnodemap(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       uint32_t vnn;
+       int i, ret;
+       struct ctdb_node_map *nodemap;
+
+       if (argc < 1) {
+               usage();
+       }
+
+       vnn = strtoul(argv[0], NULL, 0);
+
+       nodemap = talloc_zero(ctdb, struct ctdb_node_map);
+       ret = ctdb_getnodemap(ctdb, vnn, nodemap);
+       if (ret != 0) {
+               printf("Unable to get nodemap from node %u\n", vnn);
+               talloc_free(nodemap);
+               return ret;
+       }
+
+       printf("Number of nodes:%d\n", nodemap->num);
+       for(i=0;i<nodemap->num;i++){
+               printf("vnn:0x%08x %s\n", nodemap->nodes[i].vnn, nodemap->nodes[i].flags&NODE_FLAGS_CONNECTED?"UNAVAILABLE":"CONNECTED");
+       }
+       talloc_free(nodemap);
+       return 0;
+}
+
 /*
   set remote ctdb vnn map
  */
@@ -341,6 +373,8 @@ int main(int argc, const char *argv[])
                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, "getnodemap") == 0) {
+               ret = control_getnodemap(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) {