Esempio n. 1
0
static int
_cs_cmap_dispatch(int fd, int revents, void *data)
{
	cs_error_t err;

	err = cmap_dispatch(cmap_handle, CS_DISPATCH_ONE);

	if (err != CS_OK && err != CS_ERR_TRY_AGAIN && err != CS_ERR_TIMEOUT &&
		err != CS_ERR_QUEUE_FULL) {
		qb_log(LOG_ERR, "Could not dispatch cmap events. Error %u", err);
		qb_loop_stop(main_loop);

		return -1;
	}

	return 0;
}
Esempio n. 2
0
static void track_changes(cmap_handle_t handle)
{
	struct pollfd pfd[2];
	int cmap_fd;
	cs_error_t err;
	int poll_res;
	char inbuf[3];
	int quit = CS_FALSE;

	err = cmap_fd_get(handle, &cmap_fd);
	if (err != CS_OK) {
		fprintf(stderr, "Failed to get file handle. Error %s\n", cs_strerror(err));
		exit (EXIT_FAILURE);
	}

	pfd[0].fd = cmap_fd;
	pfd[1].fd = STDIN_FILENO;
	pfd[0].events = pfd[1].events = POLLIN;

	printf("Type \"q\" to finish\n");
	do {
		pfd[0].revents = pfd[1].revents = 0;
		poll_res = poll(pfd, 2, INFTIM);
		if (poll_res == -1) {
			perror("poll");
		}

		if (pfd[1].revents & POLLIN) {
			if (fgets(inbuf, sizeof(inbuf), stdin) == NULL) {
				quit = CS_TRUE;
			} else if (strncmp(inbuf, "q", 1) == 0) {
				quit = CS_TRUE;
			}
		}

		if (pfd[0].revents & POLLIN) {
			err = cmap_dispatch(handle, CS_DISPATCH_ALL);
			if (err != CS_OK) {
				fprintf(stderr, "Dispatch error %s\n", cs_strerror(err));
				quit = CS_TRUE;
			}
		}
	} while (poll_res > 0 && !quit);
}
Esempio n. 3
0
int
qdevice_cmap_dispatch(struct qdevice_instance *instance)
{
	cs_error_t res;

	/*
	 * dispatch can block if corosync is during sync phase
	 */
	if (instance->sync_in_progress) {
		return (0);
	}

	res = cmap_dispatch(instance->cmap_handle, CS_DISPATCH_ALL);

	if (res != CS_OK && res != CS_ERR_TRY_AGAIN) {
		qdevice_log(LOG_ERR, "Can't dispatch cmap messages");

		return (-1);
	}

	return (0);
}
Esempio n. 4
0
static gboolean
cmap_dispatch_callback (gpointer user_data)
{
    cmap_dispatch(cmap_handle, CS_DISPATCH_ALL);
    return TRUE;
}
Esempio n. 5
0
int
main(int argc, char *argv[])
{
#ifdef USE_CONFDB
	confdb_handle_t handle;
	confdb_callbacks_t callbacks;
	hdb_handle_t object_handle;
#endif
#ifdef USE_CMAP
	cmap_handle_t handle;
	cmap_track_handle_t track_handle;
	int retries;
	cs_error_t result;
#endif
	uint32_t u32;
	int status;
	int i;
	cs_error_t res;
	char str_val[255];
	int ch;
	char *ep;

	change_uint32 = 0;
	change_str_len = 0;
	no_childs = 16;
	burst_count = 64;

	while ((ch = getopt(argc, argv, "hus:c:n:")) != -1) {
		switch (ch) {
		case 'u':
			change_uint32 = 1;
			break;
		case 's':
			change_str_len = strtol(optarg, &ep, 10);
			if (change_str_len <= 0 || *ep != '\0') {
				warnx("illegal number, -s argument -- %s", optarg);
				usage();
			}
			break;
		case 'c':
			no_childs = strtol(optarg, &ep, 10);
			if (no_childs <= 0 || *ep != '\0') {
				warnx("illegal number, -c argument -- %s", optarg);
				usage();
			}
			break;
		case 'n':
			burst_count = strtol(optarg, &ep, 10);
			if (burst_count <= 0 || *ep != '\0') {
				warnx("illegal number, -n argument -- %s", optarg);
				usage();
			}
			break;
		case 'h':
		case '?':
		default:
			usage();
			/* NOTREACHED */
		}
	}

	signal(SIGPIPE, SIG_IGN);

	setlinebuf(stdout);

#ifdef USE_CONFDB
	memset(&callbacks, 0, sizeof(callbacks));
	assert(confdb_initialize(&handle, &callbacks) == CS_OK);
	assert(confdb_object_create(handle, OBJECT_PARENT_HANDLE,
		"testconfdb", strlen("testconfdb"), &object_handle) == CS_OK);
	assert(confdb_finalize(handle) == CS_OK);
#endif

	my_id = create_childs();
	u32 = my_id;

#ifdef USE_CONFDB
	snprintf(my_key_uint, sizeof(my_key_uint), "testkeyu32id%u", my_id);

	snprintf(my_key_str, sizeof(my_key_str), "testkeystrid%u", my_id);
#endif

#ifdef USE_CMAP
	snprintf(my_key_uint, sizeof(my_key_uint), "testconfdb.testkeyu32id%u", my_id);

	snprintf(my_key_str, sizeof(my_key_str), "testconfdb.testkeystrid%u", my_id);
#endif

	for (i = 0; i < change_str_len; i++) {
		str_val[i] = ((my_id + i) % ('Z' - 'A' + 1)) + 'A';
	}
	str_val[i] = '\0';

	if (my_id > 0) {
#ifdef USE_CONFDB
		memset(&callbacks, 0, sizeof(callbacks));
		callbacks.confdb_key_change_notify_fn = confdb_key_change_notify;

		assert(confdb_initialize(&handle, &callbacks) == CS_OK);
#endif

#ifdef USE_CMAP
		retries = 0;
		cs_repeat(retries, 30, result = cmap_initialize(&handle));
		assert(result == CS_OK);
#endif
		if (change_uint32) {
#ifdef USE_CONFDB
			assert(confdb_key_create_typed(handle, object_handle, my_key_uint,
				&u32, sizeof(u32), CONFDB_VALUETYPE_UINT32) == CS_OK);
#endif
#ifdef USE_CMAP
			assert(cmap_set_uint32(handle, my_key_uint, u32) == CS_OK);
#endif
		}

		if (change_str_len > 0) {
#ifdef USE_CONFDB
			assert(confdb_key_create_typed(handle, object_handle, my_key_str,
				str_val, strlen(str_val), CONFDB_VALUETYPE_STRING) == CS_OK);
#endif
#ifdef USE_CMAP
			assert(cmap_set_string(handle, my_key_str, str_val) == CS_OK);
#endif
		}
	} else {
		/*
		 * "Wait" for other processes to initialize
		 */
		poll(NULL, 0, 1000);

		printf("Confdb-track-and-change initialization finished\n");
	}

	if (my_id > 0) {
		signal(SIGINT, sigint_handler_child);

#ifdef USE_CONFDB
		assert(confdb_track_changes(handle, object_handle, OBJECT_KEY_REPLACED) == CS_OK);
#endif

#ifdef USE_CMAP
		assert(cmap_track_add(handle, "testconfdb.", CMAP_TRACK_MODIFY | CMAP_TRACK_PREFIX,
			cmap_notify, NULL, &track_handle) == CS_OK);
#endif

		if (change_uint32) {
#ifdef USE_CONFDB
			assert(confdb_key_increment(handle, object_handle, my_key_uint,
						strlen(my_key_uint), &u32) == CS_OK);
#endif
#ifdef USE_CMAP
			assert(cmap_inc(handle, my_key_uint) == CS_OK);
#endif
			expected_msgs_uint = 1;
		}

		if (change_str_len > 0) {
			inc_str(str_val, change_str_len);
#ifdef USE_CONFDB
			assert(confdb_key_replace(handle, object_handle, my_key_str, strlen(my_key_str), NULL, 0,
					str_val, strlen(str_val)) == CS_OK);
#endif
#ifdef USE_CMAP
			assert(cmap_set_string(handle, my_key_str, str_val) == CS_OK);
#endif
			expected_msgs_str = 1;
		}

		/*
		 * Give other processes a little time to initialize
		 */
		poll(NULL, 0, 250);

		do {
#ifdef USE_CONFDB
			res = confdb_dispatch(handle, CS_DISPATCH_BLOCKING);
#endif
#ifdef USE_CMAP
			res = cmap_dispatch(handle, CS_DISPATCH_BLOCKING);
#endif
		} while (res == CS_OK || res == CS_ERR_TRY_AGAIN);
	} else {
		signal(SIGINT, sigint_handler_parent);

		for (i = 0; i < no_childs; i++) {
			wait(&status);
		}

#ifdef USE_CONFDB
		confdb_object_destroy(handle, object_handle);
#endif
		printf("Confdb-track-and-change finalization finished\n");
	}

	return (0);
}