Abstract the copy of a received mcast packet out, so that it can eventually
be replaced by a driver-specific version that does not require a memcpy().

Signed-off-by: Zane Bitter <[email protected]>
---
 exec/totemiba.c  |    9 +++++++++
 exec/totemiba.h  |    2 ++
 exec/totemnet.c  |   13 +++++++++++++
 exec/totemnet.h  |    2 ++
 exec/totemrrp.c  |    7 +++++++
 exec/totemrrp.h  |    4 ++++
 exec/totemsrp.c  |   11 ++++++++---
 exec/totemudp.c  |    9 +++++++++
 exec/totemudp.h  |    2 ++
 exec/totemudpu.c |    9 +++++++++
 exec/totemudpu.h |    2 ++
 11 files changed, 67 insertions(+), 3 deletions(-)

diff --git a/exec/totemiba.c b/exec/totemiba.c
index c8839a1..5aa2787 100644
--- a/exec/totemiba.c
+++ b/exec/totemiba.c
@@ -1322,6 +1322,15 @@ void *totemiba_buffer_alloc (void)
        return malloc (MAX_MTU_SIZE);
 }
 
+void *totemiba_buffer_retain (void *ptr)
+{
+       void *new_buf = totemiba_buffer_alloc();
+       if (new_buf) {
+               memcpy (new_buf, ptr, FRAME_SIZE_MAX);
+       }
+       return new_buf;
+}
+
 void totemiba_buffer_release (void *ptr)
 {
        return free (ptr);
diff --git a/exec/totemiba.h b/exec/totemiba.h
index a507ffb..5cf4738 100644
--- a/exec/totemiba.h
+++ b/exec/totemiba.h
@@ -64,6 +64,8 @@ extern int totemiba_initialize (
 
 extern void *totemiba_buffer_alloc (void);
 
+extern void *totemiba_buffer_retain (void *ptr);
+
 extern void totemiba_buffer_release (void *ptr);
 
 extern int totemiba_processor_count_set (
diff --git a/exec/totemnet.c b/exec/totemnet.c
index 948caa1..167af59 100644
--- a/exec/totemnet.c
+++ b/exec/totemnet.c
@@ -71,6 +71,8 @@ struct transport {
 
        void *(*buffer_alloc) (void);
 
+       void *(*buffer_retain) (void *ptr);
+
        void (*buffer_release) (void *ptr);
 
        int (*processor_count_set) (
@@ -132,6 +134,7 @@ struct transport transport_entries[] = {
                .name = "UDP/IP Multicast",
                .initialize = totemudp_initialize,
                .buffer_alloc = totemudp_buffer_alloc,
+               .buffer_retain = totemudp_buffer_retain,
                .buffer_release = totemudp_buffer_release,
                .processor_count_set = totemudp_processor_count_set,
                .token_send = totemudp_token_send,
@@ -151,6 +154,7 @@ struct transport transport_entries[] = {
                .name = "UDP/IP Unicast",
                .initialize = totemudpu_initialize,
                .buffer_alloc = totemudpu_buffer_alloc,
+               .buffer_retain = totemudpu_buffer_retain,
                .buffer_release = totemudpu_buffer_release,
                .processor_count_set = totemudpu_processor_count_set,
                .token_send = totemudpu_token_send,
@@ -173,6 +177,7 @@ struct transport transport_entries[] = {
                .name = "Infiniband/IP",
                .initialize = totemiba_initialize,
                .buffer_alloc = totemiba_buffer_alloc,
+               .buffer_retain = totemiba_buffer_retain,
                .buffer_release = totemiba_buffer_release,
                .processor_count_set = totemiba_processor_count_set,
                .token_send = totemiba_token_send,
@@ -311,6 +316,14 @@ void *totemnet_buffer_alloc (void *net_context)
        return instance->transport->buffer_alloc();
 }
 
+void *totemnet_buffer_retain (void *net_context, void *ptr)
+{
+       struct totemnet_instance *instance = net_context;
+       assert (instance != NULL);
+       assert (instance->transport != NULL);
+       return instance->transport->buffer_retain(ptr);
+}
+
 void totemnet_buffer_release (void *net_context, void *ptr)
 {
        struct totemnet_instance *instance = net_context;
diff --git a/exec/totemnet.h b/exec/totemnet.h
index 5806bf9..3fe50bd 100644
--- a/exec/totemnet.h
+++ b/exec/totemnet.h
@@ -75,6 +75,8 @@ extern int totemnet_initialize (
 
 extern void *totemnet_buffer_alloc (void *net_context);
 
+extern void *totemnet_buffer_retain (void *net_context, void *ptr);
+
 extern void totemnet_buffer_release (void *net_context, void *ptr);
 
 extern int totemnet_processor_count_set (
diff --git a/exec/totemrrp.c b/exec/totemrrp.c
index ea6efbf..2fcbe85 100644
--- a/exec/totemrrp.c
+++ b/exec/totemrrp.c
@@ -1626,6 +1626,13 @@ void *totemrrp_buffer_alloc (void *rrp_context)
        return totemnet_buffer_alloc (instance->net_handles[0]);
 }
 
+void *totemrrp_buffer_retain (void *rrp_context, void *ptr)
+{
+       struct totemrrp_instance *instance = rrp_context;
+       assert (instance != NULL);
+       return totemnet_buffer_retain (instance->net_handles[0], ptr);
+}
+
 void totemrrp_buffer_release (void *rrp_context, void *ptr)
 {
        struct totemrrp_instance *instance = rrp_context;
diff --git a/exec/totemrrp.h b/exec/totemrrp.h
index 7cec356..397f384 100644
--- a/exec/totemrrp.h
+++ b/exec/totemrrp.h
@@ -84,6 +84,10 @@ extern int totemrrp_initialize (
 extern void *totemrrp_buffer_alloc (
        void *rrp_context);
 
+extern void *totemrrp_buffer_retain (
+       void *rrp_context,
+       void *ptr);
+
 extern void totemrrp_buffer_release (
        void *rrp_context,
        void *ptr);
diff --git a/exec/totemsrp.c b/exec/totemsrp.c
index d300d4b..992e466 100644
--- a/exec/totemsrp.c
+++ b/exec/totemsrp.c
@@ -611,6 +611,7 @@ static void timer_function_token_retransmit_timeout (void 
*data);
 static void timer_function_token_hold_retransmit_timeout (void *data);
 static void timer_function_merge_detect_timeout (void *data);
 static void *totemsrp_buffer_alloc (struct totemsrp_instance *instance);
+static void *totemsrp_buffer_retain (struct totemsrp_instance *instance, void 
*ptr);
 static void totemsrp_buffer_release (struct totemsrp_instance *instance, void 
*ptr);
 
 void main_deliver_fn (
@@ -1370,6 +1371,12 @@ static void *totemsrp_buffer_alloc (struct 
totemsrp_instance *instance)
        return totemrrp_buffer_alloc (instance->totemrrp_context);
 }
 
+static void *totemsrp_buffer_retain (struct totemsrp_instance *instance, void 
*ptr)
+{
+       assert (instance != NULL);
+       return totemrrp_buffer_retain (instance->totemrrp_context, ptr);
+}
+
 static void totemsrp_buffer_release (struct totemsrp_instance *instance, void 
*ptr)
 {
        assert (instance != NULL);
@@ -3854,12 +3861,10 @@ static int message_handler_mcast (
                /*
                 * Allocate new multicast memory block
                 */
-// TODO LEAK
-               sort_queue_item.mcast = totemsrp_buffer_alloc (instance);
+               sort_queue_item.mcast = totemsrp_buffer_retain (instance, (void 
*)msg);
                if (sort_queue_item.mcast == NULL) {
                        return (-1); /* error here is corrected by the 
algorithm */
                }
-               memcpy (sort_queue_item.mcast, msg, msg_len);
                sort_queue_item.msg_len = msg_len;
 
                if (sq_lt_compare (instance->my_high_seq_received,
diff --git a/exec/totemudp.c b/exec/totemudp.c
index 804d00b..e53a94e 100644
--- a/exec/totemudp.c
+++ b/exec/totemudp.c
@@ -1829,6 +1829,15 @@ void *totemudp_buffer_alloc (void)
        return malloc (FRAME_SIZE_MAX);
 }
 
+void *totemudp_buffer_retain (void *ptr)
+{
+       void *new_buf = totemudp_buffer_alloc();
+       if (new_buf) {
+               memcpy (new_buf, ptr, FRAME_SIZE_MAX);
+       }
+       return new_buf;
+}
+
 void totemudp_buffer_release (void *ptr)
 {
        return free (ptr);
diff --git a/exec/totemudp.h b/exec/totemudp.h
index 68cc56f..f15abfd 100644
--- a/exec/totemudp.h
+++ b/exec/totemudp.h
@@ -65,6 +65,8 @@ extern int totemudp_initialize (
 
 extern void *totemudp_buffer_alloc (void);
 
+extern void *totemudp_buffer_retain (void *ptr);
+
 extern void totemudp_buffer_release (void *ptr);
 
 extern int totemudp_processor_count_set (
diff --git a/exec/totemudpu.c b/exec/totemudpu.c
index c18e59f..a708593 100644
--- a/exec/totemudpu.c
+++ b/exec/totemudpu.c
@@ -1477,6 +1477,15 @@ void *totemudpu_buffer_alloc (void)
        return malloc (FRAME_SIZE_MAX);
 }
 
+void *totemudpu_buffer_retain (void *ptr)
+{
+       void *new_buf = totemudpu_buffer_alloc();
+       if (new_buf) {
+               memcpy (new_buf, ptr, FRAME_SIZE_MAX);
+       }
+       return new_buf;
+}
+
 void totemudpu_buffer_release (void *ptr)
 {
        return free (ptr);
diff --git a/exec/totemudpu.h b/exec/totemudpu.h
index 89fb1e5..607246a 100644
--- a/exec/totemudpu.h
+++ b/exec/totemudpu.h
@@ -65,6 +65,8 @@ extern int totemudpu_initialize (
 
 extern void *totemudpu_buffer_alloc (void);
 
+extern void *totemudpu_buffer_retain (void *ptr);
+
 extern void totemudpu_buffer_release (void *ptr);
 
 extern int totemudpu_processor_count_set (

_______________________________________________
Openais mailing list
[email protected]
https://lists.linux-foundation.org/mailman/listinfo/openais

Reply via email to