[Pkg-ofed-commits] [librdmacm] 07/18: Imported Upstream version 1.0.10

Ana Beatriz Guerrero López ana at moszumanska.debian.org
Wed Jul 2 13:58:24 UTC 2014


This is an automated email from the git hooks/post-receive script.

ana pushed a commit to branch master
in repository librdmacm.

commit 50621656c772f240914e684af6b48e5be8357c88
Author: Ana Guerrero López <ana at ekaia.org>
Date:   Wed Jul 2 15:58:06 2014 +0200

    Imported Upstream version 1.0.10
---
 configure          |  20 ++++----
 configure.in       |   4 +-
 examples/cmatose.c |  69 ++++++++++++++------------
 examples/mckey.c   |  12 ++---
 examples/rping.c   |  56 +++++++++++----------
 examples/udaddy.c  |  20 ++++----
 librdmacm.spec     |   4 +-
 librdmacm.spec.in  |   2 +-
 man/rdma_cm.7      |  16 +++---
 src/cma.c          | 140 +++++++++++++++++++++++++++++------------------------
 10 files changed, 185 insertions(+), 158 deletions(-)

diff --git a/configure b/configure
index ea33723..9299a2b 100755
--- a/configure
+++ b/configure
@@ -1,6 +1,6 @@
 #! /bin/sh
 # Guess values for system-dependent variables and create Makefiles.
-# Generated by GNU Autoconf 2.59 for librdmacm 1.0.8.
+# Generated by GNU Autoconf 2.59 for librdmacm 1.0.10.
 #
 # Report bugs to <general at lists.openfabrics.org>.
 #
@@ -423,8 +423,8 @@ SHELL=${CONFIG_SHELL-/bin/sh}
 # Identity of this package.
 PACKAGE_NAME='librdmacm'
 PACKAGE_TARNAME='librdmacm'
-PACKAGE_VERSION='1.0.8'
-PACKAGE_STRING='librdmacm 1.0.8'
+PACKAGE_VERSION='1.0.10'
+PACKAGE_STRING='librdmacm 1.0.10'
 PACKAGE_BUGREPORT='general at lists.openfabrics.org'
 
 ac_unique_file="src/cma.c"
@@ -954,7 +954,7 @@ if test "$ac_init_help" = "long"; then
   # Omit some internal or obsolete options to make the list less imposing.
   # This message is too long to be a string in the A/UX 3.1 sh.
   cat <<_ACEOF
-\`configure' configures librdmacm 1.0.8 to adapt to many kinds of systems.
+\`configure' configures librdmacm 1.0.10 to adapt to many kinds of systems.
 
 Usage: $0 [OPTION]... [VAR=VALUE]...
 
@@ -1020,7 +1020,7 @@ fi
 
 if test -n "$ac_init_help"; then
   case $ac_init_help in
-     short | recursive ) echo "Configuration of librdmacm 1.0.8:";;
+     short | recursive ) echo "Configuration of librdmacm 1.0.10:";;
    esac
   cat <<\_ACEOF
 
@@ -1161,7 +1161,7 @@ fi
 test -n "$ac_init_help" && exit 0
 if $ac_init_version; then
   cat <<\_ACEOF
-librdmacm configure 1.0.8
+librdmacm configure 1.0.10
 generated by GNU Autoconf 2.59
 
 Copyright (C) 2003 Free Software Foundation, Inc.
@@ -1175,7 +1175,7 @@ cat >&5 <<_ACEOF
 This file contains any messages produced by compilers while
 running configure, to aid debugging if configure makes a mistake.
 
-It was created by librdmacm $as_me 1.0.8, which was
+It was created by librdmacm $as_me 1.0.10, which was
 generated by GNU Autoconf 2.59.  Invocation command line was
 
   $ $0 $@
@@ -1821,7 +1821,7 @@ fi
 
 # Define the identity of the package.
  PACKAGE=librdmacm
- VERSION=1.0.8
+ VERSION=1.0.10
 
 
 cat >>confdefs.h <<_ACEOF
@@ -20908,7 +20908,7 @@ _ASBOX
 } >&5
 cat >&5 <<_CSEOF
 
-This file was extended by librdmacm $as_me 1.0.8, which was
+This file was extended by librdmacm $as_me 1.0.10, which was
 generated by GNU Autoconf 2.59.  Invocation command line was
 
   CONFIG_FILES    = $CONFIG_FILES
@@ -20971,7 +20971,7 @@ _ACEOF
 
 cat >>$CONFIG_STATUS <<_ACEOF
 ac_cs_version="\\
-librdmacm config.status 1.0.8
+librdmacm config.status 1.0.10
 configured by $0, generated by GNU Autoconf 2.59,
   with options \\"`echo "$ac_configure_args" | sed 's/[\\""\`\$]/\\\\&/g'`\\"
 
diff --git a/configure.in b/configure.in
index c06f65e..0dfd666 100644
--- a/configure.in
+++ b/configure.in
@@ -1,11 +1,11 @@
 dnl Process this file with autoconf to produce a configure script.
 
 AC_PREREQ(2.57)
-AC_INIT(librdmacm, 1.0.8, general at lists.openfabrics.org)
+AC_INIT(librdmacm, 1.0.10, general at lists.openfabrics.org)
 AC_CONFIG_SRCDIR([src/cma.c])
 AC_CONFIG_AUX_DIR(config)
 AM_CONFIG_HEADER(config.h)
-AM_INIT_AUTOMAKE(librdmacm, 1.0.8)
+AM_INIT_AUTOMAKE(librdmacm, 1.0.10)
 
 AM_PROG_LIBTOOL
 
diff --git a/examples/cmatose.c b/examples/cmatose.c
index ba6299e..8c12347 100644
--- a/examples/cmatose.c
+++ b/examples/cmatose.c
@@ -58,11 +58,16 @@ struct cmatest_node {
 	struct rdma_cm_id	*cma_id;
 	int			connected;
 	struct ibv_pd		*pd;
-	struct ibv_cq		*cq;
+	struct ibv_cq		*cq[2];
 	struct ibv_mr		*mr;
 	void			*mem;
 };
 
+enum CQ_INDEX {
+	SEND_CQ_INDEX,
+	RECV_CQ_INDEX
+};
+
 struct cmatest {
 	struct rdma_event_channel *channel;
 	struct cmatest_node	*nodes;
@@ -124,27 +129,28 @@ static int init_node(struct cmatest_node *node)
 		goto out;
 	}
 
-	cqe = message_count ? message_count * 2 : 2;
-	node->cq = ibv_create_cq(node->cma_id->verbs, cqe, node, 0, 0);
-	if (!node->cq) {
+	cqe = message_count ? message_count : 1;
+	node->cq[SEND_CQ_INDEX] = ibv_create_cq(node->cma_id->verbs, cqe, node, 0, 0);
+	node->cq[RECV_CQ_INDEX] = ibv_create_cq(node->cma_id->verbs, cqe, node, 0, 0);
+	if (!node->cq[SEND_CQ_INDEX] || !node->cq[RECV_CQ_INDEX]) {
 		ret = -ENOMEM;
 		printf("cmatose: unable to create CQ\n");
 		goto out;
 	}
 
 	memset(&init_qp_attr, 0, sizeof init_qp_attr);
-	init_qp_attr.cap.max_send_wr = message_count ? message_count : 1;
-	init_qp_attr.cap.max_recv_wr = message_count ? message_count : 1;
+	init_qp_attr.cap.max_send_wr = cqe;
+	init_qp_attr.cap.max_recv_wr = cqe;
 	init_qp_attr.cap.max_send_sge = 1;
 	init_qp_attr.cap.max_recv_sge = 1;
 	init_qp_attr.qp_context = node;
 	init_qp_attr.sq_sig_all = 1;
 	init_qp_attr.qp_type = IBV_QPT_RC;
-	init_qp_attr.send_cq = node->cq;
-	init_qp_attr.recv_cq = node->cq;
+	init_qp_attr.send_cq = node->cq[SEND_CQ_INDEX];
+	init_qp_attr.recv_cq = node->cq[RECV_CQ_INDEX];
 	ret = rdma_create_qp(node->cma_id, node->pd, &init_qp_attr);
 	if (ret) {
-		printf("cmatose: unable to create QP: %d\n", ret);
+		perror("cmatose: unable to create QP");
 		goto out;
 	}
 
@@ -227,12 +233,12 @@ static int addr_handler(struct cmatest_node *node)
 		ret = rdma_set_option(node->cma_id, RDMA_OPTION_ID,
 				      RDMA_OPTION_ID_TOS, &tos, sizeof tos);
 		if (ret)
-			printf("cmatose: set TOS option failed: %d\n", ret);
+			perror("cmatose: set TOS option failed");
 	}
 
 	ret = rdma_resolve_route(node->cma_id, 2000);
 	if (ret) {
-		printf("cmatose: resolve route failed: %d\n", ret);
+		perror("cmatose: resolve route failed");
 		connect_error();
 	}
 	return ret;
@@ -257,7 +263,7 @@ static int route_handler(struct cmatest_node *node)
 	conn_param.retry_count = 5;
 	ret = rdma_connect(node->cma_id, &conn_param);
 	if (ret) {
-		printf("cmatose: failure connecting: %d\n", ret);
+		perror("cmatose: failure connecting");
 		goto err;
 	}
 	return 0;
@@ -294,7 +300,7 @@ static int connect_handler(struct rdma_cm_id *cma_id)
 	conn_param.initiator_depth = 1;
 	ret = rdma_accept(node->cma_id, &conn_param);
 	if (ret) {
-		printf("cmatose: failure accepting: %d\n", ret);
+		perror("cmatose: failure accepting");
 		goto err2;
 	}
 	return 0;
@@ -356,8 +362,11 @@ static void destroy_node(struct cmatest_node *node)
 	if (node->cma_id->qp)
 		rdma_destroy_qp(node->cma_id);
 
-	if (node->cq)
-		ibv_destroy_cq(node->cq);
+	if (node->cq[SEND_CQ_INDEX])
+		ibv_destroy_cq(node->cq[SEND_CQ_INDEX]);
+
+	if (node->cq[RECV_CQ_INDEX])
+		ibv_destroy_cq(node->cq[RECV_CQ_INDEX]);
 
 	if (node->mem) {
 		ibv_dereg_mr(node->mr);
@@ -409,7 +418,7 @@ static void destroy_nodes(void)
 	free(test.nodes);
 }
 
-static int poll_cqs(void)
+static int poll_cqs(enum CQ_INDEX index)
 {
 	struct ibv_wc wc[8];
 	int done, i, ret;
@@ -419,7 +428,7 @@ static int poll_cqs(void)
 			continue;
 
 		for (done = 0; done < message_count; done += ret) {
-			ret = ibv_poll_cq(test.nodes[i].cq, 8, wc);
+			ret = ibv_poll_cq(test.nodes[i].cq[index], 8, wc);
 			if (ret < 0) {
 				printf("cmatose: failed polling CQ: %d\n", ret);
 				return ret;
@@ -440,8 +449,8 @@ static int connect_events(void)
 			cma_handler(event->id, event);
 			rdma_ack_cm_event(event);
 		} else {
-			printf("cmatose: failure in rdma_get_cm_event in connect events\n");
-			ret = err;
+			perror("cmatose: failure in rdma_get_cm_event in connect events");
+			ret = errno;
 		}
 	}
 
@@ -459,8 +468,8 @@ static int disconnect_events(void)
 			cma_handler(event->id, event);
 			rdma_ack_cm_event(event);
 		} else {
-			printf("cmatose: failure in rdma_get_cm_event in disconnect events\n");
-			ret = err;
+			perror("cmatose: failure in rdma_get_cm_event in disconnect events");
+			ret = errno;
 		}
 	}
 
@@ -476,7 +485,7 @@ static int migrate_channel(struct rdma_cm_id *listen_id)
 
 	channel = rdma_create_event_channel();
 	if (!channel) {
-		printf("cmatose: failed to create event channel\n");
+		perror("cmatose: failed to create event channel");
 		return -1;
 	}
 
@@ -491,7 +500,7 @@ static int migrate_channel(struct rdma_cm_id *listen_id)
 		rdma_destroy_event_channel(test.channel);
 		test.channel = channel;
 	} else
-		printf("cmatose: failure migrating to channel: %d\n", ret);
+		perror("cmatose: failure migrating to channel");
 
 	return ret;
 }
@@ -526,7 +535,7 @@ static int run_server(void)
 	printf("cmatose: starting server\n");
 	ret = rdma_create_id(test.channel, &listen_id, &test, RDMA_PS_TCP);
 	if (ret) {
-		printf("cmatose: listen request failed\n");
+		perror("cmatose: listen request failed");
 		return ret;
 	}
 
@@ -540,13 +549,13 @@ static int run_server(void)
 	test.src_in.sin_port = port;
 	ret = rdma_bind_addr(listen_id, test.src_addr);
 	if (ret) {
-		printf("cmatose: bind address failed: %d\n", ret);
+		perror("cmatose: bind address failed");
 		goto out;
 	}
 
 	ret = rdma_listen(listen_id, 0);
 	if (ret) {
-		printf("cmatose: failure trying to listen: %d\n", ret);
+		perror("cmatose: failure trying to listen");
 		goto out;
 	}
 
@@ -563,12 +572,12 @@ static int run_server(void)
 		}
 
 		printf("completing sends\n");
-		ret = poll_cqs();
+		ret = poll_cqs(SEND_CQ_INDEX);
 		if (ret)
 			goto out;
 
 		printf("receiving data transfers\n");
-		ret = poll_cqs();
+		ret = poll_cqs(RECV_CQ_INDEX);
 		if (ret)
 			goto out;
 		printf("data transfers complete\n");
@@ -622,7 +631,7 @@ static int run_client(void)
 					src_addr ? test.src_addr : NULL,
 					test.dst_addr, 2000);
 		if (ret) {
-			printf("cmatose: failure getting addr: %d\n", ret);
+			perror("cmatose: failure getting addr");
 			connect_error();
 			return ret;
 		}
@@ -634,7 +643,7 @@ static int run_client(void)
 
 	if (message_count) {
 		printf("receiving data transfers\n");
-		ret = poll_cqs();
+		ret = poll_cqs(RECV_CQ_INDEX);
 		if (ret)
 			goto disc;
 
diff --git a/examples/mckey.c b/examples/mckey.c
index 15371b6..467873d 100644
--- a/examples/mckey.c
+++ b/examples/mckey.c
@@ -159,7 +159,7 @@ static int init_node(struct cmatest_node *node)
 	init_qp_attr.recv_cq = node->cq;
 	ret = rdma_create_qp(node->cma_id, node->pd, &init_qp_attr);
 	if (ret) {
-		printf("mckey: unable to create QP: %d\n", ret);
+		perror("mckey: unable to create QP");
 		goto out;
 	}
 
@@ -258,7 +258,7 @@ static int addr_handler(struct cmatest_node *node)
 
 	ret = rdma_join_multicast(node->cma_id, test.dst_addr, node);
 	if (ret) {
-		printf("mckey: failure joining: %d\n", ret);
+		perror("mckey: failure joining");
 		goto err;
 	}
 	return 0;
@@ -452,7 +452,7 @@ static int run(void)
 			ret = rdma_bind_addr(test.nodes[i].cma_id,
 					     test.src_addr);
 			if (ret) {
-				printf("mckey: addr bind failure: %d\n", ret);
+				perror("mckey: addr bind failure");
 				connect_error();
 				return ret;
 			}
@@ -465,7 +465,7 @@ static int run(void)
 						test.src_addr, test.dst_addr,
 						2000);
 		if (ret) {
-			printf("mckey: resolve addr failure: %d\n", ret);
+			perror("mckey: resolve addr failure");
 			connect_error();
 			return ret;
 		}
@@ -502,7 +502,7 @@ out:
 		ret = rdma_leave_multicast(test.nodes[i].cma_id,
 					   test.dst_addr);
 		if (ret)
-			printf("mckey: failure leaving: %d\n", ret);
+			perror("mckey: failure leaving");
 	}
 	return ret;
 }
@@ -561,7 +561,7 @@ int main(int argc, char **argv)
 
 	test.channel = rdma_create_event_channel();
 	if (!test.channel) {
-		printf("failed to create event channel\n");
+		perror("failed to create event channel");
 		exit(1);
 	}
 
diff --git a/examples/rping.c b/examples/rping.c
index f5dd701..91952e7 100644
--- a/examples/rping.c
+++ b/examples/rping.c
@@ -143,7 +143,7 @@ struct rping_cb {
 	enum test_state state;		/* used for cond/signalling */
 	sem_t sem;
 
-	struct sockaddr_in sin;
+	struct sockaddr_storage sin;
 	uint16_t port;			/* dst port in NBO */
 	int verbose;			/* verbose logging */
 	int count;			/* ping count */
@@ -174,7 +174,7 @@ static int rping_cma_event_handler(struct rdma_cm_id *cma_id,
 		ret = rdma_resolve_route(cma_id, 2000);
 		if (ret) {
 			cb->state = ERROR;
-			fprintf(stderr, "rdma_resolve_route error %d\n", ret);
+			perror("rdma_resolve_route");
 			sem_post(&cb->sem);
 		}
 		break;
@@ -352,7 +352,7 @@ static int rping_accept(struct rping_cb *cb)
 
 	ret = rdma_accept(cb->child_cm_id, &conn_param);
 	if (ret) {
-		fprintf(stderr, "rdma_accept error: %d\n", ret);
+		perror("rdma_accept");
 		return ret;
 	}
 
@@ -546,7 +546,7 @@ static int rping_setup_qp(struct rping_cb *cb, struct rdma_cm_id *cm_id)
 
 	ret = rping_create_qp(cb);
 	if (ret) {
-		fprintf(stderr, "rping_create_qp failed: %d\n", ret);
+		perror("rdma_create_qp");
 		goto err3;
 	}
 	DEBUG_LOG("created qp %p\n", cb->qp);
@@ -570,7 +570,7 @@ static void *cm_thread(void *arg)
 	while (1) {
 		ret = rdma_get_cm_event(cb->cm_channel, &event);
 		if (ret) {
-			fprintf(stderr, "rdma_get_cm_event err %d\n", ret);
+			perror("rdma_get_cm_event");
 			exit(ret);
 		}
 		ret = rping_cma_event_handler(event->id, event);
@@ -729,10 +729,14 @@ static int rping_bind_server(struct rping_cb *cb)
 {
 	int ret;
 
-	cb->sin.sin_port = cb->port;
+	if (cb->sin.ss_family == AF_INET)
+		((struct sockaddr_in *) &cb->sin)->sin_port = cb->port;
+	else
+		((struct sockaddr_in6 *) &cb->sin)->sin6_port = cb->port;
+
 	ret = rdma_bind_addr(cb->cm_id, (struct sockaddr *) &cb->sin);
 	if (ret) {
-		fprintf(stderr, "rdma_bind_addr error %d\n", ret);
+		perror("rdma_bind_addr");
 		return ret;
 	}
 	DEBUG_LOG("rdma_bind_addr successful\n");
@@ -740,7 +744,7 @@ static int rping_bind_server(struct rping_cb *cb)
 	DEBUG_LOG("rdma_listen\n");
 	ret = rdma_listen(cb->cm_id, 3);
 	if (ret) {
-		fprintf(stderr, "rdma_listen failed: %d\n", ret);
+		perror("rdma_listen");
 		return ret;
 	}
 
@@ -974,7 +978,7 @@ static int rping_connect_client(struct rping_cb *cb)
 
 	ret = rdma_connect(cb->cm_id, &conn_param);
 	if (ret) {
-		fprintf(stderr, "rdma_connect error %d\n", ret);
+		perror("rdma_connect");
 		return ret;
 	}
 
@@ -992,10 +996,14 @@ static int rping_bind_client(struct rping_cb *cb)
 {
 	int ret;
 
-	cb->sin.sin_port = cb->port;
+	if (cb->sin.ss_family == AF_INET)
+		((struct sockaddr_in *) &cb->sin)->sin_port = cb->port;
+	else
+		((struct sockaddr_in6 *) &cb->sin)->sin6_port = cb->port;
+
 	ret = rdma_resolve_addr(cb->cm_id, NULL, (struct sockaddr *) &cb->sin, 2000);
 	if (ret) {
-		fprintf(stderr, "rdma_resolve_addr error %d\n", ret);
+		perror("rdma_resolve_addr");
 		return ret;
 	}
 
@@ -1055,7 +1063,7 @@ err1:
 	return ret;
 }
 
-static int get_addr(char *dst, struct sockaddr_in *addr)
+static int get_addr(char *dst, struct sockaddr *addr)
 {
 	struct addrinfo *res;
 	int ret;
@@ -1066,13 +1074,13 @@ static int get_addr(char *dst, struct sockaddr_in *addr)
 		return ret;
 	}
 
-	if (res->ai_family != PF_INET) {
+	if (res->ai_family == PF_INET)
+		memcpy(addr, res->ai_addr, sizeof(struct sockaddr_in));
+	else if (res->ai_family == PF_INET6)
+		memcpy(addr, res->ai_addr, sizeof(struct sockaddr_in6));
+	else
 		ret = -1;
-		goto out;
-	}
-
-	*addr = *(struct sockaddr_in *) res->ai_addr;
-out:
+	
 	freeaddrinfo(res);
 	return ret;
 }
@@ -1084,7 +1092,7 @@ static void usage(char *name)
 	printf("%s -c [-vVd] [-S size] [-C count] -a addr [-p port]\n", 
 	       basename(name));
 	printf("\t-c\t\tclient side\n");
-	printf("\t-s\t\tserver side\n");
+	printf("\t-s\t\tserver side.  To bind to any address with IPv6 use -a ::0\n");
 	printf("\t-v\t\tdisplay ping data to stdout\n");
 	printf("\t-V\t\tvalidate ping data\n");
 	printf("\t-d\t\tdebug printfs\n");
@@ -1110,7 +1118,7 @@ int main(int argc, char *argv[])
 	cb->server = -1;
 	cb->state = IDLE;
 	cb->size = 64;
-	cb->sin.sin_family = PF_INET;
+	cb->sin.ss_family = PF_INET;
 	cb->port = htons(7174);
 	sem_init(&cb->sem, 0, 0);
 
@@ -1118,7 +1126,7 @@ int main(int argc, char *argv[])
 	while ((op=getopt(argc, argv, "a:Pp:C:S:t:scvVd")) != -1) {
 		switch (op) {
 		case 'a':
-			ret = get_addr(optarg, &cb->sin);
+			ret = get_addr(optarg, (struct sockaddr *) &cb->sin);
 			break;
 		case 'P':
 			persistent_server = 1;
@@ -1183,15 +1191,13 @@ int main(int argc, char *argv[])
 
 	cb->cm_channel = rdma_create_event_channel();
 	if (!cb->cm_channel) {
-		ret = errno;
-		fprintf(stderr, "rdma_create_event_channel error %d\n", ret);
+		perror("rdma_create_event_channel");
 		goto out;
 	}
 
 	ret = rdma_create_id(cb->cm_channel, &cb->cm_id, cb, RDMA_PS_TCP);
 	if (ret) {
-		ret = errno;
-		fprintf(stderr, "rdma_create_id error %d\n", ret);
+		perror("rdma_create_id");
 		goto out2;
 	}
 	DEBUG_LOG("created cm_id %p\n", cb->cm_id);
diff --git a/examples/udaddy.c b/examples/udaddy.c
index 0d69b05..637306a 100644
--- a/examples/udaddy.c
+++ b/examples/udaddy.c
@@ -158,7 +158,7 @@ static int init_node(struct cmatest_node *node)
 	init_qp_attr.recv_cq = node->cq;
 	ret = rdma_create_qp(node->cma_id, node->pd, &init_qp_attr);
 	if (ret) {
-		printf("udaddy: unable to create QP: %d\n", ret);
+		perror("udaddy: unable to create QP");
 		goto out;
 	}
 
@@ -245,12 +245,12 @@ static int addr_handler(struct cmatest_node *node)
 		ret = rdma_set_option(node->cma_id, RDMA_OPTION_ID,
 				      RDMA_OPTION_ID_TOS, &tos, sizeof tos);
 		if (ret)
-			printf("udaddy: set TOS option failed: %d\n", ret);
+			perror("udaddy: set TOS option failed");
 	}
 
 	ret = rdma_resolve_route(node->cma_id, 2000);
 	if (ret) {
-		printf("udaddy: resolve route failed: %d\n", ret);
+		perror("udaddy: resolve route failed");
 		connect_error();
 	}
 	return ret;
@@ -276,7 +276,7 @@ static int route_handler(struct cmatest_node *node)
 	memset(&conn_param, 0, sizeof conn_param);
 	ret = rdma_connect(node->cma_id, &conn_param);
 	if (ret) {
-		printf("udaddy: failure connecting: %d\n", ret);
+		perror("udaddy: failure connecting");
 		goto err;
 	}
 	return 0;
@@ -316,7 +316,7 @@ static int connect_handler(struct rdma_cm_id *cma_id)
 	conn_param.qp_num = node->cma_id->qp->qp_num;
 	ret = rdma_accept(node->cma_id, &conn_param);
 	if (ret) {
-		printf("udaddy: failure accepting: %d\n", ret);
+		perror("udaddy: failure accepting");
 		goto err2;
 	}
 	node->connected = 1;
@@ -532,7 +532,7 @@ static int run_server(void)
 	printf("udaddy: starting server\n");
 	ret = rdma_create_id(test.channel, &listen_id, &test, port_space);
 	if (ret) {
-		printf("udaddy: listen request failed\n");
+		perror("udaddy: listen request failed");
 		return ret;
 	}
 
@@ -546,13 +546,13 @@ static int run_server(void)
 	test.src_in.sin_port = port;
 	ret = rdma_bind_addr(listen_id, test.src_addr);
 	if (ret) {
-		printf("udaddy: bind address failed: %d\n", ret);
+		perror("udaddy: bind address failed");
 		return ret;
 	}
 
 	ret = rdma_listen(listen_id, 0);
 	if (ret) {
-		printf("udaddy: failure trying to listen: %d\n", ret);
+		perror("udaddy: failure trying to listen");
 		goto out;
 	}
 
@@ -604,7 +604,7 @@ static int run_client(void)
 					src_addr ? test.src_addr : NULL,
 					test.dst_addr, 2000);
 		if (ret) {
-			printf("udaddy: failure getting addr: %d\n", ret);
+			perror("udaddy: failure getting addr");
 			connect_error();
 			return ret;
 		}
@@ -680,7 +680,7 @@ int main(int argc, char **argv)
 
 	test.channel = rdma_create_event_channel();
 	if (!test.channel) {
-		printf("failed to create event channel\n");
+		perror("failed to create event channel");
 		exit(1);
 	}
 
diff --git a/librdmacm.spec b/librdmacm.spec
index cef1016..adb33bb 100644
--- a/librdmacm.spec
+++ b/librdmacm.spec
@@ -1,7 +1,7 @@
-%define ver 1.0.8
+%define ver 1.0.10
 
 Name: librdmacm
-Version: 1.0.8
+Version: 1.0.10
 Release: 1%{?dist}
 Summary: Userspace RDMA Connection Manager
 
diff --git a/librdmacm.spec.in b/librdmacm.spec.in
index 2c873c4..2339ecb 100644
--- a/librdmacm.spec.in
+++ b/librdmacm.spec.in
@@ -1,7 +1,7 @@
 %define ver @VERSION@
 
 Name: librdmacm
-Version: 1.0.8
+Version: 1.0.10
 Release: 1%{?dist}
 Summary: Userspace RDMA Connection Manager
 
diff --git a/man/rdma_cm.7 b/man/rdma_cm.7
index 23571b2..fd04959 100644
--- a/man/rdma_cm.7
+++ b/man/rdma_cm.7
@@ -108,18 +108,18 @@ release the event channel
 success
 .IP "= -1"
 error - see errno for more details
-.IP "< -1"
-error - see include/asm-generic/errno*.h for more details
 .P
-Librdmacm functions return 0 to indicate success, and a negative return value
+Librdmacm functions return 0 to indicate success, and a -1 return value
 to indicate failure.  If a function operates asynchronously, a return value of 0
 means that the operation was successfully started.  The operation could still
 complete in error; users should check the status of the related event.  If the
-return value is -1, then errno can be examined for additional information
-regarding the reason for the failure.  If the return value is < -1, then
-additional error reasons can be obtained by comparing the returned value with
-the values listed in include/asm-generic/errno-base.h and
-include/asm-generic/errno.h.
+return value is -1, then errno will contain additional information
+regarding the reason for the failure.
+.P
+Prior versions of the library would return -errno and not set errno for some cases
+related to ENOMEM, ENODEV, ENODATA, EINVAL, and EADDRNOTAVAIL codes. Applications
+that want to check these codes and have compatability with prior library versions
+must manually set errno to the negative of the return code if it is < -1.
 .SH "SEE ALSO"
 rdma_create_event_channel(3), rdma_get_cm_event(3), rdma_create_id(3),
 rdma_resolve_addr(3), rdma_bind_addr(3), rdma_create_qp(3),
diff --git a/src/cma.c b/src/cma.c
index d4441ce..efad6ae 100644
--- a/src/cma.c
+++ b/src/cma.c
@@ -76,6 +76,12 @@ static inline uint64_t htonll(uint64_t x) { return x; }
 static inline uint64_t ntohll(uint64_t x) { return x; }
 #endif
 
+static inline int ERR(int err)
+{
+	errno = err;
+	return -1;
+}
+
 #define CMA_CREATE_MSG_CMD_RESP(msg, cmd, resp, type, size) \
 do {                                        \
 	struct ucma_abi_cmd_hdr *hdr;         \
@@ -83,7 +89,7 @@ do {                                        \
 	size = sizeof(*hdr) + sizeof(*cmd); \
 	msg = alloca(size);                 \
 	if (!msg)                           \
-		return -ENOMEM;             \
+		return ERR(ENOMEM);         \
 	hdr = msg;                          \
 	cmd = msg + sizeof(*hdr);           \
 	hdr->cmd = type;                    \
@@ -92,18 +98,18 @@ do {                                        \
 	memset(cmd, 0, sizeof(*cmd));       \
 	resp = alloca(sizeof(*resp));       \
 	if (!resp)                          \
-		return -ENOMEM;             \
+		return ERR(ENOMEM);         \
 	cmd->response = (uintptr_t)resp;\
 } while (0)
 
 #define CMA_CREATE_MSG_CMD(msg, cmd, type, size) \
 do {                                        \
-	struct ucma_abi_cmd_hdr *hdr;         \
+	struct ucma_abi_cmd_hdr *hdr;       \
                                             \
 	size = sizeof(*hdr) + sizeof(*cmd); \
 	msg = alloca(size);                 \
 	if (!msg)                           \
-		return -ENOMEM;             \
+		return ERR(ENOMEM);         \
 	hdr = msg;                          \
 	cmd = msg + sizeof(*hdr);           \
 	hdr->cmd = type;                    \
@@ -140,9 +146,7 @@ struct cma_multicast {
 	uint32_t	handle;
 	union ibv_gid	mgid;
 	uint16_t	mlid;
-	struct sockaddr addr;
-	uint8_t		pad[sizeof(struct sockaddr_in6) -
-			    sizeof(struct sockaddr)];
+	struct sockaddr_storage addr;
 };
 
 struct cma_event {
@@ -207,59 +211,67 @@ static int ucma_init(void)
 	struct ibv_device **dev_list = NULL;
 	struct cma_device *cma_dev;
 	struct ibv_device_attr attr;
-	int i, ret;
+	int i, ret, dev_cnt;
 
 	pthread_mutex_lock(&mut);
-	if (cma_dev_cnt)
-		goto out;
+	if (cma_dev_cnt) {
+		pthread_mutex_unlock(&mut);
+		return 0;
+	}
 
 	ret = check_abi_version();
 	if (ret)
-		goto err;
+		goto err1;
 
-	dev_list = ibv_get_device_list(&cma_dev_cnt);
+	dev_list = ibv_get_device_list(&dev_cnt);
 	if (!dev_list) {
 		printf("CMA: unable to get RDMA device list\n");
-		ret = -ENODEV;
-		goto err;
+		ret = ERR(ENODEV);
+		goto err1;
 	}
 
-	cma_dev_array = malloc(sizeof *cma_dev * cma_dev_cnt);
+	cma_dev_array = malloc(sizeof *cma_dev * dev_cnt);
 	if (!cma_dev_array) {
-		ret = -ENOMEM;
-		goto err;
+		ret = ERR(ENOMEM);
+		goto err2;
 	}
 
-	for (i = 0; dev_list[i]; ++i) {
+	for (i = 0; dev_list[i];) {
 		cma_dev = &cma_dev_array[i];
 
 		cma_dev->guid = ibv_get_device_guid(dev_list[i]);
 		cma_dev->verbs = ibv_open_device(dev_list[i]);
 		if (!cma_dev->verbs) {
 			printf("CMA: unable to open RDMA device\n");
-			ret = -ENODEV;
-			goto err;
+			ret = ERR(ENODEV);
+			goto err3;
 		}
 
+		i++;
 		ret = ibv_query_device(cma_dev->verbs, &attr);
 		if (ret) {
 			printf("CMA: unable to query RDMA device\n");
-			goto err;
+			goto err3;
 		}
 
 		cma_dev->port_cnt = attr.phys_port_cnt;
 		cma_dev->max_initiator_depth = (uint8_t) attr.max_qp_init_rd_atom;
 		cma_dev->max_responder_resources = (uint8_t) attr.max_qp_rd_atom;
 	}
-out:
+
+	cma_dev_cnt = dev_cnt;
 	pthread_mutex_unlock(&mut);
 	ibv_free_device_list(dev_list);
 	return 0;
-err:
-	ucma_cleanup();
+
+err3:
+	while (i--)
+		ibv_close_device(cma_dev_array[i].verbs);
+	free(cma_dev_array);
+err2:
+	ibv_free_device_list(dev_list);
+err1:
 	pthread_mutex_unlock(&mut);
-	if (dev_list)
-		ibv_free_device_list(dev_list);
 	return ret;
 }
 
@@ -336,7 +348,7 @@ static int ucma_get_device(struct cma_id_private *id_priv, uint64_t guid)
 		}
 	}
 
-	return -ENODEV;
+	return ERR(ENODEV);
 }
 
 static void ucma_free_id(struct cma_id_private *id_priv)
@@ -388,7 +400,7 @@ int rdma_create_id(struct rdma_event_channel *channel,
 
 	id_priv = ucma_alloc_id(channel, context, ps);
 	if (!id_priv)
-		return -ENOMEM;
+		return ERR(ENOMEM);
 
 	CMA_CREATE_MSG_CMD_RESP(msg, cmd, resp, UCMA_CMD_CREATE_ID, size);
 	cmd->uid = (uintptr_t) id_priv;
@@ -420,7 +432,7 @@ static int ucma_destroy_kern_id(int fd, uint32_t handle)
 
 	ret = write(fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
 
@@ -475,7 +487,7 @@ static int ucma_query_route(struct rdma_cm_id *id)
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
 
@@ -483,7 +495,7 @@ static int ucma_query_route(struct rdma_cm_id *id)
 		id->route.path_rec = malloc(sizeof *id->route.path_rec *
 					    resp->num_paths);
 		if (!id->route.path_rec)
-			return -ENOMEM;
+			return ERR(ENOMEM);
 
 		id->route.num_paths = resp->num_paths;
 		for (i = 0; i < resp->num_paths; i++)
@@ -520,7 +532,7 @@ int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr)
 	
 	addrlen = ucma_addrlen(addr);
 	if (!addrlen)
-		return -EINVAL;
+		return ERR(EINVAL);
 
 	CMA_CREATE_MSG_CMD(msg, cmd, UCMA_CMD_BIND_ADDR, size);
 	id_priv = container_of(id, struct cma_id_private, id);
@@ -529,7 +541,7 @@ int rdma_bind_addr(struct rdma_cm_id *id, struct sockaddr *addr)
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	return ucma_query_route(id);
 }
@@ -544,7 +556,7 @@ int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr,
 	
 	daddrlen = ucma_addrlen(dst_addr);
 	if (!daddrlen)
-		return -EINVAL;
+		return ERR(EINVAL);
 
 	CMA_CREATE_MSG_CMD(msg, cmd, UCMA_CMD_RESOLVE_ADDR, size);
 	id_priv = container_of(id, struct cma_id_private, id);
@@ -556,7 +568,7 @@ int rdma_resolve_addr(struct rdma_cm_id *id, struct sockaddr *src_addr,
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	memcpy(&id->route.addr.dst_addr, dst_addr, daddrlen);
 	return 0;
@@ -576,7 +588,7 @@ int rdma_resolve_route(struct rdma_cm_id *id, int timeout_ms)
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	return 0;
 }
@@ -602,7 +614,7 @@ static int rdma_init_qp_attr(struct rdma_cm_id *id, struct ibv_qp_attr *qp_attr,
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
 
@@ -618,7 +630,7 @@ static int ucma_modify_qp_rtr(struct rdma_cm_id *id,
 	int qp_attr_mask, ret;
 
 	if (!id->qp)
-		return -EINVAL;
+		return ERR(EINVAL);
 
 	/* Need to update QP attributes from default values. */
 	qp_attr.qp_state = IBV_QPS_INIT;
@@ -688,7 +700,7 @@ static int ucma_find_pkey(struct cma_device *cma_dev, uint8_t port_num,
 			return 0;
 		}
 	}
-	return -EINVAL;
+	return ERR(EINVAL);
 }
 
 static int ucma_init_conn_qp3(struct cma_id_private *id_priv, struct ibv_qp *qp)
@@ -792,11 +804,11 @@ int rdma_create_qp(struct rdma_cm_id *id, struct ibv_pd *pd,
 
 	id_priv = container_of(id, struct cma_id_private, id);
 	if (id->verbs != pd->context)
-		return -EINVAL;
+		return ERR(EINVAL);
 
 	qp = ibv_create_qp(pd, qp_init_attr);
 	if (!qp)
-		return -ENOMEM;
+		return ERR(ENOMEM);
 
 	if (ucma_is_ud_ps(id->ps))
 		ret = ucma_init_ud_qp(id_priv, qp);
@@ -827,7 +839,7 @@ static int ucma_valid_param(struct cma_id_private *id_priv,
 	     id_priv->cma_dev->max_responder_resources) ||
 	    (conn_param->initiator_depth >
 	     id_priv->cma_dev->max_initiator_depth))
-		return -EINVAL;
+		return ERR(EINVAL);
 
 	return 0;
 }
@@ -877,7 +889,7 @@ int rdma_connect(struct rdma_cm_id *id, struct rdma_conn_param *conn_param)
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	return 0;
 }
@@ -896,7 +908,7 @@ int rdma_listen(struct rdma_cm_id *id, int backlog)
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	return ucma_query_route(id);
 }
@@ -934,7 +946,7 @@ int rdma_accept(struct rdma_cm_id *id, struct rdma_conn_param *conn_param)
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size) {
 		ucma_modify_qp_err(id);
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 	}
 
 	return 0;
@@ -960,7 +972,7 @@ int rdma_reject(struct rdma_cm_id *id, const void *private_data,
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	return 0;
 }
@@ -979,7 +991,7 @@ int rdma_notify(struct rdma_cm_id *id, enum ibv_event_type event)
 	cmd->event = event;
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	return 0;
 }
@@ -999,7 +1011,7 @@ int rdma_disconnect(struct rdma_cm_id *id)
 		ret = ucma_modify_qp_sqd(id);
 		break;
 	default:
-		ret = -EINVAL;
+		ret = ERR(EINVAL);
 	}
 	if (ret)
 		return ret;
@@ -1010,7 +1022,7 @@ int rdma_disconnect(struct rdma_cm_id *id)
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	return 0;
 }
@@ -1028,17 +1040,17 @@ int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
 	id_priv = container_of(id, struct cma_id_private, id);
 	addrlen = ucma_addrlen(addr);
 	if (!addrlen)
-		return -EINVAL;
+		return ERR(EINVAL);
 
 	mc = malloc(sizeof *mc);
 	if (!mc)
-		return -ENOMEM;
+		return ERR(ENOMEM);
 
 	memset(mc, 0, sizeof *mc);
 	mc->context = context;
 	mc->id_priv = id_priv;
 	memcpy(&mc->addr, addr, addrlen);
-	if (pthread_cond_init(&id_priv->cond, NULL)) {
+	if (pthread_cond_init(&mc->cond, NULL)) {
 		ret = -1;
 		goto err1;
 	}
@@ -1055,7 +1067,7 @@ int rdma_join_multicast(struct rdma_cm_id *id, struct sockaddr *addr,
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size) {
-		ret = (ret > 0) ? -ENODATA : ret;
+		ret = (ret >= 0) ? ERR(ENODATA) : -1;
 		goto err2;
 	}
 
@@ -1085,7 +1097,7 @@ int rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
 	
 	addrlen = ucma_addrlen(addr);
 	if (!addrlen)
-		return -EINVAL;
+		return ERR(EINVAL);
 
 	id_priv = container_of(id, struct cma_id_private, id);
 	pthread_mutex_lock(&id_priv->mut);
@@ -1098,7 +1110,7 @@ int rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
 		*pos = mc->next;
 	pthread_mutex_unlock(&id_priv->mut);
 	if (!mc)
-		return -EADDRNOTAVAIL;
+		return ERR(EADDRNOTAVAIL);
 
 	if (id->qp)
 		ibv_detach_mcast(id->qp, &mc->mgid, mc->mlid);
@@ -1108,7 +1120,7 @@ int rdma_leave_multicast(struct rdma_cm_id *id, struct sockaddr *addr)
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size) {
-		ret = (ret > 0) ? -ENODATA : ret;
+		ret = (ret >= 0) ? ERR(ENODATA) : -1;
 		goto free;
 	}
 
@@ -1148,7 +1160,7 @@ int rdma_ack_cm_event(struct rdma_cm_event *event)
 	struct cma_event *evt;
 
 	if (!event)
-		return -EINVAL;
+		return ERR(EINVAL);
 
 	evt = container_of(event, struct cma_event, event);
 
@@ -1170,7 +1182,7 @@ static int ucma_process_conn_req(struct cma_event *evt,
 				evt->id_priv->id.context, evt->id_priv->id.ps);
 	if (!id_priv) {
 		ucma_destroy_kern_id(evt->id_priv->id.channel->fd, handle);
-		ret = -ENOMEM;
+		ret = ERR(ENOMEM);
 		goto err;
 	}
 
@@ -1209,7 +1221,7 @@ static int ucma_process_conn_resp(struct cma_id_private *id_priv)
 
 	ret = write(id_priv->id.channel->fd, msg, size);
 	if (ret != size) {
-		ret = (ret > 0) ? -ENODATA : ret;
+		ret = (ret >= 0) ? ERR(ENODATA) : -1;
 		goto err;
 	}
 
@@ -1294,11 +1306,11 @@ int rdma_get_cm_event(struct rdma_event_channel *channel,
 		return ret;
 
 	if (!event)
-		return -EINVAL;
+		return ERR(EINVAL);
 
 	evt = malloc(sizeof *evt);
 	if (!evt)
-		return -ENOMEM;
+		return ERR(ENOMEM);
 
 retry:
 	memset(evt, 0, sizeof *evt);
@@ -1306,7 +1318,7 @@ retry:
 	ret = write(channel->fd, msg, size);
 	if (ret != size) {
 		free(evt);
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 	}
 	
 	VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
@@ -1465,7 +1477,7 @@ int rdma_set_option(struct rdma_cm_id *id, int level, int optname,
 
 	ret = write(id->channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	return 0;
 }
@@ -1485,7 +1497,7 @@ int rdma_migrate_id(struct rdma_cm_id *id, struct rdma_event_channel *channel)
 
 	ret = write(channel->fd, msg, size);
 	if (ret != size)
-		return (ret > 0) ? -ENODATA : ret;
+		return (ret >= 0) ? ERR(ENODATA) : -1;
 
 	VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ofed/librdmacm.git



More information about the Pkg-ofed-commits mailing list