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 <abologna@redhat.com>
This commit is contained in:
Andrea Bolognani 2019-06-13 12:55:10 +02:00 committed by Cole Robinson
parent fb81adea7e
commit eda3c22458
33 changed files with 73 additions and 0 deletions

View File

@ -40,6 +40,7 @@
<video> <video>
<model type="virtio"/> <model type="virtio"/>
</video> </video>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -34,6 +34,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -41,6 +41,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -34,6 +34,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -34,6 +34,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -34,6 +34,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -34,6 +34,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -57,6 +57,7 @@
</video> </video>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -61,6 +61,7 @@
</video> </video>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>
@ -127,6 +128,7 @@
</video> </video>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -51,6 +51,7 @@
<video> <video>
<model type="qxl"/> <model type="qxl"/>
</video> </video>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>
@ -107,6 +108,7 @@
<video> <video>
<model type="qxl"/> <model type="qxl"/>
</video> </video>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -66,6 +66,7 @@
</video> </video>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>
@ -135,6 +136,7 @@
</video> </video>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -71,6 +71,7 @@
</video> </video>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>
@ -145,6 +146,7 @@
</video> </video>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/> <redirdev bus="usb" type="spicevmc"/>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -515,6 +515,7 @@
<source path="/tmp/foo.socket"/> <source path="/tmp/foo.socket"/>
<log file="/tmp/123.log"/> <log file="/tmp/123.log"/>
</redirdev> </redirdev>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -43,6 +43,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>
@ -90,6 +91,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -49,6 +49,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>
@ -100,6 +101,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -43,6 +43,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>
@ -90,6 +91,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -53,6 +53,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>
@ -110,6 +111,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -43,6 +43,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>
@ -90,6 +91,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -38,6 +38,7 @@
<video> <video>
<model type="vga"/> <model type="vga"/>
</video> </video>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -32,6 +32,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -39,6 +39,7 @@
<video> <video>
<model type="vga"/> <model type="vga"/>
</video> </video>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -44,6 +44,7 @@
<video> <video>
<model type="vga"/> <model type="vga"/>
</video> </video>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -38,6 +38,7 @@
<video> <video>
<model type="vga"/> <model type="vga"/>
</video> </video>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -40,6 +40,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -38,6 +38,7 @@
<video> <video>
<model type="virtio"/> <model type="virtio"/>
</video> </video>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -32,6 +32,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -46,6 +46,7 @@
<model type="virtio"/> <model type="virtio"/>
</video> </video>
<watchdog model="diag288" action="reset"/> <watchdog model="diag288" action="reset"/>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -41,6 +41,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -39,6 +39,7 @@
<video> <video>
<model type="virtio"/> <model type="virtio"/>
</video> </video>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -33,6 +33,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -50,6 +50,7 @@
<video> <video>
<model type="qxl"/> <model type="qxl"/>
</video> </video>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -45,6 +45,7 @@
<source mode="bind"/> <source mode="bind"/>
<target type="virtio" name="org.qemu.guest_agent.0"/> <target type="virtio" name="org.qemu.guest_agent.0"/>
</channel> </channel>
<memballoon model="virtio"/>
<rng model="virtio"> <rng model="virtio">
<backend model="random">/dev/urandom</backend> <backend model="random">/dev/urandom</backend>
</rng> </rng>

View File

@ -735,6 +735,7 @@ class Guest(XMLBuilder):
self._add_default_usb_controller() self._add_default_usb_controller()
self._add_default_channels() self._add_default_channels()
self._add_default_rng() self._add_default_rng()
self._add_default_memballoon()
self.clock.set_defaults(self) self.clock.set_defaults(self)
self.cpu.set_defaults(self) self.cpu.set_defaults(self)
@ -946,6 +947,37 @@ class Guest(XMLBuilder):
dev.device = "/dev/urandom" dev.device = "/dev/urandom"
self.add_device(dev) 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): def _add_implied_controllers(self):
has_any_scsi = False has_any_scsi = False
for dev in self.devices.controller: for dev in self.devices.controller: