提交 d3889db0 编写于 作者: P Peter Krempa

qemu: Refactor qemuDomainGetInfo

Since the returned structure uses "unsigned long" for memory sizes add a
few overflow checks to notify the user in case we are not able to
represent given values.
上级 eaf43208
...@@ -2611,9 +2611,12 @@ static int qemuDomainSendKey(virDomainPtr domain, ...@@ -2611,9 +2611,12 @@ static int qemuDomainSendKey(virDomainPtr domain,
return ret; return ret;
} }
static int qemuDomainGetInfo(virDomainPtr dom,
virDomainInfoPtr info) static int
qemuDomainGetInfo(virDomainPtr dom,
virDomainInfoPtr info)
{ {
unsigned long long maxmem;
virQEMUDriverPtr driver = dom->conn->privateData; virQEMUDriverPtr driver = dom->conn->privateData;
virDomainObjPtr vm; virDomainObjPtr vm;
int ret = -1; int ret = -1;
...@@ -2624,11 +2627,27 @@ static int qemuDomainGetInfo(virDomainPtr dom, ...@@ -2624,11 +2627,27 @@ static int qemuDomainGetInfo(virDomainPtr dom,
if (virDomainGetInfoEnsureACL(dom->conn, vm->def) < 0) if (virDomainGetInfoEnsureACL(dom->conn, vm->def) < 0)
goto cleanup; goto cleanup;
if (qemuDomainUpdateCurrentMemorySize(driver, vm) < 0)
goto cleanup;
memset(info, 0, sizeof(*info));
info->state = virDomainObjGetState(vm, NULL); info->state = virDomainObjGetState(vm, NULL);
if (!virDomainObjIsActive(vm)) { maxmem = virDomainDefGetMemoryActual(vm->def);
info->cpuTime = 0; if (VIR_ASSIGN_IS_OVERFLOW(info->maxMem, maxmem)) {
} else { virReportError(VIR_ERR_OVERFLOW, "%s",
_("Initial memory size too large"));
goto cleanup;
}
if (virDomainObjIsActive(vm)) {
if (VIR_ASSIGN_IS_OVERFLOW(info->memory, vm->def->mem.cur_balloon)) {
virReportError(VIR_ERR_OVERFLOW, "%s",
_("Current memory size too large"));
goto cleanup;
}
if (qemuGetProcessInfo(&(info->cpuTime), NULL, NULL, vm->pid, 0) < 0) { if (qemuGetProcessInfo(&(info->cpuTime), NULL, NULL, vm->pid, 0) < 0) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s", virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("cannot read cputime for domain")); _("cannot read cputime for domain"));
...@@ -2636,18 +2655,11 @@ static int qemuDomainGetInfo(virDomainPtr dom, ...@@ -2636,18 +2655,11 @@ static int qemuDomainGetInfo(virDomainPtr dom,
} }
} }
info->maxMem = virDomainDefGetMemoryActual(vm->def); if (VIR_ASSIGN_IS_OVERFLOW(info->nrVirtCpu, vm->def->vcpus)) {
virReportError(VIR_ERR_OVERFLOW, "%s", _("cpu count too large"));
if (virDomainObjIsActive(vm)) { goto cleanup;
if (qemuDomainUpdateCurrentMemorySize(driver, vm) < 0)
goto cleanup;
info->memory = vm->def->mem.cur_balloon;
} else {
info->memory = 0;
} }
info->nrVirtCpu = vm->def->vcpus;
ret = 0; ret = 0;
cleanup: cleanup:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册