Esempio n. 1
0
static void dump_daemon_nodes(void)
{
	int fd, i;

	user_sig &= ~(1 << SIGUSR1);

	fd = open("/tmp/merlind.nodeinfo", O_CREAT | O_TRUNC | O_WRONLY, 0644);
	if (fd < 0) {
		lerr("USERSIG: Failed to open /tmp/merlind.nodeinfo for dumping: %s", strerror(errno));
		return;
	}

	dump_nodeinfo(&ipc, fd, 0);
	for (i = 0; i < num_nodes; i++)
		dump_nodeinfo(node_table[i], fd, i + 1);
}
Esempio n. 2
0
static void
getnode_callback(SaInvocationT invocation, SaClmClusterNodeT *clusterNode
,	SaErrorT error)
{
	if (error != SA_OK) {
		fprintf(stderr, "Get Node Callback failed [%d]\n", error);
		exit(1);
	}
	fprintf(stderr, "Invocation [%d]\n", invocation);
	dump_nodeinfo(clusterNode);
}
Esempio n. 3
0
int main(void)
{
	SaSelectionObjectT st;
	SaErrorT ret;
	SaClmNodeIdT nid;

	SaClmCallbacksT my_callbacks = {
		.saClmClusterTrackCallback
		=	(SaClmClusterTrackCallbackT)track_callback,
		.saClmClusterNodeGetCallback
		=	(SaClmClusterNodeGetCallbackT)getnode_callback
	};

	if ((ret = saClmInitialize(&hd, &my_callbacks, NULL)) != SA_OK) {
		fprintf(stderr, "saClmInitialize error, errno [%d]\n",ret);
		return 1;
	}
	if ((ret = saClmSelectionObjectGet(&hd, &st)) != SA_OK) {
		fprintf(stderr, "saClmSelectionObjectGet error, errno [%d]\n"
		,	ret);
		return 1;
	}

	nid = 0;

	/* Synchronously get nodeId information */
	printf("-------------------------------------------------\n");
	printf("Get nodeId [%lu] info by SaClmClusterNodeGet\n", nid);
	if ((ret = saClmClusterNodeGet(nid, 10, &cn)) != SA_OK) {
		if (ret == SA_ERR_INVALID_PARAM) {
			fprintf(stderr, "NodeId [%lu] record not found!\n",nid);
		} else {
			fprintf(stderr
			,	"saClmClusterNodeGet error, errno [%d]\n"
			,	ret);
			return 1;
		}
	} else {
		dump_nodeinfo(&cn);
	}

	/* Asynchronously get my nodeId information */
	nid = 1;
	printf("-------------------------------------------------\n");
	printf("Get nodeId [%lu] info by SaClmClusterNodeGetAsync\n", nid);
	if ((ret = saClmClusterNodeGetAsync(&hd, 1234, nid, &cn)) != SA_OK) {
		if (ret == SA_ERR_INVALID_PARAM) {
			fprintf(stderr, "NodeId [%lu] record not found!\n",nid);
		} else {
			fprintf(stderr
			,	"saClmClusterNodeGet error, errno [%d]\n"
			,	ret);
			return 1;
		}
	}

	/* Start to track cluster membership changes events */
	track_start(SIGUSR1);
	signal(SIGUSR2, &track_stop);

	for (;;) {
		fd_set rset;

		FD_ZERO(&rset);
		FD_SET(st, &rset);

		if (select(st + 1, &rset, NULL, NULL, NULL) == -1) {
			/* TODO should we use pselect here? */
			if (errno == EINTR)
				continue;
			else {
				perror("select");
				return 1;
			}
		}
		if ((ret = saClmDispatch(&hd, SA_DISPATCH_ALL)) != SA_OK) {
			if (ret == SA_ERR_LIBRARY) {
				fprintf(stderr, "I am evicted!\n");
				return 1;
			}
			fprintf(stderr, "saClmDispatch error, errno [%d]\n"
			,	ret);
			return 1;
		}
	}

	return 0;
}