common.h revision 331769
1/* 2 * Copyright (c) 2005-2012 Intel Corporation. All rights reserved. 3 * 4 * This software is available to you under a choice of one of two 5 * licenses. You may choose to be licensed under the terms of the GNU 6 * General Public License (GPL) Version 2, available from the file 7 * COPYING in the main directory of this source tree, or the 8 * OpenIB.org BSD license below: 9 * 10 * Redistribution and use in source and binary forms, with or 11 * without modification, are permitted provided that the following 12 * conditions are met: 13 * 14 * - Redistributions of source code must retain the above 15 * copyright notice, this list of conditions and the following 16 * disclaimer. 17 * 18 * - Redistributions in binary form must reproduce the above 19 * copyright notice, this list of conditions and the following 20 * disclaimer in the documentation and/or other materials 21 * provided with the distribution. 22 * 23 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 24 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 25 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 26 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 27 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 28 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 29 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 30 * SOFTWARE. 31 * 32 * $Id$ 33 */ 34 35#include <stdlib.h> 36#include <sys/types.h> 37#include <infiniband/endian.h> 38#include <poll.h> 39 40#include <rdma/rdma_cma.h> 41#include <rdma/rsocket.h> 42#include <infiniband/ib.h> 43 44extern int use_rs; 45 46#define rs_socket(f,t,p) use_rs ? rsocket(f,t,p) : socket(f,t,p) 47#define rs_bind(s,a,l) use_rs ? rbind(s,a,l) : bind(s,a,l) 48#define rs_listen(s,b) use_rs ? rlisten(s,b) : listen(s,b) 49#define rs_connect(s,a,l) use_rs ? rconnect(s,a,l) : connect(s,a,l) 50#define rs_accept(s,a,l) use_rs ? raccept(s,a,l) : accept(s,a,l) 51#define rs_shutdown(s,h) use_rs ? rshutdown(s,h) : shutdown(s,h) 52#define rs_close(s) use_rs ? rclose(s) : close(s) 53#define rs_recv(s,b,l,f) use_rs ? rrecv(s,b,l,f) : recv(s,b,l,f) 54#define rs_send(s,b,l,f) use_rs ? rsend(s,b,l,f) : send(s,b,l,f) 55#define rs_recvfrom(s,b,l,f,a,al) \ 56 use_rs ? rrecvfrom(s,b,l,f,a,al) : recvfrom(s,b,l,f,a,al) 57#define rs_sendto(s,b,l,f,a,al) \ 58 use_rs ? rsendto(s,b,l,f,a,al) : sendto(s,b,l,f,a,al) 59#define rs_poll(f,n,t) use_rs ? rpoll(f,n,t) : poll(f,n,t) 60#define rs_fcntl(s,c,p) use_rs ? rfcntl(s,c,p) : fcntl(s,c,p) 61#define rs_setsockopt(s,l,n,v,ol) \ 62 use_rs ? rsetsockopt(s,l,n,v,ol) : setsockopt(s,l,n,v,ol) 63#define rs_getsockopt(s,l,n,v,ol) \ 64 use_rs ? rgetsockopt(s,l,n,v,ol) : getsockopt(s,l,n,v,ol) 65 66union socket_addr { 67 struct sockaddr sa; 68 struct sockaddr_in sin; 69 struct sockaddr_in6 sin6; 70}; 71 72enum rs_optimization { 73 opt_mixed, 74 opt_latency, 75 opt_bandwidth 76}; 77 78int get_rdma_addr(const char *src, const char *dst, const char *port, 79 struct rdma_addrinfo *hints, struct rdma_addrinfo **rai); 80 81void size_str(char *str, size_t ssize, long long size); 82void cnt_str(char *str, size_t ssize, long long cnt); 83int size_to_count(int size); 84void format_buf(void *buf, int size); 85int verify_buf(void *buf, int size); 86int do_poll(struct pollfd *fds, int timeout); 87