ctdb-protocol: Fix marshalling for uint64_t
authorAmitay Isaacs <amitay@gmail.com>
Thu, 29 Jun 2017 12:15:43 +0000 (22:15 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 30 Aug 2017 12:59:21 +0000 (14:59 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/protocol/protocol_basic.c
ctdb/protocol/protocol_control.c
ctdb/protocol/protocol_private.h
ctdb/tests/src/protocol_basic_test.c
ctdb/tests/src/protocol_common.c
ctdb/tests/src/protocol_common.h

index 048dca44bcb8987f550c55cdc798971844bec66d..6f3ddfb49b36a21e073bc69cf65183ec53e05c3d 100644 (file)
@@ -118,24 +118,25 @@ int ctdb_uint32_pull(uint8_t *buf, size_t buflen, uint32_t *out, size_t *npull)
        return 0;
 }
 
-size_t ctdb_uint64_len(uint64_t val)
+size_t ctdb_uint64_len(uint64_t *in)
 {
        return sizeof(uint64_t);
 }
 
-void ctdb_uint64_push(uint64_t val, uint8_t *buf)
+void ctdb_uint64_push(uint64_t *in, uint8_t *buf, size_t *npush)
 {
-       memcpy(buf, &val, sizeof(uint64_t));
+       memcpy(buf, in, sizeof(uint64_t));
+       *npush = sizeof(uint64_t);
 }
 
-int ctdb_uint64_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                    uint64_t *out)
+int ctdb_uint64_pull(uint8_t *buf, size_t buflen, uint64_t *out, size_t *npull)
 {
        if (buflen < sizeof(uint64_t)) {
                return EMSGSIZE;
        }
 
-       *out = *(uint64_t *)buf;
+       memcpy(out, buf, sizeof(uint64_t));
+       *npull = sizeof(uint64_t);
        return 0;
 }
 
index 05a087747dbd5821d29979a356c96305d7112748..bc76a6c31a5c7516ef7be4bb28d5c7ecaf72e859 100644 (file)
@@ -311,7 +311,7 @@ static size_t ctdb_req_control_data_len(struct ctdb_req_control_data *cd)
                break;
 
        case CTDB_CONTROL_DEREGISTER_NOTIFY:
-               len = ctdb_uint64_len(cd->data.srvid);
+               len = ctdb_uint64_len(&cd->data.srvid);
                break;
 
        case CTDB_CONTROL_TRANS3_COMMIT:
@@ -603,7 +603,7 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
                break;
 
        case CTDB_CONTROL_DEREGISTER_NOTIFY:
-               ctdb_uint64_push(cd->data.srvid, buf);
+               ctdb_uint64_push(&cd->data.srvid, buf, &np);
                break;
 
        case CTDB_CONTROL_TRANS3_COMMIT:
@@ -914,8 +914,7 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
                break;
 
        case CTDB_CONTROL_DEREGISTER_NOTIFY:
-               ctdb_uint64_pull(buf, buflen, mem_ctx,
-                                &cd->data.srvid);
+               ctdb_uint64_pull(buf, buflen, &cd->data.srvid, &np);
                break;
 
        case CTDB_CONTROL_TRANS3_COMMIT:
@@ -1305,7 +1304,7 @@ static size_t ctdb_reply_control_data_len(struct ctdb_reply_control_data *cd)
                break;
 
        case CTDB_CONTROL_GET_DB_SEQNUM:
-               len = ctdb_uint64_len(cd->data.seqnum);
+               len = ctdb_uint64_len(&cd->data.seqnum);
                break;
 
        case CTDB_CONTROL_DB_SET_HEALTHY:
@@ -1517,7 +1516,7 @@ static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
                break;
 
        case CTDB_CONTROL_GET_DB_SEQNUM:
-               ctdb_uint64_push(cd->data.seqnum, buf);
+               ctdb_uint64_push(&cd->data.seqnum, buf, &np);
                break;
 
        case CTDB_CONTROL_DB_GET_HEALTH:
@@ -1697,8 +1696,7 @@ static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
                break;
 
        case CTDB_CONTROL_GET_DB_SEQNUM:
-               ret = ctdb_uint64_pull(buf, buflen, mem_ctx,
-                                      &cd->data.seqnum);
+               ret = ctdb_uint64_pull(buf, buflen, &cd->data.seqnum, &np);
                break;
 
        case CTDB_CONTROL_DB_GET_HEALTH:
index 632fb4fbf20a29856823113da8257b2c08aa1016..4be7a1e44edc32d7ce5dd74f04d633c326ed4a50 100644 (file)
@@ -44,10 +44,10 @@ void ctdb_uint32_push(uint32_t *in, uint8_t *buf, size_t *npush);
 int ctdb_uint32_pull(uint8_t *buf, size_t buflen, uint32_t *out,
                     size_t *npull);
 
-size_t ctdb_uint64_len(uint64_t val);
-void ctdb_uint64_push(uint64_t val, uint8_t *buf);
-int ctdb_uint64_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
-                    uint64_t *out);
+size_t ctdb_uint64_len(uint64_t *in);
+void ctdb_uint64_push(uint64_t *in, uint8_t *buf, size_t *npush);
+int ctdb_uint64_pull(uint8_t *buf, size_t buflen, uint64_t *out,
+                    size_t *npull);
 
 size_t ctdb_double_len(double val);
 void ctdb_double_push(double val, uint8_t *buf);
index f82be99b57287540ddffb5cdf4e17b4993fd323b..fc093ff126199d83fa3bbf7b192b45a34709537e 100644 (file)
@@ -29,20 +29,7 @@ PROTOCOL_TYPE1_TEST(uint8_t, ctdb_uint8);
 PROTOCOL_TYPE1_TEST(uint16_t, ctdb_uint16);
 PROTOCOL_TYPE1_TEST(int32_t, ctdb_int32);
 PROTOCOL_TYPE1_TEST(uint32_t, ctdb_uint32);
-
-static void test_ctdb_uint64(void)
-{
-       uint64_t p1, p2;
-       size_t buflen;
-       int ret;
-
-       p1 = rand64();
-       buflen = ctdb_uint64_len(p1);
-       ctdb_uint64_push(p1, BUFFER);
-       ret = ctdb_uint64_pull(BUFFER, buflen, NULL, &p2);
-       assert(ret == 0);
-       assert(p1 == p2);
-}
+PROTOCOL_TYPE1_TEST(uint64_t, ctdb_uint64);
 
 static void test_ctdb_double(void)
 {
@@ -115,8 +102,8 @@ int main(int argc, char *argv[])
        TEST_FUNC(ctdb_uint16)();
        TEST_FUNC(ctdb_int32)();
        TEST_FUNC(ctdb_uint32)();
+       TEST_FUNC(ctdb_uint64)();
 
-       test_ctdb_uint64();
        test_ctdb_double();
 
        test_ctdb_string();
index 59ee01b5d6466f24fff972d0bf07a52918ec8606..7f4dee66bb7a9c11edc2fdc73e10505843000c5b 100644 (file)
@@ -128,6 +128,16 @@ void verify_ctdb_uint32(uint32_t *p1, uint32_t *p2)
        assert(*p1 == *p2);
 }
 
+void fill_ctdb_uint64(uint64_t *p)
+{
+       *p = rand64();
+}
+
+void verify_ctdb_uint64(uint64_t *p1, uint64_t *p2)
+{
+       assert(*p1 == *p2);
+}
+
 void fill_ctdb_string(TALLOC_CTX *mem_ctx, const char **out)
 {
        char *p;
index 32c8332ea972ad3a8f4e35c08042bf4d23fd49af..84f09b18ce7e1ca0ab9b7562f702c5e604a2cd15 100644 (file)
@@ -164,6 +164,9 @@ void verify_ctdb_int32(int32_t *p1, int32_t *p2);
 void fill_ctdb_uint32(uint32_t *p);
 void verify_ctdb_uint32(uint32_t *p1, uint32_t *p2);
 
+void fill_ctdb_uint64(uint64_t *p);
+void verify_ctdb_uint64(uint64_t *p1, uint64_t *p2);
+
 void fill_ctdb_string(TALLOC_CTX *mem_ctx, const char **out);
 void verify_ctdb_string(const char *p1, const char *p2);