Commit 1ce7c1d2 changed domainGetInfo to set virDomainInfoPtr->memory to 0 when domain is inactive, but only did this for the LXC and QEMU drivers. Make a similar change to the other virt drivers so they all behave the same. Signed-off-by: Jim Fehlig <jfehlig@xxxxxxxx> --- FYI, commit 1ce7c1d2 also broke libvirt-tck 110-memory-balloon.t test not ok 13 - Get current memory is 924288 Failed test 'Get current memory is 924288' at /usr/share/libvirt-tck/tests/domain/110-memory-balloon.t line 120. got: '0' expected: '924288' A patch to fix the TCK test has been added to my TODO list. src/bhyve/bhyve_driver.c | 4 ++-- src/hyperv/hyperv_driver.c | 3 ++- src/libxl/libxl_driver.c | 4 ++-- src/openvz/openvz_driver.c | 10 ++++++---- src/phyp/phyp_driver.c | 10 +++++++--- src/uml/uml_driver.c | 8 ++++---- src/vmware/vmware_driver.c | 6 ++++-- src/vz/vz_driver.c | 6 ++++-- src/xen/xen_driver.c | 2 ++ src/xen/xen_hypervisor.c | 7 ++++--- src/xen/xend_internal.c | 8 +++++--- src/xen/xm_internal.c | 3 --- src/xenapi/xenapi_driver.c | 7 +++++-- 13 files changed, 47 insertions(+), 31 deletions(-) diff --git a/src/bhyve/bhyve_driver.c b/src/bhyve/bhyve_driver.c index 7f365b1..a85f7c7 100644 --- a/src/bhyve/bhyve_driver.c +++ b/src/bhyve/bhyve_driver.c @@ -295,11 +295,11 @@ bhyveDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) if (virDomainGetInfoEnsureACL(domain->conn, vm->def) < 0) goto cleanup; + memset(info, 0, sizeof(*info)); + if (virDomainObjIsActive(vm)) { if (virBhyveGetDomainTotalCpuStats(vm, &(info->cpuTime)) < 0) goto cleanup; - } else { - info->cpuTime = 0; } info->state = virDomainObjGetState(vm, NULL); diff --git a/src/hyperv/hyperv_driver.c b/src/hyperv/hyperv_driver.c index b539541..2524878 100644 --- a/src/hyperv/hyperv_driver.c +++ b/src/hyperv/hyperv_driver.c @@ -713,8 +713,9 @@ hypervDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) /* Fill struct */ info->state = hypervMsvmComputerSystemEnabledStateToDomainState(computerSystem); + if (info->state != VIR_DOMAIN_SHUTOFF) + info->memory = memorySettingData->data->VirtualQuantity * 1024; /* megabyte to kilobyte */ info->maxMem = memorySettingData->data->Limit * 1024; /* megabyte to kilobyte */ - info->memory = memorySettingData->data->VirtualQuantity * 1024; /* megabyte to kilobyte */ info->nrVirtCpu = processorSettingData->data->VirtualQuantity; info->cpuTime = 0; diff --git a/src/libxl/libxl_driver.c b/src/libxl/libxl_driver.c index 5f69b49..9d9b9a6 100644 --- a/src/libxl/libxl_driver.c +++ b/src/libxl/libxl_driver.c @@ -1577,9 +1577,9 @@ libxlDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) if (virDomainGetInfoEnsureACL(dom->conn, vm->def) < 0) goto cleanup; + memset(info, 0, sizeof(*info)); + if (!virDomainObjIsActive(vm)) { - info->cpuTime = 0; - info->memory = vm->def->mem.cur_balloon; info->maxMem = virDomainDefGetMemoryActual(vm->def); } else { if (libxl_domain_info(cfg->ctx, &d_info, vm->def->id) != 0) { diff --git a/src/openvz/openvz_driver.c b/src/openvz/openvz_driver.c index fc8db7e..6005946 100644 --- a/src/openvz/openvz_driver.c +++ b/src/openvz/openvz_driver.c @@ -449,13 +449,13 @@ static int openvzDomainGetInfo(virDomainPtr dom, goto cleanup; } + memset(info, 0, sizeof(*info)); + if (openvzGetVEStatus(vm, &state, NULL) == -1) goto cleanup; info->state = state; - if (info->state != VIR_DOMAIN_RUNNING) { - info->cpuTime = 0; - } else { + if (info->state == VIR_DOMAIN_RUNNING) { if (openvzGetProcessInfo(&(info->cpuTime), dom->id) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, _("cannot read cputime for domain %d"), dom->id); @@ -463,8 +463,10 @@ static int openvzDomainGetInfo(virDomainPtr dom, } } + if (info->state != VIR_DOMAIN_SHUTOFF) + info->memory = vm->def->mem.cur_balloon; + info->maxMem = virDomainDefGetMemoryActual(vm->def); - info->memory = vm->def->mem.cur_balloon; info->nrVirtCpu = vm->def->vcpus; ret = 0; diff --git a/src/phyp/phyp_driver.c b/src/phyp/phyp_driver.c index 54dec70..c35675a 100644 --- a/src/phyp/phyp_driver.c +++ b/src/phyp/phyp_driver.c @@ -3402,15 +3402,19 @@ phypDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) phyp_driverPtr phyp_driver = dom->conn->privateData; char *managed_system = phyp_driver->managed_system; + memset(info, 0, sizeof(*info)); + info->state = phypGetLparState(dom->conn, dom->id); if ((info->maxMem = phypGetLparMem(dom->conn, managed_system, dom->id, 0)) == 0) VIR_WARN("Unable to determine domain's max memory."); - if ((info->memory = - phypGetLparMem(dom->conn, managed_system, dom->id, 1)) == 0) - VIR_WARN("Unable to determine domain's memory."); + if (info->state != VIR_DOMAIN_SHUTOFF) { + if ((info->memory = + phypGetLparMem(dom->conn, managed_system, dom->id, 1)) == 0) + VIR_WARN("Unable to determine domain's memory."); + } if ((info->nrVirtCpu = phypGetLparCPU(dom->conn, managed_system, dom->id)) == 0) diff --git a/src/uml/uml_driver.c b/src/uml/uml_driver.c index c3c5fa7..5d05da1 100644 --- a/src/uml/uml_driver.c +++ b/src/uml/uml_driver.c @@ -1900,20 +1900,20 @@ static int umlDomainGetInfo(virDomainPtr dom, if (virDomainGetInfoEnsureACL(dom->conn, vm->def) < 0) goto cleanup; + memset(info, 0, sizeof(*info)); + info->state = virDomainObjGetState(vm, NULL); - if (!virDomainObjIsActive(vm)) { - info->cpuTime = 0; - } else { + if (virDomainObjIsActive(vm)) { if (umlGetProcessInfo(&(info->cpuTime), vm->pid) < 0) { virReportError(VIR_ERR_OPERATION_FAILED, "%s", _("cannot read cputime for domain")); goto cleanup; } + info->memory = vm->def->mem.cur_balloon; } info->maxMem = virDomainDefGetMemoryActual(vm->def); - info->memory = vm->def->mem.cur_balloon; info->nrVirtCpu = vm->def->vcpus; ret = 0; diff --git a/src/vmware/vmware_driver.c b/src/vmware/vmware_driver.c index ec74fe3..d42f6b7 100644 --- a/src/vmware/vmware_driver.c +++ b/src/vmware/vmware_driver.c @@ -1123,13 +1123,15 @@ vmwareDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) goto cleanup; } + memset(info, 0, sizeof(*info)); + if (vmwareUpdateVMStatus(driver, vm) < 0) goto cleanup; info->state = virDomainObjGetState(vm, NULL); - info->cpuTime = 0; + if (info->state != VIR_DOMAIN_SHUTOFF) + info->memory = vm->def->mem.cur_balloon; info->maxMem = virDomainDefGetMemoryActual(vm->def); - info->memory = vm->def->mem.cur_balloon; info->nrVirtCpu = vm->def->vcpus; ret = 0; diff --git a/src/vz/vz_driver.c b/src/vz/vz_driver.c index 8fa7957..2cef2e1 100644 --- a/src/vz/vz_driver.c +++ b/src/vz/vz_driver.c @@ -563,11 +563,13 @@ vzDomainGetInfo(virDomainPtr domain, virDomainInfoPtr info) if (!(privdom = vzDomObjFromDomain(domain))) goto cleanup; + memset(info, 0, sizeof(*info)); + info->state = virDomainObjGetState(privdom, NULL); - info->memory = privdom->def->mem.cur_balloon; + if (info->state != VIR_DOMAIN_SHUTOFF) + info->memory = privdom->def->mem.cur_balloon; info->maxMem = virDomainDefGetMemoryActual(privdom->def); info->nrVirtCpu = privdom->def->vcpus; - info->cpuTime = 0; ret = 0; cleanup: diff --git a/src/xen/xen_driver.c b/src/xen/xen_driver.c index ce31f0f..3d0bb08 100644 --- a/src/xen/xen_driver.c +++ b/src/xen/xen_driver.c @@ -1173,6 +1173,8 @@ xenUnifiedDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) if (virDomainGetInfoEnsureACL(dom->conn, def) < 0) goto cleanup; + memset(info, 0, sizeof(*info)); + if (def->id < 0) { if (priv->xendConfigVersion < XEND_CONFIG_VERSION_3_0_4) ret = xenXMDomainGetInfo(dom->conn, def, info); diff --git a/src/xen/xen_hypervisor.c b/src/xen/xen_hypervisor.c index 431c47a..920dae1 100644 --- a/src/xen/xen_hypervisor.c +++ b/src/xen/xen_hypervisor.c @@ -2776,7 +2776,6 @@ xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info) kb_per_pages = 4; } - memset(info, 0, sizeof(virDomainInfo)); XEN_GETDOMAININFO_CLEAR(dominfo); ret = virXen_getdomaininfo(priv->handle, id, &dominfo); @@ -2820,8 +2819,10 @@ xenHypervisorGetDomInfo(virConnectPtr conn, int id, virDomainInfoPtr info) * convert to microseconds, same thing convert to * kilobytes from page counts */ - info->cpuTime = XEN_GETDOMAININFO_CPUTIME(dominfo); - info->memory = XEN_GETDOMAININFO_TOT_PAGES(dominfo) * kb_per_pages; + if (info->state != VIR_DOMAIN_SHUTOFF) { + info->cpuTime = XEN_GETDOMAININFO_CPUTIME(dominfo); + info->memory = XEN_GETDOMAININFO_TOT_PAGES(dominfo) * kb_per_pages; + } info->maxMem = XEN_GETDOMAININFO_MAX_PAGES(dominfo); if (info->maxMem != UINT_MAX) info->maxMem *= kb_per_pages; diff --git a/src/xen/xend_internal.c b/src/xen/xend_internal.c index b81c0b7..1de642e 100644 --- a/src/xen/xend_internal.c +++ b/src/xen/xend_internal.c @@ -953,10 +953,12 @@ sexpr_to_xend_domain_info(virDomainDefPtr def, int vcpus; info->state = sexpr_to_xend_domain_state(def, root); - info->memory = sexpr_u64(root, "domain/memory") << 10; + if (info->state != VIR_DOMAIN_SHUTOFF) { + info->memory = sexpr_u64(root, "domain/memory") << 10; + info->cpuTime = sexpr_float(root, "domain/cpu_time") * 1000000000; + } + info->maxMem = sexpr_u64(root, "domain/maxmem") << 10; - info->cpuTime = sexpr_float(root, "domain/cpu_time") * 1000000000; - vcpus = sexpr_int(root, "domain/vcpus"); info->nrVirtCpu = count_one_bits_l(sexpr_u64(root, "domain/vcpu_avail")); if (!info->nrVirtCpu || vcpus < info->nrVirtCpu) diff --git a/src/xen/xm_internal.c b/src/xen/xm_internal.c index 59b1cd4..4a49014 100644 --- a/src/xen/xm_internal.c +++ b/src/xen/xm_internal.c @@ -481,12 +481,9 @@ xenXMDomainGetInfo(virConnectPtr conn, if (!(entry = virHashLookup(priv->configCache, filename))) goto error; - memset(info, 0, sizeof(virDomainInfo)); info->maxMem = virDomainDefGetMemoryActual(entry->def); - info->memory = entry->def->mem.cur_balloon; info->nrVirtCpu = entry->def->vcpus; info->state = VIR_DOMAIN_SHUTOFF; - info->cpuTime = 0; xenUnifiedUnlock(priv); return 0; diff --git a/src/xenapi/xenapi_driver.c b/src/xenapi/xenapi_driver.c index 11f6e91..b052f63 100644 --- a/src/xenapi/xenapi_driver.c +++ b/src/xenapi/xenapi_driver.c @@ -1074,7 +1074,9 @@ xenapiDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) xen_vm_record *record; xen_vm_set *vms; xen_session *session = ((struct _xenapiPrivate *)(dom->conn->privateData))->session; - info->cpuTime = 0; /* CPU time is not advertised */ + + memset(info, 0, sizeof(*info)); + if (xen_vm_get_by_name_label(session, &vms, dom->name) && vms->size > 0) { if (vms->size != 1) { xenapiSessionErrorHandler(dom->conn, VIR_ERR_INTERNAL_ERROR, @@ -1091,7 +1093,8 @@ xenapiDomainGetInfo(virDomainPtr dom, virDomainInfoPtr info) xen_vm_get_record(session, &record, vm); if (record != NULL) { xen_vm_metrics_get_memory_actual(session, &memory, record->metrics->u.handle); - info->memory = (memory / 1024); + if (info->state != VIR_DOMAIN_SHUTOFF) + info->memory = (memory / 1024); xen_vm_record_free(record); } xen_vm_get_vcpus_max(session, &vcpu, vm); -- 2.1.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list