From 4436eed7d1b5e841a87604de85ff0267dfd1a631 Mon Sep 17 00:00:00 2001 From: Pavel Rochnyack Date: Fri, 24 May 2019 04:16:47 +0700 Subject: [PATCH] virt plugin: Do not request cpu maps when not required --- src/virt.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/virt.c b/src/virt.c index 17420269..64f9415d 100644 --- a/src/virt.c +++ b/src/virt.c @@ -1589,7 +1589,6 @@ static void vcpu_pin_submit(virDomainPtr dom, int max_cpus, int vcpu, static int get_vcpu_stats(virDomainPtr domain, unsigned short nr_virt_cpu) { int max_cpus = VIR_NODEINFO_MAXCPUS(nodeinfo); - int cpu_map_len = VIR_CPU_MAPLEN(max_cpus); virVcpuInfoPtr vinfo = calloc(nr_virt_cpu, sizeof(*vinfo)); if (vinfo == NULL) { @@ -1597,11 +1596,17 @@ static int get_vcpu_stats(virDomainPtr domain, unsigned short nr_virt_cpu) { return -1; } - unsigned char *cpumaps = calloc(nr_virt_cpu, cpu_map_len); - if (cpumaps == NULL) { - ERROR(PLUGIN_NAME " plugin: calloc failed."); - sfree(vinfo); - return -1; + int cpu_map_len = 0; + unsigned char *cpumaps = NULL; + if (extra_stats & ex_stats_vcpupin) { + cpu_map_len = VIR_CPU_MAPLEN(max_cpus); + cpumaps = calloc(nr_virt_cpu, cpu_map_len); + + if (cpumaps == NULL) { + ERROR(PLUGIN_NAME " plugin: calloc failed."); + sfree(vinfo); + return -1; + } } int status = -- 2.11.0