mirror of
https://github.com/samba-team/samba.git
synced 2024-12-24 21:34:56 +03:00
ctdb-protocol: Add marshalling for ctdb_dbid
Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net>
This commit is contained in:
parent
28734f1bb1
commit
917c0eca0d
@ -122,6 +122,11 @@ void ctdb_vnn_map_push(struct ctdb_vnn_map *in, uint8_t *buf, size_t *npush);
|
||||
int ctdb_vnn_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_vnn_map **out, size_t *npull);
|
||||
|
||||
size_t ctdb_dbid_len(struct ctdb_dbid *in);
|
||||
void ctdb_dbid_push(struct ctdb_dbid *in, uint8_t *buf, size_t *npush);
|
||||
int ctdb_dbid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_dbid **out, size_t *npull);
|
||||
|
||||
size_t ctdb_dbid_map_len(struct ctdb_dbid_map *dbmap);
|
||||
void ctdb_dbid_map_push(struct ctdb_dbid_map *dbmap, uint8_t *buf);
|
||||
int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
|
@ -932,6 +932,81 @@ fail:
|
||||
return ret;
|
||||
}
|
||||
|
||||
size_t ctdb_dbid_len(struct ctdb_dbid *in)
|
||||
{
|
||||
return ctdb_uint32_len(&in->db_id) +
|
||||
ctdb_uint8_len(&in->flags) +
|
||||
ctdb_padding_len(3);
|
||||
}
|
||||
|
||||
void ctdb_dbid_push(struct ctdb_dbid *in, uint8_t *buf, size_t *npush)
|
||||
{
|
||||
size_t offset = 0, np;
|
||||
|
||||
ctdb_uint32_push(&in->db_id, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
ctdb_uint8_push(&in->flags, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
ctdb_padding_push(3, buf+offset, &np);
|
||||
offset += np;
|
||||
|
||||
*npush = offset;
|
||||
}
|
||||
|
||||
static int ctdb_dbid_pull_elems(uint8_t *buf, size_t buflen,
|
||||
TALLOC_CTX *mem_ctx, struct ctdb_dbid *out,
|
||||
size_t *npull)
|
||||
{
|
||||
size_t offset = 0, np;
|
||||
int ret;
|
||||
|
||||
ret = ctdb_uint32_pull(buf+offset, buflen-offset, &out->db_id, &np);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
ret = ctdb_uint8_pull(buf+offset, buflen-offset, &out->flags, &np);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
ret = ctdb_padding_pull(buf+offset, buflen-offset, 3, &np);
|
||||
if (ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
offset += np;
|
||||
|
||||
*npull = offset;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int ctdb_dbid_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
|
||||
struct ctdb_dbid **out, size_t *npull)
|
||||
{
|
||||
struct ctdb_dbid *val;
|
||||
size_t np;
|
||||
int ret;
|
||||
|
||||
val = talloc(mem_ctx, struct ctdb_dbid);
|
||||
if (val == NULL) {
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
ret = ctdb_dbid_pull_elems(buf, buflen, val, val, &np);
|
||||
if (ret != 0) {
|
||||
talloc_free(val);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*out = val;
|
||||
*npull = np;
|
||||
return 0;
|
||||
}
|
||||
|
||||
struct ctdb_dbid_map_wire {
|
||||
uint32_t num;
|
||||
struct ctdb_dbid dbs[1];
|
||||
|
@ -65,6 +65,7 @@ static void test_ctdb_g_lock(void)
|
||||
|
||||
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);
|
||||
DEFINE_TEST(struct ctdb_dbid_map, ctdb_dbid_map);
|
||||
DEFINE_TEST(struct ctdb_pulldb, ctdb_pulldb);
|
||||
DEFINE_TEST(struct ctdb_pulldb_ext, ctdb_pulldb_ext);
|
||||
@ -164,6 +165,7 @@ int main(int argc, char *argv[])
|
||||
|
||||
TEST_FUNC(ctdb_statistics)();
|
||||
TEST_FUNC(ctdb_vnn_map)();
|
||||
TEST_FUNC(ctdb_dbid)();
|
||||
TEST_FUNC(ctdb_dbid_map)();
|
||||
TEST_FUNC(ctdb_pulldb)();
|
||||
TEST_FUNC(ctdb_pulldb_ext)();
|
||||
|
Loading…
Reference in New Issue
Block a user