int ctdb_node_map_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
struct ctdb_node_map **out, size_t *npull);
-size_t ctdb_script_len(struct ctdb_script *script);
-void ctdb_script_push(struct ctdb_script *script, uint8_t *buf);
+size_t ctdb_script_len(struct ctdb_script *in);
+void ctdb_script_push(struct ctdb_script *in, uint8_t *buf, size_t *npush);
int ctdb_script_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_script **out);
+ struct ctdb_script **out, size_t *npull);
size_t ctdb_script_list_len(struct ctdb_script_list *script_list);
void ctdb_script_list_push(struct ctdb_script_list *script_list, uint8_t *buf);
return ret;
}
-size_t ctdb_script_len(struct ctdb_script *script)
+size_t ctdb_script_len(struct ctdb_script *in)
{
- return sizeof(struct ctdb_script);
+ return ctdb_chararray_len(in->name, MAX_SCRIPT_NAME+1) +
+ ctdb_timeval_len(&in->start) +
+ ctdb_timeval_len(&in->finished) +
+ ctdb_int32_len(&in->status) +
+ ctdb_chararray_len(in->output, MAX_SCRIPT_OUTPUT+1) +
+ ctdb_padding_len(4);
}
-void ctdb_script_push(struct ctdb_script *script, uint8_t *buf)
+void ctdb_script_push(struct ctdb_script *in, uint8_t *buf, size_t *npush)
{
- memcpy(buf, script, sizeof(struct ctdb_script));
+ size_t offset = 0, np;
+
+ ctdb_chararray_push(in->name, MAX_SCRIPT_NAME+1, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->start, buf+offset, &np);
+ offset += np;
+
+ ctdb_timeval_push(&in->finished, buf+offset, &np);
+ offset += np;
+
+ ctdb_int32_push(&in->status, buf+offset, &np);
+ offset += np;
+
+ ctdb_chararray_push(in->output, MAX_SCRIPT_OUTPUT+1, buf+offset, &np);
+ offset += np;
+
+ ctdb_padding_push(4, buf+offset, &np);
+ offset += np;
+
+ *npush = offset;
}
static int ctdb_script_pull_elems(uint8_t *buf, size_t buflen,
TALLOC_CTX *mem_ctx,
- struct ctdb_script *out)
+ struct ctdb_script *out, size_t *npull)
{
- if (buflen < sizeof(struct ctdb_script)) {
- return EMSGSIZE;
+ size_t offset = 0, np;
+ int ret;
+
+ ret = ctdb_chararray_pull(buf+offset, buflen-offset,
+ out->name, MAX_SCRIPT_NAME+1, &np);
+ if (ret != 0) {
+ return ret;
}
+ offset += np;
- memcpy(out, buf, sizeof(struct ctdb_script));
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->start, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+ ret = ctdb_timeval_pull(buf+offset, buflen-offset, &out->finished,
+ &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_int32_pull(buf+offset, buflen-offset, &out->status, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_chararray_pull(buf+offset, buflen-offset,
+ out->output, MAX_SCRIPT_OUTPUT+1, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ ret = ctdb_padding_pull(buf+offset, buflen-offset, 4, &np);
+ if (ret != 0) {
+ return ret;
+ }
+ offset += np;
+
+ *npull = offset;
return 0;
}
int ctdb_script_pull(uint8_t *buf, size_t buflen, TALLOC_CTX *mem_ctx,
- struct ctdb_script **out)
+ struct ctdb_script **out, size_t *npull)
{
- struct ctdb_script *script;
+ struct ctdb_script *val;
+ size_t np;
int ret;
- script = talloc(mem_ctx, struct ctdb_script);
- if (script == NULL) {
+ val = talloc(mem_ctx, struct ctdb_script);
+ if (val == NULL) {
return ENOMEM;
}
- ret = ctdb_script_pull_elems(buf, buflen, script, script);
+ ret = ctdb_script_pull_elems(buf, buflen, val, val, &np);
if (ret != 0) {
- TALLOC_FREE(script);
+ TALLOC_FREE(val);
+ return ret;
}
- *out = script;
+ *out = val;
+ *npull = np;
return ret;
}
{
struct ctdb_script_list_wire *wire =
(struct ctdb_script_list_wire *)buf;
- size_t offset;
+ size_t offset, np;
int i;
if (script_list == NULL) {
offset = offsetof(struct ctdb_script_list_wire, script);
for (i=0; i<script_list->num_scripts; i++) {
- ctdb_script_push(&script_list->script[i], &buf[offset]);
- offset += ctdb_script_len(&script_list->script[i]);
+ ctdb_script_push(&script_list->script[i], &buf[offset], &np);
+ offset += np;
}
}
struct ctdb_script_list *script_list;
struct ctdb_script_list_wire *wire =
(struct ctdb_script_list_wire *)buf;
- size_t offset;
+ size_t offset, np;
int i;
bool ret;
for (i=0; i<wire->num_scripts; i++) {
ret = ctdb_script_pull_elems(&buf[offset], buflen-offset,
script_list->script,
- &script_list->script[i]);
+ &script_list->script[i], &np);
if (ret != 0) {
talloc_free(script_list);
return ret;
}
- offset += ctdb_script_len(&script_list->script[i]);
+ offset += np;
}
*out = script_list;
void fill_ctdb_script(TALLOC_CTX *mem_ctx, struct ctdb_script *p)
{
- fill_buffer(p, sizeof(struct ctdb_script));
+ fill_string(p->name, MAX_SCRIPT_NAME+1);
+ fill_ctdb_timeval(&p->start);
+ fill_ctdb_timeval(&p->finished);
+ p->status = rand32i();
+ fill_string(p->output, MAX_SCRIPT_OUTPUT+1);
}
void verify_ctdb_script(struct ctdb_script *p1, struct ctdb_script *p2)
{
- verify_buffer(p1, p2, sizeof(struct ctdb_script));
+ verify_string(p1->name, p2->name);
+ verify_ctdb_timeval(&p1->start, &p2->start);
+ verify_ctdb_timeval(&p1->finished, &p2->finished);
+ assert(p1->status == p2->status);
+ verify_string(p1->output, p2->output);
}
void fill_ctdb_script_list(TALLOC_CTX *mem_ctx, struct ctdb_script_list *p)
return 0;
}
+static size_t ctdb_script_len_old(struct ctdb_script *in)
+{
+ return sizeof(struct ctdb_script);
+}
+
+static void ctdb_script_push_old(struct ctdb_script *in, uint8_t *buf)
+{
+ memcpy(buf, in, sizeof(struct ctdb_script));
+}
+
+static int ctdb_script_pull_elems_old(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx,
+ struct ctdb_script *out)
+{
+ if (buflen < sizeof(struct ctdb_script)) {
+ return EMSGSIZE;
+ }
+
+ memcpy(out, buf, sizeof(struct ctdb_script));
+
+ return 0;
+}
+
+static int ctdb_script_pull_old(uint8_t *buf, size_t buflen,
+ TALLOC_CTX *mem_ctx, struct ctdb_script **out)
+{
+ struct ctdb_script *val;
+ int ret;
+
+ val = talloc(mem_ctx, struct ctdb_script);
+ if (val == NULL) {
+ return ENOMEM;
+ }
+
+ ret = ctdb_script_pull_elems_old(buf, buflen, val, val);
+ if (ret != 0) {
+ TALLOC_FREE(val);
+ return ret;
+ }
+
+ *out = val;
+ return ret;
+}
+
COMPAT_TYPE3_TEST(struct ctdb_statistics, ctdb_statistics);
COMPAT_TYPE3_TEST(struct ctdb_vnn_map, ctdb_vnn_map);
COMPAT_TYPE3_TEST(struct ctdb_public_ip_list, ctdb_public_ip_list);
COMPAT_TYPE3_TEST(struct ctdb_node_and_flags, ctdb_node_and_flags);
COMPAT_TYPE3_TEST(struct ctdb_node_map, ctdb_node_map);
+COMPAT_TYPE3_TEST(struct ctdb_script, ctdb_script);
int main(int argc, char *argv[])
{
COMPAT_TEST_FUNC(ctdb_public_ip_list)();
COMPAT_TEST_FUNC(ctdb_node_and_flags)();
COMPAT_TEST_FUNC(ctdb_node_map)();
+ COMPAT_TEST_FUNC(ctdb_script)();
return 0;
}