Example #1
0
int md_init_disk(char *path)
{
	md_nr_disks++;

	if (xmkdir(path, def_dmode) < 0)
			panic("%s, %m", path);
	pstrcpy(md_disks[md_nr_disks - 1].path, PATH_MAX, path);
	sd_iprintf("%s added to md, nr %d", md_disks[md_nr_disks - 1].path,
		   md_nr_disks);
	return 0;
}
Example #2
0
static void check_tmp_config(void)
{
	int ret;
	char tmp_config_path[PATH_MAX];

	snprintf(tmp_config_path, PATH_MAX, "%s.tmp", config_path);

	ret = unlink(tmp_config_path);
	if (!ret || ret != ENOENT)
		return;

	sd_iprintf("removed temporal config file");
}
Example #3
0
static void interpret_msg_pre_join(void)
{
	int ret;
	struct sph_msg snd, rcv;
	struct sph_msg_join_reply *join_reply;
	enum cluster_join_result res;

retry:
	read_msg(&rcv);

	if (rcv.type == SPH_SRV_MSG_JOIN_RETRY) {
		sd_iprintf("join request is rejected, retrying");

		do_shepherd_join();
		goto retry;
	} else if (rcv.type == SPH_SRV_MSG_NEW_NODE) {
		struct sph_msg_join *join;
		int join_len;

		join_len = rcv.body_len;
		join = xzalloc(join_len);
		ret = xread(sph_comm_fd, join, join_len);
		if (ret != join_len) {
			sd_eprintf("xread() failed: %m");
			exit(1);
		}

		res = sd_check_join_cb(&join->node, join->opaque);
		if (res == CJ_RES_FAIL) {
			sd_eprintf("sd_check_join_cb() failed");
			exit(1);
		}
		assert(res == CJ_RES_SUCCESS);

		/* FIXME: join->master_elected is needed? */
		assert(join->master_elected);
		is_master = true;

		snd.type = SPH_CLI_MSG_NEW_NODE_REPLY;
		snd.body_len = join_len;

		ret = writev2(sph_comm_fd, &snd, join, join_len);
		if (sizeof(snd) + join_len != ret) {
			sd_eprintf("writev2() failed: %m");
			exit(1);
		}

		free(join);

		read_msg(&rcv);
	}

	if (rcv.type != SPH_SRV_MSG_JOIN_REPLY) {
		sd_eprintf("unexpected message from shepherd, "
			"received message: %s", sph_srv_msg_to_str(rcv.type));

		/*
		 * In this case, the state of this sheep in shepherd must be
		 * SHEEP_STATE_CONNECTED. Messages other than SPH_MSG_JOIN_REPLY
		 * mean bugs of shepherd.
		 */
		exit(1);
	}

	join_reply = xzalloc(rcv.body_len);
	ret = xread(sph_comm_fd, join_reply, rcv.body_len);
	if (ret != rcv.body_len) {
		sd_eprintf("xread() failed: %m");
		exit(1);
	}

	sd_iprintf("join reply arrived, nr_nodes: %d", join_reply->nr_nodes);

	if (join_reply->res == CJ_RES_MASTER_TRANSFER) {
		is_master = true;

		/* FIXME: This code is tricky, but Sheepdog assumes that */
		/* nr_nodes = 1 when join_result = MASTER_TRANSFER... */
		nr_nodes = 1;
		nodes[0] = this_node;
	} else {
		memcpy(nodes, join_reply->nodes,
			join_reply->nr_nodes * sizeof(struct sd_node));

		nr_nodes = join_reply->nr_nodes;
	}

	sd_join_handler(&this_node, nodes, nr_nodes,
			join_reply->res, join_reply->opaque);

	free(join_reply);

	sd_iprintf("shepherd_join() succeed");
	state = STATE_JOINED;
}
Example #4
0
static void interpret_msg_pre_join(void)
{
	int ret;
	struct sph_msg snd, rcv;
	struct sph_msg_join_reply *join_reply;

retry:
	read_msg(&rcv);

	if (rcv.type == SPH_SRV_MSG_JOIN_RETRY) {
		sd_iprintf("join request is rejected, retrying");

		do_shepherd_join();
		goto retry;
	} else if (rcv.type == SPH_SRV_MSG_NEW_NODE) {
		struct sph_msg_join *join;
		int join_len;

		join_len = rcv.body_len;
		join = xzalloc(join_len);
		ret = xread(sph_comm_fd, join, join_len);
		if (ret != join_len) {
			sd_eprintf("xread() failed: %m");
			exit(1);
		}

		/*
		 * FIXME: member change events must be ordered with nonblocked
		 *        events
		 */
		if (!sd_join_handler(&join->new_node, NULL, 0, join->opaque))
			panic("sd_accept_handler() failed");

		snd.type = SPH_CLI_MSG_ACCEPT;
		snd.body_len = join_len;

		ret = writev2(sph_comm_fd, &snd, join, join_len);
		if (sizeof(snd) + join_len != ret) {
			sd_eprintf("writev2() failed: %m");
			exit(1);
		}

		free(join);

		read_msg(&rcv);
	}

	if (rcv.type != SPH_SRV_MSG_JOIN_REPLY) {
		sd_eprintf("unexpected message from shepherd, "
			"received message: %s", sph_srv_msg_to_str(rcv.type));

		/*
		 * In this case, the state of this sheep in shepherd must be
		 * SHEEP_STATE_CONNECTED. Messages other than SPH_MSG_JOIN_REPLY
		 * mean bugs of shepherd.
		 */
		exit(1);
	}

	join_reply = xzalloc(rcv.body_len);
	ret = xread(sph_comm_fd, join_reply, rcv.body_len);
	if (ret != rcv.body_len) {
		sd_eprintf("xread() failed: %m");
		exit(1);
	}

	sd_iprintf("join reply arrived, nr_nodes: %d", join_reply->nr_nodes);

	memcpy(nodes, join_reply->nodes,
	       join_reply->nr_nodes * sizeof(struct sd_node));
	nr_nodes = join_reply->nr_nodes;

	/* FIXME: member change events must be ordered with nonblocked events */
	sd_accept_handler(&this_node, nodes, nr_nodes, join_reply->opaque);

	free(join_reply);

	sd_iprintf("shepherd_join() succeed");
	state = STATE_JOINED;
}