diff mbox series

[rdma-core,4/4] pyverbs: Fix assignments of bad work requests

Message ID 20190710142251.9396-5-noaos@mellanox.com (mailing list archive)
State Not Applicable
Headers show
Series pyverbs fixes | expand

Commit Message

Noa Osherovich July 10, 2019, 2:22 p.m. UTC
The bad work request content wasn't properly copied from the C
object, fix copying to contain the bad work request data.

Signed-off-by: Noa Osherovich <noaos@mellanox.com>
Reviewd-by: Maor Gottlieb <maorg@mellanox.com>
---
 pyverbs/qp.pyx | 15 +++++++++++----
 1 file changed, 11 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/pyverbs/qp.pyx b/pyverbs/qp.pyx
index 47a2158a5acc..ad89c94c002e 100644
--- a/pyverbs/qp.pyx
+++ b/pyverbs/qp.pyx
@@ -14,6 +14,9 @@  cimport pyverbs.libibverbs as v
 from pyverbs.pd cimport PD
 
 
+cdef extern from 'string.h':
+    void *memcpy(void *dest, const void *src, size_t n);
+
 cdef class QPCap(PyverbsObject):
     def __cinit__(self, max_send_wr=1, max_recv_wr=10, max_send_sge=1,
                       max_recv_sge=1, max_inline_data=0):
@@ -963,10 +966,12 @@  cdef class QP(PyverbsCM):
         :return: None
         """
         cdef v.ibv_recv_wr *my_bad_wr
+        # In order to provide a pointer to a pointer, use a temporary cdef'ed
+        # variable.
         rc = v.ibv_post_recv(self.qp, &wr.recv_wr, &my_bad_wr)
         if rc != 0:
-            if bad_wr is not None:
-                bad_wr.wr = <object>my_bad_wr
+            if (bad_wr):
+                memcpy(&bad_wr.recv_wr, my_bad_wr, sizeof(bad_wr.recv_wr))
             raise PyverbsRDMAErrno('Failed to post recv (returned {rc})'.
                                    format(rc=rc))
 
@@ -978,11 +983,13 @@  cdef class QP(PyverbsCM):
                        case of a failure
         :return: None
         """
+        # In order to provide a pointer to a pointer, use a temporary cdef'ed
+        # variable.
         cdef v.ibv_send_wr *my_bad_wr
         rc = v.ibv_post_send(self.qp, &wr.send_wr, &my_bad_wr)
         if rc != 0:
-            if bad_wr is not None:
-                bad_wr.wr = <object>my_bad_wr
+            if (bad_wr):
+                memcpy(&bad_wr.send_wr, my_bad_wr, sizeof(bad_wr.send_wr))
             raise PyverbsRDMAErrno('Failed to post send (returned {rc})'.
                                    format(rc=rc))