guest: Add default virtio-rng /dev/urandom (bz 1212082)

For guests that support it, per libosinfo, and new enough libvirt
to handle /dev/urandom. See the bug for discussion

https://bugzilla.redhat.com/show_bug.cgi?id=1212082
This commit is contained in:
Cole Robinson 2017-03-08 16:54:16 -05:00
parent dff27a298e
commit d62e975568
9 changed files with 61 additions and 0 deletions

View File

@ -63,5 +63,8 @@
</video>
<redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
</domain>

View File

@ -55,6 +55,9 @@
<video>
<model type="qxl"/>
</video>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
</domain>
<domain type="kvm">
@ -111,5 +114,8 @@
<video>
<model type="qxl"/>
</video>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
</domain>

View File

@ -72,6 +72,9 @@
</video>
<redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
</domain>
<domain type="kvm">
@ -144,5 +147,8 @@
</video>
<redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
</domain>

View File

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

View File

@ -63,5 +63,8 @@
</video>
<redirdev bus="usb" type="spicevmc"/>
<redirdev bus="usb" type="spicevmc"/>
<rng model="virtio">
<backend model="random">/dev/urandom</backend>
</rng>
</devices>
</domain>

View File

@ -2359,6 +2359,7 @@ class ParserRNG(VirtCLIParser):
cli_arg_name = "rng"
objclass = VirtualRNGDevice
remove_first = "type"
stub_none = False
def set_hosts_cb(self, inst, val, virtarg):
namemap = {}
@ -2386,6 +2387,10 @@ class ParserRNG(VirtCLIParser):
inst.cli_backend_type = val
def _parse(self, inst):
if self.optstr == "none":
self.guest.skip_default_rng = True
return
inst.cli_backend_mode = "connect"
inst.cli_backend_type = "udp"

View File

@ -39,6 +39,7 @@ from .devicedisk import VirtualDisk
from .devicegraphics import VirtualGraphics
from .deviceinput import VirtualInputDevice
from .deviceredirdev import VirtualRedirDevice
from .devicerng import VirtualRNGDevice
from .devicevideo import VirtualVideoDevice
from .distroinstaller import DistroInstaller
from .domainblkiotune import DomainBlkiotune
@ -124,6 +125,7 @@ class Guest(XMLBuilder):
self.skip_default_sound = False
self.skip_default_usbredir = False
self.skip_default_graphics = False
self.skip_default_rng = False
self.x86_cpu_default = self.cpu.SPECIAL_MODE_HOST_MODEL_ONLY
self.__os_object = None
@ -641,6 +643,25 @@ class Guest(XMLBuilder):
return
self.add_device(VirtualGraphics(self.conn))
def add_default_rng(self):
if self.skip_default_rng:
return
if self.get_devices("rng"):
return
if not self.os.is_x86():
# Not strictly x86 specific, but some other archs like
# arm have limited virtio options in some situations, so
# it needs more work there.
return
if (self.conn.is_qemu() and
self._os_object.supports_virtiorng() and
self.conn.check_support(self.conn.SUPPORT_CONN_RNG_URANDOM)):
dev = VirtualRNGDevice(self.conn)
dev.type = "random"
dev.device = "/dev/urandom"
self.add_device(dev)
def add_default_devices(self):
self.add_default_graphics()
self.add_default_video_device()
@ -648,6 +669,7 @@ class Guest(XMLBuilder):
self.add_default_console_device()
self.add_default_usb_controller()
self.add_default_channels()
self.add_default_rng()
def _add_install_cdrom(self):
if self._install_cdrom_device:

View File

@ -494,6 +494,18 @@ class _OsVariant(object):
return False
def supports_virtiorng(self):
if self._os:
fltr = libosinfo.Filter()
fltr.add_constraint("class", "rng")
devs = self._os.get_all_devices(fltr)
for dev in range(devs.get_length()):
d = devs.get_nth(dev)
if d.get_name() == "virtio-rng":
return True
return False
def supports_qemu_ga(self):
return self._is_related_to(["debian8", "fedora18", "rhel6.0", "sles11sp4"])

View File

@ -320,6 +320,7 @@ SUPPORT_CONN_SPICE_RENDERNODE = _make(version="3.1.0",
SUPPORT_CONN_VIDEO_VIRTIO_ACCEL3D = _make(version="1.3.0",
hv_version={"qemu": "2.5.0", "test": 0})
SUPPORT_CONN_GRAPHICS_LISTEN_NONE = _make(version="2.0.0")
SUPPORT_CONN_RNG_URANDOM = _make(version="1.3.4")
# This is for disk <driver name=qemu>. xen supports this, but it's