Move the rng->model == VIRTIO check to parse time. This also
allows us to remove similar checks throughout the qemu driver
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
src/qemu/qemu_command.c | 8 --------
src/qemu/qemu_domain.c | 23 +++++++++++++++++++++--
src/qemu/qemu_domain_address.c | 9 ++++-----
tests/qemuxml2xmltest.c | 9 ++++++---
4 files changed, 31 insertions(+), 18 deletions(-)
diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c
index 2d05b4a93b..bbc85e75f0 100644
--- a/src/qemu/qemu_command.c
+++ b/src/qemu/qemu_command.c
@@ -5871,14 +5871,6 @@ qemuBuildRNGDevStr(const virDomainDef *def,
{
virBuffer buf = VIR_BUFFER_INITIALIZER;
- if (dev->model != VIR_DOMAIN_RNG_MODEL_VIRTIO ||
- !virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_RNG)) {
- virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
- _("this qemu doesn't support RNG device type
'%s'"),
- virDomainRNGModelTypeToString(dev->model));
- goto error;
- }
-
if (!qemuDomainCheckCCWS390AddressSupport(def, dev->info, qemuCaps,
dev->source.file))
goto error;
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index a0ab55d5db..27cdb30ca2 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4536,12 +4536,31 @@ qemuDomainSmartcardDefValidate(const virDomainSmartcardDef *def)
static int
-qemuDomainRNGDefValidate(const virDomainRNGDef *def)
+qemuDomainRNGDefValidate(const virDomainRNGDef *def,
+ virQEMUCapsPtr qemuCaps)
{
+ bool model_supported = false;
+
if (def->backend == VIR_DOMAIN_RNG_BACKEND_EGD &&
qemuDomainChrSourceDefValidate(def->source.chardev) < 0)
return -1;
+ switch ((virDomainRNGModel) def->model) {
+ case VIR_DOMAIN_RNG_MODEL_VIRTIO:
+ model_supported = virQEMUCapsGet(qemuCaps,
+ QEMU_CAPS_DEVICE_VIRTIO_RNG);
+ break;
+ case VIR_DOMAIN_RNG_MODEL_LAST:
+ break;
+ }
+
+ if (!model_supported) {
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
+ _("this qemu doesn't support RNG device type
'%s'"),
+ virDomainRNGModelTypeToString(def->model));
+ return -1;
+ }
+
return 0;
}
@@ -6073,7 +6092,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
break;
case VIR_DOMAIN_DEVICE_RNG:
- ret = qemuDomainRNGDefValidate(dev->data.rng);
+ ret = qemuDomainRNGDefValidate(dev->data.rng, qemuCaps);
break;
case VIR_DOMAIN_DEVICE_REDIRDEV:
diff --git a/src/qemu/qemu_domain_address.c b/src/qemu/qemu_domain_address.c
index 1802c36b86..f2ae0804a8 100644
--- a/src/qemu/qemu_domain_address.c
+++ b/src/qemu/qemu_domain_address.c
@@ -364,8 +364,8 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def,
def->memballoon->info.type = type;
for (i = 0; i < def->nrngs; i++) {
- if (def->rngs[i]->model == VIR_DOMAIN_RNG_MODEL_VIRTIO &&
- def->rngs[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
+ /* All <rng> devices accepted by the qemu driver are virtio */
+ if (def->rngs[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
def->rngs[i]->info.type = type;
}
@@ -2276,10 +2276,9 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def,
goto error;
}
- /* VirtIO RNG */
+ /* rng. the qemu driver only accepts virtio rng devices */
for (i = 0; i < def->nrngs; i++) {
- if (def->rngs[i]->model != VIR_DOMAIN_RNG_MODEL_VIRTIO ||
- !virDeviceInfoPCIAddressIsWanted(&def->rngs[i]->info))
+ if (!virDeviceInfoPCIAddressIsWanted(&def->rngs[i]->info))
continue;
if (qemuDomainPCIAddressReserveNextAddr(addrs, &def->rngs[i]->info)
< 0)
diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c
index 82e2c0ee0f..b2c0c8505d 100644
--- a/tests/qemuxml2xmltest.c
+++ b/tests/qemuxml2xmltest.c
@@ -585,8 +585,10 @@ mymain(void)
DO_TEST("disk-serial", NONE);
- DO_TEST("virtio-rng-random", NONE);
- DO_TEST("virtio-rng-egd", NONE);
+ DO_TEST("virtio-rng-random",
+ QEMU_CAPS_DEVICE_VIRTIO_RNG);
+ DO_TEST("virtio-rng-egd",
+ QEMU_CAPS_DEVICE_VIRTIO_RNG);
DO_TEST("pseries-nvram",
QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
@@ -1019,7 +1021,8 @@ mymain(void)
DO_TEST("disk-backing-chains-index", NONE);
DO_TEST("disk-backing-chains-noindex", NONE);
- DO_TEST("chardev-label", NONE);
+ DO_TEST("chardev-label",
+ QEMU_CAPS_DEVICE_VIRTIO_RNG);
DO_TEST("cpu-numa1", NONE);
DO_TEST("cpu-numa2", NONE);
--
2.20.1