1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

ctdb-protocol: Fix marshalling for ctdb_transdb

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-07-05 17:51:03 +10:00 committed by Martin Schwenke
parent 4d70b972f2
commit e893b46e5e
5 changed files with 78 additions and 23 deletions

View File

@ -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:

View File

@ -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);

View File

@ -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;
}
transdb = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_transdb));
if (transdb == NULL) {
val = talloc(mem_ctx, struct ctdb_transdb);
if (val == NULL) {
return ENOMEM;
}
*out = transdb;
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->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)

View File

@ -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;
}

View File

@ -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);