Esempio n. 1
0
static void test_req_control_data_test(void)
{
	TALLOC_CTX *mem_ctx;
	size_t buflen;
	int ret;
	struct ctdb_req_control_data cd, cd2;
	uint32_t opcode;

	printf("ctdb_req_control_data\n");
	fflush(stdout);

	for (opcode=0; opcode<NUM_CONTROLS; opcode++) {
		mem_ctx = talloc_new(NULL);
		assert(mem_ctx != NULL);

		printf("%u.. ", opcode);
		fflush(stdout);
		fill_ctdb_req_control_data(mem_ctx, &cd, opcode);
		buflen = ctdb_req_control_data_len(&cd);
		ctdb_req_control_data_push(&cd, BUFFER);
		ret = ctdb_req_control_data_pull(BUFFER, buflen, opcode, mem_ctx, &cd2);
		assert(ret == 0);
		verify_ctdb_req_control_data(&cd, &cd2);
		talloc_free(mem_ctx);
	}

	printf("\n");
	fflush(stdout);
}
Esempio n. 2
0
size_t ctdb_req_control_len(struct ctdb_req_header *h,
			    struct ctdb_req_control *c)
{
	uint32_t u32 = 0;

	return ctdb_req_header_len(h) +
		ctdb_uint32_len(&c->opcode) +
		ctdb_uint32_len(&c->pad) +
		ctdb_uint64_len(&c->srvid) +
		ctdb_uint32_len(&c->client_id) +
		ctdb_uint32_len(&c->flags) +
		ctdb_uint32_len(&u32) +
		ctdb_req_control_data_len(&c->rdata);
}
Esempio n. 3
0
int ctdb_req_control_push(struct ctdb_req_header *h,
			  struct ctdb_req_control *c,
			  uint8_t *buf, size_t *buflen)
{
	size_t offset = 0, np;
	size_t length;
	uint32_t u32;

	length = ctdb_req_control_len(h, c);
	if (*buflen < length) {
		*buflen = length;
		return EMSGSIZE;
	}

	h->length = *buflen;
	ctdb_req_header_push(h, buf+offset, &np);
	offset += np;

	ctdb_uint32_push(&c->opcode, buf+offset, &np);
	offset += np;

	ctdb_uint32_push(&c->pad, buf+offset, &np);
	offset += np;

	ctdb_uint64_push(&c->srvid, buf+offset, &np);
	offset += np;

	ctdb_uint32_push(&c->client_id, buf+offset, &np);
	offset += np;

	ctdb_uint32_push(&c->flags, buf+offset, &np);
	offset += np;

	u32 = ctdb_req_control_data_len(&c->rdata);
	ctdb_uint32_push(&u32, buf+offset, &np);
	offset += np;

	ctdb_req_control_data_push(&c->rdata, buf+offset, &np);
	offset += np;

	if (offset > *buflen) {
		return EMSGSIZE;
	}

	return 0;
}
Esempio n. 4
0
int ctdb_req_control_push(struct ctdb_req_header *h,
			  struct ctdb_req_control *request,
			  TALLOC_CTX *mem_ctx,
			  uint8_t **pkt, size_t *pkt_len)
{
	struct ctdb_req_control_wire *wire;
	uint8_t *buf;
	size_t length, buflen, datalen;
	int ret;

	datalen = ctdb_req_control_data_len(&request->rdata);
	length = offsetof(struct ctdb_req_control_wire, data) + datalen;

	ret = allocate_pkt(mem_ctx, length, &buf, &buflen);
	if (ret != 0) {
		return ret;
	}

	wire = (struct ctdb_req_control_wire *)buf;

	h->length = buflen;
	memcpy(&wire->hdr, h, sizeof(struct ctdb_req_header));

	wire->opcode = request->opcode;
	wire->pad = request->pad;
	wire->srvid = request->srvid;
	wire->client_id = request->client_id;
	wire->flags = request->flags;

	wire->datalen = datalen;
	ctdb_req_control_data_push(&request->rdata, wire->data);

	*pkt = buf;
	*pkt_len = buflen;
	return 0;
}