[PATCH v3 12/15] qemuDomainSetMemoryFlags: Take virtio-mem into consideration

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

 



The qemuDomainSetMemoryFlags() allows for memballoon
(<currentMemory/>) changes for both active and inactive guests.
And just before doing any change, we have to make sure that the
new size is not greater than the total memory (<memory/>).

However, the total memory includes not only the regular guest
memory, but also sum of maximum sizes of all virtio-mems (in fact
all memory devices for that matter). But virtio-mem devices are
modified differently (via virDomainUpdateDevice()) and thus the
upper limit for new balloon size has to be lowered.

Signed-off-by: Michal Privoznik <mprivozn@xxxxxxxxxx>
---
 src/qemu/qemu_driver.c | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index d5891e32c3..235cc8566e 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2432,12 +2432,28 @@ static int qemuDomainSetMemoryFlags(virDomainPtr dom, unsigned long newmem,
     } else {
         /* resize the current memory */
         unsigned long oldmax = 0;
+        size_t i;
 
-        if (def)
+        if (def) {
             oldmax = virDomainDefGetMemoryTotal(def);
+
+            /* While virtio-mem is regular mem from guest POV, it can't be
+             * modified through this API. */
+            for (i = 0; i < def->nmems; i++) {
+                if (def->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM)
+                    oldmax -= def->mems[i]->size;
+            }
+        }
+
         if (persistentDef) {
-            if (!oldmax || oldmax > virDomainDefGetMemoryTotal(persistentDef))
+            if (!oldmax || oldmax > virDomainDefGetMemoryTotal(persistentDef)) {
                 oldmax = virDomainDefGetMemoryTotal(persistentDef);
+
+                for (i = 0; i < persistentDef->nmems; i++) {
+                    if (persistentDef->mems[i]->model == VIR_DOMAIN_MEMORY_MODEL_VIRTIO_MEM)
+                        oldmax -= persistentDef->mems[i]->size;
+                }
+            }
         }
 
         if (newmem > oldmax) {
-- 
2.26.2




[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]

  Powered by Linux