ctdb-protocol: Fix marshalling for ctdb_uptime
authorAmitay Isaacs <amitay@gmail.com>
Thu, 6 Jul 2017 05:34:51 +0000 (15:34 +1000)
committerMartin Schwenke <martins@samba.org>
Wed, 30 Aug 2017 12:59:24 +0000 (14:59 +0200)
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
ctdb/protocol/protocol_control.c
ctdb/protocol/protocol_private.h
ctdb/protocol/protocol_types.c
ctdb/tests/src/protocol_common.c
ctdb/tests/src/protocol_types_compat_test.c
ctdb/tests/src/protocol_types_test.c

index 71892aa124923daae2572e79a179f4a7ac23cb99..ddbc75fd48ac572efdaa8074153944f5ed5f4387 100644 (file)
@@ -1488,7 +1488,7 @@ static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
                break;
 
        case CTDB_CONTROL_UPTIME:
-               ctdb_uptime_push(cd->data.uptime, buf);
+               ctdb_uptime_push(cd->data.uptime, buf, &np);
                break;
 
        case CTDB_CONTROL_TRY_DELETE_RECORDS:
@@ -1663,7 +1663,7 @@ static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
 
        case CTDB_CONTROL_UPTIME:
                ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
-                                      &cd->data.uptime);
+                                      &cd->data.uptime, &np);
                break;
 
        case CTDB_CONTROL_TRY_DELETE_RECORDS:
index 6c253a70dd89c00c1e41a9741d1a0871b2870351..9496b54fbc26f0238fe414e6f0aca3adf62eb9c7 100644 (file)
@@ -226,10 +226,10 @@ void ctdb_transdb_push(struct ctdb_transdb *in, uint8_t *buf, size_t *npush);
 int ctdb_transdb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
                     struct ctdb_transdb **out, size_t *npull);
 
-size_t ctdb_uptime_len(struct ctdb_uptime *uptime);
-void ctdb_uptime_push(struct ctdb_uptime *uptime, uint8_t *buf);
+size_t ctdb_uptime_len(struct ctdb_uptime *in);
+void ctdb_uptime_push(struct ctdb_uptime *in, uint8_t *buf, size_t *npush);
 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);
 
 size_t ctdb_public_ip_len(struct ctdb_public_ip *public_ip);
 void ctdb_public_ip_push(struct ctdb_public_ip *public_ip, uint8_t *buf);
index 8de43ec271499a03e57783078ba4a60a969074f3..4e8b575496edfa7a4ed8078c8b1ba295d4e8f242 100644 (file)
@@ -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)
index 6aa9720027a9ed1bddc23f9817446bad8f29fd0e..f459c019b8319fcad21549cd3e8c14f23ee7d27d 100644 (file)
@@ -951,12 +951,20 @@ void verify_ctdb_transdb(struct ctdb_transdb *p1, struct ctdb_transdb *p2)
 
 void fill_ctdb_uptime(TALLOC_CTX *mem_ctx, struct ctdb_uptime *p)
 {
-       fill_buffer(p, sizeof(struct ctdb_uptime));
+       fill_ctdb_timeval(&p->current_time);
+       fill_ctdb_timeval(&p->ctdbd_start_time);
+       fill_ctdb_timeval(&p->last_recovery_started);
+       fill_ctdb_timeval(&p->last_recovery_finished);
 }
 
 void verify_ctdb_uptime(struct ctdb_uptime *p1, struct ctdb_uptime *p2)
 {
-       verify_buffer(p1, p2, sizeof(struct ctdb_uptime));
+       verify_ctdb_timeval(&p1->current_time, &p2->current_time);
+       verify_ctdb_timeval(&p1->ctdbd_start_time, &p2->ctdbd_start_time);
+       verify_ctdb_timeval(&p1->last_recovery_started,
+                           &p2->last_recovery_started);
+       verify_ctdb_timeval(&p1->last_recovery_finished,
+                           &p2->last_recovery_finished);
 }
 
 void fill_ctdb_public_ip(TALLOC_CTX *mem_ctx, struct ctdb_public_ip *p)
index 5c13ceea4f4bee21fc96a8defa0567be2737a3e3..ad908d0b515ee3a077666776ff82403dad25892e 100644 (file)
@@ -1138,6 +1138,34 @@ static int ctdb_transdb_pull_old(uint8_t *buf, size_t buflen,
        return 0;
 }
 
+static size_t ctdb_uptime_len_old(struct ctdb_uptime *in)
+{
+       return sizeof(struct ctdb_uptime);
+}
+
+static void ctdb_uptime_push_old(struct ctdb_uptime *in, uint8_t *buf)
+{
+       memcpy(buf, in, sizeof(struct ctdb_uptime));
+}
+
+static int ctdb_uptime_pull_old(uint8_t *buf, size_t buflen,
+                               TALLOC_CTX *mem_ctx, struct ctdb_uptime **out)
+{
+       struct ctdb_uptime *val;
+
+       if (buflen < sizeof(struct ctdb_uptime)) {
+               return EMSGSIZE;
+       }
+
+       val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_uptime));
+       if (val == NULL) {
+               return ENOMEM;
+       }
+
+       *out = val;
+       return 0;
+}
+
 
 COMPAT_TYPE3_TEST(struct ctdb_statistics, ctdb_statistics);
 COMPAT_TYPE3_TEST(struct ctdb_vnn_map, ctdb_vnn_map);
@@ -1162,6 +1190,7 @@ COMPAT_TYPE3_TEST(struct ctdb_tunable_list, ctdb_tunable_list);
 COMPAT_TYPE3_TEST(struct ctdb_tickle_list, ctdb_tickle_list);
 COMPAT_TYPE3_TEST(struct ctdb_addr_info, ctdb_addr_info);
 COMPAT_TYPE3_TEST(struct ctdb_transdb, ctdb_transdb);
+COMPAT_TYPE3_TEST(struct ctdb_uptime, ctdb_uptime);
 
 int main(int argc, char *argv[])
 {
@@ -1191,6 +1220,7 @@ int main(int argc, char *argv[])
        COMPAT_TEST_FUNC(ctdb_tickle_list)();
        COMPAT_TEST_FUNC(ctdb_addr_info)();
        COMPAT_TEST_FUNC(ctdb_transdb)();
+       COMPAT_TEST_FUNC(ctdb_uptime)();
 
        return 0;
 }
index bd9c6e314111e463d61736906b1b848665892ef8..d17beb47d1e2d4ea2177fbb923b04c516145deae 100644 (file)
@@ -69,7 +69,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_tunable_list, ctdb_tunable_list);
 PROTOCOL_TYPE3_TEST(struct ctdb_tickle_list, ctdb_tickle_list);
 PROTOCOL_TYPE3_TEST(struct ctdb_addr_info, ctdb_addr_info);
 PROTOCOL_TYPE3_TEST(struct ctdb_transdb, ctdb_transdb);
-DEFINE_TEST(struct ctdb_uptime, ctdb_uptime);
+PROTOCOL_TYPE3_TEST(struct ctdb_uptime, ctdb_uptime);
 DEFINE_TEST(struct ctdb_public_ip, ctdb_public_ip);
 DEFINE_TEST(struct ctdb_public_ip_list, ctdb_public_ip_list);
 DEFINE_TEST(struct ctdb_node_and_flags, ctdb_node_and_flags);