]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
dispatcher daemon first try.
authorRonnie sahlberg <ronniesahlberg@gmail.com>
Mon, 9 Apr 2007 01:51:27 +0000 (11:51 +1000)
committerRonnie sahlberg <ronniesahlberg@gmail.com>
Mon, 9 Apr 2007 01:51:27 +0000 (11:51 +1000)
does not yet work

(This used to be ctdb commit ff428808c6546d6f2804a1ac1cf414d1bb9cdcb4)

ctdb/Makefile.in
ctdb/common/ctdb.c
ctdb/common/ctdb_call.c
ctdb/include/ctdb.h
ctdb/include/ctdb_private.h
ctdb/tests/ctdb_test.c
ctdb/tests/test1.sh

index 9f94f3aee89096414e5568086e3443a49d639b82..7e80852dc5f3e0e410f4a8b0603899ff5a884d97 100644 (file)
@@ -20,7 +20,7 @@ LIB_FLAGS=@LDFLAGS@ -Llib @LIBS@ -lpopt @INFINIBAND_LIBS@
 
 EVENTS_OBJ = lib/events/events.o lib/events/events_standard.o
 
-CTDB_COMMON_OBJ = common/ctdb.o common/util.o common/ctdb_util.o \
+CTDB_COMMON_OBJ = common/ctdb.o common/ctdb_daemon.o common/ctdb_io.o common/util.o common/ctdb_util.o \
        common/ctdb_call.o common/ctdb_ltdb.o common/ctdb_message.o \
        lib/util/idtree.o lib/util/db_wrap.o
 
index b98c0a3d841722bcc92545ef3c489bd716508f09..5c31bca9138c4964a10862aeba544c65fc3b2211 100644 (file)
@@ -179,14 +179,6 @@ uint32_t ctdb_get_num_nodes(struct ctdb_context *ctdb)
 }
 
 
-/*
-  start the protocol going
-*/
-int ctdb_start(struct ctdb_context *ctdb)
-{
-       return ctdb->methods->start(ctdb);
-}
-
 /*
   called by the transport layer when a packet comes in
 */
@@ -338,3 +330,7 @@ struct ctdb_context *ctdb_init(struct event_context *ev)
        return ctdb;
 }
 
+int ctdb_start(struct ctdb_context *ctdb)
+{
+       return ctdb->methods->start(ctdb);
+}
index 77ec87285241e5f225d6d1db0b17ff68eec8b337..c2b447a4e19802c2c19ef31d86d67a61c13096df 100644 (file)
@@ -380,24 +380,6 @@ void ctdb_request_call(struct ctdb_context *ctdb, struct ctdb_req_header *hdr)
        talloc_free(r);
 }
 
-enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
-
-/*
-  state of a in-progress ctdb call
-*/
-struct ctdb_call_state {
-       enum call_state state;
-       struct ctdb_req_call *c;
-       struct ctdb_db_context *ctdb_db;
-       struct ctdb_node *node;
-       const char *errmsg;
-       struct ctdb_call call;
-       int redirect_count;
-       struct ctdb_ltdb_header header;
-       void *fetch_private;
-};
-
-
 /*
   called when a CTDB_REPLY_CALL packet comes in
 
@@ -575,6 +557,7 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct c
        TDB_DATA data;
        struct ctdb_context *ctdb = ctdb_db->ctdb;
 
+
        /*
          if we are the dmaster for this key then we don't need to
          send it off at all, we can bypass the network and handle it
@@ -634,13 +617,6 @@ struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct c
 }
 
 
-
-struct ctdb_record_handle {
-       struct ctdb_db_context *ctdb_db;
-       TDB_DATA key;
-       TDB_DATA *data;
-};
-
 /*
   make a remote ctdb call - async recv. 
 
@@ -696,9 +672,6 @@ int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call)
 
 
 
-
-
-
 struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALLOC_CTX *mem_ctx, 
                                           TDB_DATA key, TDB_DATA *data)
 {
index 9049314401d8823e4343c12e642392f3418ab7b6..81df05839a22ad37c3da485d8765c8c5a57b42a9 100644 (file)
@@ -89,6 +89,10 @@ int ctdb_set_nlist(struct ctdb_context *ctdb, const char *nlist);
   start the ctdb protocol
 */
 int ctdb_start(struct ctdb_context *ctdb);
+/*
+  start the ctdb protocol in daemon mode, spawning a ctdb daemon
+*/
+int ctdbd_start(struct ctdb_context *ctdb);
 
 /*
   attach to a ctdb database
@@ -146,6 +150,15 @@ typedef void (*ctdb_message_fn_t)(struct ctdb_context *, uint32_t srvid,
 int ctdb_set_message_handler(struct ctdb_context *ctdb, ctdb_message_fn_t handler,
                             void *private);
 
+
+int ctdb_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+struct ctdb_call_state *ctdb_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+int ctdb_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
+
+int ctdbd_call(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct ctdb_call *call);
+int ctdbd_call_recv(struct ctdb_call_state *state, struct ctdb_call *call);
+
 /* send a ctdb message */
 int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
                      uint32_t srvid, TDB_DATA data);
@@ -167,4 +180,12 @@ struct ctdb_record_handle *ctdb_fetch_lock(struct ctdb_db_context *ctdb_db, TALL
 int ctdb_record_store(struct ctdb_record_handle *rec, TDB_DATA data);
 
 
+struct ctdb_partial {
+       uint8_t *data;
+       uint32_t length;
+};
+/* callback is called with data==NULL for fauilures.    the callback must test for this and do cleanup appropriately */
+typedef void (*partial_cb_fn_t)(uint8_t *data, int cnt, void *args);
+void ctdb_read_pdu(int fd, TALLOC_CTX *ctx, struct ctdb_partial *partial, partial_cb_fn_t func, void *args);
+
 #endif
index 00b74b217794d1260f6d32d61e94f60a19702228..0e572df98b29b65d1600829551716dd07adf0268 100644 (file)
@@ -54,6 +54,12 @@ struct ctdb_node {
        uint32_t vnn;
 };
 
+struct ctdb_record_handle {
+       struct ctdb_db_context *ctdb_db;
+       TDB_DATA key;
+       TDB_DATA *data;
+};
+
 /*
   transport specific methods
 */
@@ -98,6 +104,12 @@ struct ctdb_context {
        ctdb_message_fn_t message_handler;
        void *message_private;
        struct ctdb_db_context *db_list;
+       /* add all these client stuff to sub contexts */
+       int daemon_sd;
+       char *sd_name;
+       struct ctdbd_queue_packet *sd_queue;
+       struct fd_event *daemon_fde;
+       struct ctdb_partial daemon_partial;
 };
 
 struct ctdb_db_context {
@@ -109,6 +121,7 @@ struct ctdb_db_context {
        struct ctdb_registered_call *calls; /* list of registered calls */
 };
 
+
 #define CTDB_NO_MEMORY(ctdb, p) do { if (!(p)) { \
           ctdb_set_error(ctdb, "Out of memory at %s:%d", __FILE__, __LINE__); \
          return -1; }} while (0)
@@ -141,6 +154,23 @@ struct ctdb_ltdb_header {
        uint32_t lacount;
 };
 
+enum call_state {CTDB_CALL_WAIT, CTDB_CALL_DONE, CTDB_CALL_ERROR};
+
+/*
+  state of a in-progress ctdb call
+*/
+struct ctdb_call_state {
+       enum call_state state;
+       struct ctdb_req_call *c;
+       struct ctdb_db_context *ctdb_db;
+       struct ctdb_node *node;
+       const char *errmsg;
+       struct ctdb_call call;
+       int redirect_count;
+       struct ctdb_ltdb_header header;
+       void *fetch_private;
+};
+
 
 /*
   operation IDs
@@ -246,5 +276,9 @@ int ctdb_ltdb_store(struct ctdb_db_context *ctdb_db, TDB_DATA key,
                    struct ctdb_ltdb_header *header, TDB_DATA data);
 void ctdb_queue_packet(struct ctdb_context *ctdb, struct ctdb_req_header *hdr);
 
+struct ctdb_call_state *ctdb_call_local_send(struct ctdb_db_context *ctdb_db, 
+                                            struct ctdb_call *call,
+                                            struct ctdb_ltdb_header *header,
+                                            TDB_DATA *data);
 
 #endif
index 908a2eaac750385d957ebb7d2bc339844a33ae74..48f281029a875beacb8fc64dd111ad512b150677 100644 (file)
@@ -81,6 +81,7 @@ int main(int argc, const char *argv[])
        const char *transport = "tcp";
        const char *myaddress = NULL;
        int self_connect=0;
+       int daemon_mode=0;
 
        struct poptOption popt_options[] = {
                POPT_AUTOHELP
@@ -88,6 +89,7 @@ int main(int argc, const char *argv[])
                { "listen", 0, POPT_ARG_STRING, &myaddress, 0, "address to listen on", "address" },
                { "transport", 0, POPT_ARG_STRING, &transport, 0, "protocol transport", NULL },
                { "self-connect", 0, POPT_ARG_NONE, &self_connect, 0, "enable self connect", "boolean" },
+               { "daemon", 0, POPT_ARG_NONE, &daemon_mode, 0, "spawn a ctdb daemon", "boolean" },
                POPT_TABLEEND
        };
        int opt;
@@ -166,7 +168,11 @@ int main(int argc, const char *argv[])
        ret = ctdb_set_call(ctdb_db, fetch_func, FUNC_FETCH);
 
        /* start the protocol running */
-       ret = ctdb_start(ctdb);
+       if (daemon_mode) {
+               ret = ctdbd_start(ctdb);
+       } else {
+               ret = ctdb_start(ctdb);
+       }
 
        /* wait until all nodes are connected (should not be needed
           outide of test code) */
@@ -184,7 +190,11 @@ int main(int argc, const char *argv[])
                call.call_data.dptr = (uint8_t *)&v;
                call.call_data.dsize = sizeof(v);
 
-               ret = ctdb_call(ctdb_db, &call);
+               if (daemon_mode) {
+                       ret = ctdbd_call(ctdb_db, &call);
+               } else {
+                       ret = ctdb_call(ctdb_db, &call);
+               }
                if (ret == -1) {
                        printf("ctdb_call FUNC_SORT failed - %s\n", ctdb_errstr(ctdb));
                        exit(1);
@@ -196,7 +206,11 @@ int main(int argc, const char *argv[])
        call.call_data.dptr = NULL;
        call.call_data.dsize = 0;
 
-       ret = ctdb_call(ctdb_db, &call);
+       if (daemon_mode) {
+               ret = ctdbd_call(ctdb_db, &call);
+       } else {
+               ret = ctdb_call(ctdb_db, &call);
+       }
        if (ret == -1) {
                printf("ctdb_call FUNC_FETCH failed - %s\n", ctdb_errstr(ctdb));
                exit(1);
@@ -210,6 +224,8 @@ int main(int argc, const char *argv[])
        /* go into a wait loop to allow other nodes to complete */
        ctdb_wait_loop(ctdb);
 
+       /*talloc_report_full(ctdb, stdout);*/
+
        /* shut it down */
        talloc_free(ctdb);
        return 0;
index 26c6bc100275b3ccea05d5be3564d1024277470c..48a509e5d798cc4aa0bdfbf12025fc422762140a 100755 (executable)
@@ -1,6 +1,6 @@
 #!/bin/sh
 
 echo "Testing local send"
-bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001
+bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001 --daemon
 echo "Testing self connect"
-bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001 --self-connect
+bin/ctdb_test --nlist tests/1node.txt --listen 127.0.0.1:9001 --daemon --self-connect