added a ctdb_get_config call
authorAndrew Tridgell <tridge@samba.org>
Thu, 26 Apr 2007 17:27:07 +0000 (19:27 +0200)
committerAndrew Tridgell <tridge@samba.org>
Thu, 26 Apr 2007 17:27:07 +0000 (19:27 +0200)
added a ctdb ping control

(This used to be ctdb commit 7d17378b6e6076a922cffe98239e20dfbbae3bf7)

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

index 085a1334604e75b3549e4758b9e56771e69a118e..2b9d5f43c6bf9bc264720ddba783cf4176a47cbd 100644 (file)
@@ -153,5 +153,13 @@ struct ctdb_context *ctdb_cmdline_client(struct event_context *ev)
                return NULL;
        }
 
+       /* get our config */
+       ret = ctdb_get_config(ctdb);
+       if (ret != 0) {
+               DEBUG(0,(__location__ " Failed to get ctdb config\n"));
+               talloc_free(ctdb);
+               return NULL;
+       }
+
        return ctdb;
 }
index f0589e70a43c7ace298a7273c8d21950ad59fe80..5d4a9177a0ab027f7c1b03134c87e15fe999938a 100644 (file)
@@ -479,6 +479,9 @@ void ctdb_connect_wait(struct ctdb_context *ctdb)
        /* now we can go into the normal wait routine, as the reply packet
           will update the ctdb->num_connected variable */
        ctdb_daemon_connect_wait(ctdb);
+
+       /* get other config variables */
+       ctdb_get_config(ctdb);
 }
 
 /*
@@ -859,3 +862,51 @@ int ctdb_status(struct ctdb_context *ctdb, uint32_t destnode, struct ctdb_status
                        
        return 0;
 }
+
+/*
+  ping a node
+ */
+int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode)
+{
+       int ret;
+       int32_t res;
+       TDB_DATA data;
+
+       ZERO_STRUCT(data);
+       ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_PING, data, NULL, NULL, &res);
+       if (ret != 0 || res != 0) {
+               return -1;
+       }
+       return 0;
+}
+
+/*
+  get ctdb config
+ */
+int ctdb_get_config(struct ctdb_context *ctdb)
+{
+       int ret;
+       int32_t res;
+       TDB_DATA data;
+       struct ctdb_context c;
+
+       ZERO_STRUCT(data);
+       ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, CTDB_CONTROL_CONFIG, data, 
+                          ctdb, &data, &res);
+       if (ret != 0 || res != 0) {
+               return -1;
+       }
+       if (data.dsize != sizeof(c)) {
+               DEBUG(0,("Bad config size %u - expected %u\n", data.dsize, sizeof(c)));
+               return -1;
+       }
+
+       c = *(struct ctdb_context *)data.dptr;
+
+       ctdb->num_nodes = c.num_nodes;
+       ctdb->num_connected = c.num_connected;
+       ctdb->vnn = c.vnn;
+       ctdb->max_lacount = c.max_lacount;
+       
+       return 0;
+}
index 85ad371ab8061efbb51f3f1011dae49f299a7e93..a763ab5e577ab8b870a65daab354c53fcecbed3b 100644 (file)
@@ -50,11 +50,22 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                pid = *(pid_t *)indata.dptr;
                return kill(pid, 0);
        }
+
        case CTDB_CONTROL_STATUS: {
                outdata->dptr = (uint8_t *)&ctdb->status;
                outdata->dsize = sizeof(ctdb->status);
                return 0;
        }
+
+       case CTDB_CONTROL_CONFIG: {
+               outdata->dptr = (uint8_t *)ctdb;
+               outdata->dsize = sizeof(*ctdb);
+               return 0;
+       }
+
+       case CTDB_CONTROL_PING:
+               return 0;
+
        default:
                DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode));
                return -1;
index 842deb71e7734c0ffca8edfc582b79690bb7a89f..9b18dbcb0ecf026d1ef4d07290ec4a666e81964a 100644 (file)
@@ -758,6 +758,7 @@ void ctdb_request_finished(struct ctdb_context *ctdb, struct ctdb_req_header *hd
 struct daemon_control_state {
        struct ctdb_client *client;
        struct ctdb_req_control *c;
+       uint32_t reqid;
 };
 
 /*
@@ -784,6 +785,7 @@ static void daemon_control_callback(struct ctdb_context *ctdb,
        r->hdr.ctdb_magic = CTDB_MAGIC;
        r->hdr.ctdb_version = CTDB_VERSION;
        r->hdr.operation = CTDB_REPLY_CONTROL;
+       r->hdr.reqid     = state->reqid;
        r->status        = status;
        r->datalen       = data.dsize;
        memcpy(&r->data[0], data.dptr, data.dsize);
@@ -804,11 +806,16 @@ static void daemon_request_control_from_client(struct ctdb_client *client,
        int res;
        struct daemon_control_state *state;
 
+       if (c->hdr.destnode == CTDB_CURRENT_NODE) {
+               c->hdr.destnode = client->ctdb->vnn;
+       }
+
        state = talloc(client, struct daemon_control_state);
        CTDB_NO_MEMORY_VOID(client->ctdb, state);
 
        state->client = client;
        state->c = talloc_steal(state, c);
+       state->reqid = c->hdr.reqid;
        
        data.dptr = &c->data[0];
        data.dsize = c->datalen;
index 2a9622954971ba7c352de97ec8d996b1182f9798..3273d4c9fe7e0149803cffe45d0d25366dfdc575 100644 (file)
@@ -219,4 +219,8 @@ int ctdb_getdbpath(struct ctdb_db_context *ctdb_db, TDB_DATA *path);
 
 int ctdb_process_exists(struct ctdb_context *ctdb, uint32_t destnode, pid_t pid);
 
+int ctdb_ping(struct ctdb_context *ctdb, uint32_t destnode);
+
+int ctdb_get_config(struct ctdb_context *ctdb);
+
 #endif
index 88aa209d9ad1f17c959319ac5d52bb839532a060..048b5d7dc20c3eb22b980c02e6f4e3e2b0c87f41 100644 (file)
@@ -31,6 +31,7 @@
 
 
 #define CTDB_NULL_FUNC 0xf0000001
+#define CTDB_CURRENT_NODE 0xF0000001
 
 /*
   an installed ctdb remote call
@@ -228,7 +229,10 @@ struct ctdb_ltdb_header {
        uint32_t lacount;
 };
 
-enum {CTDB_CONTROL_PROCESS_EXISTS, CTDB_CONTROL_STATUS};
+enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS, 
+                   CTDB_CONTROL_STATUS, 
+                   CTDB_CONTROL_CONFIG,
+                   CTDB_CONTROL_PING};
 
 enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
 
index e5a2c22a9d6a36d6088b9125f9ab211b812f0194..9cf52aa9b1bfc32d72efdf6aded7561a40e6c5fb 100644 (file)
@@ -33,6 +33,7 @@ static void usage(void)
 {
        printf("Usage: ctdb_control [options] <control>\n");
        printf("\nControls:\n");
+       printf("  ping\n");
        printf("  process-exists <vnn:pid>\n");
        printf("  status <vnn>\n");
        exit(1);
@@ -115,6 +116,24 @@ static int control_status(struct ctdb_context *ctdb, int argc, const char **argv
        return 0;
 }
 
+
+static int control_ping(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       int ret, i;
+
+       for (i=0;i<ctdb->num_nodes;i++) {
+               struct timeval tv = timeval_current();
+               ret = ctdb_ping(ctdb, i);
+               if (ret != 0) {
+                       printf("Unable to get ping response from node %u\n", i);
+               } else {
+                       printf("response from %u time=%.6f sec\n", 
+                              i, timeval_elapsed(&tv));
+               }
+       }
+       return 0;
+}
+
 /*
   main program
 */
@@ -171,6 +190,8 @@ int main(int argc, const char *argv[])
                ret = control_process_exists(ctdb, extra_argc-1, extra_argv+1);
        } else if (strcmp(control, "status") == 0) {
                ret = control_status(ctdb, extra_argc-1, extra_argv+1);
+       } else if (strcmp(control, "ping") == 0) {
+               ret = control_ping(ctdb, extra_argc-1, extra_argv+1);
        } else {
                printf("Unknown control '%s'\n", control);
                exit(1);