librdmacm: Disable ACM support if ibacm.port is not found
authorSean Hefty <sean.hefty@intel.com>
Mon, 8 Oct 2012 17:33:21 +0000 (10:33 -0700)
committerSean Hefty <sean.hefty@intel.com>
Mon, 8 Oct 2012 17:33:21 +0000 (10:33 -0700)
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

index 3d8c912..c9ca5b5 100755 (executable)
--- a/src/acm.c
+++ b/src/acm.c
@@ -62,7 +62,7 @@ typedef struct acm_msg cma_acm_msg_t;
 
 static pthread_mutex_t acm_lock = PTHREAD_MUTEX_INITIALIZER;
 static int sock = -1;
-static short server_port = 6125;
+static short server_port;
 
 struct ib_connect_hdr {
        uint8_t  cma_version;
@@ -76,7 +76,7 @@ struct ib_connect_hdr {
 #define cma_dst_ip6 dst_addr[0]
 };
 
-static void ucma_set_server_port(void)
+static int ucma_set_server_port(void)
 {
        FILE *f;
 
@@ -84,6 +84,7 @@ static void ucma_set_server_port(void)
                fscanf(f, "%hu", (unsigned short *) &server_port);
                fclose(f);
        }
+       return server_port;
 }
 
 void ucma_ib_init(void)
@@ -96,7 +97,9 @@ void ucma_ib_init(void)
                return;
 
        pthread_mutex_lock(&acm_lock);
-       ucma_set_server_port();
+       if (!ucma_set_server_port())
+               goto out;
+
        sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
        if (sock < 0)
                goto out;