[openib-general] Re: [PATCH/RFC] change ibv_get_devices() to ibv_get_device_list()

Roland Dreier rdreier at cisco.com
Wed Dec 14 12:28:18 PST 2005


    Michael> This wont work for hotplug: you are saving the device
    Michael> pointer without opening the device, so it might go away
    Michael> from under your feet.

Good point -- see updated change below.

    Michael> I wander whether we can come up with an API that helps
    Michael> people get it right more easily?

I guess we could return some opaque cookie or validate pointers using
a hash table or something like that.

--- mvapich-gen2/mpid/ch_gen2/viainit.c	(revision 4465)
+++ mvapich-gen2/mpid/ch_gen2/viainit.c	(working copy)
@@ -74,13 +74,21 @@ static void set_malloc_options(void)
 
 static void open_hca(void)
 {
-    struct dlist *dev_list;
     struct ibv_device *ib_dev = NULL;
 
+#ifdef GEN2_OLD_DEVICE_LIST_VERB
+    struct dlist *dev_list;
+
     dev_list = ibv_get_devices();
 
     dlist_start(dev_list);
     ib_dev = dlist_next(dev_list);
+#else
+    struct ibv_device **dev_list;
+
+    dev_list = ibv_get_device_list(NULL);
+    ib_dev = dev_list[0];
+#endif
 
     if (!ib_dev) {
         fprintf(stderr, "No IB devices found\n");
@@ -90,6 +98,10 @@ static void open_hca(void)
 
     ibv_dev.context = ibv_open_device(ib_dev);
 
+#ifndef GEN2_OLD_DEVICE_LIST_VERB
+    ibv_free_device_list(dev_list);
+#endif
+
     if(!ibv_dev.context) {
         error_abort_all(GEN_EXIT_ERR, "Error getting HCA context\n");
     }



More information about the general mailing list