ctdb-protocol: Add marshalling for ctdb_connection_list
authorMartin Schwenke <martin@meltin.net>
Tue, 5 Sep 2017 00:52:58 +0000 (10:52 +1000)
committerMartin Schwenke <martins@samba.org>
Tue, 19 Sep 2017 11:30:26 +0000 (13:30 +0200)
Signed-off-by: Martin Schwenke <martin@meltin.net>
Reviewed-by: Amitay Isaacs <amitay@gmail.com>
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 a609930aae699810791f1b64676793091dee06b8..9e3ae8dfb8fc0494c34aaeacaa8f97c26fe5dbe0 100644 (file)
@@ -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,
index ae6f7ed527aee941d32ff468262a0690595eb30b..57ad07a3324a0e6cd89206faff1110d459e2d9ed 100644 (file)
@@ -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) +
index e9ba658259c232ef051ed2ba045f58bf701dc5a9..9f5e4d589e59d6e10e12784cd42aa3b460fb2918 100644 (file)
@@ -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);
index 01b1e34a440e7e58b67f12d2f2d02b27b134dfff..ae51dfdc00cb9e92b6bb05180aed3f7d61c21da7 100644 (file)
@@ -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);
 
index 7dbc99edfc69671996942d994929256c6ba19e80..dbd5cea0721f40300922d45f336bddd643851f26 100644 (file)
@@ -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)();