enforce the tcp memory alignment in packet queue
authorAndrew Tridgell <tridge@samba.org>
Tue, 19 Dec 2006 01:07:07 +0000 (12:07 +1100)
committerAndrew Tridgell <tridge@samba.org>
Tue, 19 Dec 2006 01:07:07 +0000 (12:07 +1100)
(This used to be ctdb commit 222f53a3205509a45fbc3267297521df22a414ec)

ctdb/tcp/ctdb_tcp.h
ctdb/tcp/tcp_init.c
ctdb/tcp/tcp_io.c

index 039343a99858d29b1f78e54c574ca055d0248c6f..0f8ce300b446410201204910c5e05fa187ad84e2 100644 (file)
@@ -72,3 +72,5 @@ int ctdb_tcp_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length);
 int ctdb_tcp_listen(struct ctdb_context *ctdb);
 void ctdb_tcp_node_connect(struct event_context *ev, struct timed_event *te, 
                           struct timeval t, void *private);
+
+#define CTDB_TCP_ALIGNMENT 8
index fca6506676f8215534f0d4162b47ad7858be9b19..f261d0c7dac763ede92687770f60a1f02a827fad 100644 (file)
@@ -72,7 +72,7 @@ void *ctdb_tcp_allocate_pkt(struct ctdb_context *ctdb, size_t size)
        /* tcp transport needs to round to 8 byte alignment to ensure
           that we can use a length header and 64 bit elements in
           structures */
-       size = (size+7) & ~7;
+       size = (size+(CTDB_TCP_ALIGNMENT-1)) & ~(CTDB_TCP_ALIGNMENT-1);
        return talloc_size(ctdb, size);
 }
 
index 167e3a2ca7d6b66b5fbb1d714315f19d33b9c4c5..63142f9c45b0fbc56a0196ed8087666659774942 100644 (file)
@@ -199,6 +199,10 @@ int ctdb_tcp_queue_pkt(struct ctdb_node *node, uint8_t *data, uint32_t length)
        struct ctdb_tcp_node *tnode = talloc_get_type(node->private, 
                                                      struct ctdb_tcp_node);
        struct ctdb_tcp_packet *pkt;
+
+       /* enforce the length and alignment rules from the tcp packet allocator */
+       length = (length+(CTDB_TCP_ALIGNMENT-1)) & ~(CTDB_TCP_ALIGNMENT-1);
+       *(uint32_t *)data = length;
        
        /* if the queue is empty then try an immediate write, avoiding
           queue overhead. This relies on non-blocking sockets */