From: Sean Hefty Date: Tue, 22 Jul 2008 05:23:02 +0000 (-0700) Subject: libibcm: open correct ucm file X-Git-Tag: v1.0.4~4 X-Git-Url: https://openfabrics.org/gitweb/?a=commitdiff_plain;h=ae8c050d9d069607fac5899c8fa1d4ed8a0a79e2;p=~shefty%2Flibibcm.git libibcm: open correct ucm file 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 --- diff --git a/src/cm.c b/src/cm.c index c0bcba3..571e28a 100644 --- a/src/cm.c +++ b/src/cm.c @@ -67,6 +67,10 @@ 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; }