pyverbs: Add DMA-buf fd export for Buf

Allow Python users to retrieve a caller-owned DMA-buf file
descriptor from a Buf's backing memory.

Signed-off-by: Jiri Pirko <jiri@nvidia.com>
diff --git a/pyverbs/libibverbs.pxd b/pyverbs/libibverbs.pxd
index 78b801c..a8e942a 100644
--- a/pyverbs/libibverbs.pxd
+++ b/pyverbs/libibverbs.pxd
@@ -696,6 +696,7 @@
     ibv_mr *ibv_reg_dmabuf_mr(ibv_pd *pd, uint64_t offset, size_t length,
                               uint64_t iova, int fd, int access)
     void *ibv_alloc_buf(ibv_pd *pd, size_t size, ibv_buf **buf)
+    int ibv_export_buf_dmabuf_fd(ibv_buf *buf)
     void ibv_free_buf(ibv_buf *buf)
     ibv_mr *ibv_reg_buf_mr(ibv_pd *pd, ibv_buf *buf, void *addr,
                            size_t length, int access)
diff --git a/pyverbs/mr.pyx b/pyverbs/mr.pyx
index 1921f70..53f3211 100644
--- a/pyverbs/mr.pyx
+++ b/pyverbs/mr.pyx
@@ -764,6 +764,16 @@
         else:
             raise PyverbsError('Unrecognized object type')
 
+    def export_dmabuf_fd(self):
+        """
+        Export a dmabuf FD for this Buf object.
+        :return: A file descriptor (int) for the dmabuf FD
+        """
+        fd = v.ibv_export_buf_dmabuf_fd(self.bufh)
+        if fd < 0:
+            raise PyverbsRDMAErrno('Failed to export dmabuf FD for Buf')
+        return fd
+
     @property
     def addr(self):
         return <uintptr_t>self.addr