提交 fe2a0b02 编写于 作者: H Hu Tao 提交者: Laine Stump

use virBitmap to store nodeinfo.

上级 f4b2dcf5
...@@ -739,10 +739,10 @@ cleanup: ...@@ -739,10 +739,10 @@ cleanup:
* and max cpu is 7. The map file shows 0-4,6-7. This function parses * and max cpu is 7. The map file shows 0-4,6-7. This function parses
* it and returns cpumap. * it and returns cpumap.
*/ */
static char * static virBitmapPtr
linuxParseCPUmap(int *max_cpuid, const char *path) linuxParseCPUmap(int *max_cpuid, const char *path)
{ {
char *map = NULL; virBitmapPtr map = NULL;
char *str = NULL; char *str = NULL;
int max_id = 0, i; int max_id = 0, i;
...@@ -751,20 +751,16 @@ linuxParseCPUmap(int *max_cpuid, const char *path) ...@@ -751,20 +751,16 @@ linuxParseCPUmap(int *max_cpuid, const char *path)
goto error; goto error;
} }
if (VIR_ALLOC_N(map, VIR_DOMAIN_CPUMASK_LEN) < 0) { if (virBitmapParse(str, 0, &map,
virReportOOMError(); VIR_DOMAIN_CPUMASK_LEN) < 0) {
goto error;
}
if (virDomainCpuSetParse(str, 0, map,
VIR_DOMAIN_CPUMASK_LEN) < 0) {
goto error; goto error;
} }
for (i = 0; i < VIR_DOMAIN_CPUMASK_LEN; i++) { i = -1;
if (map[i]) { while ((i = virBitmapNextSetBit(map, i)) >= 0) {
max_id = i; max_id = i;
}
} }
*max_cpuid = max_id; *max_cpuid = max_id;
VIR_FREE(str); VIR_FREE(str);
...@@ -772,7 +768,7 @@ linuxParseCPUmap(int *max_cpuid, const char *path) ...@@ -772,7 +768,7 @@ linuxParseCPUmap(int *max_cpuid, const char *path)
error: error:
VIR_FREE(str); VIR_FREE(str);
VIR_FREE(map); virBitmapFree(map);
return NULL; return NULL;
} }
#endif #endif
...@@ -911,14 +907,14 @@ int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED, ...@@ -911,14 +907,14 @@ int nodeGetMemoryStats(virConnectPtr conn ATTRIBUTE_UNUSED,
#endif #endif
} }
char * virBitmapPtr
nodeGetCPUmap(virConnectPtr conn ATTRIBUTE_UNUSED, nodeGetCPUmap(virConnectPtr conn ATTRIBUTE_UNUSED,
int *max_id ATTRIBUTE_UNUSED, int *max_id ATTRIBUTE_UNUSED,
const char *mapname ATTRIBUTE_UNUSED) const char *mapname ATTRIBUTE_UNUSED)
{ {
#ifdef __linux__ #ifdef __linux__
char *path; char *path;
char *cpumap; virBitmapPtr cpumap;
if (virAsprintf(&path, SYSFS_SYSTEM_PATH "/cpu/%s", mapname) < 0) { if (virAsprintf(&path, SYSFS_SYSTEM_PATH "/cpu/%s", mapname) < 0) {
virReportOOMError(); virReportOOMError();
......
...@@ -46,9 +46,9 @@ int nodeGetCellsFreeMemory(virConnectPtr conn, ...@@ -46,9 +46,9 @@ int nodeGetCellsFreeMemory(virConnectPtr conn,
int maxCells); int maxCells);
unsigned long long nodeGetFreeMemory(virConnectPtr conn); unsigned long long nodeGetFreeMemory(virConnectPtr conn);
char *nodeGetCPUmap(virConnectPtr conn, virBitmapPtr nodeGetCPUmap(virConnectPtr conn,
int *max_id, int *max_id,
const char *mapname); const char *mapname);
int nodeGetMemoryParameters(virConnectPtr conn, int nodeGetMemoryParameters(virConnectPtr conn,
virTypedParameterPtr params, virTypedParameterPtr params,
......
...@@ -13502,8 +13502,8 @@ qemuDomainGetPercpuStats(virDomainPtr domain, ...@@ -13502,8 +13502,8 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
int start_cpu, int start_cpu,
unsigned int ncpus) unsigned int ncpus)
{ {
char *map = NULL; virBitmapPtr map = NULL;
char *map2 = NULL; virBitmapPtr map2 = NULL;
int rv = -1; int rv = -1;
int i, id, max_id; int i, id, max_id;
char *pos; char *pos;
...@@ -13515,6 +13515,7 @@ qemuDomainGetPercpuStats(virDomainPtr domain, ...@@ -13515,6 +13515,7 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
virTypedParameterPtr ent; virTypedParameterPtr ent;
int param_idx; int param_idx;
unsigned long long cpu_time; unsigned long long cpu_time;
bool result;
/* return the number of supported params */ /* return the number of supported params */
if (nparams == 0 && ncpus != 0) if (nparams == 0 && ncpus != 0)
...@@ -13553,7 +13554,9 @@ qemuDomainGetPercpuStats(virDomainPtr domain, ...@@ -13553,7 +13554,9 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
id = start_cpu + ncpus - 1; id = start_cpu + ncpus - 1;
for (i = 0; i <= id; i++) { for (i = 0; i <= id; i++) {
if (!map[i]) { if (virBitmapGetBit(map, i, &result) < 0)
goto cleanup;
if (!result) {
cpu_time = 0; cpu_time = 0;
} else if (virStrToLong_ull(pos, &pos, 10, &cpu_time) < 0) { } else if (virStrToLong_ull(pos, &pos, 10, &cpu_time) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR, "%s", virReportError(VIR_ERR_INTERNAL_ERROR, "%s",
...@@ -13585,7 +13588,7 @@ qemuDomainGetPercpuStats(virDomainPtr domain, ...@@ -13585,7 +13588,7 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
/* Check that the mapping of online cpus didn't change mid-parse. */ /* Check that the mapping of online cpus didn't change mid-parse. */
map2 = nodeGetCPUmap(domain->conn, &max_id, "present"); map2 = nodeGetCPUmap(domain->conn, &max_id, "present");
if (!map2 || memcmp(map, map2, VIR_DOMAIN_CPUMASK_LEN) != 0) { if (!map2 || !virBitmapEqual(map, map2)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s", virReportError(VIR_ERR_OPERATION_INVALID, "%s",
_("the set of online cpus changed while reading")); _("the set of online cpus changed while reading"));
goto cleanup; goto cleanup;
...@@ -13593,7 +13596,9 @@ qemuDomainGetPercpuStats(virDomainPtr domain, ...@@ -13593,7 +13596,9 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
sum_cpu_pos = sum_cpu_time; sum_cpu_pos = sum_cpu_time;
for (i = 0; i <= id; i++) { for (i = 0; i <= id; i++) {
if (!map[i]) if (virBitmapGetBit(map, i, &result) < 0)
goto cleanup;
if (!result)
cpu_time = 0; cpu_time = 0;
else else
cpu_time = *(sum_cpu_pos++); cpu_time = *(sum_cpu_pos++);
...@@ -13611,8 +13616,8 @@ qemuDomainGetPercpuStats(virDomainPtr domain, ...@@ -13611,8 +13616,8 @@ qemuDomainGetPercpuStats(virDomainPtr domain,
cleanup: cleanup:
VIR_FREE(sum_cpu_time); VIR_FREE(sum_cpu_time);
VIR_FREE(buf); VIR_FREE(buf);
VIR_FREE(map); virBitmapFree(map);
VIR_FREE(map2); virBitmapFree(map2);
return rv; return rv;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册