ret = virDomainGetCPUStats(dom, param, nparams, -1, 1, 0); // total stats.
if (ret < 0) {
- virTypedParamsFree(param, nparams);
+ virTypedParamsClear(param, nparams);
+ sfree(param);
VIRT_ERROR(conn, "getting the disk params values");
return -1;
}
info->total_syst_cpu_time = param[i].value.ul;
}
- virTypedParamsFree(param, nparams);
+ virTypedParamsClear(param, nparams);
+ sfree(param);
#endif /* HAVE_CPU_STATS */
return 0;
const char *type) {
char type_instance[DATA_MAX_NAME_LEN];
- ssnprintf(type_instance, sizeof(type_instance), "%d", vcpu_nr);
+ snprintf(type_instance, sizeof(type_instance), "%d", vcpu_nr);
submit(dom, type, type_instance, &(value_t){.derive = value}, 1);
}
}
char flush_type_instance[DATA_MAX_NAME_LEN];
- ssnprintf(flush_type_instance, sizeof(flush_type_instance), "flush-%s",
- type_instance);
+ snprintf(flush_type_instance, sizeof(flush_type_instance), "flush-%s",
+ type_instance);
if ((binfo->bi.rd_req != -1) && (binfo->bi.wr_req != -1))
submit_derive2("disk_ops", (derive_t)binfo->bi.rd_req,
const char *reason_str = "N/A";
#endif
- ssnprintf(msg, sizeof(msg), "Domain state: %s. Reason: %s", state_str,
- reason_str);
+ snprintf(msg, sizeof(msg), "Domain state: %s. Reason: %s", state_str,
+ reason_str);
int severity;
switch (state) {
static int lv_domain_block_info(virDomainPtr dom, const char *path,
struct lv_block_info *binfo) {
#ifdef HAVE_BLOCK_STATS_FLAGS
- virTypedParameterPtr params = NULL;
int nparams = 0;
- int rc = -1;
- int ret = virDomainBlockStatsFlags(dom, path, NULL, &nparams, 0);
- if (ret < 0 || nparams == 0) {
+ if (virDomainBlockStatsFlags(dom, path, NULL, &nparams, 0) < 0 ||
+ nparams <= 0) {
VIRT_ERROR(conn, "getting the disk params count");
return -1;
}
- params = calloc(nparams, sizeof(virTypedParameter));
+ virTypedParameterPtr params = calloc((size_t)nparams, sizeof(*params));
if (params == NULL) {
ERROR("virt plugin: alloc(%i) for block=%s parameters failed.", nparams,
path);
return -1;
}
- ret = virDomainBlockStatsFlags(dom, path, params, &nparams, 0);
- if (ret < 0) {
+
+ int rc = -1;
+ if (virDomainBlockStatsFlags(dom, path, params, &nparams, 0) < 0) {
VIRT_ERROR(conn, "getting the disk params values");
- goto done;
+ } else {
+ rc = get_block_info(binfo, params, nparams);
}
- rc = get_block_info(binfo, params, nparams);
-
-done:
- virTypedParamsFree(params, nparams);
+ virTypedParamsClear(params, nparams);
+ sfree(params);
return rc;
#else
return virDomainBlockStats(dom, path, &(binfo->bi), sizeof(binfo->bi));
char type_instance[DATA_MAX_NAME_LEN];
_Bool is_set = VIR_CPU_USABLE(cpu_maps, cpu_map_len, vcpu, cpu) ? 1 : 0;
- ssnprintf(type_instance, sizeof(type_instance), "vcpu_%d-cpu_%d", vcpu,
- cpu);
+ snprintf(type_instance, sizeof(type_instance), "vcpu_%d-cpu_%d", vcpu, cpu);
submit(dom, "cpu_affinity", type_instance, &(value_t){.gauge = is_set}, 1);
}
}
memset(lv_ud, 0, sizeof(*lv_ud));
- ssnprintf(inst->tag, sizeof(inst->tag), "%s-%zu", PLUGIN_NAME, i);
+ snprintf(inst->tag, sizeof(inst->tag), "%s-%zu", PLUGIN_NAME, i);
inst->id = i;
user_data_t *ud = &(lv_ud->ud);
goto done;
}
- ssnprintf(xpath_str, sizeof(xpath_str), "/domain/metadata/%s:%s/text()",
- METADATA_VM_PARTITION_PREFIX, METADATA_VM_PARTITION_ELEMENT);
+ snprintf(xpath_str, sizeof(xpath_str), "/domain/metadata/%s:%s/text()",
+ METADATA_VM_PARTITION_PREFIX, METADATA_VM_PARTITION_ELEMENT);
xpath_obj = xmlXPathEvalExpression((xmlChar *)xpath_str, xpath_ctx);
if (xpath_obj == NULL) {
ERROR(PLUGIN_NAME " plugin: xmlXPathEval(%s) failed on domain %s",
return 0;
}
+/*
+ virConnectListAllDomains() appeared in 0.10.2
+ Note that LIBVIR_CHECK_VERSION appeared a year later, so
+ in some systems which actually have virConnectListAllDomains()
+ we can't detect this.
+ */
+#ifdef LIBVIR_CHECK_VERSION
+#if LIBVIR_CHECK_VERSION(0, 10, 2)
+#define HAVE_LIST_ALL_DOMAINS 1
+#endif
+#endif
+
static int refresh_lists(struct lv_read_instance *inst) {
struct lv_read_state *state = &inst->read_state;
int n;
lv_clean_read_state(state);
if (n > 0) {
+#ifdef HAVE_LIST_ALL_DOMAINS
+ virDomainPtr *domains;
+ n = virConnectListAllDomains(conn, &domains,
+ VIR_CONNECT_LIST_DOMAINS_ACTIVE);
+#else
int *domids;
/* Get list of domains. */
}
n = virConnectListDomains(conn, domids, n);
+#endif
+
if (n < 0) {
VIRT_ERROR(conn, "reading list of domains");
+#ifndef HAVE_LIST_ALL_DOMAINS
sfree(domids);
+#endif
return -1;
}
/* Fetch each domain and add it to the list, unless ignore. */
for (int i = 0; i < n; ++i) {
- virDomainPtr dom = NULL;
const char *name;
char *xml = NULL;
xmlDocPtr xml_doc = NULL;
virDomainInfo info;
int status;
+#ifdef HAVE_LIST_ALL_DOMAINS
+ virDomainPtr dom = domains[i];
+#else
+ virDomainPtr dom = NULL;
dom = virDomainLookupByID(conn, domids[i]);
if (dom == NULL) {
VIRT_ERROR(conn, "virDomainLookupByID");
/* Could be that the domain went away -- ignore it anyway. */
continue;
}
+#endif
name = virDomainGetName(dom);
if (name == NULL) {
sfree(xml);
}
+#ifdef HAVE_LIST_ALL_DOMAINS
+ sfree(domains);
+#else
sfree(domids);
+#endif
}
DEBUG(PLUGIN_NAME " plugin#%s: refreshing"
if ((domname == NULL) || (devpath == NULL))
return 0;
- n = sizeof(char) * (strlen(domname) + strlen(devpath) + 2);
+ n = strlen(domname) + strlen(devpath) + 2;
name = malloc(n);
if (name == NULL) {
ERROR(PLUGIN_NAME " plugin: malloc failed.");
return 0;
}
- ssnprintf(name, n, "%s:%s", domname, devpath);
+ snprintf(name, n, "%s:%s", domname, devpath);
r = ignorelist_match(il, name);
sfree(name);
return r;