提交 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,
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;
virDomainObjPtr vm;
int ret = -1;
......@@ -2624,11 +2627,27 @@ static int qemuDomainGetInfo(virDomainPtr dom,
if (virDomainGetInfoEnsureACL(dom->conn, vm->def) < 0)
goto cleanup;
if (qemuDomainUpdateCurrentMemorySize(driver, vm) < 0)
goto cleanup;
memset(info, 0, sizeof(*info));
info->state = virDomainObjGetState(vm, NULL);
if (!virDomainObjIsActive(vm)) {
info->cpuTime = 0;
} else {
maxmem = virDomainDefGetMemoryActual(vm->def);
if (VIR_ASSIGN_IS_OVERFLOW(info->maxMem, maxmem)) {
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) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("cannot read cputime for domain"));
......@@ -2636,18 +2655,11 @@ static int qemuDomainGetInfo(virDomainPtr dom,
}
}
info->maxMem = virDomainDefGetMemoryActual(vm->def);
if (virDomainObjIsActive(vm)) {
if (qemuDomainUpdateCurrentMemorySize(driver, vm) < 0)
goto cleanup;
info->memory = vm->def->mem.cur_balloon;
} else {
info->memory = 0;
if (VIR_ASSIGN_IS_OVERFLOW(info->nrVirtCpu, vm->def->vcpus)) {
virReportError(VIR_ERR_OVERFLOW, "%s", _("cpu count too large"));
goto cleanup;
}
info->nrVirtCpu = vm->def->vcpus;
ret = 0;
cleanup:
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册