always use allocated packets to avoid alignment errors
authorAndrew Tridgell <tridge@samba.org>
Fri, 27 Apr 2007 15:10:47 +0000 (17:10 +0200)
committerAndrew Tridgell <tridge@samba.org>
Fri, 27 Apr 2007 15:10:47 +0000 (17:10 +0200)
(This used to be ctdb commit 47b53d344941a3203c87788439e7df59477681be)

ctdb/common/ctdb_client.c
ctdb/common/ctdb_daemon.c

index e9f1e8eb79f96b0363fe455a8792f3808412f830..5715ce9393eee89756ae650652ff16f9a4791ff7 100644 (file)
@@ -381,7 +381,7 @@ int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
                             void *private_data)
                                    
 {
-       struct ctdb_req_register c;
+       struct ctdb_req_register *c;
        int res;
 
        /* if the domain socket is not yet open, open it */
@@ -389,15 +389,15 @@ int ctdb_set_message_handler(struct ctdb_context *ctdb, uint64_t srvid,
                ctdb_socket_connect(ctdb);
        }
 
-       ZERO_STRUCT(c);
-
-       c.hdr.length       = sizeof(c);
-       c.hdr.ctdb_magic   = CTDB_MAGIC;
-       c.hdr.ctdb_version = CTDB_VERSION;
-       c.hdr.operation    = CTDB_REQ_REGISTER;
-       c.srvid            = srvid;
+       c = ctdbd_allocate_pkt(ctdb, sizeof(*c));
+       c->hdr.length       = sizeof(*c);
+       c->hdr.ctdb_magic   = CTDB_MAGIC;
+       c->hdr.ctdb_version = CTDB_VERSION;
+       c->hdr.operation    = CTDB_REQ_REGISTER;
+       c->srvid            = srvid;
 
-       res = ctdb_client_queue_pkt(ctdb, &c.hdr);
+       res = ctdb_client_queue_pkt(ctdb, &c->hdr);
+       talloc_free(c);
        if (res != 0) {
                return res;
        }
@@ -446,15 +446,14 @@ int ctdb_send_message(struct ctdb_context *ctdb, uint32_t vnn,
  */
 void ctdb_connect_wait(struct ctdb_context *ctdb)
 {
-       struct ctdb_req_connect_wait r;
+       struct ctdb_req_connect_wait *r;
        int res;
 
-       ZERO_STRUCT(r);
-
-       r.hdr.length     = sizeof(r);
-       r.hdr.ctdb_magic = CTDB_MAGIC;
-       r.hdr.ctdb_version = CTDB_VERSION;
-       r.hdr.operation = CTDB_REQ_CONNECT_WAIT;
+       r = ctdbd_allocate_pkt(ctdb, sizeof(*r));
+       r->hdr.length     = sizeof(*r);
+       r->hdr.ctdb_magic = CTDB_MAGIC;
+       r->hdr.ctdb_version = CTDB_VERSION;
+       r->hdr.operation = CTDB_REQ_CONNECT_WAIT;
 
        DEBUG(3,("ctdb_connect_wait: sending to ctdbd\n"));
 
@@ -463,7 +462,8 @@ void ctdb_connect_wait(struct ctdb_context *ctdb)
                ctdb_socket_connect(ctdb);
        }
        
-       res = ctdb_queue_send(ctdb->daemon.queue, (uint8_t *)&r.hdr, r.hdr.length);
+       res = ctdb_queue_send(ctdb->daemon.queue, (uint8_t *)&r->hdr, r->hdr.length);
+       talloc_free(r);
        if (res != 0) {
                DEBUG(0,(__location__ " Failed to queue a connect wait request\n"));
                return;
@@ -596,23 +596,24 @@ int ctdb_record_store(struct ctdb_record_handle *h, TDB_DATA data)
 */
 void ctdb_shutdown(struct ctdb_context *ctdb)
 {
-       struct ctdb_req_shutdown r;
-       int len;
+       struct ctdb_req_shutdown *r;
 
        /* if the domain socket is not yet open, open it */
        if (ctdb->daemon.sd==-1) {
                ctdb_socket_connect(ctdb);
        }
 
-       len = sizeof(struct ctdb_req_shutdown);
-       ZERO_STRUCT(r);
-       r.hdr.length       = len;
-       r.hdr.ctdb_magic   = CTDB_MAGIC;
-       r.hdr.ctdb_version = CTDB_VERSION;
-       r.hdr.operation    = CTDB_REQ_SHUTDOWN;
-       r.hdr.reqid        = 0;
+       r = ctdbd_allocate_pkt(ctdb, sizeof(*r));
+       ZERO_STRUCT(*r);
+       r->hdr.length       = sizeof(*r);
+       r->hdr.ctdb_magic   = CTDB_MAGIC;
+       r->hdr.ctdb_version = CTDB_VERSION;
+       r->hdr.operation    = CTDB_REQ_SHUTDOWN;
+       r->hdr.reqid        = 0;
 
-       ctdb_client_queue_pkt(ctdb, &(r.hdr));
+       ctdb_client_queue_pkt(ctdb, &(r->hdr));
+
+       talloc_free(r);
 
        /* this event loop will terminate once we receive the reply */
        while (1) {
index 49f3e24a1a0c71029b8909ac44b02cec48ed64a7..124bc8a656a12a21c738bea45cdc5c20b4687546 100644 (file)
@@ -216,23 +216,23 @@ static void daemon_request_shutdown(struct ctdb_client *client,
 static void daemon_request_connect_wait(struct ctdb_client *client, 
                                        struct ctdb_req_connect_wait *c)
 {
-       struct ctdb_reply_connect_wait r;
+       struct ctdb_reply_connect_wait *r;
        int res;
 
        /* first wait - in the daemon */
        ctdb_daemon_connect_wait(client->ctdb);
 
        /* now send the reply */
-       ZERO_STRUCT(r);
-
-       r.hdr.length     = sizeof(r);
-       r.hdr.ctdb_magic = CTDB_MAGIC;
-       r.hdr.ctdb_version = CTDB_VERSION;
-       r.hdr.operation = CTDB_REPLY_CONNECT_WAIT;
-       r.vnn           = ctdb_get_vnn(client->ctdb);
-       r.num_connected = client->ctdb->num_connected;
+       r = ctdbd_allocate_pkt(client, sizeof(*r));
+       r->hdr.length     = sizeof(*r);
+       r->hdr.ctdb_magic = CTDB_MAGIC;
+       r->hdr.ctdb_version = CTDB_VERSION;
+       r->hdr.operation = CTDB_REPLY_CONNECT_WAIT;
+       r->vnn           = ctdb_get_vnn(client->ctdb);
+       r->num_connected = client->ctdb->num_connected;
        
-       res = daemon_queue_send(client, &r.hdr);
+       res = daemon_queue_send(client, &r->hdr);
+       talloc_free(r);
        if (res != 0) {
                DEBUG(0,(__location__ " Failed to queue a connect wait response\n"));
                return;