summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2006-11-28 11:51:33 +1100
committerAndrew Tridgell <tridge@samba.org>2006-11-28 11:51:33 +1100
commit5b06e73fb1051e9fe370a76ef4fc87e514a1f9e5 (patch)
tree5d512f60e8a75adfb1e17b8e55412cbca3401655 /ctdb
parent5af324a795cec880727545e143274deef9f205c2 (diff)
downloadsamba-5b06e73fb1051e9fe370a76ef4fc87e514a1f9e5.tar.gz
- split up tcp functions into more logical parts
- added upcall methods from transport to ctdb layer (This used to be ctdb commit 59f0dab652000f1c755e59567b03cf84dad7e954)
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/.bzrignore1
-rw-r--r--ctdb/Makefile.in2
-rw-r--r--ctdb/common/ctdb.c50
-rw-r--r--ctdb/include/ctdb_private.h9
-rw-r--r--ctdb/tcp/ctdb_tcp.h11
-rw-r--r--ctdb/tcp/tcp_connect.c (renamed from ctdb/tcp/ctdb_tcp.c)103
-rw-r--r--ctdb/tcp/tcp_init.c84
-rw-r--r--ctdb/tcp/tcp_io.c56
8 files changed, 198 insertions, 118 deletions
diff --git a/ctdb/.bzrignore b/ctdb/.bzrignore
index 71bdda496b6..26fa17de5c7 100644
--- a/ctdb/.bzrignore
+++ b/ctdb/.bzrignore
@@ -5,3 +5,4 @@ common
config.log
push.sh
ctdb_test
+config.cache
diff --git a/ctdb/Makefile.in b/ctdb/Makefile.in
index 0bffc2e04a6..a818a2ce273 100644
--- a/ctdb/Makefile.in
+++ b/ctdb/Makefile.in
@@ -22,7 +22,7 @@ EVENTS_OBJ = lib/events/events.o lib/events/events_standard.o
CTDB_COMMON_OBJ = common/ctdb.o common/util.o
-CTDB_TCP_OBJ = tcp/ctdb_tcp.o
+CTDB_TCP_OBJ = tcp/tcp_connect.o tcp/tcp_io.o tcp/tcp_init.o
CTDB_OBJ = $(CTDB_COMMON_OBJ) $(CTDB_TCP_OBJ)
diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c
index 9d2a6585cfd..fc82e8cf17a 100644
--- a/ctdb/common/ctdb.c
+++ b/ctdb/common/ctdb.c
@@ -24,27 +24,6 @@
#include "system/filesys.h"
#include "ctdb_private.h"
-/*
- initialise the ctdb daemon.
-
- if the ctdb dispatcher daemon has already been started then this
- does nothing. Otherwise it forks the ctdb dispatcher daemon and
- starts the daemons connecting to each other
-
- NOTE: In current code the daemon does not fork. This is for testing purposes only
- and to simplify the code.
-*/
-
-struct ctdb_context *ctdb_init(struct event_context *ev)
-{
- struct ctdb_context *ctdb;
-
- ctdb = talloc_zero(ev, struct ctdb_context);
- ctdb->ev = ev;
-
- return ctdb;
-}
-
const char *ctdb_errstr(struct ctdb_context *ctdb)
{
return ctdb->err_msg;
@@ -212,3 +191,32 @@ bool ctdb_same_address(struct ctdb_address *a1, struct ctdb_address *a2)
return strcmp(a1->address, a2->address) == 0 && a1->port == a2->port;
}
+/*
+ called by the transport layer when a packet comes in
+*/
+static void ctdb_recv_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length)
+{
+ printf("received pkt of length %d\n", length);
+}
+
+static const struct ctdb_upcalls ctdb_upcalls = {
+ .recv_pkt = ctdb_recv_pkt
+};
+
+/*
+ initialise the ctdb daemon.
+
+ NOTE: In current code the daemon does not fork. This is for testing purposes only
+ and to simplify the code.
+*/
+struct ctdb_context *ctdb_init(struct event_context *ev)
+{
+ struct ctdb_context *ctdb;
+
+ ctdb = talloc_zero(ev, struct ctdb_context);
+ ctdb->ev = ev;
+ ctdb->upcalls = &ctdb_upcalls;
+
+ return ctdb;
+}
+
diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h
index 79a60fd8292..bc13c935c5a 100644
--- a/ctdb/include/ctdb_private.h
+++ b/ctdb/include/ctdb_private.h
@@ -53,6 +53,14 @@ struct ctdb_node {
struct ctdb_methods {
int (*start)(struct ctdb_context *); /* start protocol processing */
int (*add_node)(struct ctdb_node *); /* setup a new node */
+ int (*queue_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
+};
+
+/*
+ transport calls up to the ctdb layer
+*/
+struct ctdb_upcalls {
+ void (*recv_pkt)(struct ctdb_node *, uint8_t *data, uint32_t length);
};
/* main state of the ctdb daemon */
@@ -64,6 +72,7 @@ struct ctdb_context {
char *err_msg;
struct tdb_context *ltdb;
const struct ctdb_methods *methods; /* transport methods */
+ const struct ctdb_upcalls *upcalls; /* transport upcalls */
void *private; /* private to transport */
};
diff --git a/ctdb/tcp/ctdb_tcp.h b/ctdb/tcp/ctdb_tcp.h
index 63dab87ebaa..571c20508b4 100644
--- a/ctdb/tcp/ctdb_tcp.h
+++ b/ctdb/tcp/ctdb_tcp.h
@@ -39,3 +39,14 @@ struct ctdb_tcp_node {
int fd;
};
+
+/* prototypes internal to tcp transport */
+void ctdb_tcp_node_read(struct event_context *ev, struct fd_event *fde,
+ uint16_t flags, void *private);
+void ctdb_tcp_incoming_read(struct event_context *ev, struct fd_event *fde,
+ uint16_t flags, void *private);
+int ctdb_tcp_listen(struct ctdb_context *ctdb);
+void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
+ struct timeval t, void *private);
+
+
diff --git a/ctdb/tcp/ctdb_tcp.c b/ctdb/tcp/tcp_connect.c
index 19b48e12e9d..82871465832 100644
--- a/ctdb/tcp/ctdb_tcp.c
+++ b/ctdb/tcp/tcp_connect.c
@@ -26,21 +26,6 @@
#include "ctdb_tcp.h"
/*
- called when socket becomes readable
-*/
-static void ctdb_node_read(struct event_context *ev, struct fd_event *fde,
- uint16_t flags, void *private)
-{
- struct ctdb_node *node = talloc_get_type(private, struct ctdb_node);
- printf("connection to node %s:%u is readable\n",
- node->address.address, node->address.port);
- event_set_fd_flags(fde, 0);
-}
-
-static void ctdb_node_connect(struct event_context *ev, struct timed_event *te,
- struct timeval t, void *private);
-
-/*
called when socket becomes writeable on connect
*/
static void ctdb_node_connect_write(struct event_context *ev, struct fd_event *fde,
@@ -64,7 +49,7 @@ static void ctdb_node_connect_write(struct event_context *ev, struct fd_event *f
close(tnode->fd);
tnode->fd = -1;
event_add_timed(ctdb->ev, node, timeval_current_ofs(1, 0),
- ctdb_node_connect, node);
+ ctdb_tcp_node_connect, node);
return;
}
@@ -72,14 +57,14 @@ static void ctdb_node_connect_write(struct event_context *ev, struct fd_event *f
node->address.address, node->address.port);
talloc_free(fde);
event_add_fd(node->ctdb->ev, node, tnode->fd, EVENT_FD_READ,
- ctdb_node_read, node);
+ ctdb_tcp_node_read, node);
}
/*
called when we should try and establish a tcp connection to a node
*/
-static void ctdb_node_connect(struct event_context *ev, struct timed_event *te,
- struct timeval t, void *private)
+void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te,
+ struct timeval t, void *private)
{
struct ctdb_node *node = talloc_get_type(private, struct ctdb_node);
struct ctdb_tcp_node *tnode = talloc_get_type(node->private,
@@ -102,7 +87,7 @@ static void ctdb_node_connect(struct event_context *ev, struct timed_event *te,
/* try again once a second */
close(tnode->fd);
event_add_timed(ctdb->ev, node, timeval_current_ofs(1, 0),
- ctdb_node_connect, node);
+ ctdb_tcp_node_connect, node);
return;
}
@@ -112,23 +97,6 @@ static void ctdb_node_connect(struct event_context *ev, struct timed_event *te,
}
/*
- called when an incoming connection is readable
-*/
-static void ctdb_incoming_read(struct event_context *ev, struct fd_event *fde,
- uint16_t flags, void *private)
-{
- struct ctdb_incoming *in = talloc_get_type(private, struct ctdb_incoming);
- char c;
- printf("Incoming data\n");
- if (read(in->fd, &c, 1) <= 0) {
- /* socket is dead */
- close(in->fd);
- talloc_free(in);
- }
-}
-
-
-/*
called when we get contacted by another node
currently makes no attempt to check if the connection is really from a ctdb
node in our cluster
@@ -155,7 +123,7 @@ static void ctdb_listen_event(struct event_context *ev, struct fd_event *fde,
in->ctdb = ctdb;
event_add_fd(ctdb->ev, in, in->fd, EVENT_FD_READ,
- ctdb_incoming_read, in);
+ ctdb_tcp_incoming_read, in);
printf("New incoming socket %d\n", in->fd);
}
@@ -164,7 +132,7 @@ static void ctdb_listen_event(struct event_context *ev, struct fd_event *fde,
/*
listen on our own address
*/
-static int ctdb_listen(struct ctdb_context *ctdb)
+int ctdb_tcp_listen(struct ctdb_context *ctdb)
{
struct ctdb_tcp *ctcp = talloc_get_type(ctdb->private, struct ctdb_tcp);
struct sockaddr_in sock;
@@ -202,60 +170,3 @@ static int ctdb_listen(struct ctdb_context *ctdb)
return 0;
}
-/*
- start the protocol going
-*/
-int ctdb_tcp_start(struct ctdb_context *ctdb)
-{
- struct ctdb_node *node;
-
- /* listen on our own address */
- if (ctdb_listen(ctdb) != 0) return -1;
-
- /* startup connections to the other servers - will happen on
- next event loop */
- for (node=ctdb->nodes;node;node=node->next) {
- if (ctdb_same_address(&ctdb->address, &node->address)) continue;
- event_add_timed(ctdb->ev, node, timeval_zero(),
- ctdb_node_connect, node);
- }
-
- return 0;
-}
-
-
-/*
- initialise tcp portion of a ctdb node
-*/
-int ctdb_tcp_add_node(struct ctdb_node *node)
-{
- struct ctdb_tcp_node *tnode;
- tnode = talloc_zero(node, struct ctdb_tcp_node);
- CTDB_NO_MEMORY(node->ctdb, tnode);
-
- tnode->fd = -1;
- node->private = tnode;
- return 0;
-}
-
-
-static const struct ctdb_methods ctdb_tcp_methods = {
- .start = ctdb_tcp_start,
- .add_node = ctdb_tcp_add_node
-};
-
-/*
- initialise tcp portion of ctdb
-*/
-int ctdb_tcp_init(struct ctdb_context *ctdb)
-{
- struct ctdb_tcp *ctcp;
- ctcp = talloc_zero(ctdb, struct ctdb_tcp);
- CTDB_NO_MEMORY(ctdb, ctcp);
-
- ctcp->listen_fd = -1;
- ctdb->private = ctcp;
- ctdb->methods = &ctdb_tcp_methods;
- return 0;
-}
-
diff --git a/ctdb/tcp/tcp_init.c b/ctdb/tcp/tcp_init.c
new file mode 100644
index 00000000000..d3ca1e581de
--- /dev/null
+++ b/ctdb/tcp/tcp_init.c
@@ -0,0 +1,84 @@
+/*
+ ctdb over TCP
+
+ Copyright (C) Andrew Tridgell 2006
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "includes.h"
+#include "lib/events/events.h"
+#include "system/network.h"
+#include "system/filesys.h"
+#include "ctdb_private.h"
+#include "ctdb_tcp.h"
+
+/*
+ start the protocol going
+*/
+int ctdb_tcp_start(struct ctdb_context *ctdb)
+{
+ struct ctdb_node *node;
+
+ /* listen on our own address */
+ if (ctdb_tcp_listen(ctdb) != 0) return -1;
+
+ /* startup connections to the other servers - will happen on
+ next event loop */
+ for (node=ctdb->nodes;node;node=node->next) {
+ if (ctdb_same_address(&ctdb->address, &node->address)) continue;
+ event_add_timed(ctdb->ev, node, timeval_zero(),
+ ctdb_tcp_node_connect, node);
+ }
+
+ return 0;
+}
+
+
+/*
+ initialise tcp portion of a ctdb node
+*/
+int ctdb_tcp_add_node(struct ctdb_node *node)
+{
+ struct ctdb_tcp_node *tnode;
+ tnode = talloc_zero(node, struct ctdb_tcp_node);
+ CTDB_NO_MEMORY(node->ctdb, tnode);
+
+ tnode->fd = -1;
+ node->private = tnode;
+ return 0;
+}
+
+
+static const struct ctdb_methods ctdb_tcp_methods = {
+ .start = ctdb_tcp_start,
+ .add_node = ctdb_tcp_add_node
+};
+
+/*
+ initialise tcp portion of ctdb
+*/
+int ctdb_tcp_init(struct ctdb_context *ctdb)
+{
+ struct ctdb_tcp *ctcp;
+ ctcp = talloc_zero(ctdb, struct ctdb_tcp);
+ CTDB_NO_MEMORY(ctdb, ctcp);
+
+ ctcp->listen_fd = -1;
+ ctdb->private = ctcp;
+ ctdb->methods = &ctdb_tcp_methods;
+ return 0;
+}
+
diff --git a/ctdb/tcp/tcp_io.c b/ctdb/tcp/tcp_io.c
new file mode 100644
index 00000000000..d522472cb18
--- /dev/null
+++ b/ctdb/tcp/tcp_io.c
@@ -0,0 +1,56 @@
+/*
+ ctdb over TCP
+
+ Copyright (C) Andrew Tridgell 2006
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with this library; if not, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+#include "includes.h"
+#include "lib/events/events.h"
+#include "system/network.h"
+#include "system/filesys.h"
+#include "ctdb_private.h"
+#include "ctdb_tcp.h"
+
+/*
+ called when socket becomes readable
+*/
+void ctdb_tcp_node_read(struct event_context *ev, struct fd_event *fde,
+ uint16_t flags, void *private)
+{
+ struct ctdb_node *node = talloc_get_type(private, struct ctdb_node);
+ printf("connection to node %s:%u is readable\n",
+ node->address.address, node->address.port);
+ event_set_fd_flags(fde, 0);
+}
+
+
+/*
+ called when an incoming connection is readable
+*/
+void ctdb_tcp_incoming_read(struct event_context *ev, struct fd_event *fde,
+ uint16_t flags, void *private)
+{
+ struct ctdb_incoming *in = talloc_get_type(private, struct ctdb_incoming);
+ char c;
+ printf("Incoming data\n");
+ if (read(in->fd, &c, 1) <= 0) {
+ /* socket is dead */
+ close(in->fd);
+ talloc_free(in);
+ }
+}
+