1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-22 22:04:08 +03:00

ctdb-protocol: Fix marshalling for ctdb_traverse_all

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-06-29 23:56:02 +10:00 committed by Martin Schwenke
parent c882182ecd
commit bad58078fa
5 changed files with 108 additions and 20 deletions

View File

@ -487,7 +487,7 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
break;
case CTDB_CONTROL_TRAVERSE_ALL:
ctdb_traverse_all_push(cd->data.traverse_all, buf);
ctdb_traverse_all_push(cd->data.traverse_all, buf, &np);
break;
case CTDB_CONTROL_TRAVERSE_DATA:
@ -775,7 +775,7 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
case CTDB_CONTROL_TRAVERSE_ALL:
ret = ctdb_traverse_all_pull(buf, buflen, mem_ctx,
&cd->data.traverse_all);
&cd->data.traverse_all, &np);
break;
case CTDB_CONTROL_TRAVERSE_DATA:

View File

@ -150,10 +150,11 @@ void ctdb_traverse_start_push(struct ctdb_traverse_start *in, uint8_t *buf,
int ctdb_traverse_start_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_traverse_start **out, size_t *npull);
size_t ctdb_traverse_all_len(struct ctdb_traverse_all *traverse);
void ctdb_traverse_all_push(struct ctdb_traverse_all *traverse, uint8_t *buf);
size_t ctdb_traverse_all_len(struct ctdb_traverse_all *in);
void ctdb_traverse_all_push(struct ctdb_traverse_all *in, uint8_t *buf,
size_t *npush);
int ctdb_traverse_all_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_traverse_all **out);
struct ctdb_traverse_all **out, size_t *npull);
size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *traverse);
void ctdb_traverse_start_ext_push(struct ctdb_traverse_start_ext *traverse,

View File

@ -1756,33 +1756,88 @@ fail:
return ret;
}
size_t ctdb_traverse_all_len(struct ctdb_traverse_all *traverse)
size_t ctdb_traverse_all_len(struct ctdb_traverse_all *in)
{
return sizeof(struct ctdb_traverse_all);
return ctdb_uint32_len(&in->db_id) +
ctdb_uint32_len(&in->reqid) +
ctdb_uint32_len(&in->pnn) +
ctdb_uint32_len(&in->client_reqid) +
ctdb_uint64_len(&in->srvid);
}
void ctdb_traverse_all_push(struct ctdb_traverse_all *traverse, uint8_t *buf)
void ctdb_traverse_all_push(struct ctdb_traverse_all *in, uint8_t *buf,
size_t *npush)
{
memcpy(buf, traverse, sizeof(struct ctdb_traverse_all));
size_t offset = 0, np;
ctdb_uint32_push(&in->db_id, buf+offset, &np);
offset += np;
ctdb_uint32_push(&in->reqid, buf+offset, &np);
offset += np;
ctdb_uint32_push(&in->pnn, buf+offset, &np);
offset += np;
ctdb_uint32_push(&in->client_reqid, buf+offset, &np);
offset += np;
ctdb_uint64_push(&in->srvid, buf+offset, &np);
offset += np;
*npush = offset;
}
int ctdb_traverse_all_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_traverse_all **out)
struct ctdb_traverse_all **out, size_t *npull)
{
struct ctdb_traverse_all *traverse;
struct ctdb_traverse_all *val;
size_t offset = 0, np;
int ret;
if (buflen < sizeof(struct ctdb_traverse_all)) {
return EMSGSIZE;
}
traverse = talloc_memdup(mem_ctx, buf,
sizeof(struct ctdb_traverse_all));
if (traverse == NULL) {
val = talloc(mem_ctx, struct ctdb_traverse_all);
if (val == NULL) {
return ENOMEM;
}
*out = traverse;
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->reqid, &np);
if (ret != 0) {
goto fail;
}
offset += np;
ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
if (ret != 0) {
goto fail;
}
offset += np;
ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->client_reqid,
&np);
if (ret != 0) {
goto fail;
}
offset += np;
ret = ctdb_uint64_pull(buf+offset, buflen-offset, &val->srvid, &np);
if (ret != 0) {
goto fail;
}
offset += np;
*out = val;
*npull = offset;
return 0;
fail:
talloc_free(val);
return ret;
}
size_t ctdb_traverse_start_ext_len(struct ctdb_traverse_start_ext *traverse)

View File

@ -554,6 +554,36 @@ static int ctdb_traverse_start_pull_old(uint8_t *buf, size_t buflen,
return 0;
}
static size_t ctdb_traverse_all_len_old(struct ctdb_traverse_all *in)
{
return sizeof(struct ctdb_traverse_all);
}
static void ctdb_traverse_all_push_old(struct ctdb_traverse_all *in,
uint8_t *buf)
{
memcpy(buf, in, sizeof(struct ctdb_traverse_all));
}
static int ctdb_traverse_all_pull_old(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_traverse_all **out)
{
struct ctdb_traverse_all *val;
if (buflen < sizeof(struct ctdb_traverse_all)) {
return EMSGSIZE;
}
val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_traverse_all));
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);
@ -566,6 +596,7 @@ COMPAT_TYPE1_TEST(struct ctdb_ltdb_header, ctdb_ltdb_header);
COMPAT_TYPE3_TEST(struct ctdb_rec_data, ctdb_rec_data);
COMPAT_TYPE3_TEST(struct ctdb_rec_buffer, ctdb_rec_buffer);
COMPAT_TYPE3_TEST(struct ctdb_traverse_start, ctdb_traverse_start);
COMPAT_TYPE3_TEST(struct ctdb_traverse_all, ctdb_traverse_all);
int main(int argc, char *argv[])
{
@ -583,6 +614,7 @@ int main(int argc, char *argv[])
COMPAT_TEST_FUNC(ctdb_rec_data)();
COMPAT_TEST_FUNC(ctdb_rec_buffer)();
COMPAT_TEST_FUNC(ctdb_traverse_start)();
COMPAT_TEST_FUNC(ctdb_traverse_all)();
return 0;
}

View File

@ -57,7 +57,7 @@ PROTOCOL_TYPE1_TEST(struct ctdb_ltdb_header, ctdb_ltdb_header);
PROTOCOL_TYPE3_TEST(struct ctdb_rec_data, ctdb_rec_data);
PROTOCOL_TYPE3_TEST(struct ctdb_rec_buffer, ctdb_rec_buffer);
PROTOCOL_TYPE3_TEST(struct ctdb_traverse_start, ctdb_traverse_start);
DEFINE_TEST(struct ctdb_traverse_all, ctdb_traverse_all);
PROTOCOL_TYPE3_TEST(struct ctdb_traverse_all, ctdb_traverse_all);
DEFINE_TEST(struct ctdb_traverse_start_ext, ctdb_traverse_start_ext);
DEFINE_TEST(struct ctdb_traverse_all_ext, ctdb_traverse_all_ext);
DEFINE_TEST(ctdb_sock_addr, ctdb_sock_addr);