]> git.openfabrics.org - ~shefty/librdmacm.git/commitdiff
r8523: Add calls to the RDMA CM to return its list of RDMA devices. The calls are
authorSean Hefty <sean.hefty@intel.com>
Fri, 14 Jul 2006 16:19:16 +0000 (16:19 +0000)
committerSean Hefty <sean.hefty@intel.com>
Fri, 14 Jul 2006 16:19:16 +0000 (16:19 +0000)
similar to ibv_get_device_list() / ibv_free_device_list().

Without this patch, RDMA device contexts are handed to the user only after
they create an rdma_cm_id and bind it to a local device.  By exposing the
device list to the user, it makes it easier for the user to allocate device
specific resources (such as PDs, CQs, etc.) that are shared among multiple
rdma_cm_id's.

Signed-off-by: Sean Hefty <sean.hefty@intel.com>
include/rdma/rdma_cma.h
src/cma.c
src/librdmacm.map

index 3e91414dc110365611f529046bf6f1d7068575a9..e8d0430b069f9a89418168208c87be24ccb10211 100644 (file)
@@ -332,4 +332,20 @@ static inline uint16_t rdma_get_dst_port(struct rdma_cm_id *id)
                ((struct sockaddr_in *) &id->route.addr.dst_addr)->sin_port;
 }
 
+/**
+ * rdma_get_devices - Get list of RDMA devices currently available.
+ * @num_devices: If non-NULL, set to the number of devices returned.
+ *
+ * Return a NULL-terminated array of opened RDMA devices.  Callers can use this
+ * routine to allocate resources on specific RDMA devices that will be shared
+ * across multiple rdma_cm_id's.
+ * The array must be released by calling rdma_free_devices().
+ */
+struct ibv_context **rdma_get_devices(int *num_devices);
+
+/**
+ * rdma_free_devices - Frees the list of devices returned by rdma_get_devices().
+ */
+void rdma_free_devices(struct ibv_context **list);
+
 #endif /* RDMA_CMA_H */
index 7f888d5314328f82b9ebaf380e28cc3cb24aca6e..c59f3f2d75061c2b69d01f2d3142efa80b54dd80 100644 (file)
--- a/src/cma.c
+++ b/src/cma.c
@@ -216,6 +216,32 @@ err:
        return ret;
 }
 
+struct ibv_context **rdma_get_devices(int *num_devices)
+{
+       struct ibv_context **devs = NULL;
+       int i;
+
+       if (!cma_dev_cnt && ucma_init())
+               goto out;
+
+       devs = malloc(sizeof *devs * (cma_dev_cnt + 1));
+       if (!devs)
+               goto out;
+
+       for (i = 0; i < cma_dev_cnt; i++)
+               devs[i] = cma_dev_array[i].verbs;
+       devs[i] = NULL;
+out:
+       if (num_devices)
+               *num_devices = devs ? cma_dev_cnt : 0;
+       return devs;
+}
+
+void rdma_free_devices(struct ibv_context **list)
+{
+       free(list);
+}
+
 static void __attribute__((destructor)) rdma_cma_fini(void)
 {
        ucma_cleanup();
index 7b2914a1b620842b109b9154e7dc5380929350fc..52986ca6646e41ca7f59ed5ab1a1781836ac640c 100644 (file)
@@ -21,5 +21,7 @@ RDMACM_1.0 {
                rdma_get_dst_attr;
                rdma_join_multicast;
                rdma_leave_multicast;
+               rdma_get_devices;
+               rdma_free_devices;
        local: *;
 };