]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
add a control to pull the server id list off a node
authorRonnie Sahlberg <sahlberg@ronnie>
Sun, 26 Aug 2007 00:57:02 +0000 (10:57 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Sun, 26 Aug 2007 00:57:02 +0000 (10:57 +1000)
(This used to be ctdb commit 38aa759aa88a042c31b401551f6a713fb7bbe84e)

ctdb/client/ctdb_client.c
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/server/ctdb_control.c
ctdb/server/ctdb_serverids.c
ctdb/tools/ctdb.c

index f0b22dbb0663511cfb3aab3a057c65acc60d726e..0aa0e9b97ed1c2b16172faee02e4fc18a47e8f89 100644 (file)
@@ -2385,6 +2385,30 @@ int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
        return 0;
 }
 
+/*
+   get the list of server ids that are registered on a node
+*/
+int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb,
+               TALLOC_CTX *mem_ctx,
+               struct timeval timeout, uint32_t destnode, 
+               struct ctdb_server_id_list **svid_list)
+{
+       int ret;
+       TDB_DATA outdata;
+       int32_t res;
+
+       ret = ctdb_control(ctdb, destnode, 0, 
+                          CTDB_CONTROL_GET_SERVER_ID_LIST, 0, tdb_null, 
+                          mem_ctx, &outdata, &res, &timeout, NULL);
+       if (ret != 0 || res != 0) {
+               DEBUG(0,(__location__ " ctdb_control for get_server_id_list failed\n"));
+               return -1;
+       }
+
+       *svid_list = (struct ctdb_server_id_list *)talloc_steal(mem_ctx, outdata.dptr);
+                   
+       return 0;
+}
 
 /*
   initialise the ctdb daemon for client applications
index b7c1f71a0b64a52ec09d3743697fbdbe9d440220..e46cc68a79477743448938d03ea6d804159b8edd 100644 (file)
@@ -412,6 +412,13 @@ struct ctdb_server_id {
        uint32_t vnn;
        uint32_t server_id;
 };
+
+struct ctdb_server_id_list {
+       uint32_t num;
+       struct ctdb_server_id server_ids[1];
+};
+
+
 int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb,
                struct timeval timeout,
                struct ctdb_server_id *id);
@@ -421,6 +428,10 @@ int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb,
 int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb,
                struct timeval timeout, uint32_t destnode, 
                struct ctdb_server_id *id, uint32_t *status);
+int ctdb_ctrl_get_server_id_list(struct ctdb_context *ctdb,
+               TALLOC_CTX *mem_ctx,
+               struct timeval timeout, uint32_t destnode, 
+               struct ctdb_server_id_list **svid_list);
 
 int ctdb_socket_connect(struct ctdb_context *ctdb);
 
index 9e77e58fd753770315c4f156cce7e872287a5a93..516e3111c39a8a4a48406525115ca309820aba6d 100644 (file)
@@ -1133,5 +1133,7 @@ int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb,
                      TDB_DATA indata);
 int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb, 
                      TDB_DATA indata);
+int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb, 
+                     TDB_DATA *outdata);
 
 #endif
index 346d023742634042c4b00b344138a63f163dc509..326b8edca66056f5d529c2ce80615f855d05ce07 100644 (file)
@@ -308,6 +308,10 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
                return ctdb_control_check_server_id(ctdb, indata);
 
+       case CTDB_CONTROL_GET_SERVER_ID_LIST:
+               CHECK_CONTROL_DATA_SIZE(0);
+               return ctdb_control_get_server_id_list(ctdb, outdata);
+
        default:
                DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode));
                return -1;
index b406a353f132180593e6dfd7e87b1132bd455bc3..8c8c9308744253759aaaf1e3ad7d70d270c6ad54 100644 (file)
@@ -72,8 +72,9 @@ int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb,
           when the structure is free'd it will be automatically
           removed from the tree
        */
-       server_id = talloc_memdup(client, indata.dptr, indata.dsize);
+       server_id = talloc_zero(client, struct ctdb_server_id);
        CTDB_NO_MEMORY(ctdb, server_id);
+       memcpy(server_id, indata.dptr, sizeof(struct ctdb_server_id));
 
        trbt_insertarray32_callback(ctdb->server_ids, SERVER_ID_KEY_SIZE,
                get_server_id_key(server_id), 
@@ -111,3 +112,78 @@ int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb,
 }
 
 
+
+
+struct count_server_ids {
+       int count;
+       struct ctdb_server_id_list *list;
+};
+
+static void server_id_count(void *param, void *data)
+{
+       struct count_server_ids *svid = talloc_get_type(param, 
+                                               struct count_server_ids);
+
+       if (svid == NULL) {
+               DEBUG(0, (__location__ " Got null pointer for svid\n"));
+               return;
+       }
+
+       svid->count++;
+}
+
+static void server_id_store(void *param, void *data)
+{
+       struct count_server_ids *svid = talloc_get_type(param, 
+                                               struct count_server_ids);
+       struct ctdb_server_id *server_id = talloc_get_type(data, 
+                                               struct ctdb_server_id);
+
+       if (svid == NULL) {
+               DEBUG(0, (__location__ " Got null pointer for svid\n"));
+               return;
+       }
+
+       if (svid->count >= svid->list->num) {
+               DEBUG(0, (__location__ " size of server id tree changed during traverse\n"));
+               return;
+       }
+
+       memcpy(&svid->list->server_ids[svid->count], server_id, sizeof(struct ctdb_server_id));
+       svid->count++;
+}
+
+/* 
+   returns a list of all registered server ids for a node
+*/
+int32_t ctdb_control_get_server_id_list(struct ctdb_context *ctdb, TDB_DATA *outdata)
+{
+       struct count_server_ids *svid;
+
+
+       svid = talloc_zero(outdata, struct count_server_ids);
+       CTDB_NO_MEMORY(ctdb, svid);
+
+
+       /* first we must count how many entries we have */
+       trbt_traversearray32(ctdb->server_ids, SERVER_ID_KEY_SIZE,
+                       server_id_count, svid);
+
+
+       outdata->dsize = offsetof(struct ctdb_server_id_list, 
+                               server_ids)
+                       + sizeof(struct ctdb_server_id) * svid->count;
+       outdata->dptr  = talloc_size(outdata, outdata->dsize);
+       CTDB_NO_MEMORY(ctdb, outdata->dptr);
+
+
+       /* now fill the structure in */
+       svid->list = (struct ctdb_server_id_list *)(outdata->dptr);
+       svid->list->num = svid->count;
+       svid->count=0;
+       trbt_traversearray32(ctdb->server_ids, SERVER_ID_KEY_SIZE,
+                       server_id_store, svid);
+
+
+       return 0;
+}
index 83b262f520b59af9fb108bb48e624d90d38057d9..3e56a97f6e9ea0b7ec63bb07cd5a5d6fcec59406 100644 (file)
@@ -453,6 +453,30 @@ static int chksrvid(struct ctdb_context *ctdb, int argc, const char **argv)
        return 0;
 }
 
+/*
+  get a list of all server ids that are registered on a node
+ */
+static int getsrvids(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       int i, ret;
+       struct ctdb_server_id_list *server_ids;
+
+       ret = ctdb_ctrl_get_server_id_list(ctdb, ctdb, TIMELIMIT(), options.vnn, &server_ids);
+       if (ret != 0) {
+               DEBUG(0, ("Unable to get server_id list from node %u\n", options.vnn));
+               return ret;
+       }
+
+       for (i=0; i<server_ids->num; i++) {
+               printf("Server id %d:%d:%d\n", 
+                       server_ids->server_ids[i].vnn, 
+                       server_ids->server_ids[i].type, 
+                       server_ids->server_ids[i].server_id); 
+       }
+
+       return -1;
+}
+
 /*
   send a tcp tickle ack
  */
@@ -1048,6 +1072,7 @@ static const struct {
        { "regsrvid",        regsrvid,                  false, "register a server id", "<vnn> <type> <id>" },
        { "unregsrvid",      unregsrvid,                false, "unregister a server id", "<vnn> <type> <id>" },
        { "chksrvid",        chksrvid,                  false, "check if a server id exists", "<vnn> <type> <id>" },
+       { "getsrvids",       getsrvids,                 false, "get a list of all server ids"},
 };
 
 /*