mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
- split up tcp functions into more logical parts
- added upcall methods from transport to ctdb layer (This used to be ctdb commit 59f0dab652000f1c755e59567b03cf84dad7e954)
This commit is contained in:
parent
5af324a795
commit
5b06e73fb1
@ -5,3 +5,4 @@ common
|
||||
config.log
|
||||
push.sh
|
||||
ctdb_test
|
||||
config.cache
|
||||
|
@ -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)
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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 */
|
||||
};
|
||||
|
||||
|
@ -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);
|
||||
|
||||
|
||||
|
@ -25,21 +25,6 @@
|
||||
#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
|
||||
*/
|
||||
@ -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;
|
||||
}
|
||||
|
||||
@ -111,23 +96,6 @@ static void ctdb_node_connect(struct event_context *ev, struct timed_event *te,
|
||||
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
|
||||
@ -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;
|
||||
}
|
||||
|
84
ctdb/tcp/tcp_init.c
Normal file
84
ctdb/tcp/tcp_init.c
Normal file
@ -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;
|
||||
}
|
||||
|
56
ctdb/tcp/tcp_io.c
Normal file
56
ctdb/tcp/tcp_io.c
Normal file
@ -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);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user