summaryrefslogtreecommitdiff
path: root/ctdb/protocol/protocol_types.c
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2017-07-06 17:53:24 +1000
committerMartin Schwenke <martins@samba.org>2017-08-30 14:59:22 +0200
commit917c0eca0d8fd6da10076fdfaa92d6af6bab2bba (patch)
tree1239d5fbd064f322de3c661cfcd9b6b5f7e51edd /ctdb/protocol/protocol_types.c
parent28734f1bb196919ba58970e742aea1db3c704aa0 (diff)
downloadsamba-917c0eca0d8fd6da10076fdfaa92d6af6bab2bba.tar.gz
ctdb-protocol: Add marshalling for ctdb_dbid
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb/protocol/protocol_types.c')
-rw-r--r--ctdb/protocol/protocol_types.c75
1 files changed, 75 insertions, 0 deletions
diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c
index e324af12d32..b31f6de3fbf 100644
--- a/ctdb/protocol/protocol_types.c
+++ b/ctdb/protocol/protocol_types.c
@@ -932,6 +932,81 @@ fail:
return ret;
}
+size_t ctdb_dbid_len(struct ctdb_dbid *in)
+{
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint8_len(&in->flags) +
+ ctdb_padding_len(3);
+}
+
+void ctdb_dbid_push(struct ctdb_dbid *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint8_push(&in->flags, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(3, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_dbid_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx, struct ctdb_dbid *out,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->db_id, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint8_pull(buf+offset, buflen-offset, &out->flags, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 3, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+int ctdb_dbid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_dbid **out, size_t *npull)
+{
+ struct ctdb_dbid *val;
+ size_t np;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_dbid);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_dbid_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+
+ *out = val;
+ *npull = np;
+ return 0;
+}
+
struct ctdb_dbid_map_wire {
uint32_t num;
struct ctdb_dbid dbs[1];