virt: Fetch block info stats from libvirt only if needed
authorRadoslaw Jablonski <radoslawx.jablonski@intel.com>
Thu, 28 Feb 2019 14:14:01 +0000 (14:14 +0000)
committerRadoslaw Jablonski <radoslawx.jablonski@intel.com>
Thu, 7 Mar 2019 15:50:37 +0000 (15:50 +0000)
Domain block info statistics will be retrieved from libvirt
only if one of extra stats is enabled:
- ex_stats_disk_allocation
- ex_stats_disk_capacity
- ex_stats_disk_physical

Change-Id: I0367c6ec7aafbf9558aaa100a12d40605ab9ba72
Signed-off-by: Radoslaw Jablonski <radoslawx.jablonski@intel.com>
src/virt.c

index a6f050d..93f9ceb 100644 (file)
@@ -1718,21 +1718,26 @@ static int get_disk_err(virDomainPtr domain) {
 #endif /* HAVE_DISK_ERR */
 
 static int get_block_device_stats(struct block_device *block_dev) {
-  virDomainBlockInfo binfo;
-  init_block_info(&binfo);
-
   if (!block_dev) {
     ERROR(PLUGIN_NAME " plugin: get_block_stats NULL pointer");
     return -1;
   }
 
-  /* Block info statistics can be only fetched from devices with 'source'
-   * defined */
-  if (block_dev->has_source) {
-    if (virDomainGetBlockInfo(block_dev->dom, block_dev->path, &binfo, 0) < 0) {
-      ERROR(PLUGIN_NAME " plugin: virDomainGetBlockInfo failed for path: %s",
-            block_dev->path);
-      return -1;
+  virDomainBlockInfo binfo;
+  init_block_info(&binfo);
+
+  /* Fetching block info stats only if needed*/
+  if (extra_stats & (ex_stats_disk_allocation | ex_stats_disk_capacity |
+                     ex_stats_disk_physical)) {
+    /* Block info statistics can be only fetched from devices with 'source'
+     * defined */
+    if (block_dev->has_source) {
+      if (virDomainGetBlockInfo(block_dev->dom, block_dev->path, &binfo, 0) <
+          0) {
+        ERROR(PLUGIN_NAME " plugin: virDomainGetBlockInfo failed for path: %s",
+              block_dev->path);
+        return -1;
+      }
     }
   }