Since v4.2-rc0, QEMU introduced a builtin rng backend that uses
getrandom() syscall to generate random. Add it to libvirt with the
backend model 'builtin'.
https://bugzilla.redhat.com/show_bug.cgi?id=1785091
Signed-off-by: Han Han <hhan(a)redhat.com>
---
src/qemu/qemu_capabilities.c | 2 ++
src/qemu/qemu_command.c | 15 ++++++++
src/qemu/qemu_domain.c | 3 ++
.../domaincapsdata/qemu_4.2.0-q35.x86_64.xml | 1 +
.../domaincapsdata/qemu_4.2.0-tcg.x86_64.xml | 1 +
.../qemu_4.2.0-virt.aarch64.xml | 1 +
tests/domaincapsdata/qemu_4.2.0.aarch64.xml | 1 +
tests/domaincapsdata/qemu_4.2.0.ppc64.xml | 1 +
tests/domaincapsdata/qemu_4.2.0.s390x.xml | 1 +
tests/domaincapsdata/qemu_4.2.0.x86_64.xml | 1 +
.../virtio-rng-builtin.x86_64-latest.args | 35 +++++++++++++++++++
tests/qemuxml2argvdata/virtio-rng-builtin.xml | 26 ++++++++++++++
tests/qemuxml2argvtest.c | 1 +
.../virtio-rng-builtin.x86_64-latest.xml | 31 ++++++++++++++++
tests/qemuxml2xmltest.c | 1 +
15 files changed, 121 insertions(+)
create mode 100644 tests/qemuxml2argvdata/virtio-rng-builtin.x86_64-latest.args
create mode 100644 tests/qemuxml2argvdata/virtio-rng-builtin.xml
create mode 100644 tests/qemuxml2xmloutdata/virtio-rng-builtin.x86_64-latest.xml
diff --git a/src/qemu/qemu_capabilities.c b/src/qemu/qemu_capabilities.c
index 8d7b9e368a..fe2122f320 100644
--- a/src/qemu/qemu_capabilities.c
+++ b/src/qemu/qemu_capabilities.c
@@ -5716,6 +5716,8 @@ virQEMUCapsFillDomainDeviceRNGCaps(virQEMUCapsPtr qemuCaps,
VIR_DOMAIN_CAPS_ENUM_SET(rng->backendModel, VIR_DOMAIN_RNG_BACKEND_EGD);
if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_RANDOM))
VIR_DOMAIN_CAPS_ENUM_SET(rng->backendModel, VIR_DOMAIN_RNG_BACKEND_RANDOM);
+ if (virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_BUILTIN))
+ VIR_DOMAIN_CAPS_ENUM_SET(rng->backendModel, VIR_DOMAIN_RNG_BACKEND_BUILTIN);
}
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index d0b1f34058..84529af596 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5569,6 +5569,7 @@ qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager,
switch ((virDomainRNGBackend) rng->backend) {
case VIR_DOMAIN_RNG_BACKEND_RANDOM:
+ case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
case VIR_DOMAIN_RNG_BACKEND_LAST:
/* no chardev backend is needed */
return 0;
@@ -5630,6 +5631,20 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
break;
+ case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
+ if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_BUILTIN)) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
+ _("this qemu doesn't support the rng-builtin "
+ "backend"));
+ return -1;
+ }
+
+ if (qemuMonitorCreateObjectProps(props, "rng-builtin", objAlias,
+ NULL) < 0)
+ return -1;
+
+ break;
+
case VIR_DOMAIN_RNG_BACKEND_LAST:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("unknown rng-random backend"));
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 2ec23bb52f..a5ca73e41f 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -14794,6 +14794,7 @@ qemuDomainSetupRNG(virQEMUDriverConfigPtr cfg G_GNUC_UNUSED,
return -1;
case VIR_DOMAIN_RNG_BACKEND_EGD:
+ case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
case VIR_DOMAIN_RNG_BACKEND_LAST:
/* nada */
break;
@@ -15773,6 +15774,7 @@ qemuDomainNamespaceSetupRNG(virDomainObjPtr vm,
break;
case VIR_DOMAIN_RNG_BACKEND_EGD:
+ case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
case VIR_DOMAIN_RNG_BACKEND_LAST:
break;
}
@@ -15796,6 +15798,7 @@ qemuDomainNamespaceTeardownRNG(virDomainObjPtr vm,
break;
case VIR_DOMAIN_RNG_BACKEND_EGD:
+ case VIR_DOMAIN_RNG_BACKEND_BUILTIN:
case VIR_DOMAIN_RNG_BACKEND_LAST:
break;
}
diff --git a/tests/domaincapsdata/qemu_4.2.0-q35.x86_64.xml
b/tests/domaincapsdata/qemu_4.2.0-q35.x86_64.xml
index c4c6bfb564..eaa3b75695 100644
--- a/tests/domaincapsdata/qemu_4.2.0-q35.x86_64.xml
+++ b/tests/domaincapsdata/qemu_4.2.0-q35.x86_64.xml
@@ -167,6 +167,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
+ <value>builtin</value>
</enum>
</rng>
</devices>
diff --git a/tests/domaincapsdata/qemu_4.2.0-tcg.x86_64.xml
b/tests/domaincapsdata/qemu_4.2.0-tcg.x86_64.xml
index a7f8d9c5ee..af482e3821 100644
--- a/tests/domaincapsdata/qemu_4.2.0-tcg.x86_64.xml
+++ b/tests/domaincapsdata/qemu_4.2.0-tcg.x86_64.xml
@@ -178,6 +178,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
+ <value>builtin</value>
</enum>
</rng>
</devices>
diff --git a/tests/domaincapsdata/qemu_4.2.0-virt.aarch64.xml
b/tests/domaincapsdata/qemu_4.2.0-virt.aarch64.xml
index e5954717cc..908406bf11 100644
--- a/tests/domaincapsdata/qemu_4.2.0-virt.aarch64.xml
+++ b/tests/domaincapsdata/qemu_4.2.0-virt.aarch64.xml
@@ -136,6 +136,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
+ <value>builtin</value>
</enum>
</rng>
</devices>
diff --git a/tests/domaincapsdata/qemu_4.2.0.aarch64.xml
b/tests/domaincapsdata/qemu_4.2.0.aarch64.xml
index bb02b1d850..c66550cec5 100644
--- a/tests/domaincapsdata/qemu_4.2.0.aarch64.xml
+++ b/tests/domaincapsdata/qemu_4.2.0.aarch64.xml
@@ -134,6 +134,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
+ <value>builtin</value>
</enum>
</rng>
</devices>
diff --git a/tests/domaincapsdata/qemu_4.2.0.ppc64.xml
b/tests/domaincapsdata/qemu_4.2.0.ppc64.xml
index 6d3ada3735..7906482eee 100644
--- a/tests/domaincapsdata/qemu_4.2.0.ppc64.xml
+++ b/tests/domaincapsdata/qemu_4.2.0.ppc64.xml
@@ -100,6 +100,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
+ <value>builtin</value>
</enum>
</rng>
</devices>
diff --git a/tests/domaincapsdata/qemu_4.2.0.s390x.xml
b/tests/domaincapsdata/qemu_4.2.0.s390x.xml
index c6d92542c3..0cdfd4352e 100644
--- a/tests/domaincapsdata/qemu_4.2.0.s390x.xml
+++ b/tests/domaincapsdata/qemu_4.2.0.s390x.xml
@@ -191,6 +191,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
+ <value>builtin</value>
</enum>
</rng>
</devices>
diff --git a/tests/domaincapsdata/qemu_4.2.0.x86_64.xml
b/tests/domaincapsdata/qemu_4.2.0.x86_64.xml
index f0e0f182a4..c82d12d3ce 100644
--- a/tests/domaincapsdata/qemu_4.2.0.x86_64.xml
+++ b/tests/domaincapsdata/qemu_4.2.0.x86_64.xml
@@ -167,6 +167,7 @@
<enum name='backendModel'>
<value>random</value>
<value>egd</value>
+ <value>builtin</value>
</enum>
</rng>
</devices>
diff --git a/tests/qemuxml2argvdata/virtio-rng-builtin.x86_64-latest.args
b/tests/qemuxml2argvdata/virtio-rng-builtin.x86_64-latest.args
new file mode 100644
index 0000000000..e55117728c
--- /dev/null
+++ b/tests/qemuxml2argvdata/virtio-rng-builtin.x86_64-latest.args
@@ -0,0 +1,35 @@
+LC_ALL=C \
+PATH=/bin \
+HOME=/tmp/lib/domain--1-QEMUGuest1 \
+USER=test \
+LOGNAME=test \
+XDG_DATA_HOME=/tmp/lib/domain--1-QEMUGuest1/.local/share \
+XDG_CACHE_HOME=/tmp/lib/domain--1-QEMUGuest1/.cache \
+XDG_CONFIG_HOME=/tmp/lib/domain--1-QEMUGuest1/.config \
+QEMU_AUDIO_DRV=none \
+/usr/bin/qemu-system-x86_64 \
+-name guest=QEMUGuest1,debug-threads=on \
+-S \
+-object secret,id=masterKey0,format=raw,\
+file=/tmp/lib/domain--1-QEMUGuest1/master-key.aes \
+-machine pc,accel=kvm,usb=off,dump-guest-core=off \
+-m 214 \
+-overcommit mem-lock=off \
+-smp 1,sockets=1,cores=1,threads=1 \
+-uuid c7a5fdbd-edaf-9455-926a-d65c16db1809 \
+-display none \
+-no-user-config \
+-nodefaults \
+-chardev socket,id=charmonitor,fd=1729,server,nowait \
+-mon chardev=charmonitor,id=monitor,mode=control \
+-rtc base=utc \
+-no-shutdown \
+-no-acpi \
+-boot strict=on \
+-device piix3-usb-uhci,id=usb,bus=pci.0,addr=0x1.0x2 \
+-device virtio-balloon-pci,id=balloon0,bus=pci.0,addr=0x2 \
+-object rng-builtin,id=objrng0 \
+-device virtio-rng-pci,rng=objrng0,id=rng0,bus=pci.0,addr=0x3 \
+-sandbox on,obsolete=deny,elevateprivileges=deny,spawn=deny,\
+resourcecontrol=deny \
+-msg timestamp=on
diff --git a/tests/qemuxml2argvdata/virtio-rng-builtin.xml
b/tests/qemuxml2argvdata/virtio-rng-builtin.xml
new file mode 100644
index 0000000000..0a03eafc4b
--- /dev/null
+++ b/tests/qemuxml2argvdata/virtio-rng-builtin.xml
@@ -0,0 +1,26 @@
+<domain type='kvm'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219100</memory>
+ <currentMemory unit='KiB'>219100</currentMemory>
+ <vcpu>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <controller type='usb' index='0'/>
+ <controller type='pci' index='0' model='pci-root'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='virtio'/>
+ <rng model='virtio'>
+ <backend model='builtin'/>
+ </rng>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2argvtest.c b/tests/qemuxml2argvtest.c
index 8af2ba38d3..44c86a8938 100644
--- a/tests/qemuxml2argvtest.c
+++ b/tests/qemuxml2argvtest.c
@@ -2119,6 +2119,7 @@ mymain(void)
DO_TEST("virtio-rng-egd",
QEMU_CAPS_DEVICE_VIRTIO_RNG,
QEMU_CAPS_OBJECT_RNG_EGD);
+ DO_TEST_CAPS_LATEST("virtio-rng-builtin");
DO_TEST_CAPS_VER("virtio-rng-egd-unix", "2.5.0");
DO_TEST_CAPS_LATEST("virtio-rng-egd-unix");
DO_TEST("virtio-rng-multiple",
diff --git a/tests/qemuxml2xmloutdata/virtio-rng-builtin.x86_64-latest.xml
b/tests/qemuxml2xmloutdata/virtio-rng-builtin.x86_64-latest.xml
new file mode 100644
index 0000000000..9ff57c4ad6
--- /dev/null
+++ b/tests/qemuxml2xmloutdata/virtio-rng-builtin.x86_64-latest.xml
@@ -0,0 +1,31 @@
+<domain type='kvm'>
+ <name>QEMUGuest1</name>
+ <uuid>c7a5fdbd-edaf-9455-926a-d65c16db1809</uuid>
+ <memory unit='KiB'>219100</memory>
+ <currentMemory unit='KiB'>219100</currentMemory>
+ <vcpu placement='static'>1</vcpu>
+ <os>
+ <type arch='x86_64' machine='pc'>hvm</type>
+ <boot dev='hd'/>
+ </os>
+ <clock offset='utc'/>
+ <on_poweroff>destroy</on_poweroff>
+ <on_reboot>restart</on_reboot>
+ <on_crash>destroy</on_crash>
+ <devices>
+ <emulator>/usr/bin/qemu-system-x86_64</emulator>
+ <controller type='usb' index='0' model='piix3-uhci'>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x01' function='0x2'/>
+ </controller>
+ <controller type='pci' index='0' model='pci-root'/>
+ <input type='mouse' bus='ps2'/>
+ <input type='keyboard' bus='ps2'/>
+ <memballoon model='virtio'>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x02' function='0x0'/>
+ </memballoon>
+ <rng model='virtio'>
+ <backend model='builtin'/>
+ <address type='pci' domain='0x0000' bus='0x00'
slot='0x03' function='0x0'/>
+ </rng>
+ </devices>
+</domain>
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 262fc835f5..faa9c097fb 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -629,6 +629,7 @@ mymain(void)
QEMU_CAPS_DEVICE_VIRTIO_RNG);
DO_TEST("virtio-rng-egd",
QEMU_CAPS_DEVICE_VIRTIO_RNG);
+ DO_TEST_CAPS_LATEST("virtio-rng-builtin");
DO_TEST("pseries-nvram",
QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE,
--
2.24.0.rc1