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

ctdb-protocol: Fix marshalling for ctdb_event_request_data

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-07-27 01:41:58 +10:00 committed by Martin Schwenke
parent 28414e09dc
commit a0a162a855
3 changed files with 31 additions and 40 deletions

View File

@ -484,13 +484,14 @@ static size_t ctdb_event_request_data_len(struct ctdb_event_request_data *in)
}
static void ctdb_event_request_data_push(struct ctdb_event_request_data *in,
uint8_t *buf)
uint8_t *buf, size_t *npush)
{
size_t offset = 0, np;
ctdb_event_command_push(in->command, buf, &np);
offset += np;
np = 0;
switch (in->command) {
case CTDB_EVENT_COMMAND_RUN:
ctdb_event_request_run_push(in->data.run, buf+offset, &np);
@ -516,11 +517,15 @@ static void ctdb_event_request_data_push(struct ctdb_event_request_data *in,
buf+offset, &np);
break;
}
offset += np;
*npush = offset;
}
static int ctdb_event_request_data_pull(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_event_request_data *out)
struct ctdb_event_request_data *out,
size_t *npull)
{
size_t offset = 0, np;
int ret;
@ -532,6 +537,7 @@ static int ctdb_event_request_data_pull(uint8_t *buf, size_t buflen,
}
offset += np;
np = 0;
switch (out->command) {
case CTDB_EVENT_COMMAND_RUN:
ret = ctdb_event_request_run_pull(buf+offset, buflen-offset,
@ -571,6 +577,9 @@ static int ctdb_event_request_data_pull(uint8_t *buf, size_t buflen,
return ret;
}
offset += np;
*npull = offset;
return 0;
}
@ -824,7 +833,7 @@ size_t ctdb_event_request_len(struct ctdb_event_request *in)
int ctdb_event_request_push(struct ctdb_event_request *in,
uint8_t *buf, size_t *buflen)
{
size_t len, offset = 0;
size_t len, offset = 0, np;
len = ctdb_event_request_len(in);
if (*buflen < len) {
@ -837,7 +846,7 @@ int ctdb_event_request_push(struct ctdb_event_request *in,
ctdb_event_header_push(&in->header, buf);
offset += ctdb_event_header_len(&in->header);
ctdb_event_request_data_push(&in->rdata, buf+offset);
ctdb_event_request_data_push(&in->rdata, buf+offset, &np);
return 0;
}
@ -846,7 +855,7 @@ int ctdb_event_request_pull(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_event_request *out)
{
size_t offset = 0;
size_t offset = 0, np;
int ret;
ret = ctdb_event_header_pull(buf, buflen, mem_ctx, &out->header);
@ -856,7 +865,7 @@ int ctdb_event_request_pull(uint8_t *buf, size_t buflen,
offset += ctdb_event_header_len(&out->header);
ret = ctdb_event_request_data_pull(buf+offset, buflen-offset,
mem_ctx, &out->rdata);
mem_ctx, &out->rdata, &np);
if (ret != 0) {
return ret;
}

View File

@ -11,10 +11,16 @@ command_output=$(
echo
)
generate_output ()
{
for i in $(seq 1 $last_command) ; do
echo "$1 $i"
done
}
output=$(
echo "ctdb_event_header"
echo "ctdb_event_request_data"
echo "$command_output"
generate_output "ctdb_event_request_data"
echo "ctdb_event_reply_data"
echo "$command_output"
echo "ctdb_event_request"

View File

@ -22,6 +22,7 @@
#include "protocol/protocol_basic.c"
#include "protocol/protocol_types.c"
#include "protocol/protocol_event.c"
#include "protocol/protocol_packet.c"
#include "tests/src/protocol_common.h"
#include "tests/src/protocol_common_event.h"
@ -119,37 +120,6 @@ static void test_ctdb_event_header(void)
#define NUM_COMMANDS 5
static void test_ctdb_event_request_data(void)
{
TALLOC_CTX *mem_ctx;
size_t buflen;
struct ctdb_event_request_data rd, rd2;
uint32_t command;
int ret;
printf("ctdb_event_request_data\n");
fflush(stdout);
for (command=1; command<=NUM_COMMANDS; command++) {
mem_ctx = talloc_new(NULL);
assert(mem_ctx != NULL);
printf("%u.. ", command);
fflush(stdout);
fill_ctdb_event_request_data(mem_ctx, &rd, command);
buflen = ctdb_event_request_data_len(&rd);
ctdb_event_request_data_push(&rd, BUFFER);
ret = ctdb_event_request_data_pull(BUFFER, buflen, mem_ctx, &rd2);
assert(ret == 0);
verify_ctdb_event_request_data(&rd, &rd2);
talloc_free(mem_ctx);
}
printf("\n");
fflush(stdout);
}
static void test_ctdb_event_reply_data(void)
{
TALLOC_CTX *mem_ctx;
@ -271,8 +241,12 @@ PROTOCOL_TYPE3_TEST(struct ctdb_event_request_script_disable,
DEFINE_TEST(struct ctdb_event_reply_status, ctdb_event_reply_status);
DEFINE_TEST(struct ctdb_event_reply_script_list, ctdb_event_reply_script_list);
PROTOCOL_EVENT1_TEST(struct ctdb_event_request_data, ctdb_event_request_data);
int main(int argc, char *argv[])
{
uint32_t command;
if (argc == 2) {
int seed = atoi(argv[1]);
srandom(seed);
@ -287,7 +261,9 @@ int main(int argc, char *argv[])
test_ctdb_event_header();
test_ctdb_event_request_data();
for (command=1; command<=NUM_COMMANDS; command++) {
TEST_FUNC(ctdb_event_request_data)(command);
}
test_ctdb_event_reply_data();
test_ctdb_event_request();
test_ctdb_event_reply();