mirror of
https://github.com/samba-team/samba.git
synced 2025-02-26 21:57:41 +03:00
ctdb-protocol: Fix marshalling for ctdb_tickle_list
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
9573260954
commit
bac67e1af5
@ -539,7 +539,7 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
|
case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
|
||||||
ctdb_tickle_list_push(cd->data.tickles, buf);
|
ctdb_tickle_list_push(cd->data.tickles, buf, &np);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
|
case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
|
||||||
@ -838,7 +838,7 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
|
|||||||
|
|
||||||
case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
|
case CTDB_CONTROL_SET_TCP_TICKLE_LIST:
|
||||||
ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
|
ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
|
||||||
&cd->data.tickles);
|
&cd->data.tickles, &np);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
|
case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
|
||||||
@ -1480,7 +1480,7 @@ static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
|
case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
|
||||||
ctdb_tickle_list_push(cd->data.tickles, buf);
|
ctdb_tickle_list_push(cd->data.tickles, buf, &np);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
|
case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
|
||||||
@ -1654,7 +1654,7 @@ static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
|
|||||||
|
|
||||||
case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
|
case CTDB_CONTROL_GET_TCP_TICKLE_LIST:
|
||||||
ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
|
ret = ctdb_tickle_list_pull(buf, buflen, mem_ctx,
|
||||||
&cd->data.tickles);
|
&cd->data.tickles, &np);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
|
case CTDB_CONTROL_DB_ATTACH_PERSISTENT:
|
||||||
|
@ -209,10 +209,11 @@ void ctdb_tunable_list_push(struct ctdb_tunable_list *in, uint8_t *buf,
|
|||||||
int ctdb_tunable_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
int ctdb_tunable_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||||
struct ctdb_tunable_list **out, size_t *npull);
|
struct ctdb_tunable_list **out, size_t *npull);
|
||||||
|
|
||||||
size_t ctdb_tickle_list_len(struct ctdb_tickle_list *tickles);
|
size_t ctdb_tickle_list_len(struct ctdb_tickle_list *in);
|
||||||
void ctdb_tickle_list_push(struct ctdb_tickle_list *tickles, uint8_t *buf);
|
void ctdb_tickle_list_push(struct ctdb_tickle_list *in, uint8_t *buf,
|
||||||
|
size_t *npush);
|
||||||
int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||||
struct ctdb_tickle_list **out);
|
struct ctdb_tickle_list **out, size_t *npull);
|
||||||
|
|
||||||
size_t ctdb_addr_info_len(struct ctdb_addr_info *addr_info);
|
size_t ctdb_addr_info_len(struct ctdb_addr_info *addr_info);
|
||||||
void ctdb_addr_info_push(struct ctdb_addr_info *addr_info, uint8_t *buf);
|
void ctdb_addr_info_push(struct ctdb_addr_info *addr_info, uint8_t *buf);
|
||||||
|
@ -3105,88 +3105,93 @@ int ctdb_tunable_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ctdb_tickle_list_wire {
|
size_t ctdb_tickle_list_len(struct ctdb_tickle_list *in)
|
||||||
ctdb_sock_addr addr;
|
|
||||||
uint32_t num;
|
|
||||||
struct ctdb_connection conn[1];
|
|
||||||
};
|
|
||||||
|
|
||||||
size_t ctdb_tickle_list_len(struct ctdb_tickle_list *tickles)
|
|
||||||
{
|
{
|
||||||
return offsetof(struct ctdb_tickle_list, conn) +
|
size_t len;
|
||||||
tickles->num * sizeof(struct ctdb_connection);
|
|
||||||
|
len = ctdb_sock_addr_len(&in->addr) +
|
||||||
|
ctdb_uint32_len(&in->num);
|
||||||
|
if (in->num > 0) {
|
||||||
|
len += in->num * ctdb_connection_len(&in->conn[0]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return len;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ctdb_tickle_list_push(struct ctdb_tickle_list *tickles, uint8_t *buf)
|
void ctdb_tickle_list_push(struct ctdb_tickle_list *in, uint8_t *buf,
|
||||||
|
size_t *npush)
|
||||||
{
|
{
|
||||||
struct ctdb_tickle_list_wire *wire =
|
size_t offset = 0, np;
|
||||||
(struct ctdb_tickle_list_wire *)buf;
|
uint32_t i;
|
||||||
size_t offset, np;
|
|
||||||
int i;
|
|
||||||
|
|
||||||
memcpy(&wire->addr, &tickles->addr, sizeof(ctdb_sock_addr));
|
ctdb_sock_addr_push(&in->addr, buf+offset, &np);
|
||||||
wire->num = tickles->num;
|
offset += np;
|
||||||
|
|
||||||
offset = offsetof(struct ctdb_tickle_list_wire, conn);
|
ctdb_uint32_push(&in->num, buf+offset, &np);
|
||||||
for (i=0; i<tickles->num; i++) {
|
offset += np;
|
||||||
ctdb_connection_push(&tickles->conn[i], &buf[offset], &np);
|
|
||||||
|
for (i=0; i<in->num; i++) {
|
||||||
|
ctdb_connection_push(&in->conn[i], buf+offset, &np);
|
||||||
offset += np;
|
offset += np;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
*npush = offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||||
struct ctdb_tickle_list **out)
|
struct ctdb_tickle_list **out, size_t *npull)
|
||||||
{
|
{
|
||||||
struct ctdb_tickle_list *tickles;
|
struct ctdb_tickle_list *val;
|
||||||
struct ctdb_tickle_list_wire *wire =
|
size_t offset = 0, np;
|
||||||
(struct ctdb_tickle_list_wire *)buf;
|
uint32_t i;
|
||||||
size_t offset, np;
|
int ret;
|
||||||
int i, ret;
|
|
||||||
|
|
||||||
if (buflen < offsetof(struct ctdb_tickle_list_wire, conn)) {
|
val = talloc(mem_ctx, struct ctdb_tickle_list);
|
||||||
return EMSGSIZE;
|
if (val == NULL) {
|
||||||
}
|
|
||||||
if (wire->num > buflen / sizeof(struct ctdb_connection)) {
|
|
||||||
return EMSGSIZE;
|
|
||||||
}
|
|
||||||
if (offsetof(struct ctdb_tickle_list_wire, conn) +
|
|
||||||
wire->num * sizeof(struct ctdb_connection) <
|
|
||||||
offsetof(struct ctdb_tickle_list_wire, conn)) {
|
|
||||||
return EMSGSIZE;
|
|
||||||
}
|
|
||||||
if (buflen < offsetof(struct ctdb_tickle_list_wire, conn) +
|
|
||||||
wire->num * sizeof(struct ctdb_connection)) {
|
|
||||||
return EMSGSIZE;
|
|
||||||
}
|
|
||||||
|
|
||||||
tickles = talloc(mem_ctx, struct ctdb_tickle_list);
|
|
||||||
if (tickles == NULL) {
|
|
||||||
return ENOMEM;
|
return ENOMEM;
|
||||||
}
|
}
|
||||||
|
|
||||||
offset = offsetof(struct ctdb_tickle_list, conn);
|
ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset, val,
|
||||||
memcpy(tickles, wire, offset);
|
&val->addr, &np);
|
||||||
|
if (ret != 0) {
|
||||||
|
goto fail;
|
||||||
|
}
|
||||||
|
offset += np;
|
||||||
|
|
||||||
tickles->conn = talloc_array(tickles, struct ctdb_connection,
|
ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
|
||||||
wire->num);
|
if (ret != 0) {
|
||||||
if (tickles->conn == NULL) {
|
goto fail;
|
||||||
talloc_free(tickles);
|
}
|
||||||
return ENOMEM;
|
offset += np;
|
||||||
|
|
||||||
|
if (val->num == 0) {
|
||||||
|
val->conn = NULL;
|
||||||
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i=0; i<wire->num; i++) {
|
val->conn = talloc_array(val, struct ctdb_connection, val->num);
|
||||||
ret = ctdb_connection_pull_elems(&buf[offset], buflen-offset,
|
if (val->conn == NULL) {
|
||||||
tickles->conn,
|
ret = ENOMEM;
|
||||||
&tickles->conn[i], &np);
|
goto fail;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i<val->num; i++) {
|
||||||
|
ret = ctdb_connection_pull_elems(buf+offset, buflen-offset,
|
||||||
|
val, &val->conn[i], &np);
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
talloc_free(tickles);
|
goto fail;
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
offset += np;
|
offset += np;
|
||||||
}
|
}
|
||||||
|
|
||||||
*out = tickles;
|
done:
|
||||||
|
*out = val;
|
||||||
|
*npull = offset;
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
|
fail:
|
||||||
|
talloc_free(val);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct ctdb_addr_info_wire {
|
struct ctdb_addr_info_wire {
|
||||||
|
@ -947,6 +947,92 @@ static int ctdb_tunable_list_pull_old(uint8_t *buf, size_t buflen,
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct ctdb_tickle_list_wire {
|
||||||
|
ctdb_sock_addr addr;
|
||||||
|
uint32_t num;
|
||||||
|
struct ctdb_connection conn[1];
|
||||||
|
};
|
||||||
|
|
||||||
|
static size_t ctdb_tickle_list_len_old(struct ctdb_tickle_list *in)
|
||||||
|
{
|
||||||
|
return offsetof(struct ctdb_tickle_list, conn) +
|
||||||
|
in->num * sizeof(struct ctdb_connection);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void ctdb_tickle_list_push_old(struct ctdb_tickle_list *in,
|
||||||
|
uint8_t *buf)
|
||||||
|
{
|
||||||
|
struct ctdb_tickle_list_wire *wire =
|
||||||
|
(struct ctdb_tickle_list_wire *)buf;
|
||||||
|
size_t offset;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
memcpy(&wire->addr, &in->addr, sizeof(ctdb_sock_addr));
|
||||||
|
wire->num = in->num;
|
||||||
|
|
||||||
|
offset = offsetof(struct ctdb_tickle_list_wire, conn);
|
||||||
|
for (i=0; i<in->num; i++) {
|
||||||
|
ctdb_connection_push_old(&in->conn[i], &buf[offset]);
|
||||||
|
offset += ctdb_connection_len_old(&in->conn[i]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static int ctdb_tickle_list_pull_old(uint8_t *buf, size_t buflen,
|
||||||
|
TALLOC_CTX *mem_ctx,
|
||||||
|
struct ctdb_tickle_list **out)
|
||||||
|
{
|
||||||
|
struct ctdb_tickle_list *val;
|
||||||
|
struct ctdb_tickle_list_wire *wire =
|
||||||
|
(struct ctdb_tickle_list_wire *)buf;
|
||||||
|
size_t offset;
|
||||||
|
int i, ret;
|
||||||
|
|
||||||
|
if (buflen < offsetof(struct ctdb_tickle_list_wire, conn)) {
|
||||||
|
return EMSGSIZE;
|
||||||
|
}
|
||||||
|
if (wire->num > buflen / sizeof(struct ctdb_connection)) {
|
||||||
|
return EMSGSIZE;
|
||||||
|
}
|
||||||
|
if (offsetof(struct ctdb_tickle_list_wire, conn) +
|
||||||
|
wire->num * sizeof(struct ctdb_connection) <
|
||||||
|
offsetof(struct ctdb_tickle_list_wire, conn)) {
|
||||||
|
return EMSGSIZE;
|
||||||
|
}
|
||||||
|
if (buflen < offsetof(struct ctdb_tickle_list_wire, conn) +
|
||||||
|
wire->num * sizeof(struct ctdb_connection)) {
|
||||||
|
return EMSGSIZE;
|
||||||
|
}
|
||||||
|
|
||||||
|
val = talloc(mem_ctx, struct ctdb_tickle_list);
|
||||||
|
if (val == NULL) {
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
offset = offsetof(struct ctdb_tickle_list, conn);
|
||||||
|
memcpy(val, wire, offset);
|
||||||
|
|
||||||
|
val->conn = talloc_array(val, struct ctdb_connection, wire->num);
|
||||||
|
if (val->conn == NULL) {
|
||||||
|
talloc_free(val);
|
||||||
|
return ENOMEM;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (i=0; i<wire->num; i++) {
|
||||||
|
ret = ctdb_connection_pull_elems_old(&buf[offset],
|
||||||
|
buflen-offset,
|
||||||
|
val->conn,
|
||||||
|
&val->conn[i]);
|
||||||
|
if (ret != 0) {
|
||||||
|
talloc_free(val);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
offset += ctdb_connection_len_old(&val->conn[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
*out = val;
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
COMPAT_TYPE3_TEST(struct ctdb_statistics, ctdb_statistics);
|
COMPAT_TYPE3_TEST(struct ctdb_statistics, ctdb_statistics);
|
||||||
COMPAT_TYPE3_TEST(struct ctdb_vnn_map, ctdb_vnn_map);
|
COMPAT_TYPE3_TEST(struct ctdb_vnn_map, ctdb_vnn_map);
|
||||||
@ -968,6 +1054,7 @@ COMPAT_TYPE3_TEST(struct ctdb_tunable, ctdb_tunable);
|
|||||||
COMPAT_TYPE3_TEST(struct ctdb_node_flag_change, ctdb_node_flag_change);
|
COMPAT_TYPE3_TEST(struct ctdb_node_flag_change, ctdb_node_flag_change);
|
||||||
COMPAT_TYPE3_TEST(struct ctdb_var_list, ctdb_var_list);
|
COMPAT_TYPE3_TEST(struct ctdb_var_list, ctdb_var_list);
|
||||||
COMPAT_TYPE3_TEST(struct ctdb_tunable_list, ctdb_tunable_list);
|
COMPAT_TYPE3_TEST(struct ctdb_tunable_list, ctdb_tunable_list);
|
||||||
|
COMPAT_TYPE3_TEST(struct ctdb_tickle_list, ctdb_tickle_list);
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
@ -994,6 +1081,7 @@ int main(int argc, char *argv[])
|
|||||||
COMPAT_TEST_FUNC(ctdb_node_flag_change)();
|
COMPAT_TEST_FUNC(ctdb_node_flag_change)();
|
||||||
COMPAT_TEST_FUNC(ctdb_var_list)();
|
COMPAT_TEST_FUNC(ctdb_var_list)();
|
||||||
COMPAT_TEST_FUNC(ctdb_tunable_list)();
|
COMPAT_TEST_FUNC(ctdb_tunable_list)();
|
||||||
|
COMPAT_TEST_FUNC(ctdb_tickle_list)();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -66,7 +66,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_tunable, ctdb_tunable);
|
|||||||
PROTOCOL_TYPE3_TEST(struct ctdb_node_flag_change, ctdb_node_flag_change);
|
PROTOCOL_TYPE3_TEST(struct ctdb_node_flag_change, ctdb_node_flag_change);
|
||||||
PROTOCOL_TYPE3_TEST(struct ctdb_var_list, ctdb_var_list);
|
PROTOCOL_TYPE3_TEST(struct ctdb_var_list, ctdb_var_list);
|
||||||
PROTOCOL_TYPE3_TEST(struct ctdb_tunable_list, ctdb_tunable_list);
|
PROTOCOL_TYPE3_TEST(struct ctdb_tunable_list, ctdb_tunable_list);
|
||||||
DEFINE_TEST(struct ctdb_tickle_list, ctdb_tickle_list);
|
PROTOCOL_TYPE3_TEST(struct ctdb_tickle_list, ctdb_tickle_list);
|
||||||
DEFINE_TEST(struct ctdb_addr_info, ctdb_addr_info);
|
DEFINE_TEST(struct ctdb_addr_info, ctdb_addr_info);
|
||||||
DEFINE_TEST(struct ctdb_transdb, ctdb_transdb);
|
DEFINE_TEST(struct ctdb_transdb, ctdb_transdb);
|
||||||
DEFINE_TEST(struct ctdb_uptime, ctdb_uptime);
|
DEFINE_TEST(struct ctdb_uptime, ctdb_uptime);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user