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>
((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 */
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();
rdma_get_dst_attr;
rdma_join_multicast;
rdma_leave_multicast;
+ rdma_get_devices;
+ rdma_free_devices;
local: *;
};