[PATCH 6/7] qemu: Implement request of vCPU state using the guest agent

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



This patch implements the VIR_DOMAIN_VCPU flag for the qemuDomainGetVcpusFlags()
libvirt API implementation.
---
 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 e3acdab..e54d8b9 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -4395,17 +4395,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;
@@ -4414,16 +4421,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_MODIFY) < 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

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]