mirror of
https://github.com/samba-team/samba.git
synced 2025-01-22 22:04:08 +03:00
ctdb-protocol: Fix marshalling for ctdb_pulldb
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
e347e2b496
commit
ba0b0903ea
@ -464,7 +464,7 @@ static void ctdb_req_control_data_push(struct ctdb_req_control_data *cd,
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_PULL_DB:
|
||||
ctdb_pulldb_push(cd->data.pulldb, buf);
|
||||
ctdb_pulldb_push(cd->data.pulldb, buf, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_PUSH_DB:
|
||||
@ -748,7 +748,7 @@ static int ctdb_req_control_data_pull(uint8_t *buf, size_t buflen,
|
||||
|
||||
case CTDB_CONTROL_PULL_DB:
|
||||
ret = ctdb_pulldb_pull(buf, buflen, mem_ctx,
|
||||
&cd->data.pulldb);
|
||||
&cd->data.pulldb, &np);
|
||||
break;
|
||||
|
||||
case CTDB_CONTROL_PUSH_DB:
|
||||
|
@ -133,10 +133,10 @@ void ctdb_dbid_map_push(struct ctdb_dbid_map *in, uint8_t *buf,
|
||||
int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_dbid_map **out, size_t *npull);
|
||||
|
||||
size_t ctdb_pulldb_len(struct ctdb_pulldb *pulldb);
|
||||
void ctdb_pulldb_push(struct ctdb_pulldb *pulldb, uint8_t *buf);
|
||||
size_t ctdb_pulldb_len(struct ctdb_pulldb *in);
|
||||
void ctdb_pulldb_push(struct ctdb_pulldb *in, uint8_t *buf, size_t *npush);
|
||||
int ctdb_pulldb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_pulldb **out);
|
||||
struct ctdb_pulldb **out, size_t *npull);
|
||||
|
||||
size_t ctdb_pulldb_ext_len(struct ctdb_pulldb_ext *pulldb);
|
||||
void ctdb_pulldb_ext_push(struct ctdb_pulldb_ext *pulldb, uint8_t *buf);
|
||||
|
@ -1084,31 +1084,53 @@ fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t ctdb_pulldb_len(struct ctdb_pulldb *pulldb)
|
||||
size_t ctdb_pulldb_len(struct ctdb_pulldb *in)
|
||||
{
|
||||
return sizeof(struct ctdb_pulldb);
|
||||
return ctdb_uint32_len(&in->db_id) +
|
||||
ctdb_uint32_len(&in->lmaster);
|
||||
}
|
||||
|
||||
void ctdb_pulldb_push(struct ctdb_pulldb *pulldb, uint8_t *buf)
|
||||
void ctdb_pulldb_push(struct ctdb_pulldb *in, uint8_t *buf, size_t *npush)
|
||||
{
|
||||
memcpy(buf, pulldb, sizeof(struct ctdb_pulldb));
|
||||
size_t offset = 0, np;
|
||||
|
||||
ctdb_uint32_push(&in->db_id, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
ctdb_uint32_push(&in->lmaster, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
*npush = offset;
|
||||
}
|
||||
|
||||
int ctdb_pulldb_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_pulldb **out)
|
||||
struct ctdb_pulldb **out, size_t *npull)
|
||||
{
|
||||
struct ctdb_pulldb *pulldb;
|
||||
struct ctdb_pulldb *val;
|
||||
size_t offset = 0, np;
|
||||
int ret;
|
||||
|
||||
if (buflen < sizeof(struct ctdb_pulldb)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
pulldb = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_pulldb));
|
||||
if (pulldb == NULL) {
|
||||
val = talloc(mem_ctx, struct ctdb_pulldb);
|
||||
if (val == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
*out = pulldb;
|
||||
ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->db_id, &np);
|
||||
if (ret != 0) {
|
||||
talloc_free(val);
|
||||
return ret;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->lmaster, &np);
|
||||
if (ret != 0) {
|
||||
talloc_free(val);
|
||||
return ret;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
*out = val;
|
||||
*npull = offset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -242,10 +242,39 @@ static int ctdb_dbid_map_pull_old(uint8_t *buf, size_t buflen,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static size_t ctdb_pulldb_len_old(struct ctdb_pulldb *in)
|
||||
{
|
||||
return sizeof(struct ctdb_pulldb);
|
||||
}
|
||||
|
||||
static void ctdb_pulldb_push_old(struct ctdb_pulldb *in, uint8_t *buf)
|
||||
{
|
||||
memcpy(buf, in, sizeof(struct ctdb_pulldb));
|
||||
}
|
||||
|
||||
static int ctdb_pulldb_pull_old(uint8_t *buf, size_t buflen,
|
||||
TALLOC_CTX *mem_ctx, struct ctdb_pulldb **out)
|
||||
{
|
||||
struct ctdb_pulldb *val;
|
||||
|
||||
if (buflen < sizeof(struct ctdb_pulldb)) {
|
||||
return EMSGSIZE;
|
||||
}
|
||||
|
||||
val = talloc_memdup(mem_ctx, buf, sizeof(struct ctdb_pulldb));
|
||||
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);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_dbid_map, ctdb_dbid_map);
|
||||
COMPAT_TYPE3_TEST(struct ctdb_pulldb, ctdb_pulldb);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
@ -257,6 +286,7 @@ int main(int argc, char *argv[])
|
||||
COMPAT_TEST_FUNC(ctdb_statistics)();
|
||||
COMPAT_TEST_FUNC(ctdb_vnn_map)();
|
||||
COMPAT_TEST_FUNC(ctdb_dbid_map)();
|
||||
COMPAT_TEST_FUNC(ctdb_pulldb)();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -67,7 +67,7 @@ PROTOCOL_TYPE3_TEST(struct ctdb_statistics, ctdb_statistics);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_vnn_map, ctdb_vnn_map);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_dbid, ctdb_dbid);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_dbid_map, ctdb_dbid_map);
|
||||
DEFINE_TEST(struct ctdb_pulldb, ctdb_pulldb);
|
||||
PROTOCOL_TYPE3_TEST(struct ctdb_pulldb, ctdb_pulldb);
|
||||
DEFINE_TEST(struct ctdb_pulldb_ext, ctdb_pulldb_ext);
|
||||
DEFINE_TEST(struct ctdb_rec_data, ctdb_rec_data);
|
||||
DEFINE_TEST(struct ctdb_rec_buffer, ctdb_rec_buffer);
|
||||
|
Loading…
x
Reference in New Issue
Block a user