diff options
author | Amitay Isaacs <amitay@gmail.com> | 2017-07-05 17:51:03 +1000 |
---|---|---|
committer | Martin Schwenke <martins@samba.org> | 2017-08-30 14:59:23 +0200 |
commit | e893b46e5e4147f5eb4df1eaf8537ccc81bfeb6e (patch) | |
tree | 14e872707f16dda8236576853b55413d4aa800bf | |
parent | 4d70b972f2be599bcb9e8f70234b9768ac317a7c (diff) | |
download | samba-e893b46e5e4147f5eb4df1eaf8537ccc81bfeb6e.tar.gz |
ctdb-protocol: Fix marshalling for ctdb_transdb
Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
-rw-r--r-- | ctdb/protocol/protocol_control.c | 12 | ||||
-rw-r--r-- | ctdb/protocol/protocol_private.h | 6 | ||||
-rw-r--r-- | ctdb/protocol/protocol_types.c | 48 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_types_compat_test.c | 31 | ||||
-rw-r--r-- | ctdb/tests/src/protocol_types_test.c | 2 |
5 files changed, 77 insertions, 22 deletions
diff --git a/ctdb/protocol/protocol_control.c b/ctdb/protocol/protocol_control.c index 360665caf11..71892aa1249 100644 --- a/ctdb/protocol/protocol_control.c +++ b/ctdb/protocol/protocol_control.c @@ -555,7 +555,7 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd, break; case CTDB_CONTROL_WIPE_DATABASE: - ctdb_transdb_push(cd->data.transdb, buf); + ctdb_transdb_push(cd->data.transdb, buf, &np); break; case CTDB_CONTROL_TRY_DELETE_RECORDS: @@ -686,11 +686,11 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd, break; case CTDB_CONTROL_DB_TRANSACTION_START: - ctdb_transdb_push(cd->data.transdb, buf); + ctdb_transdb_push(cd->data.transdb, buf, &np); break; case CTDB_CONTROL_DB_TRANSACTION_COMMIT: - ctdb_transdb_push(cd->data.transdb, buf); + ctdb_transdb_push(cd->data.transdb, buf, &np); break; case CTDB_CONTROL_DB_TRANSACTION_CANCEL: @@ -858,7 +858,7 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen, case CTDB_CONTROL_WIPE_DATABASE: ret = ctdb_transdb_pull(buf, buflen, mem_ctx, - &cd->data.transdb); + &cd->data.transdb, &np); break; case CTDB_CONTROL_TRY_DELETE_RECORDS: @@ -1009,12 +1009,12 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen, case CTDB_CONTROL_DB_TRANSACTION_START: ret = ctdb_transdb_pull(buf, buflen, mem_ctx, - &cd->data.transdb); + &cd->data.transdb, &np); break; case CTDB_CONTROL_DB_TRANSACTION_COMMIT: ret = ctdb_transdb_pull(buf, buflen, mem_ctx, - &cd->data.transdb); + &cd->data.transdb, &np); break; case CTDB_CONTROL_DB_TRANSACTION_CANCEL: diff --git a/ctdb/protocol/protocol_private.h b/ctdb/protocol/protocol_private.h index 8b3c9bcbbeb..6c253a70dd8 100644 --- a/ctdb/protocol/protocol_private.h +++ b/ctdb/protocol/protocol_private.h @@ -221,10 +221,10 @@ void ctdb_addr_info_push(struct ctdb_addr_info *in, uint8_t *buf, int ctdb_addr_info_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx, struct ctdb_addr_info **out, size_t *npull); -size_t ctdb_transdb_len(struct ctdb_transdb *transdb); -void ctdb_transdb_push(struct ctdb_transdb *transdb, uint8_t *buf); +size_t ctdb_transdb_len(struct ctdb_transdb *in); +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); + 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); diff --git a/ctdb/protocol/protocol_types.c b/ctdb/protocol/protocol_types.c index 90091ff1b4c..8de43ec2714 100644 --- a/ctdb/protocol/protocol_types.c +++ b/ctdb/protocol/protocol_types.c @@ -3259,32 +3259,56 @@ fail: 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; - *out = transdb; + ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->tid, &np); + if (ret != 0) { + goto fail; + } + offset += np; + + *out = val; + *npull = offset; return 0; + +fail: + talloc_free(val); + return ret; } size_t ctdb_uptime_len(struct ctdb_uptime *uptime) diff --git a/ctdb/tests/src/protocol_types_compat_test.c b/ctdb/tests/src/protocol_types_compat_test.c index 040d1a57e57..5c13ceea4f4 100644 --- a/ctdb/tests/src/protocol_types_compat_test.c +++ b/ctdb/tests/src/protocol_types_compat_test.c @@ -1109,6 +1109,35 @@ static int ctdb_addr_info_pull_old(uint8_t *buf, size_t buflen, return 0; } +static size_t ctdb_transdb_len_old(struct ctdb_transdb *in) +{ + return sizeof(struct ctdb_transdb); +} + +static void ctdb_transdb_push_old(struct ctdb_transdb *in, uint8_t *buf) +{ + memcpy(buf, in, sizeof(struct ctdb_transdb)); +} + +static int ctdb_transdb_pull_old(uint8_t *buf, size_t buflen, + TALLOC_CTX *mem_ctx, + struct ctdb_transdb **out) +{ + struct ctdb_transdb *val; + + if (buflen < sizeof(struct ctdb_transdb)) { + return EMSGSIZE; + } + + val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_transdb)); + 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); @@ -1132,6 +1161,7 @@ COMPAT_TYPE3_TEST(struct ctdb_var_list, ctdb_var_list); 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); int main(int argc, char *argv[]) { @@ -1160,6 +1190,7 @@ int main(int argc, char *argv[]) COMPAT_TEST_FUNC(ctdb_tunable_list)(); COMPAT_TEST_FUNC(ctdb_tickle_list)(); COMPAT_TEST_FUNC(ctdb_addr_info)(); + COMPAT_TEST_FUNC(ctdb_transdb)(); return 0; } diff --git a/ctdb/tests/src/protocol_types_test.c b/ctdb/tests/src/protocol_types_test.c index 3db2722fde4..bd9c6e31411 100644 --- a/ctdb/tests/src/protocol_types_test.c +++ b/ctdb/tests/src/protocol_types_test.c @@ -68,7 +68,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_var_list, ctdb_var_list); 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); -DEFINE_TEST(struct ctdb_transdb, ctdb_transdb); +PROTOCOL_TYPE3_TEST(struct ctdb_transdb, ctdb_transdb); DEFINE_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); |