From: Andrew Tridgell Date: Thu, 26 Apr 2007 13:28:13 +0000 (+0200) Subject: merge from peter X-Git-Tag: tevent-0.9.20~348^2~2842 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=c23d1694db4e19a7349300ed475bf5f7688c522b;p=thirdparty%2Fsamba.git merge from peter (This used to be ctdb commit ddf390da2bceb5b3f431433aec424d99d98c05f4) --- c23d1694db4e19a7349300ed475bf5f7688c522b diff --cc ctdb/common/ctdb.c index d7e4241250d,fb12193a06a..56c621fd7e7 --- a/ctdb/common/ctdb.c +++ b/ctdb/common/ctdb.c @@@ -31,24 -31,43 +31,11 @@@ */ int ctdb_set_transport(struct ctdb_context *ctdb, const char *transport) { - int ctdb_tcp_init(struct ctdb_context *ctdb); - #ifdef USE_INFINIBAND - int ctdb_ibw_init(struct ctdb_context *ctdb); - #endif /* USE_INFINIBAND */ - - if (strcmp(transport, "tcp") == 0) { - return ctdb_tcp_init(ctdb); - } - #ifdef USE_INFINIBAND - if (strcmp(transport, "ib") == 0) { - return ctdb_ibw_init(ctdb); - } - #endif /* USE_INFINIBAND */ - - ctdb_set_error(ctdb, "Unknown transport '%s'\n", transport); - return -1; + 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); -#ifdef USE_INFINIBAND - int ctdb_ibw_init(struct ctdb_context *ctdb); -#endif /* USE_INFINIBAND */ - - if (strcmp(ctdb->transport, "tcp") == 0) { - if (ctdb_tcp_init(ctdb)) - return -1; - } -#ifdef USE_INFINIBAND - else if (strcmp(ctdb->transport, "ib") == 0) { - if (ctdb_ibw_init(ctdb)) - return -1; - } -#endif /* USE_INFINIBAND */ - else { - ctdb_set_error(ctdb, "Unknown transport '%s'\n", ctdb->transport); - return -1; - } - - for(i=0; inum_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; -} + /* set some ctdb flags */ diff --cc ctdb/common/ctdb_daemon.c index efb3f5431ec,0ec201d29fb..053c5af6dd1 --- a/ctdb/common/ctdb_daemon.c +++ b/ctdb/common/ctdb_daemon.c @@@ -44,6 -44,11 +44,24 @@@ static void daemon_incoming_packet(voi 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); ++ int ret = -1; ++ ++ if (strcmp(ctdb->transport, "tcp") == 0) { ++ int ctdb_tcp_init(struct ctdb_context *); ++ ret = ctdb_tcp_init(ctdb); ++ } ++#ifdef USE_INFINBAND ++ if (strcmp(ctdb->transport, "ib") == 0) { ++ int ctdb_ibw_init(struct ctdb_context *); ++ ret = ctdb_ibw_init(ctdb); ++ } ++#endif ++ if (ret != 0) { ++ DEBUG(0,("Failed to initialise transport '%s'\n", ctdb->transport)); ++ return; + } + ++ /* start the transport running */ ctdb->methods->start(ctdb); /* go into a wait loop to allow other nodes to complete */ diff --cc ctdb/ib/ibw_ctdb_init.c index b4adfe6f124,b4adfe6f124..c8f9e97feb7 --- a/ctdb/ib/ibw_ctdb_init.c +++ b/ctdb/ib/ibw_ctdb_init.c @@@ -53,12 -53,12 +53,39 @@@ static int ctdb_ibw_listen(struct ctdb_ return 0; } ++/* ++ * initialise ibw portion of a ctdb node ++ */ ++static int ctdb_ibw_add_node(struct ctdb_node *node) ++{ ++ struct ibw_ctx *ictx = talloc_get_type(node->ctdb->private_data, struct ibw_ctx); ++ struct ctdb_ibw_node *cn = talloc_zero(node, struct ctdb_ibw_node); ++ ++ assert(cn!=NULL); ++ cn->conn = ibw_conn_new(ictx, node); ++ node->private_data = (void *)cn; ++ ++ return (cn->conn!=NULL ? 0 : -1); ++} ++ /* * Start infiniband */ static int ctdb_ibw_start(struct ctdb_context *ctdb) { -- int i; ++ int i, ret; ++ ++ ret = ctdb_ibw_init(ctdb); ++ if (ret != 0) { ++ return ret; ++ } ++ ++ for (i=0; inum_nodes; i++) { ++ if (ctdb_ibw_add_node(ctdb->nodes[i]) != 0) { ++ DEBUG(0, ("methods->add_node failed at %d\n", i)); ++ return -1; ++ } ++ } /* listen on our own address */ if (ctdb_ibw_listen(ctdb, 10)) /* TODO: backlog as param */ @@@ -76,21 -76,21 +103,6 @@@ return 0; } --/* -- * initialise ibw portion of a ctdb node -- */ --static int ctdb_ibw_add_node(struct ctdb_node *node) --{ -- struct ibw_ctx *ictx = talloc_get_type(node->ctdb->private_data, struct ibw_ctx); -- struct ctdb_ibw_node *cn = talloc_zero(node, struct ctdb_ibw_node); -- -- assert(cn!=NULL); -- cn->conn = ibw_conn_new(ictx, node); -- node->private_data = (void *)cn; -- -- return (cn->conn!=NULL ? 0 : -1); --} -- static int ctdb_ibw_send_pkt(struct ibw_conn *conn, uint8_t *data, uint32_t length) { void *buf, *key; @@@ -178,8 -178,8 +190,8 @@@ static int ctdb_ibw_stop(struct ctdb_co static const struct ctdb_methods ctdb_ibw_methods = { .start = ctdb_ibw_start, -- .add_node = ctdb_ibw_add_node, .queue_pkt = ctdb_ibw_queue_pkt, ++ .add_node = ctdb_ibw_add_node, .allocate_pkt = ctdb_ibw_allocate_pkt, // .stop = ctdb_ibw_stop diff --cc ctdb/include/ctdb_private.h index ee8118a750e,9f006528dd8..88aa209d9ad --- a/ctdb/include/ctdb_private.h +++ b/ctdb/include/ctdb_private.h @@@ -162,6 -162,7 +162,7 @@@ struct ctdb_context struct ctdb_address address; const char *name; const char *db_directory; - char *transport; ++ const char *transport; uint32_t vnn; /* our own vnn */ uint32_t num_nodes; uint32_t num_connected; diff --cc ctdb/tcp/tcp_init.c index 9b54bb75baf,9b54bb75baf..35b43bd5e29 --- a/ctdb/tcp/tcp_init.c +++ b/ctdb/tcp/tcp_init.c @@@ -26,6 -26,6 +26,25 @@@ #include "../include/ctdb_private.h" #include "ctdb_tcp.h" ++ ++/* ++ initialise tcp portion of a ctdb node ++*/ ++static 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_data = tnode; ++ ++ tnode->queue = ctdb_queue_setup(node->ctdb, node, tnode->fd, CTDB_TCP_ALIGNMENT, ++ ctdb_tcp_tnode_cb, node); ++ ++ return 0; ++} ++ /* start the protocol going */ @@@ -33,6 -33,6 +52,13 @@@ static int ctdb_tcp_start(struct ctdb_c { int i; ++ for (i=0; inum_nodes; i++) { ++ if (ctdb_tcp_add_node(ctdb->nodes[i]) != 0) { ++ DEBUG(0, ("methods->add_node failed at %d\n", i)); ++ return -1; ++ } ++ } ++ /* listen on our own address */ if (ctdb_tcp_listen(ctdb) != 0) return -1; @@@ -50,25 -50,25 +76,6 @@@ } --/* -- initialise tcp portion of a ctdb node --*/ --static 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_data = tnode; -- -- tnode->queue = ctdb_queue_setup(node->ctdb, node, tnode->fd, CTDB_TCP_ALIGNMENT, -- ctdb_tcp_tnode_cb, node); -- -- return 0; --} -- -- /* transport packet allocator - allows transport to control memory for packets */ @@@ -83,9 -83,9 +90,9 @@@ static void *ctdb_tcp_allocate_pkt(TALL static const struct ctdb_methods ctdb_tcp_methods = { -- .start = ctdb_tcp_start, -- .add_node = ctdb_tcp_add_node, -- .queue_pkt = ctdb_tcp_queue_pkt, ++ .start = ctdb_tcp_start, ++ .queue_pkt = ctdb_tcp_queue_pkt, ++ .add_node = ctdb_tcp_add_node, .allocate_pkt = ctdb_tcp_allocate_pkt };