Example #1
0
/*
 * This routine is called once for each pmFetch(3) operation, so is a
 * good place to do once-per-fetch functions, such as value caching or
 * instance domain evaluation.
 */
static int
pmda_ctdb_fetch(int numpmid, pmID pmidlist[], pmResult **resp, pmdaExt *pmda)
{
	int ret;
	struct timeval ctdb_timeout;

	if (client == NULL) {
		fprintf(stderr, "attempting reconnect to ctdbd\n");
		ret = pmda_ctdb_daemon_connect();
		if (ret < 0) {
			fprintf(stderr, "reconnect failed\n");
			return PM_ERR_VALUE;
		}
	}

	ret = ctdb_ctrl_statistics(client, ev, client, CTDB_CURRENT_NODE,
				   ctdb_timeout, &stats);
	if (ret != 0) {
		fprintf(stderr, "ctdb control for statistics failed, reconnecting\n");
		pmda_ctdb_daemon_disconnect();
		ret = PM_ERR_VALUE;
		goto err_out;
	}

	ret = pmdaFetch(numpmid, pmidlist, resp, pmda);

	talloc_free(stats);
err_out:
	return ret;
}
Example #2
0
/*
 * This routine is called once for each pmFetch(3) operation, so is a
 * good place to do once-per-fetch functions, such as value caching or
 * instance domain evaluation.
 */
static int
pmda_ctdb_fetch(int numpmid, pmID pmidlist[], pmResult **resp, pmdaExt *pmda)
{
	int ret;
	TDB_DATA data;
	int32_t res;
	struct timeval ctdb_timeout;

	if (ctdb == NULL) {
		fprintf(stderr, "attempting reconnect to ctdbd\n");
		ret = pmda_ctdb_daemon_connect();
		if (ret < 0) {
			fprintf(stderr, "reconnect failed\n");
			return PM_ERR_VALUE;
		}
	}

	ctdb_timeout = timeval_current_ofs(1, 0);
	ret = ctdb_control(ctdb, ctdb->pnn, 0,
			   CTDB_CONTROL_STATISTICS, 0, tdb_null,
			   ctdb, &data, &res, &ctdb_timeout, NULL);

	if (ret != 0 || res != 0) {
		fprintf(stderr, "ctdb control for statistics failed, reconnecting\n");
		pmda_ctdb_daemon_disconnect();
		ret = PM_ERR_VALUE;
		goto err_out;
	}

	stats = (struct ctdb_statistics *)data.dptr;

	if (data.dsize != sizeof(struct ctdb_statistics)) {
		fprintf(stderr, "incorrect statistics size %zu - not %zu\n",
			data.dsize, sizeof(struct ctdb_statistics));
		ret = PM_ERR_VALUE;
		goto err_stats;
	}

	ret = pmdaFetch(numpmid, pmidlist, resp, pmda);

err_stats:
	talloc_free(stats);
err_out:
	return ret;
}