diff options
author | Volker Lendecke <vl@samba.org> | 2020-04-07 16:44:58 +0200 |
---|---|---|
committer | Ralph Boehme <slow@samba.org> | 2020-04-28 09:08:39 +0000 |
commit | 6f56f45639e6404161da425bcd2654624907a439 (patch) | |
tree | 0fd50c078b26a283b2b82a2bbc2187537937f401 | |
parent | 4f3db63d5e68382fff9196ce6cf9976501519fdc (diff) | |
download | samba-6f56f45639e6404161da425bcd2654624907a439.tar.gz |
ctdb-protocol: Add marshalling for struct ctdb_echo_data
Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
-rw-r--r-- | ctdb/protocol/protocol_private.h | 10 | ||||
-rw-r--r-- | ctdb/protocol/protocol_types.c | 72 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_common.c | 13 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_common.h | 4 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_types_test.c | 2 |
5 files changed, 101 insertions, 0 deletions
diff --git a/ctdb/protocol/protocol_private.h b/ctdb/protocol/protocol_private.h index b151e64ef09..cbbba394df7 100644 --- a/ctdb/protocol/protocol_private.h +++ b/ctdb/protocol/protocol_private.h @@ -93,6 +93,16 @@ int ctdb_db_vacuum_pull(uint8_t *buf, struct ctdb_db_vacuum **out, size_t *npull); +size_t ctdb_echo_data_len(struct ctdb_echo_data *in); +void ctdb_echo_data_push(struct ctdb_echo_data *in, + uint8_t *buf, + size_t *npush); +int ctdb_echo_data_pull(uint8_t *buf, + size_t buflen, + TALLOC_CTX *mem_ctx, + struct ctdb_echo_data **out, + size_t *npull); + size_t ctdb_traverse_start_len(struct ctdb_traverse_start *in); void ctdb_traverse_start_push(struct ctdb_traverse_start *in, uint8_t *buf, size_t *npush); diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c index 29e02898346..0eb1923207e 100644 --- a/ctdb/protocol/protocol_types.c +++ b/ctdb/protocol/protocol_types.c @@ -1303,6 +1303,78 @@ fail: return ret; } +size_t ctdb_echo_data_len(struct ctdb_echo_data *in) +{ + /* + * No overflow check, none of the routines in this file do it + * and there's no way to report it anyway. + */ + return ctdb_uint32_len(&in->timeout) + ctdb_tdb_datan_len(&in->buf); +} + +void ctdb_echo_data_push(struct ctdb_echo_data *in, + uint8_t *buf, + size_t *npush) +{ + size_t offset = 0, np; + + /* + * No overflow check, none of the routines in this file do it + * and there's no way to report it anyway. + */ + + ctdb_uint32_push(&in->timeout, buf+offset, &np); + offset += np; + + ctdb_tdb_datan_push(&in->buf, buf+offset, &np); + offset += np; + + *npush = offset; +} + +int ctdb_echo_data_pull(uint8_t *buf, + size_t buflen, + TALLOC_CTX *mem_ctx, + struct ctdb_echo_data **out, + size_t *npull) +{ + struct ctdb_echo_data *val; + size_t offset = 0, np; + int ret; + + val = talloc(mem_ctx, struct ctdb_echo_data); + if (val == NULL) { + return ENOMEM; + } + + ret = ctdb_uint32_pull(buf+offset, + buflen-offset, + &val->timeout, + &np); + if (ret != 0) { + goto fail; + } + offset += np; + + ret = ctdb_tdb_datan_pull(buf+offset, + buflen-offset, + val, + &val->buf, + &np); + if (ret != 0) { + goto fail; + } + offset += np; + + *out = val; + *npull = offset; + return 0; + +fail: + talloc_free(val); + return ret; +} + size_t ctdb_ltdb_header_len(struct ctdb_ltdb_header *in) { return ctdb_uint64_len(&in->rsn) + diff --git a/ctdb/tests/src/protocol_common.c b/ctdb/tests/src/protocol_common.c index 2030b4bb5e5..212c23ce965 100644 --- a/ctdb/tests/src/protocol_common.c +++ b/ctdb/tests/src/protocol_common.c @@ -323,6 +323,19 @@ void verify_ctdb_db_vacuum(struct ctdb_db_vacuum *p1, verify_ctdb_bool(&p1->full_vacuum_run, &p2->full_vacuum_run); } +void fill_ctdb_echo_data(TALLOC_CTX *mem_ctx, struct ctdb_echo_data *p) +{ + fill_ctdb_uint32(&p->timeout); + fill_tdb_data(mem_ctx, &p->buf); +} + +void verify_ctdb_echo_data(struct ctdb_echo_data *p1, + struct ctdb_echo_data *p2) +{ + verify_ctdb_uint32(&p1->timeout, &p2->timeout); + verify_tdb_data(&p1->buf, &p2->buf); +} + void fill_ctdb_ltdb_header(struct ctdb_ltdb_header *p) { p->rsn = rand64(); diff --git a/ctdb/tests/src/protocol_common.h b/ctdb/tests/src/protocol_common.h index 2b4fb6a07a9..171b19b88c3 100644 --- a/ctdb/tests/src/protocol_common.h +++ b/ctdb/tests/src/protocol_common.h @@ -68,6 +68,10 @@ void fill_ctdb_db_vacuum(TALLOC_CTX *mem_ctx, struct ctdb_db_vacuum *p); void verify_ctdb_db_vacuum(struct ctdb_db_vacuum *p1, struct ctdb_db_vacuum *p2); +void fill_ctdb_echo_data(TALLOC_CTX *mem_ctx, struct ctdb_echo_data *p); +void verify_ctdb_echo_data(struct ctdb_echo_data *p1, + struct ctdb_echo_data *p2); + void fill_ctdb_ltdb_header(struct ctdb_ltdb_header *p); void verify_ctdb_ltdb_header(struct ctdb_ltdb_header *p1, struct ctdb_ltdb_header *p2); diff --git a/ctdb/tests/src/protocol_types_test.c b/ctdb/tests/src/protocol_types_test.c index e9cf4debe89..4a304d5aa4d 100644 --- a/ctdb/tests/src/protocol_types_test.c +++ b/ctdb/tests/src/protocol_types_test.c @@ -39,6 +39,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_dbid_map, ctdb_dbid_map); PROTOCOL_TYPE3_TEST(struct ctdb_pulldb, ctdb_pulldb); PROTOCOL_TYPE3_TEST(struct ctdb_pulldb_ext, ctdb_pulldb_ext); PROTOCOL_TYPE3_TEST(struct ctdb_db_vacuum, ctdb_db_vacuum); +PROTOCOL_TYPE3_TEST(struct ctdb_echo_data, ctdb_echo_data); PROTOCOL_TYPE1_TEST(struct ctdb_ltdb_header, ctdb_ltdb_header); PROTOCOL_TYPE3_TEST(struct ctdb_rec_data, ctdb_rec_data); PROTOCOL_TYPE3_TEST(struct ctdb_rec_buffer, ctdb_rec_buffer); @@ -145,6 +146,7 @@ int main(int argc, char *argv[]) TEST_FUNC(ctdb_pulldb)(); TEST_FUNC(ctdb_pulldb_ext)(); TEST_FUNC(ctdb_db_vacuum)(); + TEST_FUNC(ctdb_echo_data)(); TEST_FUNC(ctdb_ltdb_header)(); TEST_FUNC(ctdb_rec_data)(); TEST_FUNC(ctdb_rec_buffer)(); |