diff --git a/src/virt.c b/src/virt.c
index e32150af96cc9ad251df6fd9e21fee1573ca541f..6e1cd2194609c8368e90b7bfbb91b2b99de1effd 100644 (file)
--- a/src/virt.c
+++ b/src/virt.c
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <libxml/xpath.h>
-#include <libgen.h>
+#include <libgen.h> /* for basename(3) */
/* Plugin name */
#define PLUGIN_NAME "virt"
/* BlockDeviceFormat */
enum bd_field {
- dev,
+ target,
source
};
};
/* BlockDeviceFormatBasename */
-char *blockdevice_format_basename="false";
-static enum bd_field blockdevice_format = dev;
+_Bool blockdevice_format_basename = 0;
+static enum bd_field blockdevice_format = target;
static enum if_field interface_format = if_name;
/* Time that we last refreshed. */
}
if (strcasecmp (key, "BlockDeviceFormat") == 0) {
- if (strcasecmp (value, "dev") == 0)
- blockdevice_format = dev;
+ if (strcasecmp (value, "target") == 0)
+ blockdevice_format = target;
else if (strcasecmp (value, "source") == 0)
blockdevice_format = source;
else {
}
if (strcasecmp (key, "BlockDeviceFormatBasename") == 0) {
if (strcasecmp (value, "true") == 0)
- blockdevice_format_basename = "true";
+ blockdevice_format_basename = 1;
else if (strcasecmp (value, "false") == 0)
- blockdevice_format_basename = "false";
+ blockdevice_format_basename = 0;
else {
ERROR (PLUGIN_NAME " plugin: unknown BlockDeviceFormatBasename: %s", value);
return -1;
&stats, sizeof stats) != 0)
continue;
- char *new_path=NULL;
- if( 0==strcasecmp("true", blockdevice_format_basename) && source==blockdevice_format){ //valid only if we use source (full path to the device)
- new_path=strdup(basename(block_devices[i].path));
- }else{
- new_path=strdup(block_devices[i].path);
- }
+ char *type_instance = NULL;
+ if (blockdevice_format_basename && blockdevice_format == source)
+ type_instance = strdup(basename(block_devices[i].path));
+ else
+ type_instance = strdup(block_devices[i].path);
if ((stats.rd_req != -1) && (stats.wr_req != -1))
submit_derive2 ("disk_ops",
(derive_t) stats.rd_req, (derive_t) stats.wr_req,
- block_devices[i].dom, new_path);
+ block_devices[i].dom, type_instance);
if ((stats.rd_bytes != -1) && (stats.wr_bytes != -1))
submit_derive2 ("disk_octets",
(derive_t) stats.rd_bytes, (derive_t) stats.wr_bytes,
- block_devices[i].dom, new_path);
+ block_devices[i].dom, type_instance);
- free(new_path);
+ sfree(type_instance);
} /* for (nr_block_devices) */
/* Get interface stats for each domain. */
xpath_ctx = xmlXPathNewContext (xml_doc);
/* Block devices. */
- char * bd_xmlpath=NULL;
- if( source == blockdevice_format ){
- bd_xmlpath="/domain/devices/disk/source[@dev]";
- }else{
- if( dev == blockdevice_format ){
- bd_xmlpath="/domain/devices/disk/target[@dev]";
- }
- }
- xpath_obj = xmlXPathEval
- ((xmlChar *) bd_xmlpath,
- xpath_ctx);
+ char *bd_xmlpath = "/domain/devices/disk/target[@dev]";
+ if (blockdevice_format == source)
+ bd_xmlpath = "/domain/devices/disk/source[@dev]";
+ xpath_obj = xmlXPathEval ((xmlChar *) bd_xmlpath, xpath_ctx);
if (xpath_obj == NULL || xpath_obj->type != XPATH_NODESET ||
xpath_obj->nodesetval == NULL)