mirror of
https://github.com/samba-team/samba.git
synced 2024-12-22 13:34:15 +03:00
ctdb-protocol: Fix marshalling for ctdb_uptime
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
e893b46e5e
commit
d7c247dd72
@ -1488,7 +1488,7 @@ static void ctdb_reply_control_data_push(struct ctdb_reply_control_data *cd,
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_UPTIME:
|
||||
ctdb_uptime_push(cd->data.uptime, buf);
|
||||
ctdb_uptime_push(cd->data.uptime, buf, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_TRY_DELETE_RECORDS:
|
||||
@ -1663,7 +1663,7 @@ static int ctdb_reply_control_data_pull(uint8_t *buf, size_t buflen,
|
||||
|
||||
case CTDB_CONTROL_UPTIME:
|
||||
ret = ctdb_uptime_pull(buf, buflen, mem_ctx,
|
||||
&cd->data.uptime);
|
||||
&cd->data.uptime, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_TRY_DELETE_RECORDS:
|
||||
|
@ -226,10 +226,10 @@ void ctdb_transdb_push(struct ctdb_transdb *in, uint8_t *buf, size_t *npush);
|
||||
int ctdb_transdb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_transdb **out, size_t *npull);
|
||||
|
||||
size_t ctdb_uptime_len(struct ctdb_uptime *uptime);
|
||||
void ctdb_uptime_push(struct ctdb_uptime *uptime, uint8_t *buf);
|
||||
size_t ctdb_uptime_len(struct ctdb_uptime *in);
|
||||
void ctdb_uptime_push(struct ctdb_uptime *in, uint8_t *buf, size_t *npush);
|
||||
int ctdb_uptime_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_uptime **out);
|
||||
struct ctdb_uptime **out, size_t *npull);
|
||||
|
||||
size_t ctdb_public_ip_len(struct ctdb_public_ip *public_ip);
|
||||
void ctdb_public_ip_push(struct ctdb_public_ip *public_ip, uint8_t *buf);
|
||||
|
@ -3311,32 +3311,80 @@ fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t ctdb_uptime_len(struct ctdb_uptime *uptime)
|
||||
size_t ctdb_uptime_len(struct ctdb_uptime *in)
|
||||
{
|
||||
return sizeof(struct ctdb_uptime);
|
||||
return ctdb_timeval_len(&in->current_time) +
|
||||
ctdb_timeval_len(&in->ctdbd_start_time) +
|
||||
ctdb_timeval_len(&in->last_recovery_started) +
|
||||
ctdb_timeval_len(&in->last_recovery_finished);
|
||||
}
|
||||
|
||||
void ctdb_uptime_push(struct ctdb_uptime *uptime, uint8_t *buf)
|
||||
void ctdb_uptime_push(struct ctdb_uptime *in, uint8_t *buf, size_t *npush)
|
||||
{
|
||||
memcpy(buf, uptime, sizeof(struct ctdb_uptime));
|
||||
size_t offset = 0, np;
|
||||
|
||||
ctdb_timeval_push(&in->current_time, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
ctdb_timeval_push(&in->ctdbd_start_time, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
ctdb_timeval_push(&in->last_recovery_started, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
ctdb_timeval_push(&in->last_recovery_finished, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
*npush = offset;
|
||||
}
|
||||
|
||||
int ctdb_uptime_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_uptime **out)
|
||||
struct ctdb_uptime **out, size_t *npull)
|
||||
{
|
||||
struct ctdb_uptime *uptime;
|
||||
struct ctdb_uptime *val;
|
||||
size_t offset = 0, np;
|
||||
int ret;
|
||||
|
||||
if (buflen < sizeof(struct ctdb_uptime)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
uptime = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_uptime));
|
||||
if (uptime == NULL) {
|
||||
val = talloc(mem_ctx, struct ctdb_uptime);
|
||||
if (val == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
*out = uptime;
|
||||
ret = ctdb_timeval_pull(buf+offset, buflen-offset, &val->current_time,
|
||||
&np);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
ret = ctdb_timeval_pull(buf+offset, buflen-offset,
|
||||
&val->ctdbd_start_time, &np);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
ret = ctdb_timeval_pull(buf+offset, buflen-offset,
|
||||
&val->last_recovery_started, &np);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
ret = ctdb_timeval_pull(buf+offset, buflen-offset,
|
||||
&val->last_recovery_finished, &np);
|
||||
if (ret != 0) {
|
||||
goto fail;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
*out = val;
|
||||
*npull = offset;
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
talloc_free(val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t ctdb_public_ip_len(struct ctdb_public_ip *pubip)
|
||||
|
@ -951,12 +951,20 @@ void verify_ctdb_transdb(struct ctdb_transdb *p1, struct ctdb_transdb *p2)
|
||||
|
||||
void fill_ctdb_uptime(TALLOC_CTX *mem_ctx, struct ctdb_uptime *p)
|
||||
{
|
||||
fill_buffer(p, sizeof(struct ctdb_uptime));
|
||||
fill_ctdb_timeval(&p->current_time);
|
||||
fill_ctdb_timeval(&p->ctdbd_start_time);
|
||||
fill_ctdb_timeval(&p->last_recovery_started);
|
||||
fill_ctdb_timeval(&p->last_recovery_finished);
|
||||
}
|
||||
|
||||
void verify_ctdb_uptime(struct ctdb_uptime *p1, struct ctdb_uptime *p2)
|
||||
{
|
||||
verify_buffer(p1, p2, sizeof(struct ctdb_uptime));
|
||||
verify_ctdb_timeval(&p1->current_time, &p2->current_time);
|
||||
verify_ctdb_timeval(&p1->ctdbd_start_time, &p2->ctdbd_start_time);
|
||||
verify_ctdb_timeval(&p1->last_recovery_started,
|
||||
&p2->last_recovery_started);
|
||||
verify_ctdb_timeval(&p1->last_recovery_finished,
|
||||
&p2->last_recovery_finished);
|
||||
}
|
||||
|
||||
void fill_ctdb_public_ip(TALLOC_CTX *mem_ctx, struct ctdb_public_ip *p)
|
||||
|
@ -1138,6 +1138,34 @@ static int ctdb_transdb_pull_old(uint8_t *buf, size_t buflen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t ctdb_uptime_len_old(struct ctdb_uptime *in)
|
||||
{
|
||||
return sizeof(struct ctdb_uptime);
|
||||
}
|
||||
|
||||
static void ctdb_uptime_push_old(struct ctdb_uptime *in, uint8_t *buf)
|
||||
{
|
||||
memcpy(buf, in, sizeof(struct ctdb_uptime));
|
||||
}
|
||||
|
||||
static int ctdb_uptime_pull_old(uint8_t *buf, size_t buflen,
|
||||
TALLOC_CTX *mem_ctx, struct ctdb_uptime **out)
|
||||
{
|
||||
struct ctdb_uptime *val;
|
||||
|
||||
if (buflen < sizeof(struct ctdb_uptime)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_uptime));
|
||||
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);
|
||||
@ -1162,6 +1190,7 @@ COMPAT_TYPE3_TEST(struct ctdb_tunable_list, ctdb_tunable_list);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_tickle_list, ctdb_tickle_list);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_addr_info, ctdb_addr_info);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_transdb, ctdb_transdb);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_uptime, ctdb_uptime);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -1191,6 +1220,7 @@ int main(int argc, char *argv[])
|
||||
COMPAT_TEST_FUNC(ctdb_tickle_list)();
|
||||
COMPAT_TEST_FUNC(ctdb_addr_info)();
|
||||
COMPAT_TEST_FUNC(ctdb_transdb)();
|
||||
COMPAT_TEST_FUNC(ctdb_uptime)();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -69,7 +69,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_tunable_list, ctdb_tunable_list);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_tickle_list, ctdb_tickle_list);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_addr_info, ctdb_addr_info);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_transdb, ctdb_transdb);
|
||||
DEFINE_TEST(struct ctdb_uptime, ctdb_uptime);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_uptime, ctdb_uptime);
|
||||
DEFINE_TEST(struct ctdb_public_ip, ctdb_public_ip);
|
||||
DEFINE_TEST(struct ctdb_public_ip_list, ctdb_public_ip_list);
|
||||
DEFINE_TEST(struct ctdb_node_and_flags, ctdb_node_and_flags);
|
||||
|
Loading…
Reference in New Issue
Block a user