Added valgrind support to the cma code and mark buffers that were filled
by the kernel level with the macro VALGRIND_MAKE_MEM_DEFINED.

Signed-off-by: Dotan Barak <[EMAIL PROTECTED]>

---

diff --git a/src/cma.c b/src/cma.c
index 32edc1f..42fa162 100644
--- a/src/cma.c
+++ b/src/cma.c
@@ -57,6 +57,20 @@
 
 #define PFX "librdmacm: "
 
+#ifdef HAVE_VALGRIND_MEMCHECK_H
+
+#  include <valgrind/memcheck.h>
+
+#  ifndef VALGRIND_MAKE_MEM_DEFINED
+#    warning "Valgrind support requested, but VALGRIND_MAKE_MEM_DEFINED not 
available"
+#  endif
+
+#endif /* HAVE_VALGRIND_MEMCHECK_H */
+
+#ifndef VALGRIND_MAKE_MEM_DEFINED
+#  define VALGRIND_MAKE_MEM_DEFINED(addr,len)
+#endif
+
 #if __BYTE_ORDER == __LITTLE_ENDIAN
 static inline uint64_t htonll(uint64_t x) { return bswap_64(x); }
 static inline uint64_t ntohll(uint64_t x) { return bswap_64(x); }
@@ -383,6 +397,8 @@ int rdma_create_id(struct rdma_event_channel *channel,
        if (ret != size)
                goto err;
 
+       VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
        id_priv->handle = resp->id;
        *id = &id_priv->id;
        return 0;
@@ -405,6 +421,8 @@ static int ucma_destroy_kern_id(int fd, uint32_t handle)
        if (ret != size)
                return (ret > 0) ? -ENODATA : ret;
 
+       VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
        return resp->events_reported;
 }
 
@@ -458,6 +476,8 @@ static int ucma_query_route(struct rdma_cm_id *id)
        if (ret != size)
                return (ret > 0) ? -ENODATA : ret;
 
+       VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
        if (resp->num_paths) {
                id->route.path_rec = malloc(sizeof *id->route.path_rec *
                                            resp->num_paths);
@@ -583,6 +603,8 @@ static int rdma_init_qp_attr(struct rdma_cm_id *id, struct 
ibv_qp_attr *qp_attr,
        if (ret != size)
                return (ret > 0) ? -ENODATA : ret;
 
+       VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
        ibv_copy_qp_attr_from_kern(qp_attr, resp);
        *qp_attr_mask = resp->qp_attr_mask;
        return 0;
@@ -1010,6 +1032,8 @@ int rdma_join_multicast(struct rdma_cm_id *id, struct 
sockaddr *addr,
                goto err2;
        }
 
+       VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
        mc->handle = resp->id;
        return 0;
 err2:
@@ -1061,6 +1085,8 @@ int rdma_leave_multicast(struct rdma_cm_id *id, struct 
sockaddr *addr)
                goto free;
        }
 
+       VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
+
        pthread_mutex_lock(&id_priv->mut);
        while (mc->events_completed < resp->events_reported)
                pthread_cond_wait(&mc->cond, &id_priv->mut);
@@ -1255,6 +1281,8 @@ retry:
                free(evt);
                return (ret > 0) ? -ENODATA : ret;
        }
+
+       VALGRIND_MAKE_MEM_DEFINED(resp, sizeof *resp);
        
        evt->event.event = resp->event;
        switch (resp->event) {
_______________________________________________
general mailing list
general@lists.openfabrics.org
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to