ctdb-protocol: Add marshalling for struct ctdb_pid_srvid
authorAmitay Isaacs <amitay@gmail.com>
Wed, 30 Aug 2017 05:13:12 +0000 (15:13 +1000)
committerMartin Schwenke <martins@samba.org>
Thu, 21 Sep 2017 06:53:26 +0000 (08:53 +0200)
BUG: https://bugzilla.samba.org/show_bug.cgi?id=13042

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/protocol/protocol_private.h
ctdb/protocol/protocol_types.c
ctdb/tests/src/protocol_common.c
ctdb/tests/src/protocol_common.h
ctdb/tests/src/protocol_types_test.c

index 9e3ae8dfb8fc0494c34aaeacaa8f97c26fe5dbe0..c3fab3f3a24d8d489be73e8049e78a6d0b5a3a62 100644 (file)
@@ -312,6 +312,12 @@ void ctdb_db_statistics_push(struct ctdb_db_statistics *in, uint8_t *buf,
 int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
                            struct ctdb_db_statistics **out, size_t *npull);
 
+size_t ctdb_pid_srvid_len(struct ctdb_pid_srvid *in);
+void ctdb_pid_srvid_push(struct ctdb_pid_srvid *in, uint8_t *buf,
+                        size_t *npush);
+int ctdb_pid_srvid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                       struct ctdb_pid_srvid **out, size_t *npull);
+
 size_t ctdb_election_message_len(struct ctdb_election_message *in);
 void ctdb_election_message_push(struct ctdb_election_message *in,
                                uint8_t *buf, size_t *npush);
index 57ad07a3324a0e6cd89206faff1110d459e2d9ed..83d5d78fa6ec32f2ae368e6eeb9e95487ae195c4 100644 (file)
@@ -4704,6 +4704,59 @@ int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
        return 0;
 }
 
+size_t ctdb_pid_srvid_len(struct ctdb_pid_srvid *in)
+{
+       return ctdb_pid_len(&in->pid) +
+               ctdb_uint64_len(&in->srvid);
+}
+
+void ctdb_pid_srvid_push(struct ctdb_pid_srvid *in, uint8_t *buf,
+                        size_t *npush)
+{
+       size_t offset = 0, np;
+
+       ctdb_pid_push(&in->pid, buf+offset, &np);
+       offset += np;
+
+       ctdb_uint64_push(&in->srvid, buf+offset, &np);
+       offset += np;
+
+       *npush = offset;
+}
+
+int ctdb_pid_srvid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                       struct ctdb_pid_srvid **out, size_t *npull)
+{
+       struct ctdb_pid_srvid *val;
+       size_t offset = 0, np;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_pid_srvid);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_pid_pull(buf+offset, buflen-offset, &val->pid, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += np;
+
+       *out = val;
+       *npull = offset;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
+}
+
 size_t ctdb_election_message_len(struct ctdb_election_message *in)
 {
        return ctdb_uint32_len(&in->num_connected) +
index 9f5e4d589e59d6e10e12784cd42aa3b460fb2918..c06272db6cc242baae8863da5320af08182aa391 100644 (file)
@@ -1312,6 +1312,19 @@ void verify_ctdb_db_statistics(struct ctdb_db_statistics *p1,
        }
 }
 
+void fill_ctdb_pid_srvid(TALLOC_CTX *mem_ctx, struct ctdb_pid_srvid *p)
+{
+       p->pid = rand32();
+       p->srvid = rand64();
+}
+
+void verify_ctdb_pid_srvid(struct ctdb_pid_srvid *p1,
+                          struct ctdb_pid_srvid *p2)
+{
+       assert(p1->pid == p2->pid);
+       assert(p1->srvid == p2->srvid);
+}
+
 void fill_ctdb_election_message(TALLOC_CTX *mem_ctx,
                                struct ctdb_election_message *p)
 {
index ae51dfdc00cb9e92b6bb05180aed3f7d61c21da7..f1b957ae46c59154c2a22586d9ac4e81dae24778 100644 (file)
@@ -329,6 +329,10 @@ void fill_ctdb_db_statistics(TALLOC_CTX *mem_ctx,
 void verify_ctdb_db_statistics(struct ctdb_db_statistics *p1,
                               struct ctdb_db_statistics *p2);
 
+void fill_ctdb_pid_srvid(TALLOC_CTX *mem_ctx, struct ctdb_pid_srvid *p);
+void verify_ctdb_pid_srvid(struct ctdb_pid_srvid *p1,
+                          struct ctdb_pid_srvid *p2);
+
 void fill_ctdb_election_message(TALLOC_CTX *mem_ctx,
                                struct ctdb_election_message *p);
 void verify_ctdb_election_message(struct ctdb_election_message *p1,
index dbd5cea0721f40300922d45f336bddd643851f26..e607d06b820b014de94a5942cad857d2081ab99e 100644 (file)
@@ -70,6 +70,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_public_ip_info, ctdb_public_ip_info);
 PROTOCOL_TYPE3_TEST(struct ctdb_statistics_list, ctdb_statistics_list);
 PROTOCOL_TYPE3_TEST(struct ctdb_key_data, ctdb_key_data);
 PROTOCOL_TYPE3_TEST(struct ctdb_db_statistics, ctdb_db_statistics);
+PROTOCOL_TYPE3_TEST(struct ctdb_pid_srvid, ctdb_pid_srvid);
 PROTOCOL_TYPE3_TEST(struct ctdb_election_message, ctdb_election_message);
 PROTOCOL_TYPE3_TEST(struct ctdb_srvid_message, ctdb_srvid_message);
 PROTOCOL_TYPE3_TEST(struct ctdb_disable_message, ctdb_disable_message);
@@ -174,6 +175,7 @@ int main(int argc, char *argv[])
        TEST_FUNC(ctdb_statistics_list)();
        TEST_FUNC(ctdb_key_data)();
        TEST_FUNC(ctdb_db_statistics)();
+       TEST_FUNC(ctdb_pid_srvid)();
        TEST_FUNC(ctdb_election_message)();
        TEST_FUNC(ctdb_srvid_message)();
        TEST_FUNC(ctdb_disable_message)();