From eda3c224589f87fae84cb059dc2571733ebd7ab4 Mon Sep 17 00:00:00 2001 From: Andrea Bolognani Date: Thu, 13 Jun 2019 12:55:10 +0200 Subject: [PATCH] guest: Add memory balloon by default 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 --- .../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 ++ .../virt-install-osinfo-url-with-disk.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 +++++++++++++++++++ 33 files changed, 73 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 d6972aff3..dad2636b8 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 @@ + /dev/urandom 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 6bf62e3f1..86175a114 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 @@ + /dev/urandom 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 c979eb6f0..7346ad32a 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 @@ + /dev/urandom 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 2ec1e7c59..a6eb94216 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 @@ + /dev/urandom 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 6281d823c..7ddc645db 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 @@ + /dev/urandom 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 acd49a5da..1d11fd967 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 @@ + /dev/urandom 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 056668763..4f52d8e84 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 @@ + /dev/urandom 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 31b5fa667..0c79782db 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 @@ + /dev/urandom 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 6baaf1695..b17f819da 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 @@ + /dev/urandom @@ -127,6 +128,7 @@ + /dev/urandom 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 13030ebf9..c670ab7d7 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 @@ + /dev/urandom @@ -107,6 +108,7 @@ + /dev/urandom 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 17653d8bb..d5c3ce69e 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 @@ + /dev/urandom @@ -135,6 +136,7 @@ + /dev/urandom 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 94e171fca..24301520a 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 @@ + /dev/urandom @@ -145,6 +146,7 @@ + /dev/urandom 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 99e45e020..2369824c9 100644 --- a/tests/cli-test-xml/compare/virt-install-many-devices.xml +++ b/tests/cli-test-xml/compare/virt-install-many-devices.xml @@ -515,6 +515,7 @@ + /dev/urandom 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 f43118f32..c77c8e3a6 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 @@ + /dev/urandom @@ -90,6 +91,7 @@ + /dev/urandom 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 c36efa676..829054c88 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 @@ + /dev/urandom @@ -100,6 +101,7 @@ + /dev/urandom 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 8691c82ea..4a6311f73 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 @@ + /dev/urandom @@ -90,6 +91,7 @@ + /dev/urandom diff --git a/tests/cli-test-xml/compare/virt-install-osinfo-url-with-disk.xml b/tests/cli-test-xml/compare/virt-install-osinfo-url-with-disk.xml index 96371ec99..b32b88da4 100644 --- a/tests/cli-test-xml/compare/virt-install-osinfo-url-with-disk.xml +++ b/tests/cli-test-xml/compare/virt-install-osinfo-url-with-disk.xml @@ -53,6 +53,7 @@ + /dev/urandom @@ -110,6 +111,7 @@ + /dev/urandom 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 3d87a29e6..962c4bddf 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 @@ + /dev/urandom @@ -90,6 +91,7 @@ + /dev/urandom 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 f5ed6f883..f65d95bc3 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 @@ + /dev/urandom 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 a1f56b260..37aa13d5c 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 @@ + /dev/urandom 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 199a21761..80810ba35 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 @@ + /dev/urandom 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 2e90c998a..787042dd3 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 @@ + /dev/urandom 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 4f6ad26c0..262178beb 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 @@ + /dev/urandom 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 47336f728..944a5f113 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 @@ + /dev/urandom 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 61d2e7e63..eff7a2744 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 @@ + /dev/urandom 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 cc2b0ed8c..a0bb7c1be 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 @@ + /dev/urandom 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 8af2aee83..803fc755d 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 @@ + /dev/urandom 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 33ca61906..c44245659 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 @@ + /dev/urandom 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 2747254e8..f96abb002 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 @@ + /dev/urandom 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 c5344a5c8..863b69a0c 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 @@ + /dev/urandom 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 d03904016..85349b836 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 @@ + /dev/urandom 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 0a2d14a25..5014e3ca4 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 @@ + /dev/urandom diff --git a/virtinst/guest.py b/virtinst/guest.py index 593d1cb3f..ef227d173 100644 --- a/virtinst/guest.py +++ b/virtinst/guest.py @@ -735,6 +735,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) @@ -946,6 +947,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: