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)
committerKarolin Seeger <kseeger@samba.org>
Wed, 25 Oct 2017 06:43:03 +0000 (08:43 +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>
(cherry picked from commit 5d12006e29a898c503a885115069fe26f2e084bc)

ctdb/protocol/protocol_private.h
ctdb/protocol/protocol_types.c
ctdb/tests/src/protocol_types_test.c

index f887ce5e0937c439c11cce1838bb90742d0c95c4..ecbd627c33b7a630d2869f7ec383d52bf8acd766 100644 (file)
@@ -240,6 +240,11 @@ void ctdb_db_statistics_push(struct ctdb_db_statistics *dbstats, void *buf);
 int ctdb_db_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
                            struct ctdb_db_statistics **out);
 
+size_t ctdb_pid_srvid_len(struct ctdb_pid_srvid *in);
+void ctdb_pid_srvid_push(struct ctdb_pid_srvid *in, uint8_t *buf);
+int ctdb_pid_srvid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                       struct ctdb_pid_srvid **out);
+
 size_t ctdb_election_message_len(struct ctdb_election_message *election);
 void ctdb_election_message_push(struct ctdb_election_message *election,
                                uint8_t *buf);
index 4115e381c0b3468135a3e773a6371595d130f441..2fbfcdc81be69cf5d7b4d0af9bb5cbe5d5e61d55 100644 (file)
@@ -2394,6 +2394,53 @@ 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 offset = 0;
+
+       ctdb_pid_push(in->pid, buf+offset);
+       offset += ctdb_pid_len(in->pid);
+
+       ctdb_uint64_push(in->srvid, buf+offset);
+}
+
+int ctdb_pid_srvid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+                       struct ctdb_pid_srvid **out)
+{
+       struct ctdb_pid_srvid *val;
+       size_t offset = 0;
+       int ret;
+
+       val = talloc(mem_ctx, struct ctdb_pid_srvid);
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       ret = ctdb_pid_pull(buf+offset, buflen-offset, val, &val->pid);
+       if (ret != 0) {
+               goto fail;
+       }
+       offset += ctdb_pid_len(val->pid);
+
+       ret = ctdb_uint64_pull(buf+offset, buflen-offset, val, &val->srvid);
+       if (ret != 0) {
+               goto fail;
+       }
+
+       *out = val;
+       return 0;
+
+fail:
+       talloc_free(val);
+       return ret;
+}
+
 size_t ctdb_election_message_len(struct ctdb_election_message *election)
 {
        return sizeof(struct ctdb_election_message);
index 94108ead04c5a1dd589d56a60763f8598f4b4760..46976d46a3523972efd2899296de00bc2581386f 100644 (file)
@@ -1018,6 +1018,19 @@ static void verify_ctdb_event_reply_script_list(
 
 #ifndef PROTOCOL_TEST
 
+static void fill_ctdb_pid_srvid(TALLOC_CTX *mem_ctx, struct ctdb_pid_srvid *p)
+{
+       p->pid = rand32();
+       p->srvid = rand64();
+}
+
+static 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);
+}
+
 static void fill_ctdb_election_message(TALLOC_CTX *mem_ctx,
                                       struct ctdb_election_message *p)
 {
@@ -1322,6 +1335,7 @@ DEFINE_TEST(struct ctdb_key_data, ctdb_key_data);
 DEFINE_TEST(struct ctdb_uint8_array, ctdb_uint8_array);
 DEFINE_TEST(struct ctdb_uint64_array, ctdb_uint64_array);
 DEFINE_TEST(struct ctdb_db_statistics, ctdb_db_statistics);
+DEFINE_TEST(struct ctdb_pid_srvid, ctdb_pid_srvid);
 DEFINE_TEST(struct ctdb_election_message, ctdb_election_message);
 DEFINE_TEST(struct ctdb_srvid_message, ctdb_srvid_message);
 DEFINE_TEST(struct ctdb_disable_message, ctdb_disable_message);
@@ -1438,6 +1452,7 @@ int main(int argc, char *argv[])
        TEST_FUNC(ctdb_uint8_array)();
        TEST_FUNC(ctdb_uint64_array)();
        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)();