*/
int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport)
{
+ ctdb->transport = talloc_strdup(ctdb, transport);
+ return 0;
+}
+
+int ctdb_init_transport(struct ctdb_context *ctdb)
+{
+ int i;
int ctdb_tcp_init(struct ctdb_context *ctdb);
+ int transport_found = 0;
#ifdef USE_INFINIBAND
int ctdb_ibw_init(struct ctdb_context *ctdb);
#endif /* USE_INFINIBAND */
- if (strcmp(transport, "tcp") == 0) {
- return ctdb_tcp_init(ctdb);
+ if (strcmp(ctdb->transport, "tcp") == 0) {
+ transport_found = 1;
+ if (ctdb_tcp_init(ctdb))
+ return -1;
}
#ifdef USE_INFINIBAND
- if (strcmp(transport, "ib") == 0) {
- return ctdb_ibw_init(ctdb);
+ else if (strcmp(ctdb->transport, "ib") == 0) {
+ transport_found = 1;
+ if (ctdb_ibw_init(ctdb))
+ return -1;
}
#endif /* USE_INFINIBAND */
- ctdb_set_error(ctdb, "Unknown transport '%s'\n", transport);
- return -1;
+ if (!transport_found) {
+ ctdb_set_error(ctdb, "Unknown transport '%s'\n", ctdb->transport);
+ return -1;
+ }
+
+ for(i=0; i<ctdb->num_nodes; i++) {
+ if (ctdb->methods->add_node(ctdb->nodes[i]) != 0) {
+ DEBUG(0, ("methods->add_node failed at %d\n", i));
+ return -1;
+ }
+ }
+
+ return 0;
}
/*
will change! */
node->vnn = ctdb->num_nodes;
- if (ctdb->methods->add_node(node) != 0) {
- talloc_free(node);
- return -1;
- }
-
if (ctdb_same_address(&ctdb->address, &node->address)) {
ctdb->vnn = node->vnn;
}
/* if the domain socket is not yet open, open it */
if (ctdb->daemon.sd==-1) {
- ux_socket_connect(ctdb);
+ if (ux_socket_connect(ctdb)) {
+ DEBUG(0, ("ux_socket_connect failed\n"));
+ return -1;
+ }
}
ZERO_STRUCT(c);
static void ctdb_main_loop(struct ctdb_context *ctdb)
{
+ /* we are the dispatcher process now, so start the protocol going */
+ if (ctdb_init_transport(ctdb)) {
+ exit(1);
+ }
+
ctdb->methods->start(ctdb);
/* go into a wait loop to allow other nodes to complete */
close(fd[0]);
close(ctdb->daemon.sd);
ctdb->daemon.sd = -1;
+
+ /* Added because of ctdb->methods->allocate_pkt calls */
+ /* TODO: clean */
+ int ctdb_tcp_init(struct ctdb_context *ctdb);
+ ctdb_tcp_init(ctdb);
+
return 0;
}
return;
error:
if (event!=NULL && (rc=rdma_ack_cm_event(event))) {
- sprintf(ibw_lasterr, "rdma_ack_cm_event failed with %d\n", rc);
- goto error;
+ DEBUG(0, ("rdma_ack_cm_event failed with %d\n", rc));
}
DEBUG(0, ("cm event handler: %s", ibw_lasterr));
if (cma_id!=pctx->cm_id) {
conn = talloc_get_type(cma_id->context, struct ibw_conn);
- if (conn)
+ if (conn) {
conn->state = IBWC_ERROR;
- pctx->connstate_func(NULL, conn);
+ pctx->connstate_func(NULL, conn);
+ }
} else {
ctx->state = IBWS_ERROR;
pctx->connstate_func(ctx, NULL);
*/
int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport);
+/*
+ initialize the chosen transport
+ do this in the process where it is going to be used
+ */
+int ctdb_init_transport(struct ctdb_context *ctdb);
+
/*
set the directory for the local databases
*/
struct ctdb_address address;
const char *name;
const char *db_directory;
+ char *transport;
uint32_t vnn; /* our own vnn */
uint32_t num_nodes;
uint32_t num_connected;
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);
+/*
+ allocate a packet for sending via queue
+*/
+void *ctdb_queue_allocate_pkt(TALLOC_CTX *mem_ctx, size_t size);
+
/*
queue a packet for sending
*/
#include "system/time.h"
#include <unistd.h>
+static int vasprintf2(char **ptr, const char *format, va_list ap)
+{
+ int ret;
+ va_list tmp_ap;
+
+ va_copy(tmp_ap, ap);
+ ret = vsnprintf(NULL, 0, format, tmp_ap);
+ if (ret <= 0) return ret;
+
+ (*ptr) = (char *)malloc(ret+1);
+ if (!*ptr) return -1;
+ ret = vsnprintf(*ptr, ret+1, format, ap);
+
+ return ret;
+}
+
void do_debug(const char *format, ...)
{
struct timeval tm;
char *s = NULL;
va_start(ap, format);
- vasprintf(&s, format, ap);
+ vasprintf2(&s, format, ap);
va_end(ap);
gettimeofday(&tm, NULL);
/* start the protocol running */
ret = ctdb_start(ctdb);
- ctdb_set_message_handler(ctdb, 0, ring_message_handler,&msg_count);
+ if (ctdb_set_message_handler(ctdb, 0, ring_message_handler,&msg_count))
+ goto error;
/* wait until all nodes are connected (should not be needed
outside of test code) */
bench_ring(ctdb, ev);
+error:
/* shut it down */
ctdb_shutdown(ctdb);