static void ibw_event_handler_verbs(struct event_context *ev,
struct fd_event *fde, uint16_t flags, void *private_data);
-static int ibw_init_memory(ibw_conn *conn)
+static int ibw_init_memory(struct ibw_conn *conn)
{
- ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
- ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+ struct ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+ struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
int i;
- ibw_wr *p;
+ struct ibw_wr *p;
pconn->buf = memalign(pctx->page_size, pctx->max_msg_size);
if (!pconn->buf) {
return -1;
}
- pconn->wr_index = talloc_size(pconn, pctx->qsize * sizeof(ibw_wr *));
+ pconn->wr_index = talloc_size(pconn, pctx->qsize * sizeof(struct ibw_wr *));
for(i=0; i<pctx->qsize; i++) {
- p = pconn->wr_index[i] = talloc_zero(pconn, ibw_wr);
+ p = pconn->wr_index[i] = talloc_zero(pconn, struct ibw_wr);
p->msg = pconn->buf + (i * pctx->max_msg_size);
p->wr_id = i;
static int ibw_ctx_priv_destruct(void *ptr)
{
- ibw_ctx *pctx = talloc_get_type(ctx->internal, ibw_ctx_priv);
+ struct ibw_ctx *pctx = talloc_get_type(ctx->internal, struct ibw_ctx_priv);
assert(pctx!=NULL);
if (pctx->pd) {
static int ibw_ctx_destruct(void *ptr)
{
- ibw_ctx *ctx = talloc_get_type(ptr, ibw_ctx);
+ struct ibw_ctx *ctx = talloc_get_type(ptr, struct ibw_ctx);
assert(ctx!=NULL);
return 0;
static int ibw_conn_priv_destruct(void *ptr)
{
- ibw_conn *pconn = talloc_get_type(ptr, ibw_conn_priv);
+ struct ibw_conn *pconn = talloc_get_type(ptr, struct ibw_conn_priv);
assert(pconn!=NULL);
/* free memory regions */
static int ibw_conn_destruct(void *ptr)
{
- ibw_conn *conn = talloc_get_type(ptr, ibw_conn);
- ibw_ctx *ctx;
+ struct ibw_conn *conn = talloc_get_type(ptr, struct ibw_conn);
+ struct ibw_ctx *ctx;
assert(conn!=NULL);
ctx = ibw_conn->ctx;
return 0;
}
-static ibw_conn *ibw_conn_new(ibw_ctx *ctx)
+static struct ibw_conn *ibw_conn_new(struct ibw_ctx *ctx)
{
- ibw_conn *conn;
- ibw_conn_priv *pconn;
+ struct ibw_conn *conn;
+ struct ibw_conn_priv *pconn;
- conn = talloc_zero(ctx, ibw_conn);
+ conn = talloc_zero(ctx, struct ibw_conn);
assert(conn!=NULL);
- talloc_set_destructor(conn, ibw_conn_destruct);
+ talloc_set_destructor(conn, struct ibw_conn_destruct);
- pconn = talloc_zero(ctx, ibw_conn_priv);
+ pconn = talloc_zero(ctx, struct ibw_conn_priv);
assert(pconn!=NULL);
- talloc_set_destructor(pconn, ibw_conn_priv_destruct);
+ talloc_set_destructor(pconn, struct ibw_conn_priv_destruct);
conn->ctx = ctx;
return conn;
}
-static int ibw_setup_cq_qp(ibw_conn *conn)
+static int ibw_setup_cq_qp(struct ibw_conn *conn)
{
- ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
- ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+ struct ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+ struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
struct ibv_qp_init_attr init_attr;
int rc;
return rc;
}
-static int ibw_refill_cq_recv(ibw_conn *conn)
+static int ibw_refill_cq_recv(struct ibw_conn *conn)
{
- ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
- ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+ struct ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+ struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
int i, rc;
struct ibv_sge list = {
.addr = (uintptr_t) NULL,
.num_sge = 1,
};
struct ibv_recv_wr *bad_wr;
- ibw_wr *p = pconn->wr_list_avail;
+ struct ibw_wr *p = pconn->wr_list_avail;
if (p==NULL) {
sprintf(ibw_last_err, "out of wr_list_avail");
return 0;
}
-static int ibw_fill_cq(ibw_conn *conn)
+static int ibw_fill_cq(struct ibw_conn *conn)
{
- ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
- ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+ struct ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+ struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
int i, rc;
struct ibv_sge list = {
.addr = (uintptr_t) NULL,
.num_sge = 1,
};
struct ibv_recv_wr *bad_wr;
- ibw_wr *p;
+ struct ibw_wr *p;
for(i = pctx->opts.max_recv_wr; i!=0; i--) {
p = pconn->wr_list_avail;
return 0;
}
-static int ibw_manage_connect(ibw_conn *conn, struct rdma_cm_id *cma_id)
+static int ibw_manage_connect(struct ibw_conn *conn, struct rdma_cm_id *cma_id)
{
struct rdma_conn_param conn_param;
int rc;
struct fd_event *fde, uint16_t flags, void *private_data)
{
int rc;
- ibw_ctx *ctx = talloc_get_type(private_data, ibw_ctx);
- ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, ibw_ctx_priv);
- ibw_conn *conn = NULL;
- ibw_conn_priv *pconn = NULL;
+ struct ibw_ctx *ctx = talloc_get_type(private_data, struct ibw_ctx);
+ struct ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, struct ibw_ctx_priv);
+ struct ibw_conn *conn = NULL;
+ struct ibw_conn_priv *pconn = NULL;
struct rdma_cm_id *cma_id = NULL;
struct rdma_cm_event *event = NULL;
switch (event->event) {
case RDMA_CM_EVENT_ADDR_RESOLVED:
/* continuing from ibw_connect ... */
- assert(pctx->state==IWINT_INIT);
- pctx->state = IWINT_ADDR_RESOLVED;
rc = rdma_resolve_route(cma_id, 2000);
if (rc) {
ctx->state = ERROR;
case RDMA_CM_EVENT_ROUTE_RESOLVED:
/* after RDMA_CM_EVENT_ADDR_RESOLVED: */
- assert(pctx->state==IWINT_ADDR_RESOLVED);
- pctx->state = IWINT_ROUTE_RESOLVED;
assert(cma_id->context!=NULL);
- conn = talloc_get_type(cma_id->context, ibw_conn);
- pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+ conn = talloc_get_type(cma_id->context, struct ibw_conn);
rc = ibw_manage_connect(conn, cma_id);
if (rc)
case RDMA_CM_EVENT_CONNECT_REQUEST:
ctx->state = IBWS_CONNECT_REQUEST;
conn = ibw_conn_new(ctx);
- pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+ pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
pconn->cm_id = cma_id; /* !!! event will be freed but id not */
cma_id->context = (void *)conn;
DEBUG(10, "pconn->cm_id %p\n", pconn->cm_id);
case RDMA_CM_EVENT_ESTABLISHED:
/* expected after ibw_accept and ibw_connect[not directly] */
DEBUG(0, "ESTABLISHED (conn: %u)\n", cma_id->context);
- conn = talloc_get_type(cma_id->context, ibw_conn);
+ conn = talloc_get_type(cma_id->context, struct ibw_conn);
assert(conn!=NULL); /* important assumption */
- pconn = talloc_get_type(conn->internal, ibw_conn_priv);
/* client conn is up */
conn->state = IBWC_CONNECTED;
case RDMA_CM_EVENT_DISCONNECTED:
if (cma_id!=ctx->cm_id) {
DEBUG(0, "client DISCONNECT event\n");
- conn = talloc_get_type(cma_id->context, ibw_conn);
+ conn = talloc_get_type(cma_id->context, struct ibw_conn);
conn->state = IBWC_DISCONNECTED;
pctx->connstate_func(NULL, conn);
error:
DEBUG(0, "cm event handler: %s", ibw_lasterr);
if (cma_id!=ctx->cm_id) {
- conn = talloc_get_type(cma_id->context, ibw_conn);
+ conn = talloc_get_type(cma_id->context, struct ibw_conn);
if (conn)
conn->state = IBWC_ERROR;
pctx->connstate_func(NULL, conn);
static void ibw_event_handler_verbs(struct event_context *ev,
struct fd_event *fde, uint16_t flags, void *private_data)
{
- ibw_ctx *conn = talloc_get_type(private_data, ibw_conn);
- ibw_ctx_priv *pconn = talloc_get_type(conn->internal, ibw_ctx_priv);
- ibw_ctx *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
+ struct ibw_ctx *conn = talloc_get_type(private_data, struct ibw_conn);
+ struct ibw_ctx_priv *pconn = talloc_get_type(conn->internal, struct ibw_ctx_priv);
+ struct ibw_ctx *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
struct ibv_wc wc;
int rc;
switch(wc.opcode) {
case IBV_WC_SEND:
{
- ibw_wr *p;
+ struct ibw_wr *p;
DEBUG(10, "send completion\n");
assert(pconn->qp->qp_num==wc.qp_num);
case IBV_WC_RECV:
{
- ibw_wr *p;
+ struct ibw_wr *p;
assert(pconn->qp->qp_num==wc.qp_num);
assert(wc.wr_id < pctx->qsize);
pctx->connstate_func(NULL, conn);
}
-static int ibw_process_init_attrs(ibw_initattr *attr, int nattr, ibw_opts *opts)
+static int ibw_process_init_attrs(struct ibw_initattr *attr, int nattr, struct ibw_opts *opts)
{
int i, mtu;
char *name, *value;
return 0;
}
-ibw_ctx *ibw_init(ibw_initattr *attr, int nattr,
+struct ibw_ctx *ibw_init(struct ibw_initattr *attr, int nattr,
void *ctx_userdata,
ibw_connstate_fn_t ibw_connstate,
ibw_receive_fn_t ibw_receive,
event_content *ectx,
int max_msg_size)
{
- ibw_ctx *ctx = talloc_zero(NULL, ibw_ctx);
- ibw_ctx_priv *pctx;
+ struct ibw_ctx *ctx = talloc_zero(NULL, struct ibw_ctx);
+ struct ibw_ctx_priv *pctx;
int rc;
/* initialize basic data structures */
talloc_set_destructor(ctx, ibw_ctx_destruct);
ctx->userdata = userdata;
- pctx = talloc_zero(ctx, ibw_ctx_priv);
+ pctx = talloc_zero(ctx, struct ibw_ctx_priv);
talloc_set_destructor(pctx, ibw_ctx_priv_destruct);
ctx->internal = (void *)pctx;
assert(pctx!=NULL);
return NULL;
}
-int ibw_stop(ibw_ctx *ctx)
+int ibw_stop(struct ibw_ctx *ctx)
{
- ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
- ibw_conn *p;
+ struct ibw_ctx_priv *pctx = (struct ibw_ctx_priv *)ctx->internal;
+ struct ibw_conn *p;
for(p=ctx->conn_list; p!=NULL; p=p->next) {
if (ctx->state==IBWC_ERROR || ctx->state==IBWC_CONNECTED) {
return 0;
}
-int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr)
+int ibw_bind(struct ibw_ctx *ctx, struct sockaddr_in *my_addr)
{
- ibw_ctx_priv *pctx = (ibw_ctx_priv *)ctx->internal;
+ struct ibw_ctx_priv *pctx = (struct ibw_ctx_priv *)ctx->internal;
int rc;
rc = rdma_bind_addr(pctx->cm_id, (struct sockaddr *) my_addr);
return 0;
}
-int ibw_listen(ibw_ctx *ctx, int backlog)
+int ibw_listen(struct ibw_ctx *ctx, int backlog)
{
- ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, ibw_ctx_priv);
+ struct ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, struct ibw_ctx_priv);
int rc;
DEBUG_LOG("rdma_listen...\n");
return 0;
}
-int ibw_accept(ibw_ctx *ctx, ibw_conn *conn, void *conn_userdata)
+int ibw_accept(struct ibw_ctx *ctx, struct ibw_conn *conn, void *conn_userdata)
{
- ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, ibw_ctx_priv);
- ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+ struct ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, struct ibw_ctx_priv);
+ struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
struct rdma_conn_param conn_param;
conn->conn_userdata = conn_userdata;
return 0;
}
-int ibw_connect(ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata)
+int ibw_connect(struct ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata)
{
- ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, ibw_ctx_priv);
- ibw_conn *conn = NULL;
+ struct ibw_ctx_priv *pctx = talloc_get_type(ctx->internal, struct ibw_ctx_priv);
+ struct ibw_conn *conn = NULL;
int rc;
conn = ibw_conn_new(ctx);
conn->conn_userdata = conn_userdata;
- pconn = talloc_get_type(conn->internal, ibw_conn_priv);
+ pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
rc = rdma_create_id(pctx->cm_channel, &pconn->cm_id, conn, RDMA_PS_TCP);
if (rc) {
return 0;
}
-void ibw_disconnect(ibw_conn *conn)
+void ibw_disconnect(struct ibw_conn *conn)
{
- ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
- ibw_ctx *ctx = conn->ctx;
- ibw_ctx_priv *pctx = talloc_get_type(ctx->internal);
+ struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
+ struct ibw_ctx *ctx = conn->ctx;
+ struct ibw_ctx_priv *pctx = talloc_get_type(ctx->internal);
rdma_disconnect(pctx->cm_id);
return 0;
}
-int ibw_alloc_send_buf(ibw_conn *conn, void **buf, void **key)
+int ibw_alloc_send_buf(struct ibw_conn *conn, void **buf, void **key)
{
- ibw_conn_priv *pconn = talloc_get_type(conn->internal, ibw_conn_priv);
- ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
- ibw_wr *p = pctx->wr_list_avail;
+ struct ibw_conn_priv *pconn = talloc_get_type(conn->internal, struct ibw_conn_priv);
+ struct ibw_ctx_priv *pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+ struct ibw_wr *p = pctx->wr_list_avail;
if (p==NULL) {
sprintf(ibw_last_err, "insufficient wr chunks\n");
return pctx->buf;
}
-int ibw_send(ibw_conn *conn, void *buf, void *key, int n)
+int ibw_send(struct ibw_conn *conn, void *buf, void *key, int n)
{
- ibw_ctx_priv pctx = talloc_get_type(conn->ctx->internal, ibw_ctx_priv);
- ibw_wr *p = talloc_get_type(key, ibw_wr);
+ struct ibw_ctx_priv pctx = talloc_get_type(conn->ctx->internal, struct ibw_ctx_priv);
+ struct ibw_wr *p = talloc_get_type(key, struct ibw_wr);
struct ibv_sge list = {
.addr = (uintptr_t) p->msg,
.length = n,
*/
/* Server communication state */
-typedef enum {
+enum ibw_state_ctx {
IBWS_INIT = 0, /* ctx start - after ibw_init */
IBWS_READY, /* after ibw_bind & ibw_listen */
IBWS_CONNECT_REQUEST, /* after [IBWS_READY + incoming request] */
/* => [(ibw_accept)IBWS_READY | (ibw_disconnect)STOPPED | ERROR] */
IBWS_STOPPED, /* normal stop <= ibw_disconnect+(IBWS_READY | IBWS_CONNECT_REQUEST) */
IBWS_ERROR /* abnormal state; ibw_stop must be called after this */
-} ibw_state_ctx;
+};
/* Connection state */
-typedef struct _ibw_ctx {
+typedef struct ibw_ctx {
void *ctx_userdata; /* see ibw_init */
- ibw_state_ctx state;
+ struct ibw_state_ctx state;
void *internal;
- ibw_conn *conn_list; /* 1st elem of double linked list */
-} ibw_ctx;
+ struct ibw_conn *conn_list; /* 1st elem of double linked list */
+};
-typedef enum {
+enum ibw_state_conn {
IBWC_INIT = 0, /* conn start - internal state */
IBWC_CONNECTED, /* after ibw_accept or ibw_connect */
IBWC_DISCONNECTED, /* after ibw_disconnect */
IBWC_ERROR
-} ibw_state_conn;
+};
-typedef struct _ibw_conn {
- ibw_ctx *ctx;
- ibw_state_conn state;
+struct ibw_conn {
+ struct ibw_ctx *ctx;
+ struct ibw_state_conn state;
void *conn_userdata; /* see ibw_connect and ibw_accept */
void *internal;
- ibw_conn *prev, next;
-} ibw_conn;
+ struct ibw_conn *prev, next;
+};
/*
* (name, value) pair for array param of ibw_init
*/
-typedef struct _ibw_initattr {
+struct ibw_initattr {
const char *name;
const char *value;
-} ibw_initattr;
+};
/*
* Callback function definition which should inform you about
* connection state change
- * This callback is invoked from within ibw_process_event.
+ * This callback is invoked whenever server or client connection changes.
* Both <conn> and <ctx> can be NULL if their state didn't change.
* Return nonzero on error.
*/
/*
* Callback function definition which should process incoming packets
- * This callback is invoked from within ibw_process_event.
+ * This callback is invoked whenever any message arrives.
* Return nonzero on error.
*
- * Important: you mustn't store buf pointer for later use. Process its contents before returning.
+ * Important: you mustn't store buf pointer for later use.
+ * Process its contents before returning.
*/
-typedef int (*ibw_receive_fn_t)(ibw_conn *conn, void *buf, int n);
+typedef int (*ibw_receive_fn_t)(struct ibw_conn *conn, void *buf, int n);
/*
* settings: array of (name, value) pairs
* it will close resources by destructor
* connections(ibw_conn *) must have been closed prior talloc_free
*/
-ibw_ctx *ibw_init(ibw_initattr *attr, int nattr,
+struct ibw_ctx *ibw_init(struct ibw_initattr *attr, int nattr,
void *ctx_userdata,
ibw_connstate_fn_t ibw_connstate,
ibw_receive_fn_t ibw_receive,
- event_content *ectx,
+ struct event_context *ectx,
int max_msg_size);
/*
* During that time, you mustn't send/recv/disconnect any more.
* Only after ctx->state=IBWS_STOPPED you can talloc_free the ctx.
*/
-int ibw_stop(ibw_ctx *ctx);
+int ibw_stop(struct ibw_ctx *ctx);
/*************** connection initiation - like stream sockets *****/
*
* return 0 on success
*/
-int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr);
+int ibw_bind(struct ibw_ctx *ctx, struct sockaddr_in *my_addr);
/*
* works like socket listen
*
* returns 0 on success
*/
-int ibw_listen(ibw_ctx *ctx, int backlog);
+int ibw_listen(struct ibw_ctx *ctx, int backlog);
/*
* works like socket accept
*
* Important: you won't get remote IP address (only internal conn info)
*/
-int ibw_accept(ibw_ctx *ctx, ibw_conn *conn, void *conn_userdata);
+int ibw_accept(struct ibw_ctx *ctx, struct ibw_conn *conn, void *conn_userdata);
/*
* Needs a normal internet address here
* You have +1 waiting here: you will get ibw_conn (having the
* same <conn_userdata> member) structure in ibw_connstate_fn_t.
*/
-int ibw_connect(ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata);
+int ibw_connect(struct ibw_ctx *ctx, struct sockaddr_in *serv_addr, void *conn_userdata);
/*
* Sends out a disconnect request.
* You mustn't talloc_free <conn> yet right after this,
* first wait for IBWC_DISCONNECTED.
*/
-void ibw_disconnect(ibw_conn *conn);
+void ibw_disconnect(struct ibw_conn *conn);
/************ Infiniband specific event loop wrapping ******************/
*
* Returns 0 on success.
*/
-int ibw_alloc_send_buf(ibw_conn *conn, void **buf, void **key);
+int ibw_alloc_send_buf(struct ibw_conn *conn, void **buf, void **key);
/*
* Send the message in one
*
* You mustn't use (buf, key) any more for sending.
*/
-int ibw_send(ibw_conn *conn, void *buf, void *key, int n);
+int ibw_send(struct ibw_conn *conn, void *buf, void *key, int n);
/*
* Retrieves the last error