1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-10 01:18:15 +03:00

ctdb-protocol: Fix marshalling for ctdb_node_flag_change

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-06-30 00:42:53 +10:00 committed by Martin Schwenke
parent 60cb067885
commit 7f57cc0ec2
6 changed files with 98 additions and 27 deletions

View File

@ -531,7 +531,7 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
break;
case CTDB_CONTROL_MODIFY_FLAGS:
ctdb_node_flag_change_push(cd->data.flag_change, buf);
ctdb_node_flag_change_push(cd->data.flag_change, buf, &np);
break;
case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
@ -828,7 +828,7 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
case CTDB_CONTROL_MODIFY_FLAGS:
ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
&cd->data.flag_change);
&cd->data.flag_change, &np);
break;
case CTDB_CONTROL_GET_TCP_TICKLE_LIST:

View File

@ -140,7 +140,7 @@ static void ctdb_message_data_push(union ctdb_message_data *mdata,
break;
case CTDB_SRVID_SET_NODE_FLAGS:
ctdb_node_flag_change_push(mdata->flag_change, buf);
ctdb_node_flag_change_push(mdata->flag_change, buf, &np);
break;
case CTDB_SRVID_RECD_UPDATE_IP:
@ -160,7 +160,7 @@ static void ctdb_message_data_push(union ctdb_message_data *mdata,
break;
case CTDB_SRVID_PUSH_NODE_FLAGS:
ctdb_node_flag_change_push(mdata->flag_change, buf);
ctdb_node_flag_change_push(mdata->flag_change, buf, &np);
break;
case CTDB_SRVID_RELOAD_NODES:
@ -224,7 +224,7 @@ static int ctdb_message_data_pull(uint8_t *buf, size_t buflen,
case CTDB_SRVID_SET_NODE_FLAGS:
ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
&mdata->flag_change);
&mdata->flag_change, &np);
break;
case CTDB_SRVID_RECD_UPDATE_IP:
@ -248,7 +248,7 @@ static int ctdb_message_data_pull(uint8_t *buf, size_t buflen,
case CTDB_SRVID_PUSH_NODE_FLAGS:
ret = ctdb_node_flag_change_pull(buf, buflen, mem_ctx,
&mdata->flag_change);
&mdata->flag_change, &np);
break;
case CTDB_SRVID_RELOAD_NODES:

View File

@ -191,11 +191,12 @@ void ctdb_tunable_push(struct ctdb_tunable *in, uint8_t *buf, size_t *npush);
int ctdb_tunable_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_tunable **out, size_t *npull);
size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *flag_change);
void ctdb_node_flag_change_push(struct ctdb_node_flag_change *flag_change,
uint8_t *buf);
size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *in);
void ctdb_node_flag_change_push(struct ctdb_node_flag_change *in,
uint8_t *buf, size_t *npush);
int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_node_flag_change **out);
struct ctdb_node_flag_change **out,
size_t *npull);
size_t ctdb_var_list_len(struct ctdb_var_list *var_list);
void ctdb_var_list_push(struct ctdb_var_list *var_list, uint8_t *buf);

View File

@ -2203,34 +2203,71 @@ fail:
return ret;
}
size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *flag_change)
size_t ctdb_node_flag_change_len(struct ctdb_node_flag_change *in)
{
return sizeof(struct ctdb_node_flag_change);
return ctdb_uint32_len(&in->pnn) +
ctdb_uint32_len(&in->new_flags) +
ctdb_uint32_len(&in->old_flags);
}
void ctdb_node_flag_change_push(struct ctdb_node_flag_change *flag_change,
uint8_t *buf)
void ctdb_node_flag_change_push(struct ctdb_node_flag_change *in,
uint8_t *buf, size_t *npush)
{
memcpy(buf, flag_change, sizeof(struct ctdb_node_flag_change));
size_t offset = 0, np;
ctdb_uint32_push(&in->pnn, buf+offset, &np);
offset += np;
ctdb_uint32_push(&in->new_flags, buf+offset, &np);
offset += np;
ctdb_uint32_push(&in->old_flags, buf+offset, &np);
offset += np;
*npush = offset;
}
int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_node_flag_change **out)
int ctdb_node_flag_change_pull(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_node_flag_change **out,
size_t *npull)
{
struct ctdb_node_flag_change *flag_change;
struct ctdb_node_flag_change *val;
size_t offset = 0, np;
int ret;
if (buflen < sizeof(struct ctdb_node_flag_change)) {
return EMSGSIZE;
}
flag_change = talloc_memdup(mem_ctx, buf,
sizeof(struct ctdb_node_flag_change));
if (flag_change == NULL) {
val = talloc(mem_ctx, struct ctdb_node_flag_change);
if (val == NULL) {
return ENOMEM;
}
*out = flag_change;
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->new_flags,
&np);
if (ret != 0) {
goto fail;
}
offset += np;
ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->old_flags,
&np);
if (ret != 0) {
goto fail;
}
offset += np;
*out = val;
*npull = offset;
return 0;
fail:
talloc_free(val);
return ret;
}
struct ctdb_var_list_wire {

View File

@ -794,6 +794,37 @@ static int ctdb_tunable_pull_old(uint8_t *buf, size_t buflen,
return 0;
}
static size_t ctdb_node_flag_change_len_old(struct ctdb_node_flag_change *in)
{
return sizeof(struct ctdb_node_flag_change);
}
static void ctdb_node_flag_change_push_old(struct ctdb_node_flag_change *in,
uint8_t *buf)
{
memcpy(buf, in, sizeof(struct ctdb_node_flag_change));
}
static int ctdb_node_flag_change_pull_old(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_node_flag_change **out)
{
struct ctdb_node_flag_change *val;
if (buflen < sizeof(struct ctdb_node_flag_change)) {
return EMSGSIZE;
}
val = talloc_memdup(mem_ctx, buf,
sizeof(struct ctdb_node_flag_change));
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);
@ -812,6 +843,7 @@ COMPAT_TYPE3_TEST(struct ctdb_traverse_all_ext, ctdb_traverse_all_ext);
COMPAT_TYPE3_TEST(ctdb_sock_addr, ctdb_sock_addr);
COMPAT_TYPE3_TEST(struct ctdb_connection, ctdb_connection);
COMPAT_TYPE3_TEST(struct ctdb_tunable, ctdb_tunable);
COMPAT_TYPE3_TEST(struct ctdb_node_flag_change, ctdb_node_flag_change);
int main(int argc, char *argv[])
{
@ -835,6 +867,7 @@ int main(int argc, char *argv[])
COMPAT_TEST_FUNC(ctdb_sock_addr)();
COMPAT_TEST_FUNC(ctdb_connection)();
COMPAT_TEST_FUNC(ctdb_tunable)();
COMPAT_TEST_FUNC(ctdb_node_flag_change)();
return 0;
}

View File

@ -63,7 +63,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_traverse_all_ext, ctdb_traverse_all_ext);
PROTOCOL_TYPE3_TEST(ctdb_sock_addr, ctdb_sock_addr);
PROTOCOL_TYPE3_TEST(struct ctdb_connection, ctdb_connection);
PROTOCOL_TYPE3_TEST(struct ctdb_tunable, ctdb_tunable);
DEFINE_TEST(struct ctdb_node_flag_change, ctdb_node_flag_change);
PROTOCOL_TYPE3_TEST(struct ctdb_node_flag_change, ctdb_node_flag_change);
DEFINE_TEST(struct ctdb_var_list, ctdb_var_list);
DEFINE_TEST(struct ctdb_tunable_list, ctdb_tunable_list);
DEFINE_TEST(struct ctdb_tickle_list, ctdb_tickle_list);