Ejemplo n.º 1
0
int update_node_list(int max_nodes, uint32_t epoch)
{
	int fd, ret;
	unsigned int size;
	char *buf = NULL;
	struct sd_node *ent;
	struct sd_node_req hdr;
	struct sd_node_rsp *rsp = (struct sd_node_rsp *)&hdr;

	fd = connect_to(sdhost, sdport);
	if (fd < 0)
		return -1;

	size = sizeof(*ent) * max_nodes;
	buf = xzalloc(size);
	sd_init_req((struct sd_req *)&hdr, SD_OP_GET_NODE_LIST);
	hdr.request_ver = epoch;

	hdr.data_length = size;

	ret = collie_exec_req(fd, (struct sd_req *)&hdr, buf);
	if (ret) {
		ret = -1;
		goto out;
	}

	if (rsp->result != SD_RES_SUCCESS) {
		fprintf(stderr, "Failed to update node list: %s\n",
				sd_strerror(rsp->result));
		ret = -1;
		goto out;
	}

	size = rsp->data_length;
	sd_nodes_nr = size / sizeof(*ent);
	if (sd_nodes_nr == 0) {
		fprintf(stderr, "There are no active sheep daemons\n");
		exit(EXIT_FAILURE);
	}

	/* FIXME */
	if (sd_nodes_nr > max_nodes) {
		ret = -1;
		goto out;
	}

	memcpy(sd_nodes, buf, size);
	sd_vnodes_nr = nodes_to_vnodes(sd_nodes, sd_nodes_nr, sd_vnodes);
	sd_epoch = hdr.epoch;
	master_idx = rsp->master_idx;
out:
	if (buf)
		free(buf);
	if (fd >= 0)
		close(fd);

	return ret;
}
Ejemplo n.º 2
0
int update_node_list(int max_nodes)
{
	int ret;
	unsigned int size;
	char *buf = NULL;
	struct sd_node *ent;
	struct sd_req hdr;
	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;

	size = sizeof(*ent) * max_nodes;
	buf = xzalloc(size);
	sd_init_req(&hdr, SD_OP_GET_NODE_LIST);

	hdr.data_length = size;

	ret = dog_exec_req(sdhost, sdport, &hdr, buf);
	if (ret < 0)
		goto out;

	if (rsp->result != SD_RES_SUCCESS) {
		sd_err("Failed to update node list: %s",
		       sd_strerror(rsp->result));
		ret = -1;
		goto out;
	}

	size = rsp->data_length;
	sd_nodes_nr = size / sizeof(*ent);
	if (sd_nodes_nr == 0) {
		sd_err("There are no active sheep daemons");
		exit(EXIT_FAILURE);
	}

	/* FIXME */
	if (sd_nodes_nr > max_nodes) {
		ret = -1;
		goto out;
	}

	memcpy(sd_nodes, buf, size);
	sd_vnodes_nr = nodes_to_vnodes(sd_nodes, sd_nodes_nr, sd_vnodes);
	sd_epoch = hdr.epoch;
out:
	if (buf)
		free(buf);

	return ret;
}
Ejemplo n.º 3
0
static int update_vnode_info(void)
{
	struct vnode_info *vnode_info;

	vnode_info = zalloc(sizeof(*vnode_info));
	if (!vnode_info) {
		eprintf("failed to allocate memory\n");
		return 1;
	}

	vnode_info->nr_vnodes = nodes_to_vnodes(sys->nodes, sys->nr_nodes,
						vnode_info->entries);
	vnode_info->nr_zones = get_zones_nr_from(sys->nodes, sys->nr_nodes);
	vnode_info->refcnt = 1;

	put_vnode_info(current_vnode_info);
	current_vnode_info = vnode_info;
	return 0;
}
Ejemplo n.º 4
0
struct vnode_info *alloc_vnode_info(struct sd_node *nodes,
					   size_t nr_nodes)
{
	struct vnode_info *vnode_info;

	vnode_info = xzalloc(sizeof(*vnode_info));

	vnode_info->nr_nodes = nr_nodes;
	memcpy(vnode_info->nodes, nodes, sizeof(*nodes) * nr_nodes);
	qsort(vnode_info->nodes, nr_nodes, sizeof(*nodes), node_id_cmp);

	recalculate_vnodes(vnode_info->nodes, nr_nodes);

	vnode_info->nr_vnodes = nodes_to_vnodes(vnode_info->nodes, nr_nodes,
						vnode_info->vnodes);
	vnode_info->nr_zones = get_zones_nr_from(nodes, nr_nodes);
	uatomic_set(&vnode_info->refcnt, 1);
	return vnode_info;
}
Ejemplo n.º 5
0
int update_node_list(int max_nodes)
{
	int ret;
	unsigned int size;
	struct sd_node *buf = NULL;
	struct sd_node *ent;
	struct sd_req hdr;
	struct sd_rsp *rsp = (struct sd_rsp *)&hdr;

	size = sizeof(*ent) * max_nodes;
	buf = xzalloc(size);
	sd_init_req(&hdr, SD_OP_GET_NODE_LIST);

	hdr.data_length = size;

	ret = dog_exec_req(&sd_nid, &hdr, buf);
	if (ret < 0)
		goto out;

	if (rsp->result != SD_RES_SUCCESS) {
		sd_err("Failed to update node list: %s",
		       sd_strerror(rsp->result));
		ret = -1;
		goto out;
	}

	size = rsp->data_length;
	sd_nodes_nr = size / sizeof(*ent);
	if (sd_nodes_nr == 0) {
		sd_err("There are no active sheep daemons");
		exit(EXIT_FAILURE);
	}

	/* FIXME */
	if (sd_nodes_nr > max_nodes) {
		ret = -1;
		goto out;
	}

	for (int i = 0; i < sd_nodes_nr; i++) {
		struct sd_node *n = xmalloc(sizeof(*n));
		int j;

		*n = buf[i];
		rb_insert(&sd_nroot, n, rb, node_cmp);

		for (j = 0; j < sd_zones_nr; j++) {
			if (sd_zones[j] == n->zone)
				break;
		}

		if (j == sd_zones_nr)
			sd_zones[sd_zones_nr++] = n->zone;
	}

	nodes_to_vnodes(&sd_nroot, &sd_vroot);
	sd_epoch = hdr.epoch;
out:
	if (buf)
		free(buf);

	return ret;
}
Ejemplo n.º 6
0
static int update_node_list(int max_nodes, uint32_t epoch)
{
	int fd, ret;
	unsigned int size, wlen;
	char *buf = NULL;
	struct sd_node *ent;
	struct sd_node_req hdr;
	struct sd_node_rsp *rsp = (struct sd_node_rsp *)&hdr;

	fd = connect_to(sdhost, sdport);
	if (fd < 0)
		return -1;

	size = sizeof(*ent) * max_nodes;
	buf = zalloc(size);
	if (!buf) {
		ret = -1;
		goto out;
	}

	memset(&hdr, 0, sizeof(hdr));
	hdr.opcode = SD_OP_GET_NODE_LIST;
	hdr.request_ver = epoch;

	hdr.data_length = size;

	wlen = 0;

	ret = exec_req(fd, (struct sd_req *)&hdr, buf, &wlen, &size);
	if (ret) {
		ret = -1;
		goto out;
	}

	if (rsp->result != SD_RES_SUCCESS) {
		fprintf(stderr, "Failed to update node list: %s\n",
				sd_strerror(rsp->result));
		ret = -1;
		goto out;
	}

	nr_nodes = size / sizeof(*ent);
	if (nr_nodes == 0) {
		fprintf(stderr, "There are no active sheep daemons\n");
		exit(EXIT_FAILURE);
	}

	/* FIXME */
	if (nr_nodes > max_nodes) {
		ret = -1;
		goto out;
	}

	memcpy(node_list_entries, buf, size);
	nr_vnodes = nodes_to_vnodes(node_list_entries, nr_nodes, vnode_list_entries);
	node_list_version = hdr.epoch;
	master_idx = rsp->master_idx;
out:
	if (buf)
		free(buf);
	if (fd >= 0)
		close(fd);

	return ret;
}