From: Andrew Tridgell Date: Tue, 19 Dec 2006 01:07:07 +0000 (+1100) Subject: enforce the tcp memory alignment in packet queue X-Git-Tag: tevent-0.9.20~348^2~2990 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a3f91ddf57ea1fa4159cdad47a604770670f5a08;p=thirdparty%2Fsamba.git enforce the tcp memory alignment in packet queue (This used to be ctdb commit 222f53a3205509a45fbc3267297521df22a414ec) --- diff --git a/ctdb/tcp/ctdb_tcp.h b/ctdb/tcp/ctdb_tcp.h index 039343a9985..0f8ce300b44 100644 --- a/ctdb/tcp/ctdb_tcp.h +++ b/ctdb/tcp/ctdb_tcp.h @@ -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 diff --git a/ctdb/tcp/tcp_init.c b/ctdb/tcp/tcp_init.c index fca6506676f..f261d0c7dac 100644 --- a/ctdb/tcp/tcp_init.c +++ b/ctdb/tcp/tcp_init.c @@ -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); } diff --git a/ctdb/tcp/tcp_io.c b/ctdb/tcp/tcp_io.c index 167e3a2ca7d..63142f9c45b 100644 --- a/ctdb/tcp/tcp_io.c +++ b/ctdb/tcp/tcp_io.c @@ -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 */