mirror of
https://github.com/samba-team/samba.git
synced 2025-01-22 22:04:08 +03:00
ctdb-protocol: Fix marshalling for ctdb_statistics_list
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
b03f3b5663
commit
132f201fc1
@ -1535,7 +1535,7 @@ static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_GET_STAT_HISTORY:
|
||||
ctdb_statistics_list_push(cd->data.stats_list, buf);
|
||||
ctdb_statistics_list_push(cd->data.stats_list, buf, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_CHECK_SRVIDS:
|
||||
@ -1719,7 +1719,7 @@ static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
|
||||
|
||||
case CTDB_CONTROL_GET_STAT_HISTORY:
|
||||
ret = ctdb_statistics_list_pull(buf, buflen, mem_ctx,
|
||||
&cd->data.stats_list);
|
||||
&cd->data.stats_list, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_CHECK_SRVIDS:
|
||||
|
@ -111,11 +111,12 @@ void ctdb_statistics_push(struct ctdb_statistics *in, uint8_t *buf,
|
||||
int ctdb_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_statistics **out, size_t *npull);
|
||||
|
||||
size_t ctdb_statistics_list_len(struct ctdb_statistics_list *stats_list);
|
||||
void ctdb_statistics_list_push(struct ctdb_statistics_list *stats_list,
|
||||
uint8_t *buf);
|
||||
size_t ctdb_statistics_list_len(struct ctdb_statistics_list *in);
|
||||
void ctdb_statistics_list_push(struct ctdb_statistics_list *in,
|
||||
uint8_t *buf, size_t *npull);
|
||||
int ctdb_statistics_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_statistics_list **out);
|
||||
struct ctdb_statistics_list **out,
|
||||
size_t *npull);
|
||||
|
||||
size_t ctdb_vnn_map_len(struct ctdb_vnn_map *in);
|
||||
void ctdb_vnn_map_push(struct ctdb_vnn_map *in, uint8_t *buf, size_t *npush);
|
||||
|
@ -779,70 +779,91 @@ int ctdb_statistics_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ctdb_statistics_list_wire {
|
||||
uint32_t num;
|
||||
struct ctdb_statistics stats[1];
|
||||
};
|
||||
|
||||
size_t ctdb_statistics_list_len(struct ctdb_statistics_list *stats_list)
|
||||
size_t ctdb_statistics_list_len(struct ctdb_statistics_list *in)
|
||||
{
|
||||
return offsetof(struct ctdb_statistics_list_wire, stats) +
|
||||
stats_list->num * sizeof(struct ctdb_statistics);
|
||||
size_t len;
|
||||
|
||||
len = ctdb_int32_len(&in->num) + ctdb_padding_len(4);
|
||||
if (in->num > 0) {
|
||||
len += in->num * ctdb_statistics_len(&in->stats[0]);
|
||||
}
|
||||
|
||||
return len;
|
||||
}
|
||||
|
||||
void ctdb_statistics_list_push(struct ctdb_statistics_list *stats_list,
|
||||
uint8_t *buf)
|
||||
void ctdb_statistics_list_push(struct ctdb_statistics_list *in,
|
||||
uint8_t *buf, size_t *npush)
|
||||
{
|
||||
struct ctdb_statistics_list_wire *wire =
|
||||
(struct ctdb_statistics_list_wire *)buf;
|
||||
size_t offset = 0, np;
|
||||
int i;
|
||||
|
||||
wire->num = stats_list->num;
|
||||
memcpy(wire->stats, stats_list->stats,
|
||||
stats_list->num * sizeof(struct ctdb_statistics));
|
||||
ctdb_int32_push(&in->num, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
ctdb_padding_push(4, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
for (i=0; i<in->num; i++) {
|
||||
ctdb_statistics_push(&in->stats[i], buf+offset, &np);
|
||||
offset += np;
|
||||
}
|
||||
|
||||
*npush = offset;
|
||||
}
|
||||
|
||||
int ctdb_statistics_list_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_statistics_list **out)
|
||||
struct ctdb_statistics_list **out,
|
||||
size_t *npull)
|
||||
{
|
||||
struct ctdb_statistics_list *stats_list;
|
||||
struct ctdb_statistics_list_wire *wire =
|
||||
(struct ctdb_statistics_list_wire *)buf;
|
||||
struct ctdb_statistics_list *val;
|
||||
size_t offset = 0, np;
|
||||
int ret, i;
|
||||
|
||||
if (buflen < offsetof(struct ctdb_statistics_list_wire, stats)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (wire->num > buflen / sizeof(struct ctdb_statistics)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (offsetof(struct ctdb_statistics_list_wire, stats) +
|
||||
wire->num * sizeof(struct ctdb_statistics) <
|
||||
offsetof(struct ctdb_statistics_list_wire, stats)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (buflen < offsetof(struct ctdb_statistics_list_wire, stats) +
|
||||
wire->num * sizeof(struct ctdb_statistics)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
stats_list = talloc(mem_ctx, struct ctdb_statistics_list);
|
||||
if (stats_list == NULL) {
|
||||
val = talloc(mem_ctx, struct ctdb_statistics_list);
|
||||
if (val == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
stats_list->num = wire->num;
|
||||
ret = ctdb_int32_pull(buf+offset, buflen-offset, &val->num, &np);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
stats_list->stats = talloc_array(stats_list, struct ctdb_statistics,
|
||||
wire->num);
|
||||
if (stats_list->stats == NULL) {
|
||||
talloc_free(stats_list);
|
||||
return ENOMEM;
|
||||
ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
if (val->num == 0) {
|
||||
val->stats = NULL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
memcpy(stats_list->stats, wire->stats,
|
||||
wire->num * sizeof(struct ctdb_statistics));
|
||||
val->stats = talloc_array(val, struct ctdb_statistics, val->num);
|
||||
if (val->stats == NULL) {
|
||||
ret = ENOMEM;
|
||||
goto fail;
|
||||
}
|
||||
|
||||
*out = stats_list;
|
||||
for (i=0; i<val->num; i++) {
|
||||
ret = ctdb_statistics_pull_elems(buf+offset, buflen-offset,
|
||||
val, &val->stats[i], &np);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
offset += np;
|
||||
}
|
||||
|
||||
done:
|
||||
*out = val;
|
||||
*npull = offset;
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
talloc_free(val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t ctdb_vnn_map_len(struct ctdb_vnn_map *in)
|
||||
|
@ -1189,8 +1189,8 @@ void fill_ctdb_statistics_list(TALLOC_CTX *mem_ctx,
|
||||
|
||||
p->num = rand_int(10);
|
||||
if (p->num > 0) {
|
||||
p->stats = talloc_array(mem_ctx, struct ctdb_statistics,
|
||||
p->num);
|
||||
p->stats = talloc_zero_array(mem_ctx, struct ctdb_statistics,
|
||||
p->num);
|
||||
assert(p->stats != NULL);
|
||||
|
||||
for (i=0; i<p->num; i++) {
|
||||
|
@ -1851,6 +1851,72 @@ static int ctdb_public_ip_info_pull_old(uint8_t *buf, size_t buflen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ctdb_statistics_list_wire {
|
||||
uint32_t num;
|
||||
struct ctdb_statistics stats[1];
|
||||
};
|
||||
|
||||
static size_t ctdb_statistics_list_len_old(struct ctdb_statistics_list *in)
|
||||
{
|
||||
return offsetof(struct ctdb_statistics_list_wire, stats) +
|
||||
in->num * sizeof(struct ctdb_statistics);
|
||||
}
|
||||
|
||||
static void ctdb_statistics_list_push_old(struct ctdb_statistics_list *in,
|
||||
uint8_t *buf)
|
||||
{
|
||||
struct ctdb_statistics_list_wire *wire =
|
||||
(struct ctdb_statistics_list_wire *)buf;
|
||||
|
||||
wire->num = in->num;
|
||||
memcpy(wire->stats, in->stats,
|
||||
in->num * sizeof(struct ctdb_statistics));
|
||||
}
|
||||
|
||||
static int ctdb_statistics_list_pull_old(uint8_t *buf, size_t buflen,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_statistics_list **out)
|
||||
{
|
||||
struct ctdb_statistics_list *val;
|
||||
struct ctdb_statistics_list_wire *wire =
|
||||
(struct ctdb_statistics_list_wire *)buf;
|
||||
|
||||
if (buflen < offsetof(struct ctdb_statistics_list_wire, stats)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (wire->num > buflen / sizeof(struct ctdb_statistics)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (offsetof(struct ctdb_statistics_list_wire, stats) +
|
||||
wire->num * sizeof(struct ctdb_statistics) <
|
||||
offsetof(struct ctdb_statistics_list_wire, stats)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
if (buflen < offsetof(struct ctdb_statistics_list_wire, stats) +
|
||||
wire->num * sizeof(struct ctdb_statistics)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
val = talloc(mem_ctx, struct ctdb_statistics_list);
|
||||
if (val == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
val->num = wire->num;
|
||||
|
||||
val->stats = talloc_array(val, struct ctdb_statistics, wire->num);
|
||||
if (val->stats == NULL) {
|
||||
talloc_free(val);
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
memcpy(val->stats, wire->stats,
|
||||
wire->num * sizeof(struct ctdb_statistics));
|
||||
|
||||
*out = val;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
COMPAT_TYPE3_TEST(struct ctdb_statistics, ctdb_statistics);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_vnn_map, ctdb_vnn_map);
|
||||
@ -1887,6 +1953,7 @@ COMPAT_TYPE3_TEST(struct ctdb_notify_data, ctdb_notify_data);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_iface, ctdb_iface);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_iface_list, ctdb_iface_list);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_public_ip_info, ctdb_public_ip_info);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_statistics_list, ctdb_statistics_list);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -1928,6 +1995,7 @@ int main(int argc, char *argv[])
|
||||
COMPAT_TEST_FUNC(ctdb_iface)();
|
||||
COMPAT_TEST_FUNC(ctdb_iface_list)();
|
||||
COMPAT_TEST_FUNC(ctdb_public_ip_info)();
|
||||
COMPAT_TEST_FUNC(ctdb_statistics_list)();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -81,7 +81,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_notify_data, ctdb_notify_data);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_iface, ctdb_iface);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_iface_list, ctdb_iface_list);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_public_ip_info, ctdb_public_ip_info);
|
||||
DEFINE_TEST(struct ctdb_statistics_list, ctdb_statistics_list);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_statistics_list, ctdb_statistics_list);
|
||||
DEFINE_TEST(struct ctdb_key_data, ctdb_key_data);
|
||||
DEFINE_TEST(struct ctdb_db_statistics, ctdb_db_statistics);
|
||||
DEFINE_TEST(struct ctdb_election_message, ctdb_election_message);
|
||||
|
Loading…
x
Reference in New Issue
Block a user