[virt-tools-list] [virt-manager PATCH 4/4] guest: Add memory balloon by default

Andrea Bolognani abologna at redhat.com
Thu Jun 13 10:55:10 UTC 2019


libvirt already does this for pretty much all QEMU guests, but
ARM virt guests for example don't get a memory balloon by default
at that level of the stack.

virt-manager is in a good position to make sure defaults are
consistent across architectures, and there's no downside in having
the device in the XML passed to libvirt anyway.

Signed-off-by: Andrea Bolognani <abologna at redhat.com>
---
 .../compare/virt-install-aarch64-graphics.xml |  1 +
 .../compare/virt-install-aarch64-headless.xml |  1 +
 .../compare/virt-install-aarch64-kvm-gic.xml  |  1 +
 .../virt-install-aarch64-kvm-import.xml       |  1 +
 .../virt-install-arm-defaultmach-f20.xml      |  1 +
 .../compare/virt-install-arm-kvm-import.xml   |  1 +
 .../compare/virt-install-arm-virt-f20.xml     |  1 +
 .../compare/virt-install-f21-kvm-remote.xml   |  1 +
 .../compare/virt-install-kvm-centos7.xml      |  2 ++
 .../virt-install-kvm-fedoralatest-url.xml     |  2 ++
 .../virt-install-kvm-session-defaults.xml     |  2 ++
 .../compare/virt-install-location-iso.xml     |  2 ++
 .../compare/virt-install-many-devices.xml     |  1 +
 ...virt-install-network-install-resources.xml |  2 ++
 ...virt-install-osinfo-netinst-unattended.xml |  2 ++
 .../virt-install-osinfo-url-unattended.xml    |  2 ++
 .../compare/virt-install-osinfo-url.xml       |  2 ++
 .../compare/virt-install-ppc64-graphics.xml   |  1 +
 .../compare/virt-install-ppc64-headless.xml   |  1 +
 .../virt-install-ppc64-machdefault-f20.xml    |  1 +
 .../virt-install-ppc64-pseries-f20.xml        |  1 +
 .../virt-install-ppc64le-kvm-import.xml       |  1 +
 .../compare/virt-install-qemu-32-on-64.xml    |  1 +
 .../compare/virt-install-riscv64-graphics.xml |  1 +
 .../compare/virt-install-riscv64-headless.xml |  1 +
 .../virt-install-s390x-cdrom-KVMIBM.xml       |  1 +
 .../compare/virt-install-s390x-cdrom.xml      |  1 +
 .../compare/virt-install-s390x-graphics.xml   |  1 +
 .../compare/virt-install-s390x-headless.xml   |  1 +
 .../compare/virt-install-x86_64-graphics.xml  |  1 +
 .../compare/virt-install-x86_64-headless.xml  |  1 +
 virtinst/guest.py                             | 32 +++++++++++++++++++
 32 files changed, 71 insertions(+)

diff --git a/tests/cli-test-xml/compare/virt-install-aarch64-graphics.xml b/tests/cli-test-xml/compare/virt-install-aarch64-graphics.xml
index d6972aff..dad2636b 100644
--- a/tests/cli-test-xml/compare/virt-install-aarch64-graphics.xml
+++ b/tests/cli-test-xml/compare/virt-install-aarch64-graphics.xml
@@ -40,6 +40,7 @@
     <video>
       <model type="virtio"/>
     </video>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-aarch64-headless.xml b/tests/cli-test-xml/compare/virt-install-aarch64-headless.xml
index 6bf62e3f..86175a11 100644
--- a/tests/cli-test-xml/compare/virt-install-aarch64-headless.xml
+++ b/tests/cli-test-xml/compare/virt-install-aarch64-headless.xml
@@ -34,6 +34,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-aarch64-kvm-gic.xml b/tests/cli-test-xml/compare/virt-install-aarch64-kvm-gic.xml
index bf244b7c..2c78609b 100644
--- a/tests/cli-test-xml/compare/virt-install-aarch64-kvm-gic.xml
+++ b/tests/cli-test-xml/compare/virt-install-aarch64-kvm-gic.xml
@@ -41,6 +41,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-aarch64-kvm-import.xml b/tests/cli-test-xml/compare/virt-install-aarch64-kvm-import.xml
index 2ec1e7c5..a6eb9421 100644
--- a/tests/cli-test-xml/compare/virt-install-aarch64-kvm-import.xml
+++ b/tests/cli-test-xml/compare/virt-install-aarch64-kvm-import.xml
@@ -34,6 +34,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-arm-defaultmach-f20.xml b/tests/cli-test-xml/compare/virt-install-arm-defaultmach-f20.xml
index 6281d823..7ddc645d 100644
--- a/tests/cli-test-xml/compare/virt-install-arm-defaultmach-f20.xml
+++ b/tests/cli-test-xml/compare/virt-install-arm-defaultmach-f20.xml
@@ -34,6 +34,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-arm-kvm-import.xml b/tests/cli-test-xml/compare/virt-install-arm-kvm-import.xml
index acd49a5d..1d11fd96 100644
--- a/tests/cli-test-xml/compare/virt-install-arm-kvm-import.xml
+++ b/tests/cli-test-xml/compare/virt-install-arm-kvm-import.xml
@@ -34,6 +34,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-arm-virt-f20.xml b/tests/cli-test-xml/compare/virt-install-arm-virt-f20.xml
index 05666876..4f52d8e8 100644
--- a/tests/cli-test-xml/compare/virt-install-arm-virt-f20.xml
+++ b/tests/cli-test-xml/compare/virt-install-arm-virt-f20.xml
@@ -34,6 +34,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-f21-kvm-remote.xml b/tests/cli-test-xml/compare/virt-install-f21-kvm-remote.xml
index 31b5fa66..0c79782d 100644
--- a/tests/cli-test-xml/compare/virt-install-f21-kvm-remote.xml
+++ b/tests/cli-test-xml/compare/virt-install-f21-kvm-remote.xml
@@ -57,6 +57,7 @@
     </video>
     <redirdev bus="usb" type="spicevmc"/>
     <redirdev bus="usb" type="spicevmc"/>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-kvm-centos7.xml b/tests/cli-test-xml/compare/virt-install-kvm-centos7.xml
index 6baaf169..b17f819d 100644
--- a/tests/cli-test-xml/compare/virt-install-kvm-centos7.xml
+++ b/tests/cli-test-xml/compare/virt-install-kvm-centos7.xml
@@ -61,6 +61,7 @@
     </video>
     <redirdev bus="usb" type="spicevmc"/>
     <redirdev bus="usb" type="spicevmc"/>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
@@ -127,6 +128,7 @@
     </video>
     <redirdev bus="usb" type="spicevmc"/>
     <redirdev bus="usb" type="spicevmc"/>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-kvm-fedoralatest-url.xml b/tests/cli-test-xml/compare/virt-install-kvm-fedoralatest-url.xml
index 71c19de8..4e7a579f 100644
--- a/tests/cli-test-xml/compare/virt-install-kvm-fedoralatest-url.xml
+++ b/tests/cli-test-xml/compare/virt-install-kvm-fedoralatest-url.xml
@@ -51,6 +51,7 @@
     <video>
       <model type="qxl"/>
     </video>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
@@ -106,6 +107,7 @@
     <video>
       <model type="qxl"/>
     </video>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-kvm-session-defaults.xml b/tests/cli-test-xml/compare/virt-install-kvm-session-defaults.xml
index eba2a4db..7476f106 100644
--- a/tests/cli-test-xml/compare/virt-install-kvm-session-defaults.xml
+++ b/tests/cli-test-xml/compare/virt-install-kvm-session-defaults.xml
@@ -66,6 +66,7 @@
     </video>
     <redirdev bus="usb" type="spicevmc"/>
     <redirdev bus="usb" type="spicevmc"/>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
@@ -135,6 +136,7 @@
     </video>
     <redirdev bus="usb" type="spicevmc"/>
     <redirdev bus="usb" type="spicevmc"/>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-location-iso.xml b/tests/cli-test-xml/compare/virt-install-location-iso.xml
index 808afc2b..670931df 100644
--- a/tests/cli-test-xml/compare/virt-install-location-iso.xml
+++ b/tests/cli-test-xml/compare/virt-install-location-iso.xml
@@ -71,6 +71,7 @@
     </video>
     <redirdev bus="usb" type="spicevmc"/>
     <redirdev bus="usb" type="spicevmc"/>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
@@ -145,6 +146,7 @@
     </video>
     <redirdev bus="usb" type="spicevmc"/>
     <redirdev bus="usb" type="spicevmc"/>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-many-devices.xml b/tests/cli-test-xml/compare/virt-install-many-devices.xml
index c4a8fc98..f9907578 100644
--- a/tests/cli-test-xml/compare/virt-install-many-devices.xml
+++ b/tests/cli-test-xml/compare/virt-install-many-devices.xml
@@ -508,6 +508,7 @@
       <source path="/tmp/foo.socket"/>
       <log file="/tmp/123.log"/>
     </redirdev>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-network-install-resources.xml b/tests/cli-test-xml/compare/virt-install-network-install-resources.xml
index 57653ff6..155d8b17 100644
--- a/tests/cli-test-xml/compare/virt-install-network-install-resources.xml
+++ b/tests/cli-test-xml/compare/virt-install-network-install-resources.xml
@@ -43,6 +43,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
@@ -90,6 +91,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-osinfo-netinst-unattended.xml b/tests/cli-test-xml/compare/virt-install-osinfo-netinst-unattended.xml
index cc4ead48..33cb4aa4 100644
--- a/tests/cli-test-xml/compare/virt-install-osinfo-netinst-unattended.xml
+++ b/tests/cli-test-xml/compare/virt-install-osinfo-netinst-unattended.xml
@@ -49,6 +49,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
@@ -100,6 +101,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-osinfo-url-unattended.xml b/tests/cli-test-xml/compare/virt-install-osinfo-url-unattended.xml
index 0e1d169a..7067ef9e 100644
--- a/tests/cli-test-xml/compare/virt-install-osinfo-url-unattended.xml
+++ b/tests/cli-test-xml/compare/virt-install-osinfo-url-unattended.xml
@@ -43,6 +43,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
@@ -90,6 +91,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-osinfo-url.xml b/tests/cli-test-xml/compare/virt-install-osinfo-url.xml
index 5b82be59..be1714af 100644
--- a/tests/cli-test-xml/compare/virt-install-osinfo-url.xml
+++ b/tests/cli-test-xml/compare/virt-install-osinfo-url.xml
@@ -43,6 +43,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
@@ -90,6 +91,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-ppc64-graphics.xml b/tests/cli-test-xml/compare/virt-install-ppc64-graphics.xml
index f5ed6f88..f65d95bc 100644
--- a/tests/cli-test-xml/compare/virt-install-ppc64-graphics.xml
+++ b/tests/cli-test-xml/compare/virt-install-ppc64-graphics.xml
@@ -38,6 +38,7 @@
     <video>
       <model type="vga"/>
     </video>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-ppc64-headless.xml b/tests/cli-test-xml/compare/virt-install-ppc64-headless.xml
index a1f56b26..37aa13d5 100644
--- a/tests/cli-test-xml/compare/virt-install-ppc64-headless.xml
+++ b/tests/cli-test-xml/compare/virt-install-ppc64-headless.xml
@@ -32,6 +32,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-ppc64-machdefault-f20.xml b/tests/cli-test-xml/compare/virt-install-ppc64-machdefault-f20.xml
index 199a2176..80810ba3 100644
--- a/tests/cli-test-xml/compare/virt-install-ppc64-machdefault-f20.xml
+++ b/tests/cli-test-xml/compare/virt-install-ppc64-machdefault-f20.xml
@@ -39,6 +39,7 @@
     <video>
       <model type="vga"/>
     </video>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-ppc64-pseries-f20.xml b/tests/cli-test-xml/compare/virt-install-ppc64-pseries-f20.xml
index 2e90c998..787042dd 100644
--- a/tests/cli-test-xml/compare/virt-install-ppc64-pseries-f20.xml
+++ b/tests/cli-test-xml/compare/virt-install-ppc64-pseries-f20.xml
@@ -44,6 +44,7 @@
     <video>
       <model type="vga"/>
     </video>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-ppc64le-kvm-import.xml b/tests/cli-test-xml/compare/virt-install-ppc64le-kvm-import.xml
index 4f6ad26c..262178be 100644
--- a/tests/cli-test-xml/compare/virt-install-ppc64le-kvm-import.xml
+++ b/tests/cli-test-xml/compare/virt-install-ppc64le-kvm-import.xml
@@ -38,6 +38,7 @@
     <video>
       <model type="vga"/>
     </video>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-qemu-32-on-64.xml b/tests/cli-test-xml/compare/virt-install-qemu-32-on-64.xml
index 47336f72..944a5f11 100644
--- a/tests/cli-test-xml/compare/virt-install-qemu-32-on-64.xml
+++ b/tests/cli-test-xml/compare/virt-install-qemu-32-on-64.xml
@@ -40,6 +40,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-riscv64-graphics.xml b/tests/cli-test-xml/compare/virt-install-riscv64-graphics.xml
index 61d2e7e6..eff7a274 100644
--- a/tests/cli-test-xml/compare/virt-install-riscv64-graphics.xml
+++ b/tests/cli-test-xml/compare/virt-install-riscv64-graphics.xml
@@ -38,6 +38,7 @@
     <video>
       <model type="virtio"/>
     </video>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-riscv64-headless.xml b/tests/cli-test-xml/compare/virt-install-riscv64-headless.xml
index cc2b0ed8..a0bb7c1b 100644
--- a/tests/cli-test-xml/compare/virt-install-riscv64-headless.xml
+++ b/tests/cli-test-xml/compare/virt-install-riscv64-headless.xml
@@ -32,6 +32,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-s390x-cdrom-KVMIBM.xml b/tests/cli-test-xml/compare/virt-install-s390x-cdrom-KVMIBM.xml
index 8af2aee8..803fc755 100644
--- a/tests/cli-test-xml/compare/virt-install-s390x-cdrom-KVMIBM.xml
+++ b/tests/cli-test-xml/compare/virt-install-s390x-cdrom-KVMIBM.xml
@@ -46,6 +46,7 @@
       <model type="virtio"/>
     </video>
     <watchdog model="diag288" action="reset"/>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-s390x-cdrom.xml b/tests/cli-test-xml/compare/virt-install-s390x-cdrom.xml
index 33ca6190..c4424565 100644
--- a/tests/cli-test-xml/compare/virt-install-s390x-cdrom.xml
+++ b/tests/cli-test-xml/compare/virt-install-s390x-cdrom.xml
@@ -41,6 +41,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-s390x-graphics.xml b/tests/cli-test-xml/compare/virt-install-s390x-graphics.xml
index 2747254e..f96abb00 100644
--- a/tests/cli-test-xml/compare/virt-install-s390x-graphics.xml
+++ b/tests/cli-test-xml/compare/virt-install-s390x-graphics.xml
@@ -39,6 +39,7 @@
     <video>
       <model type="virtio"/>
     </video>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-s390x-headless.xml b/tests/cli-test-xml/compare/virt-install-s390x-headless.xml
index c5344a5c..863b69a0 100644
--- a/tests/cli-test-xml/compare/virt-install-s390x-headless.xml
+++ b/tests/cli-test-xml/compare/virt-install-s390x-headless.xml
@@ -33,6 +33,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-x86_64-graphics.xml b/tests/cli-test-xml/compare/virt-install-x86_64-graphics.xml
index d0390401..85349b83 100644
--- a/tests/cli-test-xml/compare/virt-install-x86_64-graphics.xml
+++ b/tests/cli-test-xml/compare/virt-install-x86_64-graphics.xml
@@ -50,6 +50,7 @@
     <video>
       <model type="qxl"/>
     </video>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/tests/cli-test-xml/compare/virt-install-x86_64-headless.xml b/tests/cli-test-xml/compare/virt-install-x86_64-headless.xml
index 0a2d14a2..5014e3ca 100644
--- a/tests/cli-test-xml/compare/virt-install-x86_64-headless.xml
+++ b/tests/cli-test-xml/compare/virt-install-x86_64-headless.xml
@@ -45,6 +45,7 @@
       <source mode="bind"/>
       <target type="virtio" name="org.qemu.guest_agent.0"/>
     </channel>
+    <memballoon model="virtio"/>
     <rng model="virtio">
       <backend model="random">/dev/urandom</backend>
     </rng>
diff --git a/virtinst/guest.py b/virtinst/guest.py
index e1162ff7..8b5e78cc 100644
--- a/virtinst/guest.py
+++ b/virtinst/guest.py
@@ -719,6 +719,7 @@ class Guest(XMLBuilder):
         self._add_default_usb_controller()
         self._add_default_channels()
         self._add_default_rng()
+        self._add_default_memballoon()
 
         self.clock.set_defaults(self)
         self.cpu.set_defaults(self)
@@ -926,6 +927,37 @@ class Guest(XMLBuilder):
             dev.device = "/dev/urandom"
             self.add_device(dev)
 
+    def _add_default_memballoon(self):
+        if self.devices.memballoon:
+            return
+        if not self.conn.is_qemu():
+            return
+
+        # For most QEMU guests, libvirt will automatically add a memballoon
+        # device, which means that if the user has explicitly asked for it
+        # *not* to be present then we still need to create the device and
+        # set the model to "none" to let libvirt know
+        if self.disable_default_memballoon:
+            dev = DeviceMemballoon(self.conn)
+            dev.model = "none"
+            self.add_device(dev)
+            return
+
+        # We know for certain that a memballoon is good to have with these
+        # machine types; for other machine types, we leave the decision up
+        # to libvirt
+        if not (self.os.is_x86() or
+                self.os.is_arm_machvirt() or
+                self.os.is_riscv_virt() or
+                self.os.is_s390x() or
+                self.os.is_pseries()):
+            return
+
+        if self.osinfo.supports_virtioballoon():
+            dev = DeviceMemballoon(self.conn)
+            dev.model = "virtio"
+            self.add_device(dev)
+
     def _add_implied_controllers(self):
         has_any_scsi = False
         for dev in self.devices.controller:
-- 
2.21.0




More information about the virt-tools-list mailing list