ctdb-protocol: Fix marshalling for ctdb_event
authorAmitay Isaacs <amitay@gmail.com>
Wed, 26 Jul 2017 15:26:43 +0000 (01:26 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 30 Aug 2017 12:59:26 +0000 (14:59 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/protocol/protocol_event.c

index d9eb83dd0a6f31f917a572aa79f5dbf19b9d30d8..fbd85e20d78bd104b434127b31f36910b5adf038 100644 (file)
@@ -33,16 +33,19 @@ static size_t ctdb_event_len(enum ctdb_event in)
        return ctdb_uint32_len(&u32);
 }
 
-static void ctdb_event_push(enum ctdb_event in, uint8_t *buf)
+static void ctdb_event_push(enum ctdb_event in, uint8_t *buf, size_t *npush)
 {
        size_t np;
        uint32_t u32 = in;
 
        ctdb_uint32_push(&u32, buf, &np);
+
+       *npush = np;
 }
 
 static int ctdb_event_pull(uint8_t *buf, size_t buflen,
-                          TALLOC_CTX *mem_ctx, enum ctdb_event *out)
+                          TALLOC_CTX *mem_ctx, enum ctdb_event *out,
+                          size_t *npull)
 {
        uint32_t uint32_value;
        enum ctdb_event value;
@@ -116,6 +119,7 @@ static int ctdb_event_pull(uint8_t *buf, size_t buflen,
        }
 
        *out = value;
+       *npull = np;
        return 0;
 }
 
@@ -240,8 +244,8 @@ static void ctdb_event_request_run_push(struct ctdb_event_request_run *in,
 {
        size_t offset = 0, np;
 
-       ctdb_event_push(in->event, buf);
-       offset += ctdb_event_len(in->event);
+       ctdb_event_push(in->event, buf, &np);
+       offset += np;
 
        ctdb_uint32_push(&in->timeout, buf+offset, &np);
        offset += np;
@@ -262,11 +266,11 @@ static int ctdb_event_request_run_pull(uint8_t *buf, size_t buflen,
                return ENOMEM;
        }
 
-       ret = ctdb_event_pull(buf, buflen, rdata, &rdata->event);
+       ret = ctdb_event_pull(buf, buflen, rdata, &rdata->event, &np);
        if (ret != 0) {
                goto fail;
        }
-       offset += ctdb_event_len(rdata->event);
+       offset += np;
 
        ret = ctdb_uint32_pull(buf+offset, buflen-offset, &rdata->timeout,
                               &np);
@@ -300,10 +304,10 @@ static void ctdb_event_request_status_push(
                                struct ctdb_event_request_status *in,
                                uint8_t *buf)
 {
-       size_t offset = 0;
+       size_t offset = 0, np;
 
-       ctdb_event_push(in->event, buf);
-       offset += ctdb_event_len(in->event);
+       ctdb_event_push(in->event, buf, &np);
+       offset += np;
 
        ctdb_event_status_state_push(in->state, buf+offset);
 }
@@ -314,7 +318,7 @@ static int ctdb_event_request_status_pull(
                                struct ctdb_event_request_status **out)
 {
        struct ctdb_event_request_status *rdata;
-       size_t offset = 0;
+       size_t offset = 0, np;
        int ret;
 
        rdata = talloc(mem_ctx, struct ctdb_event_request_status);
@@ -322,12 +326,12 @@ static int ctdb_event_request_status_pull(
                return ENOMEM;
        }
 
-       ret = ctdb_event_pull(buf, buflen, rdata, &rdata->event);
+       ret = ctdb_event_pull(buf, buflen, rdata, &rdata->event, &np);
        if (ret != 0) {
                talloc_free(rdata);
                return ret;
        }
-       offset += ctdb_event_len(rdata->event);
+       offset += np;
 
        ret = ctdb_event_status_state_pull(buf+offset, buflen-offset,
                                           rdata, &rdata->state);