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_srvid_message

Signed-off-by: Amitay Isaacs <amitay@gmail.com>
Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
Amitay Isaacs 2017-07-13 15:01:37 +10:00 committed by Martin Schwenke
parent d8309d9548
commit 95ae006d5c
5 changed files with 89 additions and 21 deletions

View File

@ -156,7 +156,7 @@ static void ctdb_message_data_push(union ctdb_message_data *mdata,
break;
case CTDB_SRVID_MEM_DUMP:
ctdb_srvid_message_push(mdata->msg, buf);
ctdb_srvid_message_push(mdata->msg, buf, &np);
break;
case CTDB_SRVID_PUSH_NODE_FLAGS:
@ -167,7 +167,7 @@ static void ctdb_message_data_push(union ctdb_message_data *mdata,
break;
case CTDB_SRVID_TAKEOVER_RUN:
ctdb_srvid_message_push(mdata->msg, buf);
ctdb_srvid_message_push(mdata->msg, buf, &np);
break;
case CTDB_SRVID_REBALANCE_NODE:
@ -243,7 +243,7 @@ static int ctdb_message_data_pull(uint8_t *buf, size_t buflen,
case CTDB_SRVID_MEM_DUMP:
ret = ctdb_srvid_message_pull(buf, buflen, mem_ctx,
&mdata->msg);
&mdata->msg, &np);
break;
case CTDB_SRVID_PUSH_NODE_FLAGS:
@ -256,7 +256,7 @@ static int ctdb_message_data_pull(uint8_t *buf, size_t buflen,
case CTDB_SRVID_TAKEOVER_RUN:
ret = ctdb_srvid_message_pull(buf, buflen, mem_ctx,
&mdata->msg);
&mdata->msg, &np);
break;
case CTDB_SRVID_REBALANCE_NODE:

View File

@ -313,10 +313,11 @@ int ctdb_election_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_election_message **out,
size_t *npull);
size_t ctdb_srvid_message_len(struct ctdb_srvid_message *msg);
void ctdb_srvid_message_push(struct ctdb_srvid_message *msg, uint8_t *buf);
size_t ctdb_srvid_message_len(struct ctdb_srvid_message *in);
void ctdb_srvid_message_push(struct ctdb_srvid_message *in, uint8_t *buf,
size_t *npush);
int ctdb_srvid_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_srvid_message **out);
struct ctdb_srvid_message **out, size_t *npull);
size_t ctdb_disable_message_len(struct ctdb_disable_message *disable);
void ctdb_disable_message_push(struct ctdb_disable_message *disable,

View File

@ -4714,32 +4714,67 @@ fail:
return ret;
}
size_t ctdb_srvid_message_len(struct ctdb_srvid_message *msg)
size_t ctdb_srvid_message_len(struct ctdb_srvid_message *in)
{
return sizeof(struct ctdb_srvid_message);
return ctdb_uint32_len(&in->pnn) +
ctdb_padding_len(4) +
ctdb_uint64_len(&in->srvid);
}
void ctdb_srvid_message_push(struct ctdb_srvid_message *msg, uint8_t *buf)
void ctdb_srvid_message_push(struct ctdb_srvid_message *in, uint8_t *buf,
size_t *npush)
{
memcpy(buf, msg, sizeof(struct ctdb_srvid_message));
size_t offset = 0, np;
ctdb_uint32_push(&in->pnn, buf+offset, &np);
offset += np;
ctdb_padding_push(4, buf+offset, &np);
offset += np;
ctdb_uint64_push(&in->srvid, buf+offset, &np);
offset += np;
*npush = offset;
}
int ctdb_srvid_message_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_srvid_message **out)
struct ctdb_srvid_message **out, size_t *npull)
{
struct ctdb_srvid_message *msg;
struct ctdb_srvid_message *val;
size_t offset = 0, np;
int ret;
if (buflen < sizeof(struct ctdb_srvid_message)) {
return EMSGSIZE;
}
msg = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_srvid_message));
if (msg == NULL) {
val = talloc(mem_ctx, struct ctdb_srvid_message);
if (val == NULL) {
return ENOMEM;
}
*out = msg;
ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->pnn, &np);
if (ret != 0) {
goto fail;
}
offset += np;
ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &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_disable_message_len(struct ctdb_disable_message *disable)

View File

@ -2107,6 +2107,36 @@ static int ctdb_election_message_pull_old(uint8_t *buf, size_t buflen,
return 0;
}
static size_t ctdb_srvid_message_len_old(struct ctdb_srvid_message *in)
{
return sizeof(struct ctdb_srvid_message);
}
static void ctdb_srvid_message_push_old(struct ctdb_srvid_message *in,
uint8_t *buf)
{
memcpy(buf, in, sizeof(struct ctdb_srvid_message));
}
static int ctdb_srvid_message_pull_old(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
struct ctdb_srvid_message **out)
{
struct ctdb_srvid_message *val;
if (buflen < sizeof(struct ctdb_srvid_message)) {
return EMSGSIZE;
}
val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_srvid_message));
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);
@ -2148,6 +2178,7 @@ COMPAT_TYPE3_TEST(struct ctdb_key_data, ctdb_key_data);
COMPAT_TYPE3_TEST(struct ctdb_db_statistics, ctdb_db_statistics);
COMPAT_TYPE3_TEST(struct ctdb_election_message, ctdb_election_message);
COMPAT_TYPE3_TEST(struct ctdb_srvid_message, ctdb_srvid_message);
int main(int argc, char *argv[])
{
@ -2194,6 +2225,7 @@ int main(int argc, char *argv[])
COMPAT_TEST_FUNC(ctdb_db_statistics)();
COMPAT_TEST_FUNC(ctdb_election_message)();
COMPAT_TEST_FUNC(ctdb_srvid_message)();
return 0;
}

View File

@ -85,7 +85,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_statistics_list, ctdb_statistics_list);
PROTOCOL_TYPE3_TEST(struct ctdb_key_data, ctdb_key_data);
PROTOCOL_TYPE3_TEST(struct ctdb_db_statistics, ctdb_db_statistics);
PROTOCOL_TYPE3_TEST(struct ctdb_election_message, ctdb_election_message);
DEFINE_TEST(struct ctdb_srvid_message, ctdb_srvid_message);
PROTOCOL_TYPE3_TEST(struct ctdb_srvid_message, ctdb_srvid_message);
DEFINE_TEST(struct ctdb_disable_message, ctdb_disable_message);
DEFINE_TEST(struct ctdb_g_lock_list, ctdb_g_lock_list);