summaryrefslogtreecommitdiff
path: root/ctdb/protocol/protocol_types.c
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2017-07-06 15:34:51 +1000
committerMartin Schwenke <martins@samba.org>2017-08-30 14:59:24 +0200
commitd7c247dd7284097c3aa4a0c6f41551edb43d6e29 (patch)
tree26c06a285182371da3b336568c35405bae077090 /ctdb/protocol/protocol_types.c
parente893b46e5e4147f5eb4df1eaf8537ccc81bfeb6e (diff)
downloadsamba-d7c247dd7284097c3aa4a0c6f41551edb43d6e29.tar.gz
ctdb-protocol: Fix marshalling for ctdb_uptime
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
Diffstat (limited to 'ctdb/protocol/protocol_types.c')
-rw-r--r--ctdb/protocol/protocol_types.c72
1 files changed, 60 insertions, 12 deletions
diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c
index 8de43ec2714..4e8b575496e 100644
--- a/ctdb/protocol/protocol_types.c
+++ b/ctdb/protocol/protocol_types.c
@@ -3311,32 +3311,80 @@ fail:
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;
- *out = uptime;
+ 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 = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
size_t ctdb_public_ip_len(struct ctdb_public_ip *pubip)