From 5d12006e29a898c503a885115069fe26f2e084bc Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 30 Aug 2017 15:13:12 +1000 Subject: [PATCH] ctdb-protocol: Add marshalling for struct ctdb_pid_srvid BUG: https://bugzilla.samba.org/show_bug.cgi?id=13042 Signed-off-by: Amitay Isaacs Reviewed-by: Martin Schwenke --- ctdb/protocol/protocol_private.h | 6 ++++ ctdb/protocol/protocol_types.c | 53 ++++++++++++++++++++++++++++ ctdb/tests/src/protocol_common.c | 13 +++++++ ctdb/tests/src/protocol_common.h | 4 +++ ctdb/tests/src/protocol_types_test.c | 2 ++ 5 files changed, 78 insertions(+) diff --git a/ctdb/protocol/protocol_private.h b/ctdb/protocol/protocol_private.h index 9e3ae8dfb8fc..c3fab3f3a24d 100644 --- a/ctdb/protocol/protocol_private.h +++ b/ctdb/protocol/protocol_private.h @@ -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); diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c index 57ad07a3324a..83d5d78fa6ec 100644 --- a/ctdb/protocol/protocol_types.c +++ b/ctdb/protocol/protocol_types.c @@ -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) + diff --git a/ctdb/tests/src/protocol_common.c b/ctdb/tests/src/protocol_common.c index 9f5e4d589e59..c06272db6cc2 100644 --- a/ctdb/tests/src/protocol_common.c +++ b/ctdb/tests/src/protocol_common.c @@ -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) { diff --git a/ctdb/tests/src/protocol_common.h b/ctdb/tests/src/protocol_common.h index ae51dfdc00cb..f1b957ae46c5 100644 --- a/ctdb/tests/src/protocol_common.h +++ b/ctdb/tests/src/protocol_common.h @@ -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, diff --git a/ctdb/tests/src/protocol_types_test.c b/ctdb/tests/src/protocol_types_test.c index dbd5cea0721f..e607d06b820b 100644 --- a/ctdb/tests/src/protocol_types_test.c +++ b/ctdb/tests/src/protocol_types_test.c @@ -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)(); -- 2.34.1