Added infiniband transport implementation(incomplete) and interface.
[vlendec/samba-autobuild/.git] / ctdb / ib / ibwrapper.c
1 /*
2  * Unix SMB/CIFS implementation.
3  * Wrap Infiniband calls.
4  *
5  * Copyright (C) Sven Oehme <oehmes@de.ibm.com> 2006
6  *
7  * Major code contributions by Peter Somogyi <psomogyi@gamax.hu>
8  *
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.
13  *
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.
18  *
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.
22  */
23
24 #include "ibwrapper.h"
25
26 #include <stdlib.h>
27 #include <string.h>
28 #include <stdio.h>
29 #include <errno.h>
30 #include <sys/types.h>
31 #include <netinet/in.h>
32 #include <sys/socket.h>
33 #include <netdb.h>
34 #include <arpa/inet.h>
35
36 #include <rdma/rdma_cma.h>
37 #include "lib/events/events.h"
38
39 #include "ibwrapper_internal.h"
40
41
42 #define IBW_LASTERR_BUFSIZE 512
43 static char ibw_lasterr[IBW_LASTERR_BUFSIZE];
44
45 static ibw_mr *ibw_alloc_mr(ibw_ctx_priv *pctx)
46 {
47 }
48
49 static int ibwctx_destruct(void *ptr)
50 {
51         ibw_ctx *pctx = talloc_get_type(ptr, ibw_ctx);
52         assert(pctx!=NULL);
53
54         /* free memory regions */
55
56         return 0;
57 }
58
59 int ibw_process_event(ibw_ctx *ctx, int fd_index);
60
61 static void ibw_process_cm_event(struct event_context *ev,
62         struct fd_event *fde, uint16_t flags, void *private_data)
63 {
64         if (fde->
65 }
66
67 static int ibw_process_init_attrs(ibw_initattr *attr, int nattr, ibw_opts *opts)
68 {
69         int     i;
70         char *name, *value;
71         
72         for(i=0; i<nattr; i++) {
73                 name = attr[i].name;
74                 value = attr[i].value;
75
76                 assert(name!=NULL && value!=NULL);
77                 if (strcmp(name, "dev_name")==0)
78                         opts->opts.dev_name = talloc_strdup(ctx, value);
79                 else if (strcmp(name, "rx_depth")==0)
80                         opts->rx_depth = atoi(value);
81                 else if (strcmp(name, "mtu")==0)
82                         opts->mtu = atoi(value);
83                 else {
84                         sprintf(ibw_lasterr, "ibw_init: unknown name %s\n", name);
85                         return -1;
86                 }
87         }
88         return 0;
89 }
90
91 ibw_ctx *ibw_init(ibw_initattr *attr, int nattr,
92         void *ctx_userdata,
93         ibw_connstate_fn_t ibw_connstate,
94         ibw_receive_fn_t ibw_receive)
95 {
96         ibw_ctx *ctx = talloc_zero(NULL, ibw_ctx);
97         ibw_ctx_priv *pctx;
98         int     rc;
99         ibw_event_ud *event_priv;
100
101         memset(ibw_lasterr, 0, IBW_LASTERR_BUFSIZE);
102
103         assert(ctx!=NULL);
104         ibw_lasterr[0] = '\0';
105         talloc_set_destructor(ctx, ibwctx_destruct);
106         ctx->userdata = userdata;
107
108         pctx = talloc_zero(ctx, ibw_ctx_priv);
109         ctx->internal = (void *)pctx;
110         assert(pctx!=NULL);
111
112         pctx->connstate_func = ibw_connstate;
113         pctx->receive_func = ibw_receive;
114
115         assert((pctx->ectx = event_context_init(ctx))!=NULL);
116
117         /* process attributes */
118         if (ibw_process_init_attrs(attr, nattr, pctx->opts))
119                 goto cleanup;
120
121         /* initialize CM stuff */
122         pctx->cm_channel = rdma_create_event_channel();
123         if (!pctx->cm_channel) {
124                 ret = errno;
125                 sprintf(ibw_lasterr, "rdma_create_event_channel error %d\n", ret);
126                 goto cleanup;
127         }
128
129         event_priv = talloc_zero(ctx, ibw_event_ud);
130         event_priv->ctx = ctx;
131         event_priv->id = IBWET_CM;
132
133         pctx->cm_channel_event = event_add_fd(pctx->ectx, pctx,
134                 pctx->cm_channel->fd, EVENT_FD_READ, ibw_process_cm_event, event_priv);
135
136         rc = rdma_create_id(pctx->cm_channel, &pctx->cm_id, cb, RDMA_PS_TCP);
137         if (rc) {
138                 rc = errno;
139                 sprintf(ibw_lasterr, "rdma_create_id error %d\n", rc);
140                 goto cleanup;
141         }
142         DEBUG(10, "created cm_id %p\n", pctx->cm_id);
143
144         /* allocate ib memory regions */
145
146         return ctx;
147
148 cleanup:
149         if (ctx)
150                 talloc_free(ctx);
151
152         return NULL;
153 }
154
155 int ibw_stop(ibw_ctx *ctx)
156 {
157         ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
158
159 }
160
161 int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr)
162 {
163         ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
164 }
165
166 int ibw_listen(ibw_ctx *ctx, int backlog)
167 {
168         ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
169 }
170
171 int ibw_accept(ibw_ctx *ctx, void *conn_userdata)
172 {
173         ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
174 }
175
176 int ibw_connect(ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata)
177 {
178         ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
179 }
180
181 void ibw_disconnect(ibw_conn *conn)
182 {
183         ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
184 }
185
186 int ibw_process_event(ibw_ctx *ctx, ...)
187 {
188         ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
189 }
190
191 int ibw_alloc_send_buf(ibw_conn *conn, void **buf, void **key, int n)
192 {
193 }
194
195 int ibw_send(ibw_conn *conn, void *buf, void *key, int n)
196 {
197 }
198
199 const char *ibw_getLastError()
200 {
201         return ibw_lasterr;
202 }