Sophie

Sophie

distrib > Mageia > 3 > i586 > media > core-release-src > by-pkgid > 0ffedb546e146cfbef3c4cdabc46b7c3 > files > 9

librdmacm-1.0.15-5.mga3.src.rpm

From 4b5c1aa734e0e734fc2ba3cd41d0ddf02170af6d Mon Sep 17 00:00:00 2001
From: Sean Hefty <sean.hefty@intel.com>
Date: Mon, 8 Oct 2012 10:33:21 -0700
Subject: [PATCH] librdmacm: Disable ACM support if ibacm.port is not found

The librdmacm will try to connect port 6125 if ibacm.port is
not found.  The problem is that some other service or application
could be using that port and respond with garbage.  Rather
than falling back to a hard coded port number, if ibacm.port
is not found, simply disable ACM support.

This has the effect of removing support for older versions
of ibacm, unless the port file is created manually.

Patch created based on feedback from Doug Ledford and Florian
Weimer from RedHat.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
---
 src/acm.c |    9 ++++++---
 1 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/src/acm.c b/src/acm.c
index 3d8c912..c9ca5b5 100755
--- a/src/acm.c
+++ b/src/acm.c
@@ -50,7 +50,7 @@
 
 static pthread_mutex_t acm_lock = PTHREAD_MUTEX_INITIALIZER;
 static int sock;
-static short server_port = 6125;
+static short server_port;
 
 struct ib_connect_hdr {
 	uint8_t  cma_version;
@@ -64,7 +64,7 @@
 #define cma_dst_ip6 dst_addr[0]
 };
 
-static void ucma_set_server_port(void)
+static int ucma_set_server_port(void)
 {
 	FILE *f;
 
@@ -72,31 +72,37 @@
 		fscanf(f, "%hu", (unsigned short *) &server_port);
 		fclose(f);
 	}
+	return server_port;
 }
 
 void ucma_ib_init(void)
 {
 	struct sockaddr_in addr;
+	static int init;
 	int ret;
 
-	ucma_set_server_port();
+	if (init)
+		return;
+
+	if (!ucma_set_server_port())
+		goto out;
+
 	sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
 	if (sock < 0)
-		return;
+		goto out;
 
 	memset(&addr, 0, sizeof addr);
 	addr.sin_family = AF_INET;
 	addr.sin_addr.s_addr = htonl(INADDR_LOOPBACK);
 	addr.sin_port = htons(server_port);
 	ret = connect(sock, (struct sockaddr *) &addr, sizeof(addr));
-	if (ret)
-		goto err;
-
-	return;
+	if (ret) {
+		close(sock);
+		sock = 0;
+	}
 
-err:
-	close(sock);
-	sock = 0;
+out:
+	init = 1;
 }
 
 void ucma_ib_cleanup(void)
-- 
1.7.0.4