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

[libvirt] [PATCH 3/5] setmem: implement the code to address the new API in the qemu driver



This patch implements the code to address the new API
in the qemu driver.


Signed-off-by: Taku Izumi <izumi taku jp fujitsu com>
---
 src/qemu/qemu_driver.c |   64 +++++++++++++++++++++++++++++++++++++++----------
 1 file changed, 51 insertions(+), 13 deletions(-)

Index: libvirt-git/src/qemu/qemu_driver.c
===================================================================
--- libvirt-git.orig/src/qemu/qemu_driver.c
+++ libvirt-git/src/qemu/qemu_driver.c
@@ -1569,12 +1569,22 @@ cleanup:
     return ret;
 }

-static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
+static int qemudDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
+                                     unsigned int flags) {
     struct qemud_driver *driver = dom->conn->privateData;
     qemuDomainObjPrivatePtr priv;
     virDomainObjPtr vm;
+    virDomainDefPtr persistentDef;
     int ret = -1, r;

+    virCheckFlags(VIR_DOMAIN_MEM_LIVE |
+                  VIR_DOMAIN_MEM_CONFIG, -1);
+
+    if ((flags & (VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MEM_CONFIG)) == 0) {
+        qemuReportError(VIR_ERR_INVALID_ARG,
+                        _("invalid flag combination: (0x%x)"), flags);
+    }
+
     qemuDriverLock(driver);
     vm = virDomainFindByUUID(&driver->domains, dom->uuid);
     qemuDriverUnlock(driver);
@@ -1595,27 +1605,51 @@ static int qemudDomainSetMemory(virDomai
     if (qemuDomainObjBeginJob(vm) < 0)
         goto cleanup;

-    if (!virDomainObjIsActive(vm)) {
+    if (!virDomainObjIsActive(vm) && (flags & VIR_DOMAIN_MEM_LIVE)) {
         qemuReportError(VIR_ERR_OPERATION_INVALID,
                         "%s", _("domain is not running"));
         goto endjob;
     }

-    priv = vm->privateData;
-    qemuDomainObjEnterMonitor(vm);
-    r = qemuMonitorSetBalloon(priv->mon, newmem);
-    qemuDomainObjExitMonitor(vm);
-    if (r < 0)
+    if (!vm->persistent && (flags & VIR_DOMAIN_MEM_CONFIG)) {
+        qemuReportError(VIR_ERR_OPERATION_INVALID, "%s",
+                        _("cannot change persistent config of a transient domain"));
         goto endjob;
+    }

-    /* Lack of balloon support is a fatal error */
-    if (r == 0) {
-        qemuReportError(VIR_ERR_OPERATION_INVALID,
-                        "%s", _("cannot set memory of an active domain"));
+    if (!(persistentDef = virDomainObjGetPersistentDef(driver->caps, vm)))
         goto endjob;
+
+    switch (flags) {
+    case VIR_DOMAIN_MEM_CONFIG:
+        persistentDef->mem.cur_balloon = newmem;
+        ret = 0;
+        break;
+
+    case VIR_DOMAIN_MEM_LIVE:
+    case VIR_DOMAIN_MEM_LIVE | VIR_DOMAIN_MEM_CONFIG:
+        priv = vm->privateData;
+        qemuDomainObjEnterMonitor(vm);
+        r = qemuMonitorSetBalloon(priv->mon, newmem);
+        qemuDomainObjExitMonitor(vm);
+        if (r < 0)
+            goto endjob;
+        /* Lack of balloon support is a fatal error */
+        if (r == 0) {
+            qemuReportError(VIR_ERR_OPERATION_INVALID,
+                           "%s", _("cannot set memory of an active domain"));
+            goto endjob;
+        }
+        if (flags & VIR_DOMAIN_MEM_CONFIG)
+            persistentDef->mem.cur_balloon = newmem;
+        ret = 0;
+        break;
     }

-    ret = 0;
+    /* Save the persistent config to disk */
+    if (flags & VIR_DOMAIN_MEM_CONFIG)
+        ret = virDomainSaveConfig(driver->configDir, persistentDef);
+
 endjob:
     if (qemuDomainObjEndJob(vm) == 0)
         vm = NULL;
@@ -1626,6 +1660,10 @@ cleanup:
     return ret;
 }

+static int qemudDomainSetMemory(virDomainPtr dom, unsigned long newmem) {
+    return qemudDomainSetMemoryFlags(dom, newmem, VIR_DOMAIN_MEM_LIVE);
+}
+
 static int qemudDomainGetInfo(virDomainPtr dom,
                               virDomainInfoPtr info) {
     struct qemud_driver *driver = dom->conn->privateData;
@@ -6789,7 +6827,7 @@ static virDriver qemuDriver = {
     qemudDomainGetMaxMemory, /* domainGetMaxMemory */
     NULL, /* domainSetMaxMemory */
     qemudDomainSetMemory, /* domainSetMemory */
-    NULL, /* domainSetMemoryFlags */
+    qemudDomainSetMemoryFlags, /* domainSetMemoryFlags */
     qemudDomainGetInfo, /* domainGetInfo */
     qemudDomainSave, /* domainSave */
     qemudDomainRestore, /* domainRestore */



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