This patch implements the VIR_DOMAIN_VCPU_AGENT flag for the
qemuDomainGetVcpusFlags() libvirt API implementation.
---
Notes:
Version 2:
- use job type QUERY instead of MODIFY
src/qemu/qemu_driver.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 56 insertions(+), 4 deletions(-)
diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 7c167b7..d0508e9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4368,17 +4368,24 @@ static int
qemuDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
{
virQEMUDriverPtr driver = dom->conn->privateData;
+ qemuDomainObjPrivatePtr priv;
virDomainObjPtr vm;
virDomainDefPtr def;
int ret = -1;
virCapsPtr caps = NULL;
+ qemuAgentCPUInfoPtr cpuinfo = NULL;
+ int ncpuinfo;
+ int i;
virCheckFlags(VIR_DOMAIN_AFFECT_LIVE |
VIR_DOMAIN_AFFECT_CONFIG |
- VIR_DOMAIN_VCPU_MAXIMUM, -1);
+ VIR_DOMAIN_VCPU_MAXIMUM |
+ VIR_DOMAIN_VCPU_AGENT, -1);
if (!(vm = qemuDomObjFromDomain(dom)))
- goto cleanup;
+ return -1;
+
+ priv = vm->privateData;
if (!(caps = virQEMUDriverGetCapabilities(driver, false)))
goto cleanup;
@@ -4387,16 +4394,61 @@ qemuDomainGetVcpusFlags(virDomainPtr dom, unsigned int flags)
vm, &flags, &def) < 0)
goto cleanup;
- if (flags & VIR_DOMAIN_AFFECT_LIVE) {
+ if (flags & VIR_DOMAIN_AFFECT_LIVE)
def = vm->def;
+
+ if (flags & VIR_DOMAIN_VCPU_AGENT) {
+ if (flags & VIR_DOMAIN_AFFECT_CONFIG) {
+ virReportError(VIR_ERR_INVALID_ARG, "%s",
+ _("vCPU count provided by the guest agent can only be
"
+ " requested for live domains"));
+ goto cleanup;
+ }
+
+ if (qemuDomainObjBeginJob(driver, vm, QEMU_JOB_QUERY) < 0)
+ goto cleanup;
+
+ if (!virDomainObjIsActive(vm)) {
+ virReportError(VIR_ERR_OPERATION_INVALID, "%s",
+ _("domain is not running"));
+ goto endjob;
+ }
+
+ qemuDomainObjEnterAgent(vm);
+ ncpuinfo = qemuAgentGetVCPUs(priv->agent, &cpuinfo);
+ qemuDomainObjExitAgent(vm);
+
+endjob:
+ if (qemuDomainObjEndJob(driver, vm) == 0)
+ vm = NULL;
+
+ if (ncpuinfo < 0)
+ goto cleanup;
+
+ if (flags & VIR_DOMAIN_VCPU_MAXIMUM) {
+ ret = ncpuinfo;
+ goto cleanup;
+ }
+
+ /* count the online vcpus */
+ ret = 0;
+ for (i = 0; i < ncpuinfo; i++) {
+ if (cpuinfo[i].online)
+ ret++;
+ }
+ } else {
+ if (flags & VIR_DOMAIN_VCPU_MAXIMUM)
+ ret = def->maxvcpus;
+ else
+ ret = def->vcpus;
}
- ret = (flags & VIR_DOMAIN_VCPU_MAXIMUM) ? def->maxvcpus : def->vcpus;
cleanup:
if (vm)
virObjectUnlock(vm);
virObjectUnref(caps);
+ VIR_FREE(cpuinfo);
return ret;
}
--
1.8.1.5