CTDB Project ibwrapper: Difference between revisions
From SambaWiki
No edit summary |
No edit summary |
||
Line 31: | Line 31: | ||
typedef struct _ibw_ctx { |
typedef struct _ibw_ctx { |
||
int fd; /* read fd of verbs |
int fd; /* read fd of verbs events */ |
||
/* ibw_process_event must be _always_ invoked */ |
/* ibw_process_event must be _always_ invoked */ |
||
/* when this fd is set after a select/poll */ |
/* when this fd is set after a select/poll */ |
Revision as of 13:42, 20 November 2006
File ibwrapper.h:
/* * Infiniband Verbs API socket-like wrapper * Copyright (C) Peter Somogyi 2006 * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library 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 * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ /* * Basically, traditional socket is chosen for exchanging * infiniband/verbs-specific info when connecting a client. * * The socket-like functions call the real socket functions, with some * ib wrapping and error and state checking. Must be used "normally" ... * * However, ibw_write and ibw_read use real infiniband/verbs calls only. */ typedef struct _ibw_ctx { int fd; /* read fd of verbs events */ /* ibw_process_event must be _always_ invoked */ /* when this fd is set after a select/poll */ void *internal; } ibw_ctx; typedef struct _ibw_conn { ibw_ctx *ctx; void *userdata; /* see also ibw_connect and ibw_accept */ void *internal; } ibw_conn; /* * Retrieves the last error * result: always non-zero, mustn't be freed (static) */ const char *ibw_getLastError(); typedef struct _ibw_initattr { const char *name; const char *value; } ibw_initattr; /* * Callback function definition which should process incoming packets * It's called from within ibw_process_event. */ typedef int (*ibw_receive_fn_t)(ibw_conn *conn, void *buf, int nsize); /* * settings: array of (name, value) pairs * where name is one of: * dev_name [default is the first one] * rx_depth [default is 500] * mtu [default is 1024] * ib_port [default is 1] * * Must be called for each NODE _ONCE_ * * returns non-NULL on success * talloc_free must be called for the result */ ibw_ctx *ibw_init(ibw_initattr *attr, int nattr, ibw_receive_fn_t ibw_receive); /*************** connection initiation - like stream sockets *****/ /* TODO: enum nodes + verify this connection method */ /* * Call as the normal one (see man page) * returns a sockfd as the normal one */ int ibw_socket(ibw_ctx *ctx, int domain, int type, int protocol); /* * Needs a normal internet address here * return is a real socket fd */ int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr); /* * sockfd here is a real sockfd * see also the man page * !!!: it's also blocking */ int ibw_listen(ibw_ctx *ctx, int sockfd, int backlog); /* * sockfd here is a real sockfd * see also the man page * !!!: * additionally, the server exchanges ib-specific * properties (lid, qpn, psn) here with the client * + initializes a connection * * returns non-NULL on success * talloc_free must be called for the result (which calls close) * * userdata: will be put into ibw_conn (see also ibw_callback_fn_t) */ ibw_conn *ibw_accept(ibw_ctx *ctx, int sockfd, struct sockaddr_in *cli_addr, void *userdata); /* * Needs a normal internet address here * * returns non-NULL on success * talloc_free must be called for the result (which calls close) * * userdata: will be put into ibw_conn (see also ibw_callback_fn_t) */ ibw_conn *ibw_connect(ibw_ctx *ctx, int sockfd, struct sockaddr_in *serv_addr, void *userdata); /************ Infiniband specific event loop wrapping ******************/ /* * !!! Must be called in all cases after selecting/polling for ctx->fd is set. */ int ibw_process_event(ibw_ctx *ctx); /* * Send the message in one * Can be invoked any times (should fit into buffers) and at any time */ int ibw_send(ibw_conn *connctx, void *buf, int n);