[PATCH rdma-core 1/4] pyverbs: Add support for providers' context

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Providers can supply an API for a driver-specific context, extending
ibv_context.
To allow the provider to open the device given provider-specific
attributes, Context class will only locate the right ibv_device but
will not open it, leaving the provider to open it in any way it finds
fit.

Signed-off-by: Noa Osherovich <noaos@xxxxxxxxxxxx>
---
 pyverbs/device.pxd |  1 +
 pyverbs/device.pyx | 17 +++++++++++++----
 pyverbs/qp.pyx     |  2 +-
 3 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/pyverbs/device.pxd b/pyverbs/device.pxd
index 5cc13acb4331..a701a3deeabd 100755
--- a/pyverbs/device.pxd
+++ b/pyverbs/device.pxd
@@ -9,6 +9,7 @@ cimport pyverbs.libibverbs as v
 
 cdef class Context(PyverbsCM):
     cdef v.ibv_context *context
+    cdef v.ibv_device *device
     cdef object name
     cdef add_ref(self, obj)
     cdef object pds
diff --git a/pyverbs/device.pyx b/pyverbs/device.pyx
index 084086bdbc69..58a2aca27fcc 100755
--- a/pyverbs/device.pyx
+++ b/pyverbs/device.pyx
@@ -78,9 +78,13 @@ cdef class Context(PyverbsCM):
         """
         Initializes a Context object. The function searches the IB devices list
         for a device with the name provided by the user. If such a device is
-        found, it is opened.
-        :param kwargs: Currently supports 'name' argument only, the IB device's
-                       name.
+        found, it is opened (unless provider attributes were given).
+        :param kwargs: Arguments:
+            * *name* (str)
+               The RDMA device's name
+            * *attr* (object)
+               Device-specific attributes, meaning that the device is to be
+               opened by the provider
         :return: None
         """
         cdef int count
@@ -94,7 +98,7 @@ cdef class Context(PyverbsCM):
         self.xrcds = weakref.WeakSet()
 
         dev_name = kwargs.get('name')
-
+        provider_attr = kwargs.get('attr')
         if dev_name is not None:
             self.name = dev_name
         else:
@@ -106,6 +110,11 @@ cdef class Context(PyverbsCM):
         try:
             for i in range(count):
                 if dev_list[i].name.decode() == self.name:
+                    if provider_attr is not None:
+                        # A provider opens its own context, we're just
+                        # setting its IB device
+                        self.device = dev_list[i]
+                        return
                     self.context = v.ibv_open_device(dev_list[i])
                     if self.context == NULL:
                         raise PyverbsRDMAErrno('Failed to open device {dev}'.
diff --git a/pyverbs/qp.pyx b/pyverbs/qp.pyx
index 961e0d59c589..9167e5f2bd01 100755
--- a/pyverbs/qp.pyx
+++ b/pyverbs/qp.pyx
@@ -812,7 +812,7 @@ cdef class QP(PyverbsCM):
         self.update_cqs(init_attr)
         # In order to use cdef'd methods, a proper casting must be done, let's
         # infer the type.
-        if type(creator) == Context:
+        if issubclass(type(creator), Context):
             self._create_qp_ex(creator, init_attr)
             ctx = <Context>creator
             self.context = ctx
-- 
2.21.0





[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux