return 0;
}
-size_t ctdb_statistics_len(struct ctdb_statistics *stats)
+size_t ctdb_tdb_datan_len(TDB_DATA *in)
{
- return sizeof(struct ctdb_statistics);
+ uint32_t u32 = ctdb_tdb_data_len(in);
+
+ return ctdb_uint32_len(&u32) + u32;
+}
+
+void ctdb_tdb_datan_push(TDB_DATA *in, uint8_t *buf, size_t *npush)
+{
+ size_t offset = 0, np;
+ uint32_t u32 = ctdb_tdb_data_len(in);
+
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_data_push(in, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+int ctdb_tdb_datan_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ TDB_DATA *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ uint32_t u32;
+ int ret;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ if (buflen-offset < u32) {
+ return EMSGSIZE;
+ }
+
+ ret = ctdb_tdb_data_pull(buf+offset, u32, mem_ctx, out, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+size_t ctdb_latency_counter_len(struct ctdb_latency_counter *in)
+{
+ return ctdb_int32_len(&in->num) +
+ ctdb_padding_len(4) +
+ ctdb_double_len(&in->min) +
+ ctdb_double_len(&in->max) +
+ ctdb_double_len(&in->total);
+}
+
+void ctdb_latency_counter_push(struct ctdb_latency_counter *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+
+ ctdb_int32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_double_push(&in->min, buf+offset, &np);
+ offset += np;
+
+ ctdb_double_push(&in->max, buf+offset, &np);
+ offset += np;
+
+ ctdb_double_push(&in->total, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
-void ctdb_statistics_push(struct ctdb_statistics *stats, uint8_t *buf)
-{
- memcpy(buf, stats, sizeof(struct ctdb_statistics));
+int ctdb_latency_counter_pull(uint8_t *buf, size_t buflen,
+ struct ctdb_latency_counter *out, size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->num, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_double_pull(buf+offset, buflen-offset, &out->min, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_double_pull(buf+offset, buflen-offset, &out->max, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_double_pull(buf+offset, buflen-offset, &out->total, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
+}
+
+size_t ctdb_statistics_len(struct ctdb_statistics *in)
+{
+ return ctdb_uint32_len(&in->num_clients) +
+ ctdb_uint32_len(&in->frozen) +
+ ctdb_uint32_len(&in->recovering) +
+ ctdb_uint32_len(&in->client_packets_sent) +
+ ctdb_uint32_len(&in->client_packets_recv) +
+ ctdb_uint32_len(&in->node_packets_sent) +
+ ctdb_uint32_len(&in->node_packets_recv) +
+ ctdb_uint32_len(&in->keepalive_packets_sent) +
+ ctdb_uint32_len(&in->keepalive_packets_recv) +
+ ctdb_uint32_len(&in->node.req_call) +
+ ctdb_uint32_len(&in->node.reply_call) +
+ ctdb_uint32_len(&in->node.req_dmaster) +
+ ctdb_uint32_len(&in->node.reply_dmaster) +
+ ctdb_uint32_len(&in->node.reply_error) +
+ ctdb_uint32_len(&in->node.req_message) +
+ ctdb_uint32_len(&in->node.req_control) +
+ ctdb_uint32_len(&in->node.reply_control) +
+ ctdb_uint32_len(&in->client.req_call) +
+ ctdb_uint32_len(&in->client.req_message) +
+ ctdb_uint32_len(&in->client.req_control) +
+ ctdb_uint32_len(&in->timeouts.call) +
+ ctdb_uint32_len(&in->timeouts.control) +
+ ctdb_uint32_len(&in->timeouts.traverse) +
+ ctdb_padding_len(4) +
+ ctdb_latency_counter_len(&in->reclock.ctdbd) +
+ ctdb_latency_counter_len(&in->reclock.recd) +
+ ctdb_uint32_len(&in->locks.num_calls) +
+ ctdb_uint32_len(&in->locks.num_current) +
+ ctdb_uint32_len(&in->locks.num_pending) +
+ ctdb_uint32_len(&in->locks.num_failed) +
+ ctdb_latency_counter_len(&in->locks.latency) +
+ MAX_COUNT_BUCKETS * ctdb_uint32_len(&in->locks.buckets[0]) +
+ ctdb_uint32_len(&in->total_calls) +
+ ctdb_uint32_len(&in->pending_calls) +
+ ctdb_uint32_len(&in->childwrite_calls) +
+ ctdb_uint32_len(&in->pending_childwrite_calls) +
+ ctdb_uint32_len(&in->memory_used) +
+ ctdb_uint32_len(&in->__last_counter) +
+ ctdb_uint32_len(&in->max_hop_count) +
+ MAX_COUNT_BUCKETS *
+ ctdb_uint32_len(&in->hop_count_bucket[0]) +
+ ctdb_padding_len(4) +
+ ctdb_latency_counter_len(&in->call_latency) +
+ ctdb_latency_counter_len(&in->childwrite_latency) +
+ ctdb_uint32_len(&in->num_recoveries) +
+ ctdb_padding_len(4) +
+ ctdb_timeval_len(&in->statistics_start_time) +
+ ctdb_timeval_len(&in->statistics_current_time) +
+ ctdb_uint32_len(&in->total_ro_delegations) +
+ ctdb_uint32_len(&in->total_ro_revokes);
+}
+
+void ctdb_statistics_push(struct ctdb_statistics *in, uint8_t *buf,
+ size_t *npush)
+{
+ size_t offset = 0, np;
+ int i;
+
+ ctdb_uint32_push(&in->num_clients, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->frozen, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->recovering, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client_packets_sent, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client_packets_recv, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node_packets_sent, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node_packets_recv, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->keepalive_packets_sent, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->keepalive_packets_recv, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.req_call, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.reply_call, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.req_dmaster, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.reply_dmaster, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.reply_error, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.req_message, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.req_control, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->node.reply_control, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client.req_call, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client.req_message, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->client.req_control, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->timeouts.call, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->timeouts.control, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->timeouts.traverse, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->reclock.ctdbd, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->reclock.recd, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_current, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_pending, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->locks.num_failed, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->locks.latency, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ctdb_uint32_push(&in->locks.buckets[i], buf+offset, &np);
+ offset += np;
+ }
+
+ ctdb_uint32_push(&in->total_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pending_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->childwrite_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->pending_childwrite_calls, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->memory_used, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->__last_counter, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->max_hop_count, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ctdb_uint32_push(&in->hop_count_bucket[i], buf+offset, &np);
+ offset += np;
+ }
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->call_latency, buf+offset, &np);
+ offset += np;
+
+ ctdb_latency_counter_push(&in->childwrite_latency, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->num_recoveries, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->statistics_start_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->statistics_current_time, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->total_ro_delegations, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->total_ro_revokes, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
+}
+
+static int ctdb_statistics_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_statistics *out,
+ size_t *npull)
+{
+ size_t offset = 0, np;
+ int ret, i;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->num_clients,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->frozen, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->recovering,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client_packets_sent, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client_packets_recv, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node_packets_sent, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node_packets_recv, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->keepalive_packets_sent, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->keepalive_packets_recv, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.req_call, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.reply_call, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.req_dmaster, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.reply_dmaster, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.reply_error, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.req_message, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.req_control, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->node.reply_control, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client.req_call, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client.req_message, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->client.req_control, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->timeouts.call, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->timeouts.control, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->timeouts.traverse, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->reclock.ctdbd, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->reclock.recd, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_current, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_pending, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.num_failed, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->locks.latency, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->locks.buckets[i], &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ }
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->total_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->pending_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->childwrite_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->pending_childwrite_calls, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->memory_used,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->__last_counter, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->max_hop_count, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ for (i=0; i<MAX_COUNT_BUCKETS; i++) {
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->hop_count_bucket[i], &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ }
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->call_latency, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_latency_counter_pull(buf+offset, buflen-offset,
+ &out->childwrite_latency, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->num_recoveries, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &out->statistics_start_time, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset,
+ &out->statistics_current_time, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->total_ro_delegations, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &out->total_ro_revokes, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
+ return 0;
}
int ctdb_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_statistics **out)
+ struct ctdb_statistics **out, size_t *npull)
{
- struct ctdb_statistics *stats;
- struct ctdb_statistics *wire = (struct ctdb_statistics *)buf;
+ struct ctdb_statistics *val;
+ size_t np;
+ int ret;
- if (buflen < sizeof(struct ctdb_statistics)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_statistics);
+ if (val == NULL) {
+ return ENOMEM;
}
- stats = talloc(mem_ctx, struct ctdb_statistics);
- if (stats == NULL) {
- return ENOMEM;
+ ret = ctdb_statistics_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
}
- memcpy(stats, wire, sizeof(struct ctdb_statistics));
- *out = stats;
+ *out = val;
+ *npull = np;
return 0;
}
return 0;
}
-struct ctdb_vnn_map_wire {
- uint32_t generation;
- uint32_t size;
- uint32_t map[1];
-};
-
-size_t ctdb_vnn_map_len(struct ctdb_vnn_map *vnnmap)
+size_t ctdb_vnn_map_len(struct ctdb_vnn_map *in)
{
- return offsetof(struct ctdb_vnn_map, map) +
- vnnmap->size * sizeof(uint32_t);
+ size_t len;
+
+ len = ctdb_uint32_len(&in->generation) + ctdb_uint32_len(&in->size);
+ if (in->size > 0) {
+ len += in->size * ctdb_uint32_len(&in->map[0]);
+ }
+
+ return len;
}
-void ctdb_vnn_map_push(struct ctdb_vnn_map *vnnmap, uint8_t *buf)
+void ctdb_vnn_map_push(struct ctdb_vnn_map *in, uint8_t *buf, size_t *npush)
{
- struct ctdb_vnn_map_wire *wire = (struct ctdb_vnn_map_wire *)buf;
+ size_t offset = 0, np;
+ uint32_t i;
+
+ ctdb_uint32_push(&in->generation, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->size, buf+offset, &np);
+ offset += np;
- memcpy(wire, vnnmap, offsetof(struct ctdb_vnn_map, map));
- memcpy(wire->map, vnnmap->map, vnnmap->size * sizeof(uint32_t));
+ for (i=0; i<in->size; i++) {
+ ctdb_uint32_push(&in->map[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
}
int ctdb_vnn_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_vnn_map **out)
+ struct ctdb_vnn_map **out, size_t *npull)
{
- struct ctdb_vnn_map *vnnmap;
- struct ctdb_vnn_map_wire *wire = (struct ctdb_vnn_map_wire *)buf;
+ struct ctdb_vnn_map *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
- if (buflen < offsetof(struct ctdb_vnn_map_wire, map)) {
- return EMSGSIZE;
- }
- if (wire->size > buflen / sizeof(uint32_t)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_vnn_map);
+ if (val == NULL) {
+ return ENOMEM;
}
- if (offsetof(struct ctdb_vnn_map_wire, map) +
- wire->size * sizeof(uint32_t) <
- offsetof(struct ctdb_vnn_map_wire, map)) {
- return EMSGSIZE;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->generation,
+ &np);
+ if (ret != 0) {
+ goto fail;
}
- if (buflen < offsetof(struct ctdb_vnn_map_wire, map) +
- wire->size * sizeof(uint32_t)) {
- return EMSGSIZE;
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->size, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- vnnmap = talloc(mem_ctx, struct ctdb_vnn_map);
- if (vnnmap == NULL) {
- return ENOMEM;
+ if (val->size == 0) {
+ val->map = NULL;
+ goto done;
}
- memcpy(vnnmap, wire, offsetof(struct ctdb_vnn_map, map));
+ val->map = talloc_array(val, uint32_t, val->size);
+ if (val->map == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
- vnnmap->map = talloc_memdup(vnnmap, wire->map,
- wire->size * sizeof(uint32_t));
- if (vnnmap->map == NULL) {
- talloc_free(vnnmap);
- return ENOMEM;
+ for (i=0; i<val->size; i++) {
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset,
+ &val->map[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
}
- *out = vnnmap;
+done:
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-struct ctdb_dbid_map_wire {
- uint32_t num;
- struct ctdb_dbid dbs[1];
-};
+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);
+}
-size_t ctdb_dbid_map_len(struct ctdb_dbid_map *dbmap)
+void ctdb_dbid_push(struct ctdb_dbid *in, uint8_t *buf, size_t *npush)
{
- return sizeof(uint32_t) + dbmap->num * sizeof(struct ctdb_dbid);
+ 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;
}
-void ctdb_dbid_map_push(struct ctdb_dbid_map *dbmap, uint8_t *buf)
+static int ctdb_dbid_pull_elems(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx, struct ctdb_dbid *out,
+ size_t *npull)
{
- struct ctdb_dbid_map_wire *wire = (struct ctdb_dbid_map_wire *)buf;
+ 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;
- wire->num = dbmap->num;
- memcpy(wire->dbs, dbmap->dbs, dbmap->num * sizeof(struct ctdb_dbid));
+ *npull = offset;
+ return 0;
}
-int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_dbid_map **out)
+int ctdb_dbid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_dbid **out, size_t *npull)
{
- struct ctdb_dbid_map *dbmap;
- struct ctdb_dbid_map_wire *wire = (struct ctdb_dbid_map_wire *)buf;
+ struct ctdb_dbid *val;
+ size_t np;
+ int ret;
- if (buflen < sizeof(uint32_t)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_dbid);
+ if (val == NULL) {
+ return ENOMEM;
}
- if (wire->num > buflen / sizeof(struct ctdb_dbid)) {
- return EMSGSIZE;
+
+ ret = ctdb_dbid_pull_elems(buf, buflen, val, val, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
}
- if (sizeof(uint32_t) + wire->num * sizeof(struct ctdb_dbid) <
- sizeof(uint32_t)) {
- return EMSGSIZE;
+
+ *out = val;
+ *npull = np;
+ return 0;
+}
+
+size_t ctdb_dbid_map_len(struct ctdb_dbid_map *in)
+{
+ size_t len;
+
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_dbid_len(&in->dbs[0]);
}
- if (buflen < sizeof(uint32_t) + wire->num * sizeof(struct ctdb_dbid)) {
- return EMSGSIZE;
+
+ return len;
+}
+
+void ctdb_dbid_map_push(struct ctdb_dbid_map *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_dbid_push(&in->dbs[i], buf+offset, &np);
+ offset += np;
}
- dbmap = talloc(mem_ctx, struct ctdb_dbid_map);
- if (dbmap == NULL) {
+ *npush = offset;
+}
+
+int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
+ struct ctdb_dbid_map **out, size_t *npull)
+{
+ struct ctdb_dbid_map *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_dbid_map);
+ if (val == NULL) {
return ENOMEM;
}
- dbmap->num = wire->num;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
- dbmap->dbs = talloc_memdup(dbmap, wire->dbs,
- wire->num * sizeof(struct ctdb_dbid));
- if (dbmap->dbs == NULL) {
- talloc_free(dbmap);
- return ENOMEM;
+ if (val->num == 0) {
+ val->dbs = NULL;
+ goto done;
+ }
+
+ val->dbs = talloc_array(val, struct ctdb_dbid, val->num);
+ if (val->dbs == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
+
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_dbid_pull_elems(buf+offset, buflen-offset, val,
+ &val->dbs[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
}
- *out = dbmap;
+done:
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_pulldb_len(struct ctdb_pulldb *pulldb)
+size_t ctdb_pulldb_len(struct ctdb_pulldb *in)
{
- return sizeof(struct ctdb_pulldb);
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->lmaster);
}
-void ctdb_pulldb_push(struct ctdb_pulldb *pulldb, uint8_t *buf)
+void ctdb_pulldb_push(struct ctdb_pulldb *in, uint8_t *buf, size_t *npush)
{
- memcpy(buf, pulldb, sizeof(struct ctdb_pulldb));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->lmaster, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_pulldb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_pulldb **out)
+ struct ctdb_pulldb **out, size_t *npull)
{
- struct ctdb_pulldb *pulldb;
+ struct ctdb_pulldb *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < sizeof(struct ctdb_pulldb)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_pulldb);
+ if (val == NULL) {
+ return ENOMEM;
}
- pulldb = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_pulldb));
- if (pulldb == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &np);
+ if (ret != 0) {
+ talloc_free(val);
+ return ret;
}
+ offset += np;
- *out = pulldb;
+ *out = val;
+ *npull = offset;
return 0;
}
-size_t ctdb_pulldb_ext_len(struct ctdb_pulldb_ext *pulldb)
+size_t ctdb_pulldb_ext_len(struct ctdb_pulldb_ext *in)
{
- return sizeof(struct ctdb_pulldb_ext);
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->lmaster) +
+ ctdb_uint64_len(&in->srvid);
}
-void ctdb_pulldb_ext_push(struct ctdb_pulldb_ext *pulldb, uint8_t *buf)
+void ctdb_pulldb_ext_push(struct ctdb_pulldb_ext *in, uint8_t *buf,
+ size_t *npush)
{
- memcpy(buf, pulldb, sizeof(struct ctdb_pulldb_ext));
+ size_t offset = 0, np;
+
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->lmaster, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint64_push(&in->srvid, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_pulldb_ext_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_pulldb_ext **out)
+ struct ctdb_pulldb_ext **out, size_t *npull)
{
- struct ctdb_pulldb_ext *pulldb;
+ struct ctdb_pulldb_ext *val;
+ size_t offset = 0, np;
+ int ret;
- if (buflen < sizeof(struct ctdb_pulldb_ext)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_pulldb_ext);
+ if (val == NULL) {
+ return ENOMEM;
}
- pulldb = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_pulldb_ext));
- if (pulldb == NULL) {
- return ENOMEM;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- *out = pulldb;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &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 = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
-size_t ctdb_ltdb_header_len(struct ctdb_ltdb_header *header)
+size_t ctdb_ltdb_header_len(struct ctdb_ltdb_header *in)
{
- return sizeof(struct ctdb_ltdb_header);
+ return ctdb_uint64_len(&in->rsn) +
+ ctdb_uint32_len(&in->dmaster) +
+ ctdb_uint32_len(&in->reserved1) +
+ ctdb_uint32_len(&in->flags) +
+ ctdb_padding_len(4);
}
-void ctdb_ltdb_header_push(struct ctdb_ltdb_header *header, uint8_t *buf)
+void ctdb_ltdb_header_push(struct ctdb_ltdb_header *in, uint8_t *buf,
+ size_t *npush)
{
- memcpy(buf, header, sizeof(struct ctdb_ltdb_header));
+ size_t offset = 0, np;
+
+ ctdb_uint64_push(&in->rsn, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->dmaster, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reserved1, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->flags, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
int ctdb_ltdb_header_pull(uint8_t *buf, size_t buflen,
- struct ctdb_ltdb_header *header)
+ struct ctdb_ltdb_header *out, size_t *npull)
{
- if (buflen < sizeof(struct ctdb_ltdb_header)) {
- return EMSGSIZE;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_uint64_pull(buf+offset, buflen-offset, &out->rsn, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->dmaster, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->reserved1,
+ &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;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
- memcpy(header, buf, sizeof(struct ctdb_ltdb_header));
+ *npull = offset;
return 0;
}
int ctdb_ltdb_header_extract(TDB_DATA *data, struct ctdb_ltdb_header *header)
{
+ size_t np;
int ret;
- ret = ctdb_ltdb_header_pull(data->dptr, data->dsize, header);
+ ret = ctdb_ltdb_header_pull(data->dptr, data->dsize, header, &np);
if (ret != 0) {
return ret;
}
- data->dptr += sizeof(struct ctdb_ltdb_header);
- data->dsize -= sizeof(struct ctdb_ltdb_header);
+ data->dptr += np;
+ data->dsize -= np;
return 0;
}
-struct ctdb_rec_data_wire {
- uint32_t length;
- uint32_t reqid;
- uint32_t keylen;
- uint32_t datalen;
- uint8_t data[1];
-};
-
-size_t ctdb_rec_data_len(struct ctdb_rec_data *rec)
+size_t ctdb_rec_data_len(struct ctdb_rec_data *in)
{
- return offsetof(struct ctdb_rec_data_wire, data) +
- rec->key.dsize + rec->data.dsize +
- (rec->header == NULL ? 0 : sizeof(struct ctdb_ltdb_header));
+ uint32_t u32;
+
+ u32 = ctdb_uint32_len(&in->reqid) +
+ ctdb_tdb_datan_len(&in->key) +
+ ctdb_tdb_datan_len(&in->data);
+
+ if (in->header != NULL) {
+ u32 += ctdb_ltdb_header_len(in->header);
+ }
+
+ return ctdb_uint32_len(&u32) + u32;
}
-void ctdb_rec_data_push(struct ctdb_rec_data *rec, uint8_t *buf)
+void ctdb_rec_data_push(struct ctdb_rec_data *in, uint8_t *buf, size_t *npush)
{
- struct ctdb_rec_data_wire *wire = (struct ctdb_rec_data_wire *)buf;
- size_t offset;
+ size_t offset = 0, np;
+ uint32_t u32;
- wire->length = ctdb_rec_data_len(rec);
- wire->reqid = rec->reqid;
- wire->keylen = rec->key.dsize;
- wire->datalen = rec->data.dsize;
- if (rec->header != NULL) {
- wire->datalen += sizeof(struct ctdb_ltdb_header);
- }
+ u32 = ctdb_rec_data_len(in);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->reqid, buf+offset, &np);
+ offset += np;
+
+ u32 = ctdb_tdb_data_len(&in->key);
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
- memcpy(wire->data, rec->key.dptr, rec->key.dsize);
- offset = rec->key.dsize;
- if (rec->header != NULL) {
- memcpy(&wire->data[offset], rec->header,
- sizeof(struct ctdb_ltdb_header));
- offset += sizeof(struct ctdb_ltdb_header);
+ u32 = ctdb_tdb_data_len(&in->data);
+ if (in->header != NULL) {
+ u32 += ctdb_ltdb_header_len(in->header);
}
- if (rec->data.dsize > 0) {
- memcpy(&wire->data[offset], rec->data.dptr, rec->data.dsize);
+
+ ctdb_uint32_push(&u32, buf+offset, &np);
+ offset += np;
+
+ ctdb_tdb_data_push(&in->key, buf+offset, &np);
+ offset += np;
+
+ /* If ltdb header is not NULL, then it is pushed as part of the data */
+ if (in->header != NULL) {
+ ctdb_ltdb_header_push(in->header, buf+offset, &np);
+ offset += np;
}
+ ctdb_tdb_data_push(&in->data, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
static int ctdb_rec_data_pull_data(uint8_t *buf, size_t buflen,
uint32_t *reqid,
- struct ctdb_ltdb_header **header,
TDB_DATA *key, TDB_DATA *data,
- size_t *reclen)
+ size_t *npull)
{
- struct ctdb_rec_data_wire *wire = (struct ctdb_rec_data_wire *)buf;
- size_t offset;
+ size_t offset = 0, np;
+ size_t len;
+ uint32_t u32;
+ int ret;
- if (buflen < offsetof(struct ctdb_rec_data_wire, data)) {
- return EMSGSIZE;
- }
- if (wire->keylen > buflen || wire->datalen > buflen) {
- return EMSGSIZE;
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
}
- if (offsetof(struct ctdb_rec_data_wire, data) + wire->keylen <
- offsetof(struct ctdb_rec_data_wire, data)) {
+ offset += np;
+
+ if (buflen < u32) {
return EMSGSIZE;
}
- if (offsetof(struct ctdb_rec_data_wire, data) +
- wire->keylen + wire->datalen <
- offsetof(struct ctdb_rec_data_wire, data)) {
- return EMSGSIZE;
+ len = u32;
+
+ ret = ctdb_uint32_pull(buf+offset, len-offset, reqid, &np);
+ if (ret != 0) {
+ return ret;
}
- if (buflen < offsetof(struct ctdb_rec_data_wire, data) +
- wire->keylen + wire->datalen) {
- return EMSGSIZE;
+ offset += np;
+
+ ret = ctdb_uint32_pull(buf+offset, len-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
+ key->dsize = u32;
- *reqid = wire->reqid;
+ ret = ctdb_uint32_pull(buf+offset, len-offset, &u32, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ data->dsize = u32;
- key->dsize = wire->keylen;
- key->dptr = wire->data;
- offset = wire->keylen;
+ if (len-offset < key->dsize) {
+ return EMSGSIZE;
+ }
- /* Always set header to NULL. If it is required, exact it using
- * ctdb_rec_data_extract_header()
- */
- *header = NULL;
+ key->dptr = buf+offset;
+ offset += key->dsize;
- data->dsize = wire->datalen;
- data->dptr = &wire->data[offset];
+ if (len-offset < data->dsize) {
+ return EMSGSIZE;
+ }
- *reclen = offsetof(struct ctdb_rec_data_wire, data) +
- wire->keylen + wire->datalen;
+ data->dptr = buf+offset;
+ offset += data->dsize;
+ *npull = offset;
return 0;
}
static int ctdb_rec_data_pull_elems(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
- struct ctdb_rec_data *out)
+ struct ctdb_rec_data *out,
+ size_t *npull)
{
uint32_t reqid;
- struct ctdb_ltdb_header *header;
TDB_DATA key, data;
- size_t reclen;
+ size_t np;
int ret;
- ret = ctdb_rec_data_pull_data(buf, buflen, &reqid, &header,
- &key, &data, &reclen);
+ ret = ctdb_rec_data_pull_data(buf, buflen, &reqid, &key, &data, &np);
if (ret != 0) {
return ret;
}
out->reqid = reqid;
+
+ /* Always set header to NULL. If it is required, extract it using
+ * ctdb_rec_data_extract_header()
+ */
out->header = NULL;
out->key.dsize = key.dsize;
}
}
+ *npull = np;
return 0;
}
int ctdb_rec_data_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_rec_data **out)
+ struct ctdb_rec_data **out, size_t *npull)
{
- struct ctdb_rec_data *rec;
+ struct ctdb_rec_data *val;
+ size_t np;
int ret;
- rec = talloc(mem_ctx, struct ctdb_rec_data);
- if (rec == NULL) {
+ val = talloc(mem_ctx, struct ctdb_rec_data);
+ if (val == NULL) {
return ENOMEM;
}
- ret = ctdb_rec_data_pull_elems(buf, buflen, rec, rec);
+ ret = ctdb_rec_data_pull_elems(buf, buflen, val, val, &np);
if (ret != 0) {
- TALLOC_FREE(rec);
+ TALLOC_FREE(val);
+ return ret;
}
- *out = rec;
+ *out = val;
+ *npull = np;
return ret;
}
-struct ctdb_rec_buffer_wire {
- uint32_t db_id;
- uint32_t count;
- uint8_t data[1];
-};
-
-size_t ctdb_rec_buffer_len(struct ctdb_rec_buffer *recbuf)
+size_t ctdb_rec_buffer_len(struct ctdb_rec_buffer *in)
{
- return offsetof(struct ctdb_rec_buffer_wire, data) + recbuf->buflen;
+ return ctdb_uint32_len(&in->db_id) +
+ ctdb_uint32_len(&in->count) +
+ in->buflen;
}
-void ctdb_rec_buffer_push(struct ctdb_rec_buffer *recbuf, uint8_t *buf)
+void ctdb_rec_buffer_push(struct ctdb_rec_buffer *in, uint8_t *buf,
+ size_t *npush)
{
- struct ctdb_rec_buffer_wire *wire = (struct ctdb_rec_buffer_wire *)buf;
+ size_t offset = 0, np;
- wire->db_id = recbuf->db_id;
- wire->count = recbuf->count;
- if (recbuf->buflen > 0) {
- memcpy(wire->data, recbuf->buf, recbuf->buflen);
- }
+ ctdb_uint32_push(&in->db_id, buf+offset, &np);
+ offset += np;
+
+ ctdb_uint32_push(&in->count, buf+offset, &np);
+ offset += np;
+
+ memcpy(buf+offset, in->buf, in->buflen);
+ offset += in->buflen;
+
+ *npush = offset;
}
int ctdb_rec_buffer_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_rec_buffer **out)
+ struct ctdb_rec_buffer **out, size_t *npull)
{
- struct ctdb_rec_buffer *recbuf;
- struct ctdb_rec_buffer_wire *wire = (struct ctdb_rec_buffer_wire *)buf;
- size_t offset;
+ struct ctdb_rec_buffer *val;
+ size_t offset = 0, np;
+ size_t length;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_rec_buffer);
+ if (val == 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->count, &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
+
+ /* Since there is no buflen provided, walk the records to
+ * validate the length of the buffer.
+ */
+ val->buf = buf+offset;
+ val->buflen = buflen-offset;
- if (buflen < offsetof(struct ctdb_rec_buffer_wire, data)) {
- return EMSGSIZE;
+ length = 0;
+ ret = ctdb_rec_buffer_traverse(val, NULL, &length);
+ if (ret != 0) {
+ goto fail;
}
- recbuf = talloc(mem_ctx, struct ctdb_rec_buffer);
- if (recbuf == NULL) {
- return ENOMEM;
+ if (length > buflen-offset) {
+ ret = EMSGSIZE;
+ goto fail;
}
- recbuf->db_id = wire->db_id;
- recbuf->count = wire->count;
-
- offset = offsetof(struct ctdb_rec_buffer_wire, data);
- recbuf->buflen = buflen - offset;
- recbuf->buf = talloc_memdup(recbuf, wire->data, recbuf->buflen);
- if (recbuf->buf == NULL) {
- talloc_free(recbuf);
- return ENOMEM;
+ val->buf = talloc_memdup(val, buf+offset, length);
+ if (val->buf == NULL) {
+ ret = ENOMEM;
+ goto fail;
}
+ val->buflen = length;
+ offset += length;
- *out = recbuf;
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
struct ctdb_rec_buffer *ctdb_rec_buffer_init(TALLOC_CTX *mem_ctx,
TDB_DATA key, TDB_DATA data)
{
struct ctdb_rec_data recdata;
- size_t len;
+ size_t len, np;
uint8_t *ptr;
recdata.reqid = reqid;
return ENOMEM;
}
- ctdb_rec_data_push(&recdata, &ptr[recbuf->buflen]);
+ ctdb_rec_data_push(&recdata, &ptr[recbuf->buflen], &np);
recbuf->count++;
recbuf->buf = ptr;
- recbuf->buflen += len;
+ recbuf->buflen += np;
return 0;
}
ctdb_rec_parser_func_t func,
void *private_data)
{
- struct ctdb_ltdb_header *header;
TDB_DATA key, data;
uint32_t reqid;
size_t offset, reclen;
for (i=0; i<recbuf->count; i++) {
ret = ctdb_rec_data_pull_data(&recbuf->buf[offset],
recbuf->buflen - offset,
- &reqid, &header,
- &key, &data, &reclen);
+ &reqid, &key, &data, &reclen);
if (ret != 0) {
return ret;
}
- ret = func(reqid, header, key, data, private_data);
- if (ret != 0) {
- break;
+ if (func != NULL) {
+ ret = func(reqid, NULL, key, data, private_data);
+ if (ret != 0) {
+ break;
+ }
}
offset += reclen;
}
- return ret;
+ if (ret != 0) {
+ return ret;
+ }
+
+ if (func == NULL) {
+ size_t *length = (size_t *)private_data;
+
+ *length = offset;
+ }
+
+ return 0;
}
int ctdb_rec_buffer_write(struct ctdb_rec_buffer *recbuf, int fd)
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;
- *out = flag_change;
+ 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 = 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;
- }
- if (wire->length > buflen) {
- return EMSGSIZE;
- }
- if (sizeof(uint32_t) + wire->length < sizeof(uint32_t)) {
- return EMSGSIZE;
+ val = talloc_zero(mem_ctx, struct ctdb_var_list);
+ if (val == NULL) {
+ return ENOMEM;
}
- if (buflen < sizeof(uint32_t) + wire->length) {
- return EMSGSIZE;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &u32, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- str = talloc_strndup(mem_ctx, (char *)wire->list_str, wire->length);
- if (str == NULL) {
- return ENOMEM;
+ if (buflen-offset < u32) {
+ ret = EMSGSIZE;
+ goto fail;
}
- var_list = talloc_zero(mem_ctx, struct ctdb_var_list);
- if (var_list == NULL) {
+ ret = ctdb_string_pull(buf+offset, u32, val, &str, &np);
+ if (ret != 0) {
goto fail;
}
+ offset += np;
- s = str;
+ s = discard_const(str);
while ((tok = strtok_r(s, ":", &ptr)) != NULL) {
- s = NULL;
- list = talloc_realloc(var_list, var_list->var, const char *,
- var_list->count+1);
+ list = talloc_realloc(val, val->var, const char *,
+ val->count+1);
if (list == NULL) {
+ ret = ENOMEM;
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) {
+ val->var = list;
+
+ s = talloc_strdup(val, tok);
+ if (s == NULL) {
+ ret = ENOMEM;
goto fail;
}
- var_list->count++;
+
+ val->var[val->count] = s;
+ val->count += 1;
+ s = NULL;
}
- talloc_free(str);
- *out = var_list;
+ talloc_free(discard_const(str));
+ *out = val;
+ *npull = offset;
return 0;
fail:
- talloc_free(str);
- talloc_free(var_list);
- return ENOMEM;
+ talloc_free(val);
+ return ret;
}
size_t ctdb_tunable_list_len(struct ctdb_tunable_list *tun_list)
{
struct ctdb_tickle_list_wire *wire =
(struct ctdb_tickle_list_wire *)buf;
- size_t offset;
+ size_t offset, np;
int i;
memcpy(&wire->addr, &tickles->addr, sizeof(ctdb_sock_addr));
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]);
+ ctdb_connection_push(&tickles->conn[i], &buf[offset], &np);
+ offset += np;
}
}
struct ctdb_tickle_list *tickles;
struct ctdb_tickle_list_wire *wire =
(struct ctdb_tickle_list_wire *)buf;
- size_t offset;
+ size_t offset, np;
int i, ret;
if (buflen < offsetof(struct ctdb_tickle_list_wire, conn)) {
for (i=0; i<wire->num; i++) {
ret = ctdb_connection_pull_elems(&buf[offset], buflen-offset,
tickles->conn,
- &tickles->conn[i]);
+ &tickles->conn[i], &np);
if (ret != 0) {
talloc_free(tickles);
return ret;
}
- offset += ctdb_connection_len(&tickles->conn[i]);
+ offset += np;
}
*out = tickles;