diff options
author | Peter Somogyi <psomogyi@gamax.hu> | 2007-04-20 14:26:19 +0200 |
---|---|---|
committer | Peter Somogyi <psomogyi@gamax.hu> | 2007-04-20 14:26:19 +0200 |
commit | e5f2e5e5eb56c390c68c1ac79a32fb068510fc41 (patch) | |
tree | 2051f1374b1a9743cbdd3643c84d6ee1d89ea376 | |
parent | c950e5285830eb14f0fced820bbb2ad8927c5421 (diff) | |
download | samba-e5f2e5e5eb56c390c68c1ac79a32fb068510fc41.tar.gz samba-e5f2e5e5eb56c390c68c1ac79a32fb068510fc41.tar.xz samba-e5f2e5e5eb56c390c68c1ac79a32fb068510fc41.zip |
- ctdb/ib minor bugfixes (error case)
- make ctdb capable of alternative connection (like ib) again, solved the fork problem
- do_debug memory overwrite bugfix (occured using ibwrapper_test with wrong address given)
(This used to be ctdb commit da0b84cda26d544f63841dfd770ed7ebad401944)
-rw-r--r-- | ctdb/common/ctdb.c | 40 | ||||
-rw-r--r-- | ctdb/common/ctdb_client.c | 5 | ||||
-rw-r--r-- | ctdb/common/ctdb_daemon.c | 11 | ||||
-rw-r--r-- | ctdb/ib/ibwrapper.c | 8 | ||||
-rw-r--r-- | ctdb/include/ctdb.h | 6 | ||||
-rw-r--r-- | ctdb/include/ctdb_private.h | 6 | ||||
-rw-r--r-- | ctdb/lib/util/debug.c | 18 | ||||
-rw-r--r-- | ctdb/tests/ctdb_bench.c | 4 |
8 files changed, 80 insertions, 18 deletions
diff --git a/ctdb/common/ctdb.c b/ctdb/common/ctdb.c index 960d99011f..34f753a84d 100644 --- a/ctdb/common/ctdb.c +++ b/ctdb/common/ctdb.c @@ -31,22 +31,45 @@ */ 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; } /* @@ -116,11 +139,6 @@ static int ctdb_add_node(struct ctdb_context *ctdb, char *nstr) 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; } diff --git a/ctdb/common/ctdb_client.c b/ctdb/common/ctdb_client.c index f09894b555..f7dbc230db 100644 --- a/ctdb/common/ctdb_client.c +++ b/ctdb/common/ctdb_client.c @@ -373,7 +373,10 @@ int ctdb_set_message_handler(struct ctdb_context *ctdb, uint32_t srvid, /* 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); diff --git a/ctdb/common/ctdb_daemon.c b/ctdb/common/ctdb_daemon.c index 6c11c7b730..87539dc6c6 100644 --- a/ctdb/common/ctdb_daemon.c +++ b/ctdb/common/ctdb_daemon.c @@ -44,6 +44,11 @@ static void daemon_incoming_packet(void *, uint8_t *, uint32_t ); 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 */ @@ -594,6 +599,12 @@ int ctdb_start(struct ctdb_context *ctdb) 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; } diff --git a/ctdb/ib/ibwrapper.c b/ctdb/ib/ibwrapper.c index f7b233954d..908d38d584 100644 --- a/ctdb/ib/ibwrapper.c +++ b/ctdb/ib/ibwrapper.c @@ -557,17 +557,17 @@ static void ibw_event_handler_cm(struct event_context *ev, 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); diff --git a/ctdb/include/ctdb.h b/ctdb/include/ctdb.h index 997bdc6e13..7c4e6d25f7 100644 --- a/ctdb/include/ctdb.h +++ b/ctdb/include/ctdb.h @@ -71,6 +71,12 @@ struct ctdb_context *ctdb_init(struct event_context *ev); 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 */ int ctdb_set_tdb_dir(struct ctdb_context *ctdb, const char *dir); diff --git a/ctdb/include/ctdb_private.h b/ctdb/include/ctdb_private.h index 2f42cfb88a..cf6d24cc41 100644 --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@ -120,6 +120,7 @@ struct ctdb_context { 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; @@ -363,6 +364,11 @@ struct ctdb_call_state *ctdbd_call_send(struct ctdb_db_context *ctdb_db, struct 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 */ int ctdb_queue_send(struct ctdb_queue *queue, uint8_t *data, uint32_t length); diff --git a/ctdb/lib/util/debug.c b/ctdb/lib/util/debug.c index a3229015ca..ffe1dcc382 100644 --- a/ctdb/lib/util/debug.c +++ b/ctdb/lib/util/debug.c @@ -22,6 +22,22 @@ #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; @@ -29,7 +45,7 @@ void do_debug(const char *format, ...) char *s = NULL; va_start(ap, format); - vasprintf(&s, format, ap); + vasprintf2(&s, format, ap); va_end(ap); gettimeofday(&tm, NULL); diff --git a/ctdb/tests/ctdb_bench.c b/ctdb/tests/ctdb_bench.c index 02fcc1f2d4..ead3184157 100644 --- a/ctdb/tests/ctdb_bench.c +++ b/ctdb/tests/ctdb_bench.c @@ -204,7 +204,8 @@ int main(int argc, const char *argv[]) /* 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) */ @@ -212,6 +213,7 @@ int main(int argc, const char *argv[]) bench_ring(ctdb, ev); +error: /* shut it down */ ctdb_shutdown(ctdb); |