summaryrefslogtreecommitdiff
path: root/ctdb
diff options
context:
space:
mode:
authorMartin Schwenke <martin@meltin.net>2017-09-05 10:52:58 +1000
committerMartin Schwenke <martins@samba.org>2017-09-19 13:30:26 +0200
commite50cb8cb5213cf1f876a70638f37b2f8b3d36baa (patch)
tree1508193635c7dd313c31e89549580c1d5a1c055c /ctdb
parentd6f9cd19fdc815f898865ab5fbfd814577ad72dd (diff)
downloadsamba-e50cb8cb5213cf1f876a70638f37b2f8b3d36baa.tar.gz
ctdb-protocol: Add marshalling for ctdb_connection_list
Signed-off-by: Martin Schwenke <martin@meltin.net> Reviewed-by: Amitay Isaacs <amitay@gmail.com>
Diffstat (limited to 'ctdb')
-rw-r--r--ctdb/protocol/protocol_private.h6
-rw-r--r--ctdb/protocol/protocol_types.c78
-rw-r--r--ctdb/tests/src/protocol_common.c28
-rw-r--r--ctdb/tests/src/protocol_common.h5
-rw-r--r--ctdb/tests/src/protocol_types_test.c2
5 files changed, 119 insertions, 0 deletions
diff --git a/ctdb/protocol/protocol_private.h b/ctdb/protocol/protocol_private.h
index a609930aae6..9e3ae8dfb8f 100644
--- a/ctdb/protocol/protocol_private.h
+++ b/ctdb/protocol/protocol_private.h
@@ -187,6 +187,12 @@ void ctdb_connection_push(struct ctdb_connection *in, uint8_t *buf,
int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_connection **out, size_t *npull);
+size_t ctdb_connection_list_len(struct ctdb_connection_list *in);
+void ctdb_connection_list_push(struct ctdb_connection_list *in, uint8_t *buf,
+ size_t *npush);
+int ctdb_connection_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_connection_list **out, size_t *npull);
+
size_t ctdb_tunable_len(struct ctdb_tunable *in);
void ctdb_tunable_push(struct ctdb_tunable *in, uint8_t *buf, size_t *npush);
int ctdb_tunable_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c
index ae6f7ed527a..57ad07a3324 100644
--- a/ctdb/protocol/protocol_types.c
+++ b/ctdb/protocol/protocol_types.c
@@ -2171,6 +2171,84 @@ int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
return ret;
}
+size_t ctdb_connection_list_len(struct ctdb_connection_list *in)
+{
+ size_t len;
+
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_connection_len(&in->conn[0]);
+ }
+
+ return len;
+}
+
+void ctdb_connection_list_push(struct ctdb_connection_list *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t i;
+
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->num; i++) {
+ ctdb_connection_push(&in->conn[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
+}
+
+int ctdb_connection_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_connection_list **out, size_t *npull)
+{
+ struct ctdb_connection_list *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_connection_list);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ if (val->num == 0) {
+ val->conn = NULL;
+ goto done;
+ }
+
+ val->conn = talloc_array(val, struct ctdb_connection, val->num);
+ if (val->conn == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_connection_pull_elems(buf+offset, buflen-offset,
+ val, &val->conn[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ }
+
+done:
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
size_t ctdb_tunable_len(struct ctdb_tunable *in)
{
return ctdb_uint32_len(&in->value) +
diff --git a/ctdb/tests/src/protocol_common.c b/ctdb/tests/src/protocol_common.c
index e9ba658259c..9f5e4d589e5 100644
--- a/ctdb/tests/src/protocol_common.c
+++ b/ctdb/tests/src/protocol_common.c
@@ -707,6 +707,34 @@ void verify_ctdb_connection(struct ctdb_connection *p1,
verify_ctdb_sock_addr(&p1->dst, &p2->dst);
}
+void fill_ctdb_connection_list(TALLOC_CTX *mem_ctx,
+ struct ctdb_connection_list *p)
+{
+ uint32_t i;
+
+ p->num = rand_int(1000);
+ if (p->num > 0) {
+ p->conn = talloc_array(mem_ctx, struct ctdb_connection, p->num);
+ assert(p->conn != NULL);
+ for (i=0; i<p->num; i++) {
+ fill_ctdb_connection(mem_ctx, &p->conn[i]);
+ }
+ } else {
+ p->conn = NULL;
+ }
+}
+
+void verify_ctdb_connection_list(struct ctdb_connection_list *p1,
+ struct ctdb_connection_list *p2)
+{
+ uint32_t i;
+
+ assert(p1->num == p2->num);
+ for (i=0; i<p1->num; i++) {
+ verify_ctdb_connection(&p1->conn[i], &p2->conn[i]);
+ }
+}
+
void fill_ctdb_tunable(TALLOC_CTX *mem_ctx, struct ctdb_tunable *p)
{
fill_ctdb_string(mem_ctx, &p->name);
diff --git a/ctdb/tests/src/protocol_common.h b/ctdb/tests/src/protocol_common.h
index 01b1e34a440..ae51dfdc00c 100644
--- a/ctdb/tests/src/protocol_common.h
+++ b/ctdb/tests/src/protocol_common.h
@@ -238,6 +238,11 @@ void fill_ctdb_connection(TALLOC_CTX *mem_ctx, struct ctdb_connection *p);
void verify_ctdb_connection(struct ctdb_connection *p1,
struct ctdb_connection *p2);
+void fill_ctdb_connection_list(TALLOC_CTX *mem_ctx,
+ struct ctdb_connection_list *p);
+void verify_ctdb_connection_list(struct ctdb_connection_list *p1,
+ struct ctdb_connection_list *p2);
+
void fill_ctdb_tunable(TALLOC_CTX *mem_ctx, struct ctdb_tunable *p);
void verify_ctdb_tunable(struct ctdb_tunable *p1, struct ctdb_tunable *p2);
diff --git a/ctdb/tests/src/protocol_types_test.c b/ctdb/tests/src/protocol_types_test.c
index 7dbc99edfc6..dbd5cea0721 100644
--- a/ctdb/tests/src/protocol_types_test.c
+++ b/ctdb/tests/src/protocol_types_test.c
@@ -47,6 +47,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_traverse_start_ext, ctdb_traverse_start_ext);
PROTOCOL_TYPE3_TEST(struct ctdb_traverse_all_ext, ctdb_traverse_all_ext);
PROTOCOL_TYPE3_TEST(ctdb_sock_addr, ctdb_sock_addr);
PROTOCOL_TYPE3_TEST(struct ctdb_connection, ctdb_connection);
+PROTOCOL_TYPE3_TEST(struct ctdb_connection_list, ctdb_connection_list);
PROTOCOL_TYPE3_TEST(struct ctdb_tunable, ctdb_tunable);
PROTOCOL_TYPE3_TEST(struct ctdb_node_flag_change, ctdb_node_flag_change);
PROTOCOL_TYPE3_TEST(struct ctdb_var_list, ctdb_var_list);
@@ -150,6 +151,7 @@ int main(int argc, char *argv[])
TEST_FUNC(ctdb_traverse_all_ext)();
TEST_FUNC(ctdb_sock_addr)();
TEST_FUNC(ctdb_connection)();
+ TEST_FUNC(ctdb_connection_list)();
TEST_FUNC(ctdb_tunable)();
TEST_FUNC(ctdb_node_flag_change)();
TEST_FUNC(ctdb_var_list)();