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_ban_state

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-07-12 18:24:34 +10:00 committed by Martin Schwenke
parent 74eaa0361b
commit 57a4d2e631
5 changed files with 78 additions and 21 deletions

View File

@ -595,7 +595,7 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
break;
case CTDB_CONTROL_SET_BAN_STATE:
ctdb_ban_state_push(cd->data.ban_state, buf);
ctdb_ban_state_push(cd->data.ban_state, buf, &np);
break;
case CTDB_CONTROL_REGISTER_NOTIFY:
@ -906,7 +906,7 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
case CTDB_CONTROL_SET_BAN_STATE:
ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
&cd->data.ban_state);
&cd->data.ban_state, &np);
break;
case CTDB_CONTROL_REGISTER_NOTIFY:
@ -1512,7 +1512,7 @@ static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
break;
case CTDB_CONTROL_GET_BAN_STATE:
ctdb_ban_state_push(cd->data.ban_state, buf);
ctdb_ban_state_push(cd->data.ban_state, buf, &np);
break;
case CTDB_CONTROL_GET_DB_PRIORITY:
@ -1692,7 +1692,7 @@ static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
case CTDB_CONTROL_GET_BAN_STATE:
ret = ctdb_ban_state_pull(buf, buflen, mem_ctx,
&cd->data.ban_state);
&cd->data.ban_state, &np);
break;
case CTDB_CONTROL_GET_DB_PRIORITY:

View File

@ -265,10 +265,11 @@ void ctdb_script_list_push(struct ctdb_script_list *in, uint8_t *buf,
int ctdb_script_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_script_list **out, size_t *npull);
size_t ctdb_ban_state_len(struct ctdb_ban_state *ban_state);
void ctdb_ban_state_push(struct ctdb_ban_state *ban_state, uint8_t *buf);
size_t ctdb_ban_state_len(struct ctdb_ban_state *in);
void ctdb_ban_state_push(struct ctdb_ban_state *in, uint8_t *buf,
size_t *npush);
int ctdb_ban_state_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_ban_state **out);
struct ctdb_ban_state **out, size_t *npull);
size_t ctdb_notify_data_len(struct ctdb_notify_data *notify);
void ctdb_notify_data_push(struct ctdb_notify_data *notify, uint8_t *buf);

View File

@ -3900,32 +3900,57 @@ fail:
return ret;
}
size_t ctdb_ban_state_len(struct ctdb_ban_state *ban_state)
size_t ctdb_ban_state_len(struct ctdb_ban_state *in)
{
return sizeof(struct ctdb_ban_state);
return ctdb_uint32_len(&in->pnn) +
ctdb_uint32_len(&in->time);
}
void ctdb_ban_state_push(struct ctdb_ban_state *ban_state, uint8_t *buf)
void ctdb_ban_state_push(struct ctdb_ban_state *in, uint8_t *buf,
size_t *npush)
{
memcpy(buf, ban_state, sizeof(struct ctdb_ban_state));
size_t offset = 0, np;
ctdb_uint32_push(&in->pnn, buf+offset, &np);
offset += np;
ctdb_uint32_push(&in->time, buf+offset, &np);
offset += np;
*npush = offset;
}
int ctdb_ban_state_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_ban_state **out)
struct ctdb_ban_state **out, size_t *npull)
{
struct ctdb_ban_state *ban_state;
struct ctdb_ban_state *val;
size_t offset = 0, np;
int ret;
if (buflen < sizeof(struct ctdb_ban_state)) {
return EMSGSIZE;
}
ban_state = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_ban_state));
if (ban_state == NULL) {
val = talloc(mem_ctx, struct ctdb_ban_state);
if (val == NULL) {
return ENOMEM;
}
*out = ban_state;
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->time, &np);
if (ret != 0) {
goto fail;
}
offset += np;
*out = val;
*npull = offset;
return 0;
fail:
talloc_free(val);
return ret;
}
struct ctdb_notify_data_wire {

View File

@ -1577,6 +1577,35 @@ static int ctdb_script_list_pull_old(uint8_t *buf, size_t buflen,
return 0;
}
static size_t ctdb_ban_state_len_old(struct ctdb_ban_state *in)
{
return sizeof(struct ctdb_ban_state);
}
static void ctdb_ban_state_push_old(struct ctdb_ban_state *in, uint8_t *buf)
{
memcpy(buf, in, sizeof(struct ctdb_ban_state));
}
static int ctdb_ban_state_pull_old(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_ban_state **out)
{
struct ctdb_ban_state *val;
if (buflen < sizeof(struct ctdb_ban_state)) {
return EMSGSIZE;
}
val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_ban_state));
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);
@ -1608,6 +1637,7 @@ COMPAT_TYPE3_TEST(struct ctdb_node_and_flags, ctdb_node_and_flags);
COMPAT_TYPE3_TEST(struct ctdb_node_map, ctdb_node_map);
COMPAT_TYPE3_TEST(struct ctdb_script, ctdb_script);
COMPAT_TYPE3_TEST(struct ctdb_script_list, ctdb_script_list);
COMPAT_TYPE3_TEST(struct ctdb_ban_state, ctdb_ban_state);
int main(int argc, char *argv[])
{
@ -1644,6 +1674,7 @@ int main(int argc, char *argv[])
COMPAT_TEST_FUNC(ctdb_node_map)();
COMPAT_TEST_FUNC(ctdb_script)();
COMPAT_TEST_FUNC(ctdb_script_list)();
COMPAT_TEST_FUNC(ctdb_ban_state)();
return 0;
}

View File

@ -76,7 +76,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_node_and_flags, ctdb_node_and_flags);
PROTOCOL_TYPE3_TEST(struct ctdb_node_map, ctdb_node_map);
PROTOCOL_TYPE3_TEST(struct ctdb_script, ctdb_script);
PROTOCOL_TYPE3_TEST(struct ctdb_script_list, ctdb_script_list);
DEFINE_TEST(struct ctdb_ban_state, ctdb_ban_state);
PROTOCOL_TYPE3_TEST(struct ctdb_ban_state, ctdb_ban_state);
DEFINE_TEST(struct ctdb_notify_data, ctdb_notify_data);
DEFINE_TEST(struct ctdb_iface, ctdb_iface);
DEFINE_TEST(struct ctdb_iface_list, ctdb_iface_list);