]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
add an initial implementation of a service_id structure and three
authorRonnie Sahlberg <sahlberg@ronnie>
Fri, 24 Aug 2007 05:53:41 +0000 (15:53 +1000)
committerRonnie Sahlberg <sahlberg@ronnie>
Fri, 24 Aug 2007 05:53:41 +0000 (15:53 +1000)
controls to  register/unregister/check a server id.

a server id consists of TYPE:VNN:ID    where type is specific to the
application.  VNN is the node where the serverid was registered and ID
might be a node unique identifier such as a pid or similar.

Clients can register a server id for themself at the local ctdb daemon.
When a client dissappears   or when the domain socket connection for the
client drops  then any and all server ids registered across that domain
socket will also be automatically removed from the store.

clients can register as many server_ids as they want at the same time
but each TYPE:VNN:ID must be globally unique.

Clients have the option of explicitely unregister a server id by using
the UNREGISTER control.

Registration and unregistration can only be done by clients to the local
daemon. clients can not register their server id to a remote node.

clients can check if a server id does exist on any ctdb node in the
network by using the check control

(This used to be ctdb commit d44798feec26147c5cc05922cb2186f0ef0307be)

ctdb/Makefile.in
ctdb/client/ctdb_client.c
ctdb/common/cmdline.c
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/server/ctdb_control.c
ctdb/server/ctdb_serverids.c [new file with mode: 0644]
ctdb/tools/ctdb.c

index 7499b0d7ff21fb9eb8d30f10632b30e6995cf700..d8c06fab9ad84216305ad975e1295f2f010c654d 100644 (file)
@@ -48,6 +48,7 @@ CTDB_SERVER_OBJ = server/ctdbd.o server/ctdb_daemon.o server/ctdb_lockwait.o \
        server/ctdb_tunables.o server/ctdb_monitor.o server/ctdb_server.o \
        server/ctdb_control.o server/ctdb_call.o server/ctdb_ltdb_server.o \
        server/ctdb_traverse.o server/eventscript.o server/ctdb_takeover.o \
+       server/ctdb_serverids.o \
        $(CTDB_CLIENT_OBJ) $(CTDB_TCP_OBJ) @INFINIBAND_WRAPPER_OBJ@
 
 TEST_BINS=bin/ctdb_bench bin/ctdb_fetch bin/ctdb_store bin/rb_test \
index a3203c21e969d9386e882ee8106b2ede5677e79a..f0b22dbb0663511cfb3aab3a057c65acc60d726e 100644 (file)
@@ -2299,6 +2299,93 @@ int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb,
        return status;
 }
 
+/*
+  register a server id
+ */
+int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb, 
+                     struct timeval timeout, 
+                     struct ctdb_server_id *id)
+{
+       TDB_DATA data;
+       int32_t res;
+       int ret;
+
+       data.dsize = sizeof(struct ctdb_server_id);
+       data.dptr  = (unsigned char *)id;
+
+       ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, 
+                       CTDB_CONTROL_REGISTER_SERVER_ID, 
+                       0, data, NULL,
+                       NULL, &res, &timeout, NULL);
+       if (ret != 0 || res != 0) {
+               DEBUG(0,(__location__ " ctdb_control for register server id failed\n"));
+               return -1;
+       }
+
+       return 0;
+}
+
+/*
+  unregister a server id
+ */
+int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb, 
+                     struct timeval timeout, 
+                     struct ctdb_server_id *id)
+{
+       TDB_DATA data;
+       int32_t res;
+       int ret;
+
+       data.dsize = sizeof(struct ctdb_server_id);
+       data.dptr  = (unsigned char *)id;
+
+       ret = ctdb_control(ctdb, CTDB_CURRENT_NODE, 0, 
+                       CTDB_CONTROL_UNREGISTER_SERVER_ID, 
+                       0, data, NULL,
+                       NULL, &res, &timeout, NULL);
+       if (ret != 0 || res != 0) {
+               DEBUG(0,(__location__ " ctdb_control for unregister server id failed\n"));
+               return -1;
+       }
+
+       return 0;
+}
+
+
+/*
+  check if a server id exists
+ */
+int ctdb_ctrl_check_server_id(struct ctdb_context *ctdb, 
+                     struct timeval timeout, 
+                     uint32_t destnode,
+                     struct ctdb_server_id *id,
+                     uint32_t *status)
+{
+       TDB_DATA data;
+       int32_t res;
+       int ret;
+
+       data.dsize = sizeof(struct ctdb_server_id);
+       data.dptr  = (unsigned char *)id;
+
+       ret = ctdb_control(ctdb, destnode, 0, CTDB_CONTROL_CHECK_SERVER_ID, 
+                       0, data, NULL,
+                       NULL, &res, &timeout, NULL);
+       if (ret != 0) {
+               DEBUG(0,(__location__ " ctdb_control for check server id failed\n"));
+               return -1;
+       }
+
+       if (res) {
+               *status = 1;
+       } else {
+               *status = 0;
+       }
+
+       return 0;
+}
+
+
 /*
   initialise the ctdb daemon for client applications
 
index f72254e29560e0f287b12a0ec225c97f96e2e81a..fb5c76aeae5733716f1546f1365a121f159fb9fa 100644 (file)
@@ -23,6 +23,7 @@
 #include "popt.h"
 #include "../include/ctdb.h"
 #include "../include/ctdb_private.h"
+#include "../common/rb_tree.h"
 
 /* Handle common command line options for ctdb test progs
  */
@@ -87,6 +88,9 @@ struct ctdb_context *ctdb_cmdline_init(struct event_context *ev)
                exit(1);
        }
 
+       /* set up the tree to store server ids */
+       ctdb->server_ids = trbt_create(ctdb, 0);
+
        return ctdb;
 }
 
index 8f52aa79a0babde453797e0ea81076b14d221ef8..b7c1f71a0b64a52ec09d3743697fbdbe9d440220 100644 (file)
@@ -405,6 +405,23 @@ int ctdb_ctrl_modflags(struct ctdb_context *ctdb,
                       uint32_t destnode, 
                       uint32_t set, uint32_t clear);
 
+enum ctdb_server_id_type { SERVER_TYPE_SAMBA=1 };
+
+struct ctdb_server_id {
+       enum ctdb_server_id_type type;
+       uint32_t vnn;
+       uint32_t server_id;
+};
+int ctdb_ctrl_register_server_id(struct ctdb_context *ctdb,
+               struct timeval timeout,
+               struct ctdb_server_id *id);
+int ctdb_ctrl_unregister_server_id(struct ctdb_context *ctdb, 
+               struct timeval timeout, 
+               struct ctdb_server_id *id);
+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_socket_connect(struct ctdb_context *ctdb);
 
 #endif
index 8a61131593dbba06887ca02f001634fc96be901a..9e77e58fd753770315c4f156cce7e872287a5a93 100644 (file)
@@ -349,6 +349,7 @@ struct ctdb_context {
        bool do_setsched;
        void *saved_scheduler_param;
        struct ctdb_kill_tcp *killtcp;
+       struct _trbt_tree_t *server_ids;        
 };
 
 struct ctdb_db_context {
@@ -451,7 +452,11 @@ enum ctdb_controls {CTDB_CONTROL_PROCESS_EXISTS          = 0,
                    CTDB_CONTROL_KILL_TCP                = 54,
                    CTDB_CONTROL_GET_TCP_TICKLE_LIST     = 55,
                    CTDB_CONTROL_SET_TCP_TICKLE_LIST     = 56,
-};
+                   CTDB_CONTROL_REGISTER_SERVER_ID      = 57,
+                   CTDB_CONTROL_UNREGISTER_SERVER_ID    = 58,
+                   CTDB_CONTROL_CHECK_SERVER_ID         = 59,
+                   CTDB_CONTROL_GET_SERVER_ID_LIST      = 60,
+};     
 
 /*
   structure passed in ctdb_control_set_rsn_nonempty
@@ -1120,4 +1125,13 @@ int ctdb_ctrl_get_tcp_tickles(struct ctdb_context *ctdb,
                      uint32_t vnn,
                      struct ctdb_control_tcp_tickle_list **list);
 
+
+int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb, 
+                     uint32_t client_id,
+                     TDB_DATA indata);
+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);
+
 #endif
index e134850cf46318be362cf50b4f235a77730e1bec..346d023742634042c4b00b344138a63f163dc509 100644 (file)
@@ -26,6 +26,7 @@
 #include "lib/util/dlinklist.h"
 #include "db_wrap.h"
 
+
 struct ctdb_control_state {
        struct ctdb_context *ctdb;
        uint32_t reqid;
@@ -34,6 +35,7 @@ struct ctdb_control_state {
        unsigned flags;
 };
 
+
 /*
   process a control request
  */
@@ -294,6 +296,18 @@ static int32_t ctdb_control_dispatch(struct ctdb_context *ctdb,
                /* data size is verified in the called function */
                return ctdb_control_set_tcp_tickle_list(ctdb, indata);
 
+       case CTDB_CONTROL_REGISTER_SERVER_ID: 
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
+               return ctdb_control_register_server_id(ctdb, client_id, indata);
+
+       case CTDB_CONTROL_UNREGISTER_SERVER_ID: 
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
+               return ctdb_control_unregister_server_id(ctdb, indata);
+
+       case CTDB_CONTROL_CHECK_SERVER_ID: 
+               CHECK_CONTROL_DATA_SIZE(sizeof(struct ctdb_server_id));
+               return ctdb_control_check_server_id(ctdb, indata);
+
        default:
                DEBUG(0,(__location__ " Unknown CTDB control opcode %u\n", opcode));
                return -1;
diff --git a/ctdb/server/ctdb_serverids.c b/ctdb/server/ctdb_serverids.c
new file mode 100644 (file)
index 0000000..b406a35
--- /dev/null
@@ -0,0 +1,113 @@
+/* 
+   ctdb_control protocol code to manage server ids
+
+   Copyright (C) Ronnie Sahlberg 2007
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 3 of the License, or
+   (at your option) any later version.
+   
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU General Public License for more details.
+   
+   You should have received a copy of the GNU General Public License
+   along with this program; if not, see <http://www.gnu.org/licenses/>.
+*/
+#include "includes.h"
+#include "../include/ctdb_private.h"
+#include "../common/rb_tree.h"
+
+
+#define SERVER_ID_KEY_SIZE 3
+static uint32_t *get_server_id_key(struct ctdb_server_id *server_id)
+{
+       static uint32_t key[SERVER_ID_KEY_SIZE];
+
+       key[0] = server_id->type;
+       key[1] = server_id->vnn;
+       key[2] = server_id->server_id;
+
+       return &key[0];
+}
+
+/* add a server_id to the tree.
+   if we had already 'data' in the tree then this is a duplicate and we can
+   just talloc_free the structure in parm and leave data in the tree.
+   othervise if this is a new node we return parm and that is inserted
+   into the tree.
+*/
+static void *add_server_id_callback(void *parm, void *data)
+{
+       if (data) {
+               talloc_free(parm);
+               return data;
+       }
+       return parm;
+}
+
+/*
+  register a server id
+  a serverid that is registered with ctdb will be automatically unregistered
+  once the client domain socket dissappears.
+ */
+int32_t ctdb_control_register_server_id(struct ctdb_context *ctdb, 
+                                uint32_t client_id,
+                                TDB_DATA indata)
+{
+       struct ctdb_server_id *server_id;
+       struct ctdb_client *client = ctdb_reqid_find(ctdb, client_id, struct ctdb_client);
+
+
+       if (client == NULL) {
+               DEBUG(0,(__location__ " Could not find client parent structure. You can not send this control to a remote node\n"));
+               return 1;
+       }
+
+       /* hang the server_id structure off client before storing it in the
+          tree so that is will be automatically destroyed when client
+          is destroyed. 
+          when the structure is free'd it will be automatically
+          removed from the tree
+       */
+       server_id = talloc_memdup(client, indata.dptr, indata.dsize);
+       CTDB_NO_MEMORY(ctdb, server_id);
+
+       trbt_insertarray32_callback(ctdb->server_ids, SERVER_ID_KEY_SIZE,
+               get_server_id_key(server_id), 
+               add_server_id_callback, server_id);
+
+       return 0;
+}
+
+
+/*
+  check whether a server id exists
+ */
+int32_t ctdb_control_check_server_id(struct ctdb_context *ctdb, 
+                                TDB_DATA indata)
+{
+       struct ctdb_server_id *server_id = (struct ctdb_server_id *)indata.dptr;
+
+       return (int32_t)trbt_lookuparray32(ctdb->server_ids, 
+                               SERVER_ID_KEY_SIZE,
+                               get_server_id_key(server_id));
+}
+
+/*
+  unregisters a server id
+ */
+int32_t ctdb_control_unregister_server_id(struct ctdb_context *ctdb, 
+                                TDB_DATA indata)
+{
+       struct ctdb_server_id *server_id = (struct ctdb_server_id *)indata.dptr;
+
+       talloc_free(trbt_lookuparray32(ctdb->server_ids, 
+                       SERVER_ID_KEY_SIZE,
+                       get_server_id_key(server_id)));
+       return 0;
+}
+
+
index 7a6ff94233a7fa37b04a109d0e02b55b22483193..83b262f520b59af9fb108bb48e624d90d38057d9 100644 (file)
@@ -373,6 +373,86 @@ static int kill_tcp(struct ctdb_context *ctdb, int argc, const char **argv)
        return -1;
 }
 
+
+/*
+  register a server id
+ */
+static int regsrvid(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       int ret;
+       struct ctdb_server_id server_id;
+
+       if (argc < 3) {
+               usage();
+       }
+
+       server_id.vnn       = strtoul(argv[0], NULL, 0);
+       server_id.type      = strtoul(argv[1], NULL, 0);
+       server_id.server_id = strtoul(argv[2], NULL, 0);
+
+       ret = ctdb_ctrl_register_server_id(ctdb, TIMELIMIT(), &server_id);
+       if (ret != 0) {
+               DEBUG(0, ("Unable to register server_id from node %u\n", options.vnn));
+               return ret;
+       }
+       return -1;
+}
+
+/*
+  unregister a server id
+ */
+static int unregsrvid(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       int ret;
+       struct ctdb_server_id server_id;
+
+       if (argc < 3) {
+               usage();
+       }
+
+       server_id.vnn       = strtoul(argv[0], NULL, 0);
+       server_id.type      = strtoul(argv[1], NULL, 0);
+       server_id.server_id = strtoul(argv[2], NULL, 0);
+
+       ret = ctdb_ctrl_unregister_server_id(ctdb, TIMELIMIT(), &server_id);
+       if (ret != 0) {
+               DEBUG(0, ("Unable to unregister server_id from node %u\n", options.vnn));
+               return ret;
+       }
+       return -1;
+}
+
+/*
+  check if a server id exists
+ */
+static int chksrvid(struct ctdb_context *ctdb, int argc, const char **argv)
+{
+       uint32_t status;
+       int ret;
+       struct ctdb_server_id server_id;
+
+       if (argc < 3) {
+               usage();
+       }
+
+       server_id.vnn       = strtoul(argv[0], NULL, 0);
+       server_id.type      = strtoul(argv[1], NULL, 0);
+       server_id.server_id = strtoul(argv[2], NULL, 0);
+
+       ret = ctdb_ctrl_check_server_id(ctdb, TIMELIMIT(), options.vnn, &server_id, &status);
+       if (ret != 0) {
+               DEBUG(0, ("Unable to check server_id from node %u\n", options.vnn));
+               return ret;
+       }
+
+       if (status) {
+               printf("Server id %d:%d:%d EXISTS\n", server_id.vnn, server_id.type, server_id.server_id);
+       } else {
+               printf("Server id %d:%d:%d does NOT exist\n", server_id.vnn, server_id.type, server_id.server_id);
+       }
+       return 0;
+}
+
 /*
   send a tcp tickle ack
  */
@@ -964,6 +1044,10 @@ static const struct {
        { "killtcp",         kill_tcp,                  false, "kill a tcp connection.", "<srcip:port> <dstip:port>" },
        { "tickle",          tickle_tcp,                false, "send a tcp tickle ack", "<srcip:port> <dstip:port>" },
        { "gettickles",      control_get_tickles,       false, "get the list of tickles registered for this vnn", "<vnn>" },
+
+       { "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>" },
 };
 
 /*