]> git.openfabrics.org - ~shefty/libibcm.git/commitdiff
libibcm: open correct ucm file
authorSean Hefty <sean.hefty@intel.com>
Tue, 22 Jul 2008 05:23:02 +0000 (22:23 -0700)
committerSean Hefty <sean.hefty@intel.com>
Tue, 22 Jul 2008 05:23:02 +0000 (22:23 -0700)
When opening the ucm* file, we need to select the correct file based
on the underlying libibverbs device.  We cannot base the file name
on the uverbs* file name, since iwarp devices do not result in ucm*
files.  Instead, we need to search for the correct file name based
on the device name.

This fixes a problem reported by Jeff Squires of Cisco running ib_cm
on a system with both iwarp and ib devices present.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
src/cm.c

index c0bcba3c5ea3d20252662a1d1bd56e1fdb9195a0..571e28a1726e54ee20e38d991c2384179e0e75f2 100644 (file)
--- a/src/cm.c
+++ b/src/cm.c
 static int abi_ver;
 static pthread_mutex_t mut = PTHREAD_MUTEX_INITIALIZER;
 
+enum {
+       IB_UCM_MAX_DEVICES = 32
+};
+
 #define CM_CREATE_MSG_CMD_RESP(msg, cmd, resp, type, size) \
 do {                                        \
        struct cm_abi_cmd_hdr *hdr;         \
@@ -147,35 +151,64 @@ static int ucm_init(void)
        return ret;
 }
 
+static int ucm_get_dev_index(char *dev_name)
+{
+       char *dev_path;
+       char ibdev[IBV_SYSFS_NAME_MAX];
+       int i, ret;
+
+       for (i = 0; i < IB_UCM_MAX_DEVICES; i++) {
+               ret = asprintf(&dev_path, "/sys/class/infiniband_cm/ucm%d", i);
+               if (ret < 0)
+                       return -1;
+
+               ret = ibv_read_sysfs_file(dev_path, "ibdev", ibdev, sizeof ibdev);
+               if (ret < 0)
+                       continue;
+
+               if (!strcmp(dev_name, ibdev)) {
+                       free(dev_path);
+                       return i;
+               }
+
+               free(dev_path);
+       }
+       return -1;
+}
+
 struct ib_cm_device* ib_cm_open_device(struct ibv_context *device_context)
 {
        struct ib_cm_device *dev;
        char *dev_path;
+       int index, ret;
 
        if (ucm_init())
                return NULL;
 
+       index = ucm_get_dev_index(device_context->device->name);
+       if (index < 0)
+               return NULL;
+
        dev = malloc(sizeof *dev);
        if (!dev)
                return NULL;
 
        dev->device_context = device_context;
 
-       if (asprintf(&dev_path, "/dev/infiniband/ucm%s",
-                device_context->device->dev_name + sizeof("uverbs") - 1) < 0)
-               goto err2;
+       ret = asprintf(&dev_path, "/dev/infiniband/ucm%d", index);
+       if (ret < 0)
+               goto err1;
 
        dev->fd = open(dev_path, O_RDWR);
-       if (dev->fd < 0) {
-               goto err;
-       }
+       if (dev->fd < 0)
+               goto err2;
 
        free(dev_path);
        return dev;
 
-err:
-       free(dev_path);
 err2:
+       free(dev_path);
+err1:
        free(dev);
        return NULL;
 }