don't zero beyond packet header unnecessarily
authorAndrew Tridgell <tridge@samba.org>
Thu, 3 May 2007 03:44:27 +0000 (13:44 +1000)
committerAndrew Tridgell <tridge@samba.org>
Thu, 3 May 2007 03:44:27 +0000 (13:44 +1000)
(This used to be ctdb commit 4cf88ca2ce81db8fe10b0dfedb81d99a2bd93328)

ctdb/common/ctdb_daemon.c

index 5d619e0a9078d99cd2b0f1485f791a453cfb4998..55af203c581ffce76962236f750cdc34824f172d 100644 (file)
@@ -727,7 +727,9 @@ struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
 {
        int size;
        struct ctdb_req_header *hdr;
-       size = ((length+1)+(CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);
+
+       length = MAX(length, slength);
+       size = (length+(CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);
 
        hdr = (struct ctdb_req_header *)talloc_size(mem_ctx, size);
        if (hdr == NULL) {
@@ -736,9 +738,9 @@ struct ctdb_req_header *_ctdbd_allocate_pkt(struct ctdb_context *ctdb,
                return NULL;
        }
        talloc_set_name_const(hdr, type);
-       memset(hdr, 0, size);
+       memset(hdr, 0, slength);
+       hdr->length       = length;
        hdr->operation    = operation;
-       hdr->length       = size;
        hdr->ctdb_magic   = CTDB_MAGIC;
        hdr->ctdb_version = CTDB_VERSION;
        hdr->srcnode      = ctdb->vnn;
@@ -761,7 +763,10 @@ struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
 {
        int size;
        struct ctdb_req_header *hdr;
-       size = ((length+1)+(CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);
+
+       length = MAX(length, slength);
+       size = (length+(CTDB_DS_ALIGNMENT-1)) & ~(CTDB_DS_ALIGNMENT-1);
+
        hdr = (struct ctdb_req_header *)ctdb->methods->allocate_pkt(mem_ctx, size);
        if (hdr == NULL) {
                DEBUG(0,("Unable to allocate transport packet for operation %u of length %u\n",
@@ -769,9 +774,9 @@ struct ctdb_req_header *_ctdb_transport_allocate(struct ctdb_context *ctdb,
                return NULL;
        }
        talloc_set_name_const(hdr, type);
-       memset(hdr, 0, size);
+       memset(hdr, 0, slength);
+       hdr->length       = length;
        hdr->operation    = operation;
-       hdr->length       = size;
        hdr->ctdb_magic   = CTDB_MAGIC;
        hdr->ctdb_version = CTDB_VERSION;
        hdr->generation   = ctdb->vnn_map->generation;