return 0;
}
-size_t ctdb_traverse_start_len(struct ctdb_traverse_start *traverse)
+size_t ctdb_traverse_start_len(struct ctdb_traverse_start *in)
{
- return sizeof(struct ctdb_traverse_start);
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->reqid) +
+ ctdb_uint64_len(&in->srvid);
}
-void ctdb_traverse_start_push(struct ctdb_traverse_start *traverse,
- uint8_t *buf)
+void ctdb_traverse_start_push(struct ctdb_traverse_start *in, uint8_t *buf,
+ size_t *npush)
{
- memcpy(buf, traverse, sizeof(struct ctdb_traverse_start));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_traverse_start_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_traverse_start **out)
+ struct ctdb_traverse_start **out, size_t *npull)
{
- struct ctdb_traverse_start *traverse;
+ struct ctdb_traverse_start *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < sizeof(struct ctdb_traverse_start)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_traverse_start);
+ if (val == NULL) {
+ return ENOMEM;
}
- traverse = talloc_memdup(mem_ctx, buf,
- sizeof(struct ctdb_traverse_start));
- if (traverse == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &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 = traverse;
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_traverse_all_len(struct ctdb_traverse_all *traverse)
+size_t ctdb_traverse_all_len(struct ctdb_traverse_all *in)
{
- return sizeof(struct ctdb_traverse_all);
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->reqid) +
+ ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->client_reqid) +
+ ctdb_uint64_len(&in->srvid);
}
-void ctdb_traverse_all_push(struct ctdb_traverse_all *traverse, uint8_t *buf)
+void ctdb_traverse_all_push(struct ctdb_traverse_all *in, uint8_t *buf,
+ size_t *npush)
{
- memcpy(buf, traverse, sizeof(struct ctdb_traverse_all));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_traverse_all_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_traverse_all **out)
+ struct ctdb_traverse_all **out, size_t *npull)
{
- struct ctdb_traverse_all *traverse;
+ struct ctdb_traverse_all *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < sizeof(struct ctdb_traverse_all)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_traverse_all);
+ if (val == NULL) {
+ return ENOMEM;
}
- traverse = talloc_memdup(mem_ctx, buf,
- sizeof(struct ctdb_traverse_all));
- if (traverse == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
+ &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 = traverse;
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *traverse)
+size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *in)
{
- return sizeof(struct ctdb_traverse_start_ext);
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->reqid) +
+ ctdb_uint64_len(&in->srvid) +
+ ctdb_bool_len(&in->withemptyrecords) +
+ ctdb_padding_len(7);
}
-void ctdb_traverse_start_ext_push(struct ctdb_traverse_start_ext *traverse,
- uint8_t *buf)
+void ctdb_traverse_start_ext_push(struct ctdb_traverse_start_ext *in,
+ uint8_t *buf, size_t *npush)
{
- memcpy(buf, traverse, sizeof(struct ctdb_traverse_start_ext));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ ctdb_bool_push(&in->withemptyrecords, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(7, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_traverse_start_ext_pull(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
- struct ctdb_traverse_start_ext **out)
+ struct ctdb_traverse_start_ext **out,
+ size_t *npull)
{
- struct ctdb_traverse_start_ext *traverse;
+ struct ctdb_traverse_start_ext *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < sizeof(struct ctdb_traverse_start_ext)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_traverse_start_ext);
+ if (val == NULL) {
+ return ENOMEM;
}
- traverse = talloc_memdup(mem_ctx, buf,
- sizeof(struct ctdb_traverse_start_ext));
- if (traverse == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &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;
+
+ ret = ctdb_bool_pull(buf+offset, buflen-offset,
+ &val->withemptyrecords, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 7, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
- *out = traverse;
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_traverse_all_ext_len(struct ctdb_traverse_all_ext *traverse)
+size_t ctdb_traverse_all_ext_len(struct ctdb_traverse_all_ext *in)
{
- return sizeof(struct ctdb_traverse_all_ext);
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->reqid) +
+ ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->client_reqid) +
+ ctdb_uint64_len(&in->srvid) +
+ ctdb_bool_len(&in->withemptyrecords) +
+ ctdb_padding_len(7);
}
-void ctdb_traverse_all_ext_push(struct ctdb_traverse_all_ext *traverse,
- uint8_t *buf)
+void ctdb_traverse_all_ext_push(struct ctdb_traverse_all_ext *in,
+ uint8_t *buf, size_t *npush)
{
- memcpy(buf, traverse, sizeof(struct ctdb_traverse_all_ext));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ ctdb_bool_push(&in->withemptyrecords, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(7, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_traverse_all_ext_pull(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
- struct ctdb_traverse_all_ext **out)
+ struct ctdb_traverse_all_ext **out,
+ size_t *npull)
{
- struct ctdb_traverse_all_ext *traverse;
+ struct ctdb_traverse_all_ext *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < sizeof(struct ctdb_traverse_all_ext)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_traverse_all_ext);
+ if (val == NULL) {
+ return ENOMEM;
}
- traverse = talloc_memdup(mem_ctx, buf,
- sizeof(struct ctdb_traverse_all_ext));
- if (traverse == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->reqid, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
+ &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;
+
+ ret = ctdb_bool_pull(buf+offset, buflen-offset,
+ &val->withemptyrecords, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 7, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
- *out = traverse;
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_sock_addr_len(ctdb_sock_addr *addr)
+size_t ctdb_sock_addr_len(ctdb_sock_addr *in)
{
return sizeof(ctdb_sock_addr);
}
-void ctdb_sock_addr_push(ctdb_sock_addr *addr, uint8_t *buf)
+void ctdb_sock_addr_push(ctdb_sock_addr *in, uint8_t *buf, size_t *npush)
{
- memcpy(buf, addr, sizeof(ctdb_sock_addr));
+ memcpy(buf, in, sizeof(ctdb_sock_addr));
+ *npush = sizeof(ctdb_sock_addr);
}
-static int ctdb_sock_addr_pull_elems(uint8_t *buf, size_t buflen,
- TALLOC_CTX *mem_ctx, ctdb_sock_addr *out)
+int ctdb_sock_addr_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx, ctdb_sock_addr *out,
+ size_t *npull)
{
if (buflen < sizeof(ctdb_sock_addr)) {
return EMSGSIZE;
}
memcpy(out, buf, sizeof(ctdb_sock_addr));
+ *npull = sizeof(ctdb_sock_addr);
return 0;
}
int ctdb_sock_addr_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- ctdb_sock_addr **out)
+ ctdb_sock_addr **out, size_t *npull)
{
- ctdb_sock_addr *addr;
+ ctdb_sock_addr *val;
+ size_t np;
int ret;
- addr = talloc(mem_ctx, ctdb_sock_addr);
- if (addr == NULL) {
- return false;
+ val = talloc(mem_ctx, ctdb_sock_addr);
+ if (val == NULL) {
+ return ENOMEM;
}
- ret = ctdb_sock_addr_pull_elems(buf, buflen, addr, addr);
+ ret = ctdb_sock_addr_pull_elems(buf, buflen, val, val, &np);
if (ret != 0) {
- TALLOC_FREE(addr);
+ talloc_free(val);
+ return ret;
}
- *out = addr;
+ *out = val;
+ *npull = np;
return ret;
}
-size_t ctdb_connection_len(struct ctdb_connection *conn)
+size_t ctdb_connection_len(struct ctdb_connection *in)
{
- return sizeof(struct ctdb_connection);
+ return ctdb_sock_addr_len(&in->src) +
+ ctdb_sock_addr_len(&in->dst);
}
-void ctdb_connection_push(struct ctdb_connection *conn, uint8_t *buf)
+void ctdb_connection_push(struct ctdb_connection *in, uint8_t *buf,
+ size_t *npush)
{
- memcpy(buf, conn, sizeof(struct ctdb_connection));
+ size_t offset = 0, np;
+
+ ctdb_sock_addr_push(&in->src, buf+offset, &np);
+ offset += np;
+
+ ctdb_sock_addr_push(&in->dst, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
static int ctdb_connection_pull_elems(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
- struct ctdb_connection *out)
+ struct ctdb_connection *out,
+ size_t *npull)
{
- if (buflen < sizeof(struct ctdb_connection)) {
- return EMSGSIZE;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
+ mem_ctx, &out->src, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
- memcpy(out, buf, sizeof(struct ctdb_connection));
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
+ mem_ctx, &out->dst, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ *npull = offset;
return 0;
}
int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_connection **out)
+ struct ctdb_connection **out, size_t *npull)
{
- struct ctdb_connection *conn;
+ struct ctdb_connection *val;
+ size_t np;
int ret;
- conn = talloc(mem_ctx, struct ctdb_connection);
- if (conn == NULL) {
+ val = talloc(mem_ctx, struct ctdb_connection);
+ if (val == NULL) {
return ENOMEM;
}
- ret = ctdb_connection_pull_elems(buf, buflen, conn, conn);
+ ret = ctdb_connection_pull_elems(buf, buflen, val, val, &np);
if (ret != 0) {
- TALLOC_FREE(conn);
+ talloc_free(val);
+ return ret;
}
- *out = conn;
+ *out = val;
+ *npull = np;
return ret;
}
-struct ctdb_tunable_wire {
- uint32_t value;
- uint32_t length;
- uint8_t name[1];
-};
-
-size_t ctdb_tunable_len(struct ctdb_tunable *tunable)
+size_t ctdb_tunable_len(struct ctdb_tunable *in)
{
- return offsetof(struct ctdb_tunable_wire, name) +
- strlen(tunable->name) + 1;
+ return ctdb_uint32_len(&in->value) +
+ ctdb_stringn_len(&in->name);
}
-void ctdb_tunable_push(struct ctdb_tunable *tunable, uint8_t *buf)
+void ctdb_tunable_push(struct ctdb_tunable *in, uint8_t *buf, size_t *npush)
{
- struct ctdb_tunable_wire *wire = (struct ctdb_tunable_wire *)buf;
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->value, buf+offset, &np);
+ offset += np;
- wire->value = tunable->value;
- wire->length = strlen(tunable->name) + 1;
- memcpy(wire->name, tunable->name, wire->length);
+ ctdb_stringn_push(&in->name, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_tunable_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_tunable **out)
+ struct ctdb_tunable **out, size_t *npull)
{
- struct ctdb_tunable *tunable;
- struct ctdb_tunable_wire *wire = (struct ctdb_tunable_wire *)buf;
+ struct ctdb_tunable *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < offsetof(struct ctdb_tunable_wire, name)) {
- return EMSGSIZE;
- }
- if (wire->length > buflen) {
- return EMSGSIZE;
- }
- if (offsetof(struct ctdb_tunable_wire, name) + wire->length <
- offsetof(struct ctdb_tunable_wire, name)) {
- return EMSGSIZE;
- }
- if (buflen < offsetof(struct ctdb_tunable_wire, name) + wire->length) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_tunable);
+ if (val == NULL) {
+ return ENOMEM;
}
- tunable = talloc(mem_ctx, struct ctdb_tunable);
- if (tunable == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->value, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- tunable->value = wire->value;
- tunable->name = talloc_memdup(tunable, wire->name, wire->length);
- if (tunable->name == NULL) {
- talloc_free(tunable);
- return ENOMEM;
+ ret = ctdb_stringn_pull(buf+offset, buflen-offset, mem_ctx,
+ &val->name, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- *out = tunable;
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *flag_change)
+size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *in)
{
- return sizeof(struct ctdb_node_flag_change);
+ return ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->new_flags) +
+ ctdb_uint32_len(&in->old_flags);
}
-void ctdb_node_flag_change_push(struct ctdb_node_flag_change *flag_change,
- uint8_t *buf)
+void ctdb_node_flag_change_push(struct ctdb_node_flag_change *in,
+ uint8_t *buf, size_t *npush)
{
- memcpy(buf, flag_change, sizeof(struct ctdb_node_flag_change));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->new_flags, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->old_flags, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
-int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_node_flag_change **out)
+int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_node_flag_change **out,
+ size_t *npull)
{
- struct ctdb_node_flag_change *flag_change;
+ struct ctdb_node_flag_change *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < sizeof(struct ctdb_node_flag_change)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_node_flag_change);
+ if (val == NULL) {
+ return ENOMEM;
}
- flag_change = talloc_memdup(mem_ctx, buf,
- sizeof(struct ctdb_node_flag_change));
- if (flag_change == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->new_flags,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->old_flags,
+ &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- *out = flag_change;
+ *out = val;
+ *npull = offset;
return 0;
-}
-struct ctdb_var_list_wire {
- uint32_t length;
- char list_str[1];
-};
+fail:
+ talloc_free(val);
+ return ret;
+}
-size_t ctdb_var_list_len(struct ctdb_var_list *var_list)
+size_t ctdb_var_list_len(struct ctdb_var_list *in)
{
+ uint32_t u32 = 0;
int i;
- size_t len = sizeof(uint32_t);
- for (i=0; i<var_list->count; i++) {
- len += strlen(var_list->var[i]) + 1;
+ for (i=0; i<in->count; i++) {
+ u32 += ctdb_string_len(&in->var[i]);
}
- return len;
+
+ return ctdb_uint32_len(&u32) + u32;
}
-void ctdb_var_list_push(struct ctdb_var_list *var_list, uint8_t *buf)
+void ctdb_var_list_push(struct ctdb_var_list *in, uint8_t *buf, size_t *npush)
{
- struct ctdb_var_list_wire *wire = (struct ctdb_var_list_wire *)buf;
- int i, n;
- size_t offset = 0;
+ size_t offset = 0, np;
+ uint32_t u32;
+ int i;
+ uint8_t sep = ':';
- if (var_list->count > 0) {
- n = sprintf(wire->list_str, "%s", var_list->var[0]);
- offset += n;
- }
- for (i=1; i<var_list->count; i++) {
- n = sprintf(&wire->list_str[offset], ":%s", var_list->var[i]);
- offset += n;
+ /* The length only corresponds to the payload size */
+ u32 = ctdb_var_list_len(in);
+ u32 -= ctdb_uint32_len(&u32);
+
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ /* The variables are separated by ':' and the complete string is null
+ * terminated.
+ */
+ for (i=0; i<in->count; i++) {
+ ctdb_string_push(&in->var[i], buf+offset, &np);
+ offset += np;
+
+ if (i < in->count - 1) {
+ /* Replace '\0' with ':' */
+ ctdb_uint8_push(&sep, buf+offset-1, &np);
+ }
}
- wire->length = offset + 1;
+
+ *npush = offset;
}
int ctdb_var_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_var_list **out)
+ struct ctdb_var_list **out, size_t *npull)
{
- struct ctdb_var_list *var_list = NULL;
- struct ctdb_var_list_wire *wire = (struct ctdb_var_list_wire *)buf;
- char *str, *s, *tok, *ptr;
- const char **list;
+ struct ctdb_var_list *val;
+ const char *str, **list;
+ char *s, *tok, *ptr = NULL;
+ size_t offset = 0, np;
+ uint32_t u32;
+ int ret;
- if (buflen < sizeof(uint32_t)) {
- return EMSGSIZE;
+ val = talloc_zero(mem_ctx, struct ctdb_var_list);
+ if (val == NULL) {
+ return ENOMEM;
}
- if (wire->length > buflen) {
- return EMSGSIZE;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ goto fail;
}
- if (sizeof(uint32_t) + wire->length < sizeof(uint32_t)) {
- return EMSGSIZE;
+ offset += np;
+
+ if (buflen-offset < u32) {
+ ret = EMSGSIZE;
+ goto fail;
}
- if (buflen < sizeof(uint32_t) + wire->length) {
- return EMSGSIZE;
+
+ ret = ctdb_string_pull(buf+offset, u32, val, &str, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ s = discard_const(str);
+ while ((tok = strtok_r(s, ":", &ptr)) != NULL) {
+ list = talloc_realloc(val, val->var, const char *,
+ val->count+1);
+ if (list == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ val->var = list;
+
+ s = talloc_strdup(val, tok);
+ if (s == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ val->var[val->count] = s;
+ val->count += 1;
+ s = NULL;
+ }
+
+ talloc_free(discard_const(str));
+ *out = val;
+ *npull = offset;
+ return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
+}
+
+size_t ctdb_tunable_list_len(struct ctdb_tunable_list *in)
+{
+ return ctdb_uint32_len(&in->max_redirect_count) +
+ ctdb_uint32_len(&in->seqnum_interval) +
+ ctdb_uint32_len(&in->control_timeout) +
+ ctdb_uint32_len(&in->traverse_timeout) +
+ ctdb_uint32_len(&in->keepalive_interval) +
+ ctdb_uint32_len(&in->keepalive_limit) +
+ ctdb_uint32_len(&in->recover_timeout) +
+ ctdb_uint32_len(&in->recover_interval) +
+ ctdb_uint32_len(&in->election_timeout) +
+ ctdb_uint32_len(&in->takeover_timeout) +
+ ctdb_uint32_len(&in->monitor_interval) +
+ ctdb_uint32_len(&in->tickle_update_interval) +
+ ctdb_uint32_len(&in->script_timeout) +
+ ctdb_uint32_len(&in->monitor_timeout_count) +
+ ctdb_uint32_len(&in->script_unhealthy_on_timeout) +
+ ctdb_uint32_len(&in->recovery_grace_period) +
+ ctdb_uint32_len(&in->recovery_ban_period) +
+ ctdb_uint32_len(&in->database_hash_size) +
+ ctdb_uint32_len(&in->database_max_dead) +
+ ctdb_uint32_len(&in->rerecovery_timeout) +
+ ctdb_uint32_len(&in->enable_bans) +
+ ctdb_uint32_len(&in->deterministic_public_ips) +
+ ctdb_uint32_len(&in->reclock_ping_period) +
+ ctdb_uint32_len(&in->no_ip_failback) +
+ ctdb_uint32_len(&in->disable_ip_failover) +
+ ctdb_uint32_len(&in->verbose_memory_names) +
+ ctdb_uint32_len(&in->recd_ping_timeout) +
+ ctdb_uint32_len(&in->recd_ping_failcount) +
+ ctdb_uint32_len(&in->log_latency_ms) +
+ ctdb_uint32_len(&in->reclock_latency_ms) +
+ ctdb_uint32_len(&in->recovery_drop_all_ips) +
+ ctdb_uint32_len(&in->verify_recovery_lock) +
+ ctdb_uint32_len(&in->vacuum_interval) +
+ ctdb_uint32_len(&in->vacuum_max_run_time) +
+ ctdb_uint32_len(&in->repack_limit) +
+ ctdb_uint32_len(&in->vacuum_limit) +
+ ctdb_uint32_len(&in->max_queue_depth_drop_msg) +
+ ctdb_uint32_len(&in->allow_unhealthy_db_read) +
+ ctdb_uint32_len(&in->stat_history_interval) +
+ ctdb_uint32_len(&in->deferred_attach_timeout) +
+ ctdb_uint32_len(&in->vacuum_fast_path_count) +
+ ctdb_uint32_len(&in->lcp2_public_ip_assignment) +
+ ctdb_uint32_len(&in->allow_client_db_attach) +
+ ctdb_uint32_len(&in->recover_pdb_by_seqnum) +
+ ctdb_uint32_len(&in->deferred_rebalance_on_node_add) +
+ ctdb_uint32_len(&in->fetch_collapse) +
+ ctdb_uint32_len(&in->hopcount_make_sticky) +
+ ctdb_uint32_len(&in->sticky_duration) +
+ ctdb_uint32_len(&in->sticky_pindown) +
+ ctdb_uint32_len(&in->no_ip_takeover) +
+ ctdb_uint32_len(&in->db_record_count_warn) +
+ ctdb_uint32_len(&in->db_record_size_warn) +
+ ctdb_uint32_len(&in->db_size_warn) +
+ ctdb_uint32_len(&in->pulldb_preallocation_size) +
+ ctdb_uint32_len(&in->no_ip_host_on_all_disabled) +
+ ctdb_uint32_len(&in->samba3_hack) +
+ ctdb_uint32_len(&in->mutex_enabled) +
+ ctdb_uint32_len(&in->lock_processes_per_db) +
+ ctdb_uint32_len(&in->rec_buffer_size_limit) +
+ ctdb_uint32_len(&in->queue_buffer_size) +
+ ctdb_uint32_len(&in->ip_alloc_algorithm) +
+ ctdb_uint32_len(&in->allow_mixed_versions);
+}
+
+void ctdb_tunable_list_push(struct ctdb_tunable_list *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->max_redirect_count, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->seqnum_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->control_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->traverse_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->keepalive_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->keepalive_limit, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recover_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recover_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->election_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->takeover_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->monitor_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->tickle_update_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->script_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->monitor_timeout_count, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->script_unhealthy_on_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recovery_grace_period, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recovery_ban_period, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->database_hash_size, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->database_max_dead, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->rerecovery_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->enable_bans, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->deterministic_public_ips, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reclock_ping_period, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->no_ip_failback, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->disable_ip_failover, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->verbose_memory_names, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recd_ping_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recd_ping_failcount, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->log_latency_ms, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reclock_latency_ms, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recovery_drop_all_ips, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->verify_recovery_lock, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->vacuum_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->vacuum_max_run_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->repack_limit, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->vacuum_limit, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->max_queue_depth_drop_msg, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->allow_unhealthy_db_read, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->stat_history_interval, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->deferred_attach_timeout, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->vacuum_fast_path_count, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->lcp2_public_ip_assignment, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->allow_client_db_attach, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recover_pdb_by_seqnum, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->deferred_rebalance_on_node_add, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->fetch_collapse, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->hopcount_make_sticky, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->sticky_duration, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->sticky_pindown, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->no_ip_takeover, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->db_record_count_warn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->db_record_size_warn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->db_size_warn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pulldb_preallocation_size, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->no_ip_host_on_all_disabled, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->samba3_hack, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->mutex_enabled, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->lock_processes_per_db, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->rec_buffer_size_limit, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->queue_buffer_size, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->ip_alloc_algorithm, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->allow_mixed_versions, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_tunable_list_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_tunable_list *out,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->max_redirect_count, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->seqnum_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->control_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->traverse_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->keepalive_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->keepalive_limit, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recover_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recover_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->election_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->takeover_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->monitor_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->tickle_update_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->script_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->monitor_timeout_count, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->script_unhealthy_on_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recovery_grace_period, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recovery_ban_period, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->database_hash_size, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->database_max_dead, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->rerecovery_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->enable_bans, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->deterministic_public_ips, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->reclock_ping_period, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->no_ip_failback, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->disable_ip_failover, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->verbose_memory_names, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recd_ping_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recd_ping_failcount, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->log_latency_ms, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->reclock_latency_ms, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recovery_drop_all_ips, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->verify_recovery_lock, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->vacuum_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->vacuum_max_run_time, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->repack_limit, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->vacuum_limit, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->max_queue_depth_drop_msg, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->allow_unhealthy_db_read, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->stat_history_interval, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->deferred_attach_timeout, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->vacuum_fast_path_count, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->lcp2_public_ip_assignment, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->allow_client_db_attach, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->recover_pdb_by_seqnum, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->deferred_rebalance_on_node_add, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->fetch_collapse, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->hopcount_make_sticky, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->sticky_duration, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->sticky_pindown, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->no_ip_takeover, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->db_record_count_warn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->db_record_size_warn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->db_size_warn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->pulldb_preallocation_size, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->no_ip_host_on_all_disabled, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->samba3_hack, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->mutex_enabled, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->lock_processes_per_db, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->rec_buffer_size_limit, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
- str = talloc_strndup(mem_ctx, (char *)wire->list_str, wire->length);
- if (str == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->queue_buffer_size, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
- var_list = talloc_zero(mem_ctx, struct ctdb_var_list);
- if (var_list == NULL) {
- goto fail;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->ip_alloc_algorithm, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
- s = str;
- while ((tok = strtok_r(s, ":", &ptr)) != NULL) {
- s = NULL;
- list = talloc_realloc(var_list, var_list->var, const char *,
- var_list->count+1);
- if (list == NULL) {
- goto fail;
- }
-
- var_list->var = list;
- var_list->var[var_list->count] = talloc_strdup(var_list, tok);
- if (var_list->var[var_list->count] == NULL) {
- goto fail;
- }
- var_list->count++;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->allow_mixed_versions, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
- talloc_free(str);
- *out = var_list;
+ *npull = offset;
return 0;
-
-fail:
- talloc_free(str);
- talloc_free(var_list);
- return ENOMEM;
-}
-
-size_t ctdb_tunable_list_len(struct ctdb_tunable_list *tun_list)
-{
- return sizeof(struct ctdb_tunable_list);
-}
-
-void ctdb_tunable_list_push(struct ctdb_tunable_list *tun_list, uint8_t *buf)
-{
- memcpy(buf, tun_list, sizeof(struct ctdb_tunable_list));
}
int ctdb_tunable_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_tunable_list **out)
+ struct ctdb_tunable_list **out, size_t *npull)
{
- struct ctdb_tunable_list *tun_list;
+ struct ctdb_tunable_list *val;
+ size_t np;
+ int ret;
- if (buflen < sizeof(struct ctdb_tunable_list)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_tunable_list);
+ if (val == NULL) {
+ return ENOMEM;
}
- tun_list = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_tunable_list));
- if (tun_list == NULL) {
- return ENOMEM;
+ ret = ctdb_tunable_list_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
}
- *out = tun_list;
+ *out = val;
+ *npull = np;
return 0;
}
-struct ctdb_tickle_list_wire {
- ctdb_sock_addr addr;
- uint32_t num;
- struct ctdb_connection conn[1];
-};
-
-size_t ctdb_tickle_list_len(struct ctdb_tickle_list *tickles)
+size_t ctdb_tickle_list_len(struct ctdb_tickle_list *in)
{
- return offsetof(struct ctdb_tickle_list, conn) +
- tickles->num * sizeof(struct ctdb_connection);
+ size_t len;
+
+ len = ctdb_sock_addr_len(&in->addr) +
+ ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_connection_len(&in->conn[0]);
+ }
+
+ return len;
}
-void ctdb_tickle_list_push(struct ctdb_tickle_list *tickles, uint8_t *buf)
+void ctdb_tickle_list_push(struct ctdb_tickle_list *in, uint8_t *buf,
+ size_t *npush)
{
- struct ctdb_tickle_list_wire *wire =
- (struct ctdb_tickle_list_wire *)buf;
- size_t offset;
- int i;
+ size_t offset = 0, np;
+ uint32_t i;
+
+ ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+ offset += np;
- memcpy(&wire->addr, &tickles->addr, sizeof(ctdb_sock_addr));
- wire->num = tickles->num;
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
- offset = offsetof(struct ctdb_tickle_list_wire, conn);
- for (i=0; i<tickles->num; i++) {
- ctdb_connection_push(&tickles->conn[i], &buf[offset]);
- offset += ctdb_connection_len(&tickles->conn[i]);
+ for (i=0; i<in->num; i++) {
+ ctdb_connection_push(&in->conn[i], buf+offset, &np);
+ offset += np;
}
+
+ *npush = offset;
}
int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_tickle_list **out)
+ struct ctdb_tickle_list **out, size_t *npull)
{
- struct ctdb_tickle_list *tickles;
- struct ctdb_tickle_list_wire *wire =
- (struct ctdb_tickle_list_wire *)buf;
- size_t offset;
- int i, ret;
+ struct ctdb_tickle_list *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
- if (buflen < offsetof(struct ctdb_tickle_list_wire, conn)) {
- return EMSGSIZE;
- }
- if (wire->num > buflen / sizeof(struct ctdb_connection)) {
- return EMSGSIZE;
- }
- if (offsetof(struct ctdb_tickle_list_wire, conn) +
- wire->num * sizeof(struct ctdb_connection) <
- offsetof(struct ctdb_tickle_list_wire, conn)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_tickle_list);
+ if (val == NULL) {
+ return ENOMEM;
}
- if (buflen < offsetof(struct ctdb_tickle_list_wire, conn) +
- wire->num * sizeof(struct ctdb_connection)) {
- return EMSGSIZE;
+
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
+ &val->addr, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- tickles = talloc(mem_ctx, struct ctdb_tickle_list);
- if (tickles == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- offset = offsetof(struct ctdb_tickle_list, conn);
- memcpy(tickles, wire, offset);
+ if (val->num == 0) {
+ val->conn = NULL;
+ goto done;
+ }
- tickles->conn = talloc_array(tickles, struct ctdb_connection,
- wire->num);
- if (tickles->conn == NULL) {
- talloc_free(tickles);
- return ENOMEM;
+ val->conn = talloc_array(val, struct ctdb_connection, val->num);
+ if (val->conn == NULL) {
+ ret = ENOMEM;
+ goto fail;
}
- for (i=0; i<wire->num; i++) {
- ret = ctdb_connection_pull_elems(&buf[offset], buflen-offset,
- tickles->conn,
- &tickles->conn[i]);
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_connection_pull_elems(buf+offset, buflen-offset,
+ val, &val->conn[i], &np);
if (ret != 0) {
- talloc_free(tickles);
- return ret;
+ goto fail;
}
- offset += ctdb_connection_len(&tickles->conn[i]);
+ offset += np;
}
- *out = tickles;
+done:
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-struct ctdb_addr_info_wire {
- ctdb_sock_addr addr;
- uint32_t mask;
- uint32_t len;
- char iface[1];
-};
+size_t ctdb_addr_info_len(struct ctdb_addr_info *in)
+{
+ return ctdb_sock_addr_len(&in->addr) +
+ ctdb_uint32_len(&in->mask) +
+ ctdb_stringn_len(&in->iface);
+}
-size_t ctdb_addr_info_len(struct ctdb_addr_info *arp)
+void ctdb_addr_info_push(struct ctdb_addr_info *in, uint8_t *buf,
+ size_t *npush)
{
- uint32_t len;
+ size_t offset = 0, np;
- len = offsetof(struct ctdb_addr_info_wire, iface);
- if (arp->iface != NULL) {
- len += strlen(arp->iface)+1;
- }
+ ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+ offset += np;
- return len;
-}
+ ctdb_uint32_push(&in->mask, buf+offset, &np);
+ offset += np;
-void ctdb_addr_info_push(struct ctdb_addr_info *addr_info, uint8_t *buf)
-{
- struct ctdb_addr_info_wire *wire = (struct ctdb_addr_info_wire *)buf;
+ ctdb_stringn_push(&in->iface, buf+offset, &np);
+ offset += np;
- wire->addr = addr_info->addr;
- wire->mask = addr_info->mask;
- if (addr_info->iface == NULL) {
- wire->len = 0;
- } else {
- wire->len = strlen(addr_info->iface)+1;
- memcpy(wire->iface, addr_info->iface, wire->len);
- }
+ *npush = offset;
}
int ctdb_addr_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_addr_info **out)
+ struct ctdb_addr_info **out, size_t *npull)
{
- struct ctdb_addr_info *addr_info;
- struct ctdb_addr_info_wire *wire = (struct ctdb_addr_info_wire *)buf;
+ struct ctdb_addr_info *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < offsetof(struct ctdb_addr_info_wire, iface)) {
- return EMSGSIZE;
- }
- if (wire->len > buflen) {
- return EMSGSIZE;
- }
- if (offsetof(struct ctdb_addr_info_wire, iface) + wire->len <
- offsetof(struct ctdb_addr_info_wire, iface)) {
- return EMSGSIZE;
- }
- if (buflen < offsetof(struct ctdb_addr_info_wire, iface) + wire->len) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_addr_info);
+ if (val == NULL) {
+ return ENOMEM;
}
- addr_info = talloc(mem_ctx, struct ctdb_addr_info);
- if (addr_info == NULL) {
- return ENOMEM;
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
+ &val->addr, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- addr_info->addr = wire->addr;
- addr_info->mask = wire->mask;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->mask, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
- if (wire->len == 0) {
- addr_info->iface = NULL;
- } else {
- addr_info->iface = talloc_strndup(addr_info, wire->iface,
- wire->len);
- if (addr_info->iface == NULL) {
- talloc_free(addr_info);
- return ENOMEM;
- }
+ ret = ctdb_stringn_pull(buf+offset, buflen-offset, val, &val->iface,
+ &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- *out = addr_info;
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_transdb_len(struct ctdb_transdb *transdb)
+size_t ctdb_transdb_len(struct ctdb_transdb *in)
{
- return sizeof(struct ctdb_transdb);
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->tid);
}
-void ctdb_transdb_push(struct ctdb_transdb *transdb, uint8_t *buf)
+void ctdb_transdb_push(struct ctdb_transdb *in, uint8_t *buf, size_t *npush)
{
- memcpy(buf, transdb, sizeof(struct ctdb_transdb));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->tid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_transdb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_transdb **out)
+ struct ctdb_transdb **out, size_t *npull)
{
- struct ctdb_transdb *transdb;
+ struct ctdb_transdb *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < sizeof(struct ctdb_transdb)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_transdb);
+ if (val == NULL) {
+ return ENOMEM;
}
- transdb = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_transdb));
- if (transdb == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->tid, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- *out = transdb;
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_uptime_len(struct ctdb_uptime *uptime)
+size_t ctdb_uptime_len(struct ctdb_uptime *in)
{
- return sizeof(struct ctdb_uptime);
+ return ctdb_timeval_len(&in->current_time) +
+ ctdb_timeval_len(&in->ctdbd_start_time) +
+ ctdb_timeval_len(&in->last_recovery_started) +
+ ctdb_timeval_len(&in->last_recovery_finished);
}
-void ctdb_uptime_push(struct ctdb_uptime *uptime, uint8_t *buf)
+void ctdb_uptime_push(struct ctdb_uptime *in, uint8_t *buf, size_t *npush)
{
- memcpy(buf, uptime, sizeof(struct ctdb_uptime));
+ size_t offset = 0, np;
+
+ ctdb_timeval_push(&in->current_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->ctdbd_start_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->last_recovery_started, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->last_recovery_finished, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_uptime_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_uptime **out)
+ struct ctdb_uptime **out, size_t *npull)
{
- struct ctdb_uptime *uptime;
+ struct ctdb_uptime *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < sizeof(struct ctdb_uptime)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_uptime);
+ if (val == NULL) {
+ return ENOMEM;
}
- uptime = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_uptime));
- if (uptime == NULL) {
- return ENOMEM;
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset, &val->current_time,
+ &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &val->ctdbd_start_time, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &val->last_recovery_started, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &val->last_recovery_finished, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- *out = uptime;
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_public_ip_len(struct ctdb_public_ip *pubip)
+size_t ctdb_public_ip_len(struct ctdb_public_ip *in)
{
- return sizeof(struct ctdb_public_ip);
+ return ctdb_uint32_len(&in->pnn) +
+ ctdb_sock_addr_len(&in->addr);
}
-void ctdb_public_ip_push(struct ctdb_public_ip *pubip, uint8_t *buf)
+void ctdb_public_ip_push(struct ctdb_public_ip *in, uint8_t *buf,
+ size_t *npush)
{
- memcpy(buf, pubip, sizeof(struct ctdb_public_ip));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
static int ctdb_public_ip_pull_elems(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
- struct ctdb_public_ip *out)
+ struct ctdb_public_ip *out, size_t *npull)
{
- if (buflen < sizeof(struct ctdb_public_ip)) {
- return EMSGSIZE;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->pnn, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
- memcpy(out, buf, sizeof(struct ctdb_public_ip));
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, mem_ctx,
+ &out->addr, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ *npull = offset;
return 0;
}
int ctdb_public_ip_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_public_ip **out)
+ struct ctdb_public_ip **out, size_t *npull)
{
- struct ctdb_public_ip *pubip;
+ struct ctdb_public_ip *val;
+ size_t np;
int ret;
- pubip = talloc(mem_ctx, struct ctdb_public_ip);
- if (pubip == NULL) {
+ val = talloc(mem_ctx, struct ctdb_public_ip);
+ if (val == NULL) {
return ENOMEM;
}
- ret = ctdb_public_ip_pull_elems(buf, buflen, pubip, pubip);
+ ret = ctdb_public_ip_pull_elems(buf, buflen, val, val, &np);
if (ret != 0) {
- TALLOC_FREE(pubip);
+ TALLOC_FREE(val);
+ return ret;
}
- *out = pubip;
+ *out = val;
+ *npull = np;
return ret;
}
-struct ctdb_public_ip_list_wire {
- uint32_t num;
- struct ctdb_public_ip ip[1];
-};
-
-size_t ctdb_public_ip_list_len(struct ctdb_public_ip_list *pubip_list)
+size_t ctdb_public_ip_list_len(struct ctdb_public_ip_list *in)
{
- int i;
size_t len;
- len = sizeof(uint32_t);
- for (i=0; i<pubip_list->num; i++) {
- len += ctdb_public_ip_len(&pubip_list->ip[i]);
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_public_ip_len(&in->ip[0]);
}
+
return len;
}
-void ctdb_public_ip_list_push(struct ctdb_public_ip_list *pubip_list,
- uint8_t *buf)
+void ctdb_public_ip_list_push(struct ctdb_public_ip_list *in, uint8_t *buf,
+ size_t *npush)
{
- struct ctdb_public_ip_list_wire *wire =
- (struct ctdb_public_ip_list_wire *)buf;
- size_t offset;
- int i;
+ size_t offset = 0, np;
+ uint32_t i;
- wire->num = pubip_list->num;
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
- offset = offsetof(struct ctdb_public_ip_list_wire, ip);
- for (i=0; i<pubip_list->num; i++) {
- ctdb_public_ip_push(&pubip_list->ip[i], &buf[offset]);
- offset += ctdb_public_ip_len(&pubip_list->ip[i]);
+ for (i=0; i<in->num; i++) {
+ ctdb_public_ip_push(&in->ip[i], buf+offset, &np);
+ offset += np;
}
+
+ *npush = offset;
}
int ctdb_public_ip_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_public_ip_list **out)
+ struct ctdb_public_ip_list **out, size_t *npull)
{
- struct ctdb_public_ip_list *pubip_list;
- struct ctdb_public_ip_list_wire *wire =
- (struct ctdb_public_ip_list_wire *)buf;
- size_t offset;
- int i;
- bool ret;
+ struct ctdb_public_ip_list *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
- if (buflen < sizeof(uint32_t)) {
- return EMSGSIZE;
- }
- if (wire->num > buflen / sizeof(struct ctdb_public_ip)) {
- return EMSGSIZE;
- }
- if (sizeof(uint32_t) + wire->num * sizeof(struct ctdb_public_ip) <
- sizeof(uint32_t)) {
- return EMSGSIZE;
- }
- if (buflen < sizeof(uint32_t) +
- wire->num * sizeof(struct ctdb_public_ip)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_public_ip_list);
+ if (val == NULL) {
+ return ENOMEM;
}
- pubip_list = talloc(mem_ctx, struct ctdb_public_ip_list);
- if (pubip_list == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- pubip_list->num = wire->num;
- if (wire->num == 0) {
- pubip_list->ip = NULL;
- *out = pubip_list;
- return 0;
+ if (val->num == 0) {
+ val->ip = NULL;
+ goto done;
}
- pubip_list->ip = talloc_array(pubip_list, struct ctdb_public_ip,
- wire->num);
- if (pubip_list->ip == NULL) {
- talloc_free(pubip_list);
- return ENOMEM;
+
+ val->ip = talloc_array(val, struct ctdb_public_ip, val->num);
+ if (val->ip == NULL) {
+ ret = ENOMEM;
+ goto fail;
}
- offset = offsetof(struct ctdb_public_ip_list_wire, ip);
- for (i=0; i<wire->num; i++) {
- ret = ctdb_public_ip_pull_elems(&buf[offset], buflen-offset,
- pubip_list->ip,
- &pubip_list->ip[i]);
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_public_ip_pull_elems(buf+offset, buflen-offset,
+ val->ip, &val->ip[i], &np);
if (ret != 0) {
- talloc_free(pubip_list);
- return ret;
+ goto fail;
}
- offset += ctdb_public_ip_len(&pubip_list->ip[i]);
+ offset += np;
}
- *out = pubip_list;
+done:
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *node)
+size_t ctdb_node_and_flags_len(struct ctdb_node_and_flags *in)
{
- return sizeof(struct ctdb_node_and_flags);
+ return ctdb_uint32_len(&in->pnn) +
+ ctdb_uint32_len(&in->flags) +
+ ctdb_sock_addr_len(&in->addr);
}
-void ctdb_node_and_flags_push(struct ctdb_node_and_flags *node, uint8_t *buf)
+void ctdb_node_and_flags_push(struct ctdb_node_and_flags *in, uint8_t *buf,
+ size_t *npush)
{
- memcpy(buf, node, sizeof(struct ctdb_node_and_flags));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->pnn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->flags, buf+offset, &np);
+ offset += np;
+
+ ctdb_sock_addr_push(&in->addr, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
-static int ctdb_node_and_flags_pull_elems(TALLOC_CTX *mem_ctx,
- uint8_t *buf, size_t buflen,
- struct ctdb_node_and_flags *out)
+static int ctdb_node_and_flags_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_node_and_flags *out,
+ size_t *npull)
{
- if (buflen < sizeof(struct ctdb_node_and_flags)) {
- return EMSGSIZE;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->pnn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->flags, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
- memcpy(out, buf, sizeof(struct ctdb_node_and_flags));
+ ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, mem_ctx,
+ &out->addr, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ *npull = offset;
return 0;
}
int ctdb_node_and_flags_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_node_and_flags **out)
+ struct ctdb_node_and_flags **out, size_t *npull)
{
- struct ctdb_node_and_flags *node;
+ struct ctdb_node_and_flags *val;
+ size_t np;
int ret;
- node = talloc(mem_ctx, struct ctdb_node_and_flags);
- if (node == NULL) {
+ val = talloc(mem_ctx, struct ctdb_node_and_flags);
+ if (val == NULL) {
return ENOMEM;
}
- ret = ctdb_node_and_flags_pull_elems(node, buf, buflen, node);
+ ret = ctdb_node_and_flags_pull_elems(buf, buflen, val, val, &np);
if (ret != 0) {
- TALLOC_FREE(node);
+ TALLOC_FREE(val);
+ return ret;
}
- *out = node;
+ *out = val;
+ *npull = np;
return ret;
}
-struct ctdb_node_map_wire {
- uint32_t num;
- struct ctdb_node_and_flags node[1];
-};
-
-size_t ctdb_node_map_len(struct ctdb_node_map *nodemap)
+size_t ctdb_node_map_len(struct ctdb_node_map *in)
{
- return sizeof(uint32_t) +
- nodemap->num * sizeof(struct ctdb_node_and_flags);
+ size_t len;
+
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_node_and_flags_len(&in->node[0]);
+ }
+
+ return len;
}
-void ctdb_node_map_push(struct ctdb_node_map *nodemap, uint8_t *buf)
+void ctdb_node_map_push(struct ctdb_node_map *in, uint8_t *buf, size_t *npush)
{
- struct ctdb_node_map_wire *wire = (struct ctdb_node_map_wire *)buf;
- size_t offset;
- int i;
+ size_t offset = 0, np;
+ uint32_t i;
- wire->num = nodemap->num;
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
- offset = offsetof(struct ctdb_node_map_wire, node);
- for (i=0; i<nodemap->num; i++) {
- ctdb_node_and_flags_push(&nodemap->node[i], &buf[offset]);
- offset += ctdb_node_and_flags_len(&nodemap->node[i]);
+ for (i=0; i<in->num; i++) {
+ ctdb_node_and_flags_push(&in->node[i], buf+offset, &np);
+ offset += np;
}
+
+ *npush = offset;
}
int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_node_map **out)
+ struct ctdb_node_map **out, size_t *npull)
{
- struct ctdb_node_map *nodemap;
- struct ctdb_node_map_wire *wire = (struct ctdb_node_map_wire *)buf;
- size_t offset;
- int i;
- bool ret;
+ struct ctdb_node_map *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
- if (buflen < sizeof(uint32_t)) {
- return EMSGSIZE;
- }
- if (wire->num > buflen / sizeof(struct ctdb_node_and_flags)) {
- return EMSGSIZE;
- }
- if (sizeof(uint32_t) + wire->num * sizeof(struct ctdb_node_and_flags) <
- sizeof(uint32_t)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_node_map);
+ if (val == NULL) {
+ return ENOMEM;
}
- if (buflen < sizeof(uint32_t) +
- wire->num * sizeof(struct ctdb_node_and_flags)) {
- return EMSGSIZE;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- nodemap = talloc(mem_ctx, struct ctdb_node_map);
- if (nodemap == NULL) {
- return ENOMEM;
+ if (val->num == 0) {
+ val->node = NULL;
+ goto done;
}
- nodemap->num = wire->num;
- nodemap->node = talloc_array(nodemap, struct ctdb_node_and_flags,
- wire->num);
- if (nodemap->node == NULL) {
- talloc_free(nodemap);
- return ENOMEM;
+ val->node = talloc_array(val, struct ctdb_node_and_flags, val->num);
+ if (val->node == NULL) {
+ ret = ENOMEM;
+ goto fail;
}
- offset = offsetof(struct ctdb_node_map_wire, node);
- for (i=0; i<wire->num; i++) {
- ret = ctdb_node_and_flags_pull_elems(nodemap->node,
- &buf[offset],
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_node_and_flags_pull_elems(buf+offset,
buflen-offset,
- &nodemap->node[i]);
+ val->node, &val->node[i],
+ &np);
if (ret != 0) {
- talloc_free(nodemap);
- return ret;
+ goto fail;
}
- offset += ctdb_node_and_flags_len(&nodemap->node[i]);
+ offset += np;
}
- *out = nodemap;
+done:
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_script_len(struct ctdb_script *script)
+size_t ctdb_script_len(struct ctdb_script *in)
{
- return sizeof(struct ctdb_script);
+ return ctdb_chararray_len(in->name, MAX_SCRIPT_NAME+1) +
+ ctdb_timeval_len(&in->start) +
+ ctdb_timeval_len(&in->finished) +
+ ctdb_int32_len(&in->status) +
+ ctdb_chararray_len(in->output, MAX_SCRIPT_OUTPUT+1) +
+ ctdb_padding_len(4);
}
-void ctdb_script_push(struct ctdb_script *script, uint8_t *buf)
+void ctdb_script_push(struct ctdb_script *in, uint8_t *buf, size_t *npush)
{
- memcpy(buf, script, sizeof(struct ctdb_script));
+ size_t offset = 0, np;
+
+ ctdb_chararray_push(in->name, MAX_SCRIPT_NAME+1, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->start, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->finished, buf+offset, &np);
+ offset += np;
+
+ ctdb_int32_push(&in->status, buf+offset, &np);
+ offset += np;
+
+ ctdb_chararray_push(in->output, MAX_SCRIPT_OUTPUT+1, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
static int ctdb_script_pull_elems(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
- struct ctdb_script *out)
+ struct ctdb_script *out, size_t *npull)
{
- if (buflen < sizeof(struct ctdb_script)) {
- return EMSGSIZE;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_chararray_pull(buf+offset, buflen-offset,
+ out->name, MAX_SCRIPT_NAME+1, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->start, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->finished,
+ &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
+
+ ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->status, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_chararray_pull(buf+offset, buflen-offset,
+ out->output, MAX_SCRIPT_OUTPUT+1, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
- memcpy(out, buf, sizeof(struct ctdb_script));
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ *npull = offset;
return 0;
}
int ctdb_script_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_script **out)
+ struct ctdb_script **out, size_t *npull)
{
- struct ctdb_script *script;
+ struct ctdb_script *val;
+ size_t np;
int ret;
- script = talloc(mem_ctx, struct ctdb_script);
- if (script == NULL) {
+ val = talloc(mem_ctx, struct ctdb_script);
+ if (val == NULL) {
return ENOMEM;
}
- ret = ctdb_script_pull_elems(buf, buflen, script, script);
+ ret = ctdb_script_pull_elems(buf, buflen, val, val, &np);
if (ret != 0) {
- TALLOC_FREE(script);
+ TALLOC_FREE(val);
+ return ret;
}
- *out = script;
+ *out = val;
+ *npull = np;
return ret;
}
-struct ctdb_script_list_wire {
- uint32_t num_scripts;
- struct ctdb_script script[1];
-};
-
-size_t ctdb_script_list_len(struct ctdb_script_list *script_list)
+size_t ctdb_script_list_len(struct ctdb_script_list *in)
{
- int i;
size_t len;
- if (script_list == NULL) {
+ if (in == NULL) {
return 0;
}
- len = offsetof(struct ctdb_script_list_wire, script);
- for (i=0; i<script_list->num_scripts; i++) {
- len += ctdb_script_len(&script_list->script[i]);
+ len = ctdb_uint32_len(&in->num_scripts) + ctdb_padding_len(4);
+ if (in->num_scripts > 0) {
+ len += in->num_scripts * ctdb_script_len(&in->script[0]);
}
+
return len;
}
-void ctdb_script_list_push(struct ctdb_script_list *script_list, uint8_t *buf)
+void ctdb_script_list_push(struct ctdb_script_list *in, uint8_t *buf,
+ size_t *npush)
{
- struct ctdb_script_list_wire *wire =
- (struct ctdb_script_list_wire *)buf;
- size_t offset;
- int i;
+ size_t offset = 0, np;
+ uint32_t i;
- if (script_list == NULL) {
+ if (in == NULL) {
+ *npush = 0;
return;
}
- wire->num_scripts = script_list->num_scripts;
+ ctdb_uint32_push(&in->num_scripts, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
- offset = offsetof(struct ctdb_script_list_wire, script);
- for (i=0; i<script_list->num_scripts; i++) {
- ctdb_script_push(&script_list->script[i], &buf[offset]);
- offset += ctdb_script_len(&script_list->script[i]);
+ for (i=0; i<in->num_scripts; i++) {
+ ctdb_script_push(&in->script[i], buf+offset, &np);
+ offset += np;
}
+
+ *npush = offset;
}
int ctdb_script_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_script_list **out)
+ struct ctdb_script_list **out, size_t *npull)
{
- struct ctdb_script_list *script_list;
- struct ctdb_script_list_wire *wire =
- (struct ctdb_script_list_wire *)buf;
- size_t offset;
- int i;
- bool ret;
+ struct ctdb_script_list *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
/* If event scripts have never been run, the result will be NULL */
if (buflen == 0) {
- *out = NULL;
- return 0;
+ val = NULL;
+ goto done;
}
- offset = offsetof(struct ctdb_script_list_wire, script);
-
- if (buflen < offset) {
- return EMSGSIZE;
- }
- if (wire->num_scripts > buflen / sizeof(struct ctdb_script)) {
- return EMSGSIZE;
- }
- if (offset + wire->num_scripts * sizeof(struct ctdb_script) < offset) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_script_list);
+ if (val == NULL) {
+ return ENOMEM;
}
- if (buflen < offset + wire->num_scripts * sizeof(struct ctdb_script)) {
- return EMSGSIZE;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num_scripts,
+ &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- script_list = talloc(mem_ctx, struct ctdb_script_list);
- if (script_list == NULL) {
- return ENOMEM;
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+ if (val->num_scripts == 0) {
+ goto done;
+ val->script = NULL;
}
- script_list->num_scripts = wire->num_scripts;
- script_list->script = talloc_array(script_list, struct ctdb_script,
- wire->num_scripts);
- if (script_list->script == NULL) {
- talloc_free(script_list);
- return ENOMEM;
+ val->script = talloc_array(val, struct ctdb_script, val->num_scripts);
+ if (val->script == NULL) {
+ ret = ENOMEM;
+ goto fail;
}
- for (i=0; i<wire->num_scripts; i++) {
- ret = ctdb_script_pull_elems(&buf[offset], buflen-offset,
- script_list->script,
- &script_list->script[i]);
+ for (i=0; i<val->num_scripts; i++) {
+ ret = ctdb_script_pull_elems(buf+offset, buflen-offset,
+ val, &val->script[i], &np);
if (ret != 0) {
- talloc_free(script_list);
- return ret;
+ goto fail;
}
- offset += ctdb_script_len(&script_list->script[i]);
+ offset += np;
}
- *out = script_list;
+done:
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
size_t ctdb_ban_state_len(struct ctdb_ban_state *ban_state)