+ utils_latency: Added latency_counter_get_rate()
[collectd.git] / src / virt.c
index 416383f..62b53dc 100644 (file)
@@ -31,8 +31,7 @@
 #include <libxml/parser.h>
 #include <libxml/tree.h>
 #include <libxml/xpath.h>
-#include <libgen.h>
-#include <stdbool.h>
+#include <libgen.h> /* for basename(3) */
 
 /* Plugin name */
 #define PLUGIN_NAME "virt"
@@ -148,7 +147,7 @@ enum if_field {
 };
 
 /* BlockDeviceFormatBasename */
-_Bool blockdevice_format_basename = false;
+_Bool blockdevice_format_basename = 0;
 static enum bd_field blockdevice_format = target;
 static enum if_field interface_format = if_name;
 
@@ -364,14 +363,7 @@ lv_config (const char *key, const char *value)
         return 0;
     }
     if (strcasecmp (key, "BlockDeviceFormatBasename") == 0) {
-        if (strcasecmp (value, "true") == 0)
-            blockdevice_format_basename = true;
-        else if (strcasecmp (value, "false") == 0)
-            blockdevice_format_basename = false;
-        else {
-            ERROR (PLUGIN_NAME " plugin: unknown BlockDeviceFormatBasename: %s", value);
-            return -1;
-        }
+        blockdevice_format_basename = IS_TRUE (value);
         return 0;
     }
     if (strcasecmp (key, "InterfaceDevice") == 0) {
@@ -614,15 +606,12 @@ lv_read (void)
                     &stats, sizeof stats) != 0)
             continue;
 
-       char *type_instance = NULL;
-       if( blockdevice_format_basename && blockdevice_format == source ) //valid only if we use "source" (full path to the device)
-       {
-               type_instance = strdup(basename(block_devices[i].path));
-       }
-       else
-       {
-               type_instance = 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,
@@ -632,8 +621,8 @@ lv_read (void)
             submit_derive2 ("disk_octets",
                     (derive_t) stats.rd_bytes, (derive_t) stats.wr_bytes,
                     block_devices[i].dom, type_instance);
-       
-       sfree(type_instance);
+
+        sfree (type_instance);
     } /* for (nr_block_devices) */
 
     /* Get interface stats for each domain. */
@@ -641,7 +630,6 @@ lv_read (void)
         struct _virDomainInterfaceStats stats;
         char *display_name = NULL;
 
-
         switch (interface_format) {
             case if_address:
                 display_name = interface_devices[i].address;
@@ -762,11 +750,9 @@ refresh_lists (void)
             xpath_ctx = xmlXPathNewContext (xml_doc);
 
             /* Block devices. */
-           char * bd_xmlpath = "/domain/devices/disk/target[@dev]";  //the default behavior
-           if( blockdevice_format == source )
-           {
-               bd_xmlpath = "/domain/devices/disk/source[@dev]";
-           }
+            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 ||