From ce2eb567629eb21d650d5c27fefe607837c061fd Mon Sep 17 00:00:00 2001 From: Radoslaw Jablonski Date: Thu, 28 Feb 2019 14:14:01 +0000 Subject: [PATCH] virt: Fetch block info stats from libvirt only if needed 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 --- src/virt.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/virt.c b/src/virt.c index a6f050d4..93f9cebf 100644 --- a/src/virt.c +++ b/src/virt.c @@ -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; + } } } -- 2.11.0