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

[libvirt] [PATCH 11/11] qemu: Implement virDomainSetGuetVcpu in qemu driver



Use the helper added earlier to implement this new API.
---
 src/qemu/qemu_driver.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 65 insertions(+)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 70acdbb..809807f 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -15231,6 +15231,70 @@ cleanup:
 }
 #undef MATCH

+
+static int
+qemuDomainSetGuestVcpu(virDomainPtr dom,
+                       unsigned int id,
+                       unsigned int online,
+                       unsigned int flags)
+{
+    virQEMUDriverPtr driver = dom->conn->privateData;
+    virDomainObjPtr vm;
+    qemuDomainObjPrivatePtr priv;
+    int ret = -1;
+
+    qemuAgentCPUInfo agentinfo = { .id = id,
+                                   .online = !!online };
+
+    virCheckFlags(0, -1);
+
+    if (!(vm = qemuDomObjFromDomain(dom)))
+        return -1;
+
+    priv = vm->privateData;
+
+    /* request data from the guest */
+    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;
+    }
+
+    if (!priv->agent) {
+        virReportError(VIR_ERR_OPERATION_UNSUPPORTED, "%s",
+                       _("guest agent is not configured"));
+        goto endjob;
+    }
+
+    qemuDomainObjEnterAgent(vm);
+    ret = qemuAgentSetVCPUs(priv->agent, &agentinfo, 1);
+    qemuDomainObjExitAgent(vm);
+
+endjob:
+    if (qemuDomainObjEndJob(driver, vm) == 0)
+        vm = NULL;
+
+    if (ret < 0)
+        goto cleanup;
+
+    if (ret != 0) {
+        virReportError(VIR_ERR_OPERATION_FAILED,
+                       _("failed to set state of vCPU '%u'"), id);
+        goto cleanup;
+    }
+
+    ret = 0;
+
+cleanup:
+    if (vm)
+        virObjectUnlock(vm);
+    return ret;
+}
+
+
 static virDriver qemuDriver = {
     .no = VIR_DRV_QEMU,
     .name = QEMU_DRIVER_NAME,
@@ -15411,6 +15475,7 @@ static virDriver qemuDriver = {
     .domainFSTrim = qemuDomainFSTrim, /* 1.0.1 */
     .domainOpenChannel = qemuDomainOpenChannel, /* 1.0.2 */
     .domainGetVCPUMap = qemuDomainGetVCPUMap, /* 1.0.7 */
+    .domainSetGuestVcpu = qemuDomainSetGuestVcpu, /* 1.0.7 */
 };


-- 
1.8.2.1


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