break;
case CTDB_CONTROL_GET_DBMAP:
- ctdb_dbid_map_push(cd->data.dbmap, buf);
+ ctdb_dbid_map_push(cd->data.dbmap, buf, &np);
break;
case CTDB_CONTROL_PULL_DB:
case CTDB_CONTROL_GET_DBMAP:
ret = ctdb_dbid_map_pull(buf, buflen, mem_ctx,
- &cd->data.dbmap);
+ &cd->data.dbmap, &np);
break;
case CTDB_CONTROL_PULL_DB:
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);
+size_t ctdb_dbid_map_len(struct ctdb_dbid_map *in);
+void ctdb_dbid_map_push(struct ctdb_dbid_map *in, uint8_t *buf,
+ size_t *npush);
int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_dbid_map **out);
+ 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);
return 0;
}
-struct ctdb_dbid_map_wire {
- uint32_t num;
- struct ctdb_dbid dbs[1];
-};
-
-size_t ctdb_dbid_map_len(struct ctdb_dbid_map *dbmap)
+size_t ctdb_dbid_map_len(struct ctdb_dbid_map *in)
{
- return sizeof(uint32_t) + dbmap->num * sizeof(struct ctdb_dbid);
+ size_t len;
+
+ len = ctdb_uint32_len(&in->num);
+ if (in->num > 0) {
+ len += in->num * ctdb_dbid_len(&in->dbs[0]);
+ }
+
+ return len;
}
-void ctdb_dbid_map_push(struct ctdb_dbid_map *dbmap, uint8_t *buf)
+void ctdb_dbid_map_push(struct ctdb_dbid_map *in, uint8_t *buf, size_t *npush)
{
- struct ctdb_dbid_map_wire *wire = (struct ctdb_dbid_map_wire *)buf;
+ size_t offset = 0, np;
+ uint32_t i;
- wire->num = dbmap->num;
- memcpy(wire->dbs, dbmap->dbs, dbmap->num * sizeof(struct ctdb_dbid));
+ ctdb_uint32_push(&in->num, buf+offset, &np);
+ offset += np;
+
+ for (i=0; i<in->num; i++) {
+ ctdb_dbid_push(&in->dbs[i], buf+offset, &np);
+ offset += np;
+ }
+
+ *npush = offset;
}
int ctdb_dbid_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_dbid_map **out)
+ struct ctdb_dbid_map **out, size_t *npull)
{
- struct ctdb_dbid_map *dbmap;
- struct ctdb_dbid_map_wire *wire = (struct ctdb_dbid_map_wire *)buf;
+ struct ctdb_dbid_map *val;
+ size_t offset = 0, np;
+ uint32_t i;
+ int ret;
- if (buflen < sizeof(uint32_t)) {
- return EMSGSIZE;
- }
- if (wire->num > buflen / sizeof(struct ctdb_dbid)) {
- return EMSGSIZE;
- }
- if (sizeof(uint32_t) + wire->num * sizeof(struct ctdb_dbid) <
- sizeof(uint32_t)) {
- return EMSGSIZE;
+ val = talloc(mem_ctx, struct ctdb_dbid_map);
+ if (val == NULL) {
+ return ENOMEM;
}
- if (buflen < sizeof(uint32_t) + wire->num * sizeof(struct ctdb_dbid)) {
- return EMSGSIZE;
+
+ ret = ctdb_uint32_pull(buf+offset, buflen-offset, &val->num, &np);
+ if (ret != 0) {
+ goto fail;
}
+ offset += np;
- dbmap = talloc(mem_ctx, struct ctdb_dbid_map);
- if (dbmap == NULL) {
- return ENOMEM;
+ if (val->num == 0) {
+ val->dbs = NULL;
+ goto done;
}
- dbmap->num = wire->num;
+ val->dbs = talloc_array(val, struct ctdb_dbid, val->num);
+ if (val->dbs == NULL) {
+ ret = ENOMEM;
+ goto fail;
+ }
- dbmap->dbs = talloc_memdup(dbmap, wire->dbs,
- wire->num * sizeof(struct ctdb_dbid));
- if (dbmap->dbs == NULL) {
- talloc_free(dbmap);
- return ENOMEM;
+ for (i=0; i<val->num; i++) {
+ ret = ctdb_dbid_pull_elems(buf+offset, buflen-offset, val,
+ &val->dbs[i], &np);
+ if (ret != 0) {
+ goto fail;
+ }
+ offset += np;
}
- *out = dbmap;
+done:
+ *out = val;
+ *npull = offset;
return 0;
+
+fail:
+ talloc_free(val);
+ return ret;
}
size_t ctdb_pulldb_len(struct ctdb_pulldb *pulldb)
p->num = rand_int(40);
if (p->num > 0) {
- p->dbs = talloc_array(mem_ctx, struct ctdb_dbid, p->num);
+ p->dbs = talloc_zero_array(mem_ctx, struct ctdb_dbid, p->num);
assert(p->dbs != NULL);
for (i=0; i<p->num; i++) {
fill_ctdb_dbid(mem_ctx, &p->dbs[i]);
return 0;
}
+struct ctdb_dbid_map_wire {
+ uint32_t num;
+ struct ctdb_dbid dbs[1];
+};
+
+static size_t ctdb_dbid_map_len_old(struct ctdb_dbid_map *in)
+{
+ return sizeof(uint32_t) + in->num * sizeof(struct ctdb_dbid);
+}
+
+static void ctdb_dbid_map_push_old(struct ctdb_dbid_map *in, uint8_t *buf)
+{
+ struct ctdb_dbid_map_wire *wire = (struct ctdb_dbid_map_wire *)buf;
+
+ wire->num = in->num;
+ memcpy(wire->dbs, in->dbs, in->num * sizeof(struct ctdb_dbid));
+}
+
+static int ctdb_dbid_map_pull_old(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_dbid_map **out)
+{
+ struct ctdb_dbid_map *val;
+ struct ctdb_dbid_map_wire *wire = (struct ctdb_dbid_map_wire *)buf;
+
+ if (buflen < sizeof(uint32_t)) {
+ return EMSGSIZE;
+ }
+ if (wire->num > buflen / sizeof(struct ctdb_dbid)) {
+ return EMSGSIZE;
+ }
+ if (sizeof(uint32_t) + wire->num * sizeof(struct ctdb_dbid) <
+ sizeof(uint32_t)) {
+ return EMSGSIZE;
+ }
+ if (buflen < sizeof(uint32_t) + wire->num * sizeof(struct ctdb_dbid)) {
+ return EMSGSIZE;
+ }
+
+ val = talloc(mem_ctx, struct ctdb_dbid_map);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ val->num = wire->num;
+
+ val->dbs = talloc_memdup(val, wire->dbs,
+ wire->num * sizeof(struct ctdb_dbid));
+ if (val->dbs == NULL) {
+ talloc_free(val);
+ 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);
int main(int argc, char *argv[])
{
COMPAT_TEST_FUNC(ctdb_statistics)();
COMPAT_TEST_FUNC(ctdb_vnn_map)();
+ COMPAT_TEST_FUNC(ctdb_dbid_map)();
return 0;
}
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);
+PROTOCOL_TYPE3_TEST(struct ctdb_dbid_map, ctdb_dbid_map);
DEFINE_TEST(struct ctdb_pulldb, ctdb_pulldb);
DEFINE_TEST(struct ctdb_pulldb_ext, ctdb_pulldb_ext);
DEFINE_TEST(struct ctdb_rec_data, ctdb_rec_data);