static int q_lib_init(void)
{
	votequorum_callbacks_t vq_callbacks;
	quorum_callbacks_t q_callbacks;
	int ret = 0;
	int retry = 3;
	int fd;

	if (vq_handle == 0) {
		qb_log (LOG_INFO, "votequorum_initialize");
		vq_callbacks.votequorum_notify_fn = votequorum_notification_fn;
		vq_callbacks.votequorum_expectedvotes_notify_fn = NULL;
		ret = CS_ERR_NOT_EXIST;
		while (ret == CS_ERR_NOT_EXIST && retry > 0) {
			ret = votequorum_initialize (&vq_handle, &vq_callbacks);
			if (ret == CS_ERR_NOT_EXIST) {
				sleep (1);
				retry--;
			}
		}
		if (ret != CS_OK) {
			qb_log (LOG_ERR, "votequorum_initialize FAILED: %d", ret);
			vq_handle = 0;
		}
		else {
			ret = votequorum_trackstart (vq_handle, vq_handle, CS_TRACK_CHANGES);
			if (ret != CS_OK) {
				qb_log (LOG_ERR, "votequorum_trackstart FAILED: %d", ret);
			}

			votequorum_fd_get (vq_handle, &fd);
			qb_loop_poll_add (ta_poll_handle_get(), QB_LOOP_MED, fd,
				POLLIN|POLLNVAL, NULL, vq_dispatch_wrapper_fn);
		}
	}
	if (q_handle == 0) {
		uint32_t q_type;
		qb_log (LOG_INFO, "quorum_initialize");
		q_callbacks.quorum_notify_fn = quorum_notification_fn;
		ret = quorum_initialize (&q_handle, &q_callbacks, &q_type);
		if (ret != CS_OK) {
			qb_log (LOG_ERR, "quorum_initialize FAILED: %d", ret);
			q_handle = 0;
		}
		else {
			ret = quorum_trackstart (q_handle, CS_TRACK_CHANGES);
			if (ret != CS_OK) {
				qb_log (LOG_ERR, "quorum_trackstart FAILED: %d", ret);
			}
			quorum_fd_get (q_handle, &fd);
			qb_loop_poll_add (ta_poll_handle_get(), QB_LOOP_MED, fd,
				POLLIN|POLLNVAL, NULL, q_dispatch_wrapper_fn);
		}
	}
	return ret;
}
Example #2
0
static void send_some_more_messages_later (void)
{
	cpg_dispatch (cpg_handle, CS_DISPATCH_ALL);
	poll_timer_add (
		ta_poll_handle_get(),
		300, NULL,
		send_some_more_messages,
		&more_messages_timer_handle);
}
Example #3
0
static void send_some_more_messages_later (void)
{
	cpg_dispatch (cpg_handle, CS_DISPATCH_ALL);
	qb_loop_timer_add (
		ta_poll_handle_get(),
		QB_LOOP_MED,
		300*QB_TIME_NS_IN_MSEC, NULL,
		send_some_more_messages,
		&more_messages_timer_handle);
}
Example #4
0
static int cpg_dispatch_wrapper_fn (hdb_handle_t handle,
	int fd,
	int revents,
	void *data)
{
	cs_error_t error;
	if (revents & POLLHUP || revents & POLLERR) {
		syslog (LOG_ERR, "%s() got POLLHUP disconnecting from CPG", __func__);
		poll_dispatch_delete (ta_poll_handle_get(), cpg_fd);
		close (cpg_fd);
		cpg_fd = -1;
		return -1;
	}
	error = cpg_dispatch (cpg_handle, CS_DISPATCH_ALL);
	if (error == CS_ERR_LIBRARY) {
		syslog (LOG_ERR, "%s() got LIB error disconnecting from CPG", __func__);
		poll_dispatch_delete (ta_poll_handle_get(), cpg_fd);
		close (cpg_fd);
		cpg_fd = -1;
		return -1;
	}
	return 0;
}
Example #5
0
static void do_command (int sock, char* func, char*args[], int num_args)
{
	int result;
	char response[100];
	struct cpg_name group_name;
	ssize_t rc;
	size_t send_len;

	qb_log (LOG_TRACE, "RPC:%s() called.", func);

	if (strcmp ("cpg_mcast_joined",func) == 0) {
		struct iovec iov[5];
		int a;

		for (a = 0; a < num_args; a++) {
			iov[a].iov_base = args[a];
			iov[a].iov_len = strlen(args[a])+1;
		}
		cpg_mcast_joined (cpg_handle, CPG_TYPE_AGREED, iov, num_args);

	} else if (strcmp ("cpg_join",func) == 0) {
		if (strlen(args[0]) >= CPG_MAX_NAME_LENGTH) {
			qb_log (LOG_ERR, "Invalid group name");
			exit (1);
		}
		strcpy (group_name.value, args[0]);
		group_name.length = strlen(args[0]);
		result = cpg_join (cpg_handle, &group_name);
		if (result != CS_OK) {
			qb_log (LOG_ERR,
				"Could not join process group, error %d", result);
			exit (1);
		}
		qb_log (LOG_INFO, "called cpg_join(%s)!", group_name.value);

	} else if (strcmp ("cpg_leave",func) == 0) {

		strcpy (group_name.value, args[0]);
		group_name.length = strlen(args[0]);

		result = cpg_leave (cpg_handle, &group_name);
		if (result != CS_OK) {
			qb_log (LOG_ERR,
				"Could not leave process group, error %d", result);
			exit (1);
		}
		qb_log (LOG_INFO, "called cpg_leave(%s)!", group_name.value);

	} else if (strcmp ("cpg_initialize",func) == 0) {
		int retry_count = 0;

		result = cpg_initialize (&cpg_handle, &callbacks);
		while (result != CS_OK) {
			qb_log (LOG_ERR,
				"cpg_initialize error %d (attempt %d)",
				result, retry_count);
			if (retry_count >= 3) {
				exit (1);
			}
			sleep(1);
			retry_count++;
			result = cpg_initialize (&cpg_handle, &callbacks);
		}

		cpg_fd_get (cpg_handle, &cpg_fd);
		qb_loop_poll_add (ta_poll_handle_get(),
			QB_LOOP_MED,
			cpg_fd,
			POLLIN|POLLNVAL,
			NULL,
			cpg_dispatch_wrapper_fn);

	} else if (strcmp ("cpg_local_get", func) == 0) {
		unsigned int local_nodeid;

		cpg_local_get (cpg_handle, &local_nodeid);
		snprintf (response, 100, "%u",local_nodeid);
		send_len = strlen (response);
		rc = send (sock, response, send_len, 0);
		assert(rc == send_len);
	} else if (strcmp ("cpg_finalize", func) == 0) {

		if (cpg_handle > 0) {
			cpg_finalize (cpg_handle);
			cpg_handle = 0;
		}

	} else if (strcmp ("record_config_events", func) == 0) {
		record_config_events (sock);
	} else if (strcmp ("record_messages", func) == 0) {
		record_messages ();
	} else if (strcmp ("read_config_event", func) == 0) {
		read_config_event (sock);
	} else if (strcmp ("read_messages", func) == 0) {
		read_messages (sock, args[0]);
	} else if (strcmp ("msg_blaster_zcb", func) == 0) {
		msg_blaster_zcb (sock, args[0]);
	} else if (strcmp ("pcmk_test", func) == 0) {
		pcmk_test = 1;
	} else if (strcmp ("msg_blaster", func) == 0) {
		msg_blaster (sock, args[0]);
	} else if (strcmp ("context_test", func) == 0) {
		context_test (sock);
	} else if (strcmp ("are_you_ok_dude", func) == 0) {
		snprintf (response, 100, "%s", OK_STR);
		send_len = strlen (response);
		rc = send (sock, response, strlen (response), 0);
		assert(rc == send_len);
	} else if (strcmp ("cfg_shutdown", func) == 0) {

		qb_log (LOG_INFO, "calling %s() called!", func);
		result = corosync_cfg_try_shutdown (cfg_handle, COROSYNC_CFG_SHUTDOWN_FLAG_REQUEST);
		qb_log (LOG_INFO,"%s() returned %d!", func, result);

	} else if (strcmp ("cfg_initialize",func) == 0) {
		int retry_count = 0;

		qb_log (LOG_INFO,"%s() called!", func);
		result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks);
		while (result != CS_OK) {
			qb_log (LOG_ERR,
				"cfg_initialize error %d (attempt %d)",
				result, retry_count);
			if (retry_count >= 3) {
				exit (1);
			}
			sleep(1);
			retry_count++;
			result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks);
		}
		qb_log (LOG_INFO,"corosync_cfg_initialize() == %d", result);

		result = corosync_cfg_fd_get (cfg_handle, &cfg_fd);
		qb_log (LOG_INFO,"corosync_cfg_fd_get() == %d", result);

		qb_loop_poll_add (ta_poll_handle_get(),
			QB_LOOP_MED,
			cfg_fd,
			POLLIN|POLLNVAL,
			NULL,
			cfg_dispatch_wrapper_fn);
	} else {
		qb_log(LOG_ERR, "RPC:%s not supported!", func);
	}
}
Example #6
0
static void do_command (int sock, char* func, char*args[], int num_args)
{
	int result;
	char response[100];
	struct cpg_name group_name;

	if (parse_debug)
		syslog (LOG_DEBUG,"RPC:%s() called.", func);

	if (strcmp ("cpg_mcast_joined",func) == 0) {
		struct iovec iov[5];
		int a;

		for (a = 0; a < num_args; a++) {
			iov[a].iov_base = args[a];
			iov[a].iov_len = strlen(args[a])+1;
		}
		cpg_mcast_joined (cpg_handle, CPG_TYPE_AGREED, iov, num_args);

	} else if (strcmp ("cpg_join",func) == 0) {

		strcpy (group_name.value, args[0]);
		group_name.length = strlen(args[0]);

		result = cpg_join (cpg_handle, &group_name);
		if (result != CS_OK) {
			syslog (LOG_ERR,
				"Could not join process group, error %d\n", result);
			exit (1);
		}
		syslog (LOG_INFO, "called cpg_join()!");

	} else if (strcmp ("cpg_leave",func) == 0) {

		strcpy (group_name.value, args[0]);
		group_name.length = strlen(args[0]);

		result = cpg_leave (cpg_handle, &group_name);
		if (result != CS_OK) {
			syslog (LOG_ERR,
				"Could not leave process group, error %d\n", result);
			exit (1);
		}
		syslog (LOG_INFO, "called cpg_leave()!");

	} else if (strcmp ("cpg_initialize",func) == 0) {
		int retry_count = 0;

		result = cpg_initialize (&cpg_handle, &callbacks);
		while (result != CS_OK) {
			syslog (LOG_ERR,
				"cpg_initialize error %d (attempt %d)\n",
				result, retry_count);
			if (retry_count >= 3) {
				exit (1);
			}
			sleep(1);
			retry_count++;
			result = cpg_initialize (&cpg_handle, &callbacks);
		}

		cpg_fd_get (cpg_handle, &cpg_fd);
		poll_dispatch_add (ta_poll_handle_get(), cpg_fd, POLLIN|POLLNVAL, NULL, cpg_dispatch_wrapper_fn);

	} else if (strcmp ("cpg_local_get", func) == 0) {
		unsigned int local_nodeid;

		cpg_local_get (cpg_handle, &local_nodeid);
		snprintf (response, 100, "%u",local_nodeid);
		send (sock, response, strlen (response), 0);
	} else if (strcmp ("cpg_finalize", func) == 0) {

		cpg_finalize (cpg_handle);
		poll_dispatch_delete (ta_poll_handle_get(), cpg_fd);
		cpg_fd = -1;

	} else if (strcmp ("record_config_events", func) == 0) {
		record_config_events (sock);
	} else if (strcmp ("record_messages", func) == 0) {
		record_messages ();
	} else if (strcmp ("read_config_event", func) == 0) {
		read_config_event (sock);
	} else if (strcmp ("read_messages", func) == 0) {
		read_messages (sock, args[0]);
	} else if (strcmp ("msg_blaster_zcb", func) == 0) {
		msg_blaster_zcb (sock, args[0]);
	} else if (strcmp ("pcmk_test", func) == 0) {
		pcmk_test = 1;
	} else if (strcmp ("msg_blaster", func) == 0) {
		msg_blaster (sock, args[0]);
	} else if (strcmp ("context_test", func) == 0) {
		context_test (sock);
	} else if (strcmp ("are_you_ok_dude", func) == 0) {
		snprintf (response, 100, "%s", OK_STR);
		send (sock, response, strlen (response), 0);

	} else if (strcmp ("cfg_shutdown", func) == 0) {

		corosync_cfg_try_shutdown (cfg_handle, COROSYNC_CFG_SHUTDOWN_FLAG_REQUEST);

	} else if (strcmp ("cfg_initialize",func) == 0) {
		int retry_count = 0;

		syslog (LOG_INFO,"%s %s() called!", __func__, func);
		result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks);
		while (result != CS_OK) {
			syslog (LOG_ERR,
				"cfg_initialize error %d (attempt %d)\n",
				result, retry_count);
			if (retry_count >= 3) {
				exit (1);
			}
			sleep(1);
			retry_count++;
			result = corosync_cfg_initialize (&cfg_handle, &cfg_callbacks);
		}

		corosync_cfg_fd_get (cfg_handle, &cfg_fd);

		corosync_cfg_state_track (cfg_handle, 0, &notification_buffer);

		poll_dispatch_add (ta_poll_handle_get(), cfg_fd, POLLIN|POLLNVAL, NULL, cfg_dispatch_wrapper_fn);
	} else {
		syslog (LOG_ERR,"%s RPC:%s not supported!", __func__, func);
	}
}