---
src/nodeinfo.c | 25 ++++++++++++-------------
src/nodeinfo.h | 2 +-
src/qemu/qemu_driver.c | 19 ++++++++++++-------
3 files changed, 25 insertions(+), 21 deletions(-)
diff --git a/src/nodeinfo.c b/src/nodeinfo.c
index e3d4a24..013eb4a 100644
--- a/src/nodeinfo.c
+++ b/src/nodeinfo.c
@@ -737,29 +737,28 @@ cleanup:
* and max cpu is 7. The map file shows 0-4,6-7. This function parses
* it and returns cpumap.
*/
-static char *
+static virBitmapPtr
linuxParseCPUmap(int *max_cpuid, const char *path)
{
- char *map = NULL;
+ virBitmapPtr map = NULL;
char *str = NULL;
int max_id = 0, i;
+ bool set = false;
if (virFileReadAll(path, 5 * VIR_DOMAIN_CPUMASK_LEN, &str) < 0) {
virReportOOMError();
goto error;
}
- if (VIR_ALLOC_N(map, VIR_DOMAIN_CPUMASK_LEN) < 0) {
- virReportOOMError();
- goto error;
- }
- if (virDomainCpuSetParse(str, 0, map,
- VIR_DOMAIN_CPUMASK_LEN) < 0) {
+ if (virBitmapParse(str, 0, &map,
+ VIR_DOMAIN_CPUMASK_LEN) < 0) {
goto error;
}
- for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) {
- if (map[i]) {
+ for (i = 0; i < virBitmapSize(map); i++) {
+ if (virBitmapGetBit(map, i, &set) < 0)
+ goto error;
+ if (set) {
max_id = i;
}
}
@@ -770,7 +769,7 @@ linuxParseCPUmap(int *max_cpuid, const char *path)
error:
VIR_FREE(str);
- VIR_FREE(map);
+ virBitmapFree(map);
return NULL;
}
#endif
@@ -909,14 +908,14 @@ int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED,
#endif
}
-char *
+virBitmapPtr
nodeGetCPUmap(virConnectPtr conn ATTRIBUTE_UNUSED,
int *max_id ATTRIBUTE_UNUSED,
const char *mapname ATTRIBUTE_UNUSED)
{
#ifdef __linux__
char *path;
- char *cpumap;
+ virBitmapPtr cpumap;
if (virAsprintf(&path, SYSFS_SYSTEM_PATH "/cpu/%s", mapname) < 0) {
virReportOOMError();
diff --git a/src/nodeinfo.h b/src/nodeinfo.h
index 12090e2..1a2b0af 100644
--- a/src/nodeinfo.h
+++ b/src/nodeinfo.h
@@ -46,7 +46,7 @@ int nodeGetCellsFreeMemory(virConnectPtr conn,
int maxCells);
unsigned long long nodeGetFreeMemory(virConnectPtr conn);
-char *nodeGetCPUmap(virConnectPtr conn,
+virBitmapPtr nodeGetCPUmap(virConnectPtr conn,
int *max_id,
const char *mapname);
#endif /* __VIR_NODEINFO_H__*/
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 0452a62..0e4a878 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -13535,8 +13535,8 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
int start_cpu,
unsigned int ncpus)
{
- char *map = NULL;
- char *map2 = NULL;
+ virBitmapPtr map = NULL;
+ virBitmapPtr map2 = NULL;
int rv = -1;
int i, max_id;
char *pos;
@@ -13548,6 +13548,7 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
virTypedParameterPtr ent;
int param_idx;
unsigned long long cpu_time;
+ bool result;
/* return the number of supported params */
if (nparams == 0 && ncpus != 0)
@@ -13583,7 +13584,9 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
max_id = start_cpu + ncpus - 1;
for (i = 0; i <= max_id; i++) {
- if (!map[i]) {
+ if (virBitmapGetBit(map, i, &result) < 0)
+ goto cleanup;
+ if (!result) {
cpu_time = 0;
} else if (virStrToLong_ull(pos, &pos, 10, &cpu_time) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
@@ -13615,7 +13618,7 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
/* Check that the mapping of online cpus didn't change mid-parse. */
map2 = nodeGetCPUmap(domain->conn, &max_id, "present");
- if (!map2 || memcmp(map, map2, VIR_DOMAIN_CPUMASK_LEN) != 0) {
+ if (!map2 || !virBitmapCmp(map, map2)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("the set of online cpus changed while reading"));
goto cleanup;
@@ -13623,7 +13626,9 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
sum_cpu_pos = sum_cpu_time;
for (i = 0; i <= max_id; i++) {
- if (!map[i])
+ if (virBitmapGetBit(map, i, &result) < 0)
+ goto cleanup;
+ if (!result)
cpu_time = 0;
else
cpu_time = *(sum_cpu_pos++);
@@ -13641,8 +13646,8 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
cleanup:
VIR_FREE(sum_cpu_time);
VIR_FREE(buf);
- VIR_FREE(map);
- VIR_FREE(map2);
+ virBitmapFree(map);
+ virBitmapFree(map2);
return rv;
}
--
1.7.10.2