From c9f04d8648cfdd573d45d47467bc964ef01f754d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 16 Apr 2007 00:18:54 +0000 Subject: r22231: merge from bzr ctdb tree (This used to be commit 807b959082d3b9a929c9f6597714e636638a940e) --- source4/cluster/ctdb/ib/ibw_ctdb_init.c | 214 ++++++++++++++++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 source4/cluster/ctdb/ib/ibw_ctdb_init.c (limited to 'source4/cluster/ctdb/ib/ibw_ctdb_init.c') diff --git a/source4/cluster/ctdb/ib/ibw_ctdb_init.c b/source4/cluster/ctdb/ib/ibw_ctdb_init.c new file mode 100644 index 0000000000..3b0c6ad28f --- /dev/null +++ b/source4/cluster/ctdb/ib/ibw_ctdb_init.c @@ -0,0 +1,214 @@ +/* + * Unix SMB/CIFS implementation. + * Join infiniband wrapper and ctdb. + * + * Copyright (C) Sven Oehme 2006 + * + * Major code contributions by Peter Somogyi + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include "includes.h" +#include "lib/events/events.h" +#include +#include +#include "ctdb_private.h" +#include "ibwrapper.h" +#include "ibw_ctdb.h" + +static int ctdb_ibw_listen(struct ctdb_context *ctdb, int backlog) +{ + struct ibw_ctx *ictx = talloc_get_type(ctdb->private_data, struct ibw_ctx); + struct sockaddr_in my_addr; + + assert(ictx!=NULL); + memset(&my_addr, 0, sizeof(struct sockaddr_in)); + my_addr.sin_port = htons(ctdb->address.port); + my_addr.sin_family = PF_INET; + inet_pton(AF_INET, ctdb->address.address, &my_addr.sin_addr); + + if (ibw_bind(ictx, &my_addr)) { + DEBUG(0, ("ctdb_ibw_listen: ibw_bind failed\n")); + return -1; + } + + if (ibw_listen(ictx, backlog)) { + DEBUG(0, ("ctdb_ibw_listen: ibw_listen failed\n")); + return -1; + } + + return 0; +} + +/* + * Start infiniband + */ +static int ctdb_ibw_start(struct ctdb_context *ctdb) +{ + int i; + + /* listen on our own address */ + if (ctdb_ibw_listen(ctdb, 10)) /* TODO: backlog as param */ + return -1; + + /* everything async here */ + for (i=0;inum_nodes;i++) { + struct ctdb_node *node = ctdb->nodes[i]; + if (!(ctdb->flags & CTDB_FLAG_SELF_CONNECT) && + ctdb_same_address(&ctdb->address, &node->address)) + continue; + ctdb_ibw_node_connect(node); + } + + 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; + + if (ibw_alloc_send_buf(conn, &buf, &key, length)) { + DEBUG(0, ("queue_pkt/ibw_alloc_send_buf failed\n")); + return -1; + } + + memcpy(buf, data, length); + return ibw_send(conn, buf, key, length); +} + +int ctdb_flush_cn_queue(struct ctdb_ibw_node *cn) +{ + struct ctdb_ibw_msg *p; + int rc = 0; + + while(cn->queue) { + p = cn->queue; + rc = ctdb_ibw_send_pkt(cn->conn, p->data, p->length); + if (rc) + return -1; /* will be retried later when conn is up */ + + DLIST_REMOVE(cn->queue, p); + cn->qcnt--; + talloc_free(p); /* it will talloc_free p->data as well */ + } + assert(cn->qcnt==0); + /* cn->queue_last = NULL is not needed - see DLIST_ADD_AFTER */ + + return rc; +} + +static int ctdb_ibw_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length) +{ + struct ctdb_ibw_node *cn = talloc_get_type(node->private_data, struct ctdb_ibw_node); + int rc; + + assert(length>=sizeof(uint32_t)); + assert(cn!=NULL); + + if (cn->conn==NULL) { + DEBUG(0, ("ctdb_ibw_queue_pkt: conn is NULL\n")); + return -1; + } + + if (cn->conn->state==IBWC_CONNECTED) { + rc = ctdb_ibw_send_pkt(cn->conn, data, length); + } else { + struct ctdb_ibw_msg *p = talloc_zero(cn, struct ctdb_ibw_msg); + p->data = talloc_memdup(p, data, length); + p->length = length; + + DLIST_ADD_AFTER(cn->queue, p, cn->queue_last); + cn->queue_last = p; + cn->qcnt++; + + rc = 0; + } + + return rc; +} + +/* + * transport packet allocator - allows transport to control memory for packets + */ +static void *ctdb_ibw_allocate_pkt(struct ctdb_context *ctdb, size_t size) +{ + /* TODO: use ibw_alloc_send_buf instead... */ + return talloc_size(ctdb, size); +} + +#ifdef __NOTDEF__ + +static int ctdb_ibw_stop(struct ctdb_context *cctx) +{ + struct ibw_ctx *ictx = talloc_get_type(cctx->private_data, struct ibw_ctx); + + assert(ictx!=NULL); + return ibw_stop(ictx); +} + +#endif /* __NOTDEF__ */ + +static const struct ctdb_methods ctdb_ibw_methods = { + .start = ctdb_ibw_start, + .add_node = ctdb_ibw_add_node, + .queue_pkt = ctdb_ibw_queue_pkt, + .allocate_pkt = ctdb_ibw_allocate_pkt, + +// .stop = ctdb_ibw_stop +}; + +/* + * initialise ibw portion of ctdb + */ +int ctdb_ibw_init(struct ctdb_context *ctdb) +{ + struct ibw_ctx *ictx; + + DEBUG(10, ("ctdb_ibw_init invoked...\n")); + ictx = ibw_init( + NULL, //struct ibw_initattr *attr, /* TODO */ + 0, //int nattr, /* TODO */ + ctdb, + ctdb_ibw_connstate_handler, + ctdb_ibw_receive_handler, + ctdb->ev); + + if (ictx==NULL) { + DEBUG(0, ("ctdb_ibw_init: ibw_init failed\n")); + return -1; + } + + ctdb->methods = &ctdb_ibw_methods; + ctdb->private_data = ictx; + + DEBUG(10, ("ctdb_ibw_init succeeded.\n")); + return 0; +} -- cgit From 650d81b252cc669ef848448afad7e9bb79c4f20e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 21 Apr 2007 07:23:42 +0000 Subject: r22421: merged in latest ctdb changes from bzr (This used to be commit 3633f862b966866819c9a0a6ad0238a858e15e62) --- source4/cluster/ctdb/ib/ibw_ctdb_init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/cluster/ctdb/ib/ibw_ctdb_init.c') diff --git a/source4/cluster/ctdb/ib/ibw_ctdb_init.c b/source4/cluster/ctdb/ib/ibw_ctdb_init.c index 3b0c6ad28f..b4adfe6f12 100644 --- a/source4/cluster/ctdb/ib/ibw_ctdb_init.c +++ b/source4/cluster/ctdb/ib/ibw_ctdb_init.c @@ -158,10 +158,10 @@ static int ctdb_ibw_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t le /* * transport packet allocator - allows transport to control memory for packets */ -static void *ctdb_ibw_allocate_pkt(struct ctdb_context *ctdb, size_t size) +static void *ctdb_ibw_allocate_pkt(TALLOC_CTX *mem_ctx, size_t size) { /* TODO: use ibw_alloc_send_buf instead... */ - return talloc_size(ctdb, size); + return talloc_size(mem_ctx, size); } #ifdef __NOTDEF__ -- cgit From b8d69a7ea2505b706ff7c74d7c97bc89d82dfa07 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:46:15 +0000 Subject: r23795: more v2->v3 conversion (This used to be commit 84b468b2f8f2dffda89593f816e8bc6a8b6d42ac) --- source4/cluster/ctdb/ib/ibw_ctdb_init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/cluster/ctdb/ib/ibw_ctdb_init.c') diff --git a/source4/cluster/ctdb/ib/ibw_ctdb_init.c b/source4/cluster/ctdb/ib/ibw_ctdb_init.c index b4adfe6f12..0812ef1a29 100644 --- a/source4/cluster/ctdb/ib/ibw_ctdb_init.c +++ b/source4/cluster/ctdb/ib/ibw_ctdb_init.c @@ -8,7 +8,7 @@ * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or + * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, -- cgit From cd1217ff5ff18e53c6c9fa3d4f4fd56193fe2a17 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 05:23:25 +0000 Subject: r23801: The FSF has moved around a lot. This fixes their Mass Ave address. (This used to be commit 5c9b19271e0e3ad897499707003ce4703ffa4870) --- source4/cluster/ctdb/ib/ibw_ctdb_init.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source4/cluster/ctdb/ib/ibw_ctdb_init.c') diff --git a/source4/cluster/ctdb/ib/ibw_ctdb_init.c b/source4/cluster/ctdb/ib/ibw_ctdb_init.c index 0812ef1a29..523a02c4df 100644 --- a/source4/cluster/ctdb/ib/ibw_ctdb_init.c +++ b/source4/cluster/ctdb/ib/ibw_ctdb_init.c @@ -17,8 +17,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + * along with this program; if not, see . */ #include "includes.h" -- cgit From 6504900f1f52927adab3489b8d04b6644ceaee7d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 08:06:51 +0000 Subject: r23806: update Samba4 with the latest ctdb code. This doesn't get the ctdb code fully working in Samba4, it just gets it building and not breaking non-clustered use of Samba. It will take a bit longer to update some of the calling ctdb_cluster.c code to make it work correctly in Samba4. Note also that Samba4 now only links to the client portion of ctdb. For the moment I am leaving the ctdbd as a separate daemon, which you install separately from http://ctdb.samba.org/. (This used to be commit b196077cbb55cbecad87065133c2d67198e31066) --- source4/cluster/ctdb/ib/ibw_ctdb_init.c | 68 ++++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 22 deletions(-) (limited to 'source4/cluster/ctdb/ib/ibw_ctdb_init.c') diff --git a/source4/cluster/ctdb/ib/ibw_ctdb_init.c b/source4/cluster/ctdb/ib/ibw_ctdb_init.c index 523a02c4df..8dbb9c241c 100644 --- a/source4/cluster/ctdb/ib/ibw_ctdb_init.c +++ b/source4/cluster/ctdb/ib/ibw_ctdb_init.c @@ -37,7 +37,8 @@ static int ctdb_ibw_listen(struct ctdb_context *ctdb, int backlog) memset(&my_addr, 0, sizeof(struct sockaddr_in)); my_addr.sin_port = htons(ctdb->address.port); my_addr.sin_family = PF_INET; - inet_pton(AF_INET, ctdb->address.address, &my_addr.sin_addr); + if (ctdb_ibw_get_address(ctdb, ctdb->address.address, &my_addr.sin_addr)) + return -1; if (ibw_bind(ictx, &my_addr)) { DEBUG(0, ("ctdb_ibw_listen: ibw_bind failed\n")); @@ -53,41 +54,63 @@ static int ctdb_ibw_listen(struct ctdb_context *ctdb, int backlog) } /* - * Start infiniband + * initialise ibw portion of a ctdb node */ -static int ctdb_ibw_start(struct ctdb_context *ctdb) +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); +} + +/* + * initialise infiniband + */ +static int ctdb_ibw_initialise(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 */ return -1; - /* everything async here */ - for (i=0;inum_nodes;i++) { - struct ctdb_node *node = ctdb->nodes[i]; - if (!(ctdb->flags & CTDB_FLAG_SELF_CONNECT) && - ctdb_same_address(&ctdb->address, &node->address)) - continue; - ctdb_ibw_node_connect(node); - } - return 0; } + /* - * initialise ibw portion of a ctdb node + * Start infiniband */ -static int ctdb_ibw_add_node(struct ctdb_node *node) +static int ctdb_ibw_start(struct ctdb_context *ctdb) { - 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); + int i, ret; - assert(cn!=NULL); - cn->conn = ibw_conn_new(ictx, node); - node->private_data = (void *)cn; + /* everything async here */ + for (i=0;inum_nodes;i++) { + struct ctdb_node *node = ctdb->nodes[i]; + if (!ctdb_same_address(&ctdb->address, &node->address)) { + ctdb_ibw_node_connect(node); + } + } - return (cn->conn!=NULL ? 0 : -1); + return 0; } static int ctdb_ibw_send_pkt(struct ibw_conn *conn, uint8_t *data, uint32_t length) @@ -176,9 +199,10 @@ static int ctdb_ibw_stop(struct ctdb_context *cctx) #endif /* __NOTDEF__ */ static const struct ctdb_methods ctdb_ibw_methods = { + .initialise= ctdb_ibw_initialise, .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 -- cgit