2 * Unix SMB/CIFS implementation.
3 * Join infiniband wrapper and ctdb.
5 * Copyright (C) Sven Oehme <oehmes@de.ibm.com> 2006
7 * Major code contributions by Peter Somogyi <psomogyi@gamax.hu>
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "lib/events/events.h"
26 #include <system/network.h>
28 #include "ctdb_private.h"
29 #include "ibwrapper.h"
32 /* not nice; temporary workaround for the current implementation... */
33 static void *last_key = NULL;
35 static int ctdb_ibw_listen(struct ctdb_context *ctdb, int backlog)
37 struct ibw_ctx *ictx = talloc_get_type(ctdb->private, struct ibw_ctx);
38 struct sockaddr_in my_addr;
41 memset(&my_addr, 0, sizeof(struct sockaddr_in));
42 my_addr.sin_port = htons(ctdb->address.port);
43 my_addr.sin_family = PF_INET;
44 inet_pton(AF_INET, ctdb->address.address, &my_addr.sin_addr);
46 if (ibw_bind(ictx, &my_addr)) {
47 DEBUG(0, ("ctdb_ibw_listen: ibw_bind failed\n"));
51 if (ibw_listen(ictx, backlog)) {
52 DEBUG(0, ("ctdb_ibw_listen: ibw_listen failed\n"));
59 int ctdb_ibw_node_connect(struct ibw_ctx *ictx, struct ctdb_node *node)
61 struct sockaddr_in sock_out;
63 inet_pton(AF_INET, node->address.address, &sock_out.sin_addr);
64 sock_out.sin_port = htons(node->address.port);
65 sock_out.sin_family = PF_INET;
67 if (ibw_connect(ictx, &sock_out, node)) {
68 DEBUG(0, ("ctdb_ibw_node_connect: ibw_connect failed\n"));
72 /* continues at ibw_ctdb.c/IBWC_CONNECTED in good case */
79 static int ctdb_ibw_start(struct ctdb_context *ctdb)
81 struct ibw_ctx *ictx = talloc_get_type(ctdb->private, struct ibw_ctx);
84 /* listen on our own address */
85 if (ctdb_ibw_listen(ctdb, 10)) /* TODO: backlog as param */
88 /* everything async here */
89 for (i=0;i<ctdb->num_nodes;i++) {
90 struct ctdb_node *node = ctdb->nodes[i];
91 if (!(ctdb->flags & CTDB_FLAG_SELF_CONNECT) &&
92 ctdb_same_address(&ctdb->address, &node->address))
94 ctdb_ibw_node_connect(ictx, node);
102 * initialise ibw portion of a ctdb node
104 static int ctdb_ibw_add_node(struct ctdb_node *node)
106 /* TODO: clarify whether is this necessary for us ?
107 - why not enough doing such thing internally at connect time ? */
111 static int ctdb_ibw_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length)
113 struct ibw_conn *conn = talloc_get_type(node->private, struct ibw_conn);
116 rc = ibw_send(conn, data, last_key, length);
124 * transport packet allocator - allows transport to control memory for packets
126 static void *ctdb_ibw_allocate_pkt(struct ctdb_node *node, size_t size)
128 struct ibw_conn *conn = NULL;
131 if (ibw_alloc_send_buf(conn, &buf, &last_key, size))
137 static void ctdb_ibw_dealloc_pkt(struct ctdb_node *node, void *data)
140 struct ibw_conn *conn = talloc_get_type(node->private, struct ibw_conn);
143 ibw_cancel_send_buf(conn, data, last_key);
144 } /* else ibw_send is already using it and will free it after completion */
147 static int ctdb_ibw_stop(struct ctdb_context *cctx)
149 struct ibw_ctx *ictx = talloc_get_type(cctx->private, struct ibw_ctx);
152 return ibw_stop(ictx);
155 #endif /* __NOTDEF__ */
157 static const struct ctdb_methods ctdb_ibw_methods = {
158 .start = ctdb_ibw_start,
159 .add_node = ctdb_ibw_add_node,
160 .queue_pkt = ctdb_ibw_queue_pkt,
161 // .allocate_pkt = ctdb_ibw_allocate_pkt,
163 // .dealloc_pkt = ctdb_ibw_dealloc_pkt,
164 // .stop = ctdb_ibw_stop
168 * initialise ibw portion of ctdb
170 int ctdb_ibw_init(struct ctdb_context *ctdb)
172 struct ibw_ctx *ictx;
175 NULL, //struct ibw_initattr *attr, /* TODO */
176 0, //int nattr, /* TODO */
178 ctdb_ibw_connstate_handler,
179 ctdb_ibw_receive_handler,
183 DEBUG(0, ("ctdb_ibw_init: ibw_init failed\n"));
187 ctdb->methods = &ctdb_ibw_methods;
188 ctdb->private = ictx;