mirror of
https://github.com/samba-team/samba.git
synced 2025-02-02 09:47:23 +03:00
ctdb-protocol: Fix marshalling for ctdb_connection
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
32539cd5cc
commit
7f34ad2a82
@ -511,15 +511,15 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_TCP_CLIENT:
|
||||
ctdb_connection_push(cd->data.conn, buf);
|
||||
ctdb_connection_push(cd->data.conn, buf, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_TCP_ADD:
|
||||
ctdb_connection_push(cd->data.conn, buf);
|
||||
ctdb_connection_push(cd->data.conn, buf, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_TCP_REMOVE:
|
||||
ctdb_connection_push(cd->data.conn, buf);
|
||||
ctdb_connection_push(cd->data.conn, buf, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_SET_TUNABLE:
|
||||
@ -637,7 +637,7 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
|
||||
ctdb_connection_push(cd->data.conn, buf);
|
||||
ctdb_connection_push(cd->data.conn, buf, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
|
||||
@ -803,17 +803,17 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
|
||||
|
||||
case CTDB_CONTROL_TCP_CLIENT:
|
||||
ret = ctdb_connection_pull(buf, buflen, mem_ctx,
|
||||
&cd->data.conn);
|
||||
&cd->data.conn, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_TCP_ADD:
|
||||
ret = ctdb_connection_pull(buf, buflen, mem_ctx,
|
||||
&cd->data.conn);
|
||||
&cd->data.conn, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_TCP_REMOVE:
|
||||
ret = ctdb_connection_pull(buf, buflen, mem_ctx,
|
||||
&cd->data.conn);
|
||||
&cd->data.conn, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_SET_TUNABLE:
|
||||
@ -955,7 +955,7 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
|
||||
|
||||
case CTDB_CONTROL_TCP_ADD_DELAYED_UPDATE:
|
||||
ret = ctdb_connection_pull(buf, buflen, mem_ctx,
|
||||
&cd->data.conn);
|
||||
&cd->data.conn, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_SCHEDULE_FOR_DELETION:
|
||||
|
@ -180,10 +180,11 @@ int ctdb_sock_addr_pull_elems(uint8_t *buf, size_t buflen,
|
||||
int ctdb_sock_addr_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
ctdb_sock_addr **out, size_t *npull);
|
||||
|
||||
size_t ctdb_connection_len(struct ctdb_connection *conn);
|
||||
void ctdb_connection_push(struct ctdb_connection *conn, uint8_t *buf);
|
||||
size_t ctdb_connection_len(struct ctdb_connection *in);
|
||||
void ctdb_connection_push(struct ctdb_connection *in, uint8_t *buf,
|
||||
size_t *npush);
|
||||
int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_connection **out);
|
||||
struct ctdb_connection **out, size_t *npull);
|
||||
|
||||
size_t ctdb_tunable_len(struct ctdb_tunable *tunable);
|
||||
void ctdb_tunable_push(struct ctdb_tunable *tunable, uint8_t *buf);
|
||||
|
@ -2081,46 +2081,72 @@ int ctdb_sock_addr_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t ctdb_connection_len(struct ctdb_connection *conn)
|
||||
size_t ctdb_connection_len(struct ctdb_connection *in)
|
||||
{
|
||||
return sizeof(struct ctdb_connection);
|
||||
return ctdb_sock_addr_len(&in->src) +
|
||||
ctdb_sock_addr_len(&in->dst);
|
||||
}
|
||||
|
||||
void ctdb_connection_push(struct ctdb_connection *conn, uint8_t *buf)
|
||||
void ctdb_connection_push(struct ctdb_connection *in, uint8_t *buf,
|
||||
size_t *npush)
|
||||
{
|
||||
memcpy(buf, conn, sizeof(struct ctdb_connection));
|
||||
size_t offset = 0, np;
|
||||
|
||||
ctdb_sock_addr_push(&in->src, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
ctdb_sock_addr_push(&in->dst, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
*npush = offset;
|
||||
}
|
||||
|
||||
static int ctdb_connection_pull_elems(uint8_t *buf, size_t buflen,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_connection *out)
|
||||
struct ctdb_connection *out,
|
||||
size_t *npull)
|
||||
{
|
||||
if (buflen < sizeof(struct ctdb_connection)) {
|
||||
return EMSGSIZE;
|
||||
size_t offset = 0, np;
|
||||
int ret;
|
||||
|
||||
ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
|
||||
mem_ctx, &out->src, &np);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
memcpy(out, buf, sizeof(struct ctdb_connection));
|
||||
ret = ctdb_sock_addr_pull_elems(buf+offset, buflen-offset,
|
||||
mem_ctx, &out->dst, &np);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
*npull = offset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ctdb_connection_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_connection **out)
|
||||
struct ctdb_connection **out, size_t *npull)
|
||||
{
|
||||
struct ctdb_connection *conn;
|
||||
struct ctdb_connection *val;
|
||||
size_t np;
|
||||
int ret;
|
||||
|
||||
conn = talloc(mem_ctx, struct ctdb_connection);
|
||||
if (conn == NULL) {
|
||||
val = talloc(mem_ctx, struct ctdb_connection);
|
||||
if (val == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
ret = ctdb_connection_pull_elems(buf, buflen, conn, conn);
|
||||
ret = ctdb_connection_pull_elems(buf, buflen, val, val, &np);
|
||||
if (ret != 0) {
|
||||
TALLOC_FREE(conn);
|
||||
talloc_free(val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*out = conn;
|
||||
*out = val;
|
||||
*npull = np;
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -2346,7 +2372,7 @@ void ctdb_tickle_list_push(struct ctdb_tickle_list *tickles, uint8_t *buf)
|
||||
{
|
||||
struct ctdb_tickle_list_wire *wire =
|
||||
(struct ctdb_tickle_list_wire *)buf;
|
||||
size_t offset;
|
||||
size_t offset, np;
|
||||
int i;
|
||||
|
||||
memcpy(&wire->addr, &tickles->addr, sizeof(ctdb_sock_addr));
|
||||
@ -2354,8 +2380,8 @@ void ctdb_tickle_list_push(struct ctdb_tickle_list *tickles, uint8_t *buf)
|
||||
|
||||
offset = offsetof(struct ctdb_tickle_list_wire, conn);
|
||||
for (i=0; i<tickles->num; i++) {
|
||||
ctdb_connection_push(&tickles->conn[i], &buf[offset]);
|
||||
offset += ctdb_connection_len(&tickles->conn[i]);
|
||||
ctdb_connection_push(&tickles->conn[i], &buf[offset], &np);
|
||||
offset += np;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2365,7 +2391,7 @@ int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_tickle_list *tickles;
|
||||
struct ctdb_tickle_list_wire *wire =
|
||||
(struct ctdb_tickle_list_wire *)buf;
|
||||
size_t offset;
|
||||
size_t offset, np;
|
||||
int i, ret;
|
||||
|
||||
if (buflen < offsetof(struct ctdb_tickle_list_wire, conn)) {
|
||||
@ -2402,12 +2428,12 @@ int ctdb_tickle_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
for (i=0; i<wire->num; i++) {
|
||||
ret = ctdb_connection_pull_elems(&buf[offset], buflen-offset,
|
||||
tickles->conn,
|
||||
&tickles->conn[i]);
|
||||
&tickles->conn[i], &np);
|
||||
if (ret != 0) {
|
||||
talloc_free(tickles);
|
||||
return ret;
|
||||
}
|
||||
offset += ctdb_connection_len(&tickles->conn[i]);
|
||||
offset += np;
|
||||
}
|
||||
|
||||
*out = tickles;
|
||||
|
@ -691,6 +691,51 @@ static int ctdb_sock_addr_pull_old(uint8_t *buf, size_t buflen,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static size_t ctdb_connection_len_old(struct ctdb_connection *in)
|
||||
{
|
||||
return sizeof(struct ctdb_connection);
|
||||
}
|
||||
|
||||
static void ctdb_connection_push_old(struct ctdb_connection *in, uint8_t *buf)
|
||||
{
|
||||
memcpy(buf, in, sizeof(struct ctdb_connection));
|
||||
}
|
||||
|
||||
static int ctdb_connection_pull_elems_old(uint8_t *buf, size_t buflen,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_connection *out)
|
||||
{
|
||||
if (buflen < sizeof(struct ctdb_connection)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
memcpy(out, buf, sizeof(struct ctdb_connection));
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int ctdb_connection_pull_old(uint8_t *buf, size_t buflen,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_connection **out)
|
||||
{
|
||||
struct ctdb_connection *val;
|
||||
int ret;
|
||||
|
||||
val = talloc(mem_ctx, struct ctdb_connection);
|
||||
if (val == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
ret = ctdb_connection_pull_elems_old(buf, buflen, val, val);
|
||||
if (ret != 0) {
|
||||
TALLOC_FREE(val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*out = val;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
COMPAT_TYPE3_TEST(struct ctdb_statistics, ctdb_statistics);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_vnn_map, ctdb_vnn_map);
|
||||
@ -707,6 +752,7 @@ COMPAT_TYPE3_TEST(struct ctdb_traverse_all, ctdb_traverse_all);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_traverse_start_ext, ctdb_traverse_start_ext);
|
||||
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);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -728,6 +774,7 @@ int main(int argc, char *argv[])
|
||||
COMPAT_TEST_FUNC(ctdb_traverse_start_ext)();
|
||||
COMPAT_TEST_FUNC(ctdb_traverse_all_ext)();
|
||||
COMPAT_TEST_FUNC(ctdb_sock_addr)();
|
||||
COMPAT_TEST_FUNC(ctdb_connection)();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -61,7 +61,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_traverse_all, ctdb_traverse_all);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_traverse_start_ext, ctdb_traverse_start_ext);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_traverse_all_ext, ctdb_traverse_all_ext);
|
||||
PROTOCOL_TYPE3_TEST(ctdb_sock_addr, ctdb_sock_addr);
|
||||
DEFINE_TEST(struct ctdb_connection, ctdb_connection);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_connection, ctdb_connection);
|
||||
DEFINE_TEST(struct ctdb_tunable, ctdb_tunable);
|
||||
DEFINE_TEST(struct ctdb_node_flag_change, ctdb_node_flag_change);
|
||||
DEFINE_TEST(struct ctdb_var_list, ctdb_var_list);
|
||||
|
Loading…
x
Reference in New Issue
Block a user