Difference between revisions of "CTDB Project ibwrapper"

(reformatting)
Line 1: Line 1:
 
File ibwrapper.h:
 
File ibwrapper.h:
  
/*
+
/*
  * Infiniband Verbs API socket-like wrapper
+
* Infiniband Verbs API socket-like wrapper
  * Copyright (C) Peter Somogyi 2006
+
* Copyright (C) Peter Somogyi 2006
  *
+
*
  * This library is free software; you can redistribute it and/or
+
* This library is free software; you can redistribute it and/or
  * modify it under the terms of the GNU Lesser General Public
+
* modify it under the terms of the GNU Lesser General Public
  * License as published by the Free Software Foundation; either
+
* License as published by the Free Software Foundation; either
  * version 2 of the License, or (at your option) any later version.
+
* version 2 of the License, or (at your option) any later version.
  *
+
*
  * This library is distributed in the hope that it will be useful,
+
* This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
+
* Lesser General Public License for more details.
  *
+
*
  * You should have received a copy of the GNU Lesser General Public
+
* You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the Free Software
+
* License along with this library; if not, write to the Free Software
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
+
*/
+
 
/*
+
/*
  * Basically, traditional socket is chosen for exchanging
+
* Basically, traditional socket is chosen for exchanging
  * infiniband/verbs-specific info when connecting a client.
+
* infiniband/verbs-specific info when connecting a client.
  *
+
*
  * The socket-like functions call the real functions, with some
+
* The socket-like functions call the real socket functions, with some
  * ib wrapping and error and state checking. Must be used "normally" ...
+
* 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 {
+
  */
void *internal;
+
 
} ibw_ctx;
+
typedef struct _ibw_ctx {
+
void *internal;
typedef struct _ibw_conn {
+
} ibw_ctx;
int *pfd; /* !!! <-- use this fd to wait for an event + ibw_can_read after then */
+
 
/* I'm not sure how often this can change... */
+
typedef struct _ibw_conn {
ibw_ctx *ctx;
+
int fd; /* normal fd */
void *internal;
+
ibw_ctx *ctx;
} ibw_conn;
+
void *internal;
+
} ibw_conn;
/*
+
 
  * Retrieves the last error
+
/*
  * result: always non-zero, mustn't be freed (static)
+
* Retrieves the last error
  */
+
* result: always non-zero, mustn't be freed (static)
const char *ibw_getLastError();
+
*/
+
const char *ibw_getLastError();
/*
+
 
  * settings: tabbed text of <name>\t<value>\n
+
/*
  * where name is one of:
+
* settings: tabbed text of <name>\t<value>\n
  * dev_name [default is the first one]
+
* where name is one of:
  * rx_depth [default is 500]
+
* dev_name [default is the first one]
  * mtu [default is 1024]
+
* rx_depth [default is 500]
  * ib_port [default is 1]
+
* mtu [default is 1024]
  *
+
* ib_port [default is 1]
  * must be set at client & server
+
*
  *
+
* Must be called at each NODE _ONCE_
  * returns non-NULL on success
+
* Starts a new process (for ib event loop).
  */
+
*
ibw_ctx *ibw_init(const char *settings);
+
* returns non-NULL on success
+
* talloc_free must be called for the result
void ibw_done(ibw_ctx *ctx);
+
*/
+
ibw_ctx *ibw_init(const char *settings);
  /*
+
 
  * Call as the normal one (see man page)
+
/*
  * returns a sockfd as the normal one
+
  * 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);
+
*/
+
int ibw_socket(ibw_ctx *ctx, int domain, int type, int protocol);
/*
+
 
  * Needs a normal internet address here
+
/*
  * return is a real socket fd
+
* Needs a normal internet address here
  */
+
* return is a real socket fd
int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr);
+
*/
+
int ibw_bind(ibw_ctx *ctx, struct sockaddr_in *my_addr);
/*
+
 
  * sockfd here is a real sockfd
+
/*
  * see also the man page
+
* sockfd here is a real sockfd
  * !!!: it's also blocking
+
* see also the man page
  */
+
* !!!: it's also blocking
int ibw_listen(ibw_ctx *ctx, int sockfd, int backlog);
+
*/
+
int ibw_listen(ibw_ctx *ctx, int sockfd, int backlog);
/*
+
 
  * sockfd here is a real sockfd
+
/*
  * see also the man page
+
* 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
+
* additionally, the server exchanges ib-specific
  * + initializes a connection
+
* properties (lid, qpn, psn) here with the client
  */
+
* + initializes a connection
ibw_conn *ibw_accept(ibw_ctx *ctx, int sockfd, struct sockaddr_in *cli_addr);
+
*
+
* returns non-NULL on success
/*
+
* talloc_free must be called for the result (which calls close)
  * Needs a normal internet address here
+
*/
  */
+
ibw_conn *ibw_accept(ibw_ctx *ctx, int sockfd, struct sockaddr_in *cli_addr);
ibw_conn *ibw_connect(ibw_ctx *ctx, int sockfd, struct sockaddr_in *serv_addr);
+
 
+
/*
/*
+
* Needs a normal internet address here
  * !!! Must be called after waiting for ibw_conn->fd
+
*
  * to see whether we really got the correct event for reading
+
* returns non-NULL on success
  * mustn't call ibw_read if we mustn't read.
+
* talloc_free must be called for the result (which calls close)
  */
+
*/
int ibw_can_read(ibw_conn *connctx);
+
ibw_conn *ibw_connect(ibw_ctx *ctx, int sockfd, struct sockaddr_in *serv_addr);
+
 
  /*
+
/*
  * Some prefetching will be performed here (to get the msg in one...)
+
  * Some prefetching will be performed here (to get the msg in one...)
  */
+
*/
int ibw_read(ibw_conn *connctx, void *buf, int n);
+
int ibw_read(ibw_conn *connctx, void *buf, int n);
+
 
/*
+
/*
  * I'm not sure here what happens if the CQ is full... TODO: check
+
* Try to send the message in one (performance reason)
  * Also try to send the message in _one_
+
*/
  */
+
int ibw_write(ibw_conn *connctx, void *buf, int n);
int ibw_write(ibw_conn *connctx, void *buf, int n);
 
 
void ibw_close(ibw_conn *connctx);
 

Revision as of 15:25, 17 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 { void *internal; } ibw_ctx;

typedef struct _ibw_conn { int fd; /* normal fd */ ibw_ctx *ctx; void *internal; } ibw_conn;

/*

* Retrieves the last error
* result: always non-zero, mustn't be freed (static)
*/

const char *ibw_getLastError();

/*

* settings: tabbed text of <name>\t<value>\n
* 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 at each NODE _ONCE_
* Starts a new process (for ib event loop).
*
* returns non-NULL on success
* talloc_free must be called for the result
*/

ibw_ctx *ibw_init(const char *settings);

/*

* 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)
*/

ibw_conn *ibw_accept(ibw_ctx *ctx, int sockfd, struct sockaddr_in *cli_addr);

/*

* Needs a normal internet address here
*
* returns non-NULL on success
* talloc_free must be called for the result (which calls close)
*/

ibw_conn *ibw_connect(ibw_ctx *ctx, int sockfd, struct sockaddr_in *serv_addr);

/*

* Some prefetching will be performed here (to get the msg in one...)
*/

int ibw_read(ibw_conn *connctx, void *buf, int n);

/*

* Try to send the message in one (performance reason)
*/

int ibw_write(ibw_conn *connctx, void *buf, int n);