config.log
push.sh
ctdb_test
+config.cache
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)
#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;
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;
+}
+
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 */
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 */
};
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);
+
+
#include "ctdb_private.h"
#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
*/
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;
}
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,
/* 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;
}
ctdb_node_connect_write, node);
}
-/*
- 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
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);
}
/*
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;
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;
-}
-
--- /dev/null
+/*
+ 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;
+}
+
--- /dev/null
+/*
+ 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);
+ }
+}
+