Signed-off-by: Daniel Henrique Barboza <danielhb413@xxxxxxxxx> --- src/qemu/qemu_command.c | 28 ++-------------------------- src/qemu/qemu_command.h | 1 - src/qemu/qemu_hotplug.c | 2 +- src/qemu/qemu_validate.c | 38 ++++++++++++++++++++++++++++++++++++-- tests/qemuxml2xmltest.c | 9 ++++++--- 5 files changed, 45 insertions(+), 33 deletions(-) diff --git a/src/qemu/qemu_command.c b/src/qemu/qemu_command.c index 29bfa665c4..f350800ff0 100644 --- a/src/qemu/qemu_command.c +++ b/src/qemu/qemu_command.c @@ -5342,7 +5342,6 @@ qemuBuildRNGBackendChrdevStr(virLogManagerPtr logManager, int qemuBuildRNGBackendProps(virDomainRNGDefPtr rng, - virQEMUCapsPtr qemuCaps, virJSONValuePtr *props) { g_autofree char *objAlias = NULL; @@ -5352,13 +5351,6 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng, switch ((virDomainRNGBackend) rng->backend) { case VIR_DOMAIN_RNG_BACKEND_RANDOM: - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_RANDOM)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("this qemu doesn't support the rng-random " - "backend")); - return -1; - } - if (qemuMonitorCreateObjectProps(props, "rng-random", objAlias, "s:filename", rng->source.file, NULL) < 0) @@ -5367,13 +5359,6 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng, break; case VIR_DOMAIN_RNG_BACKEND_EGD: - if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_EGD)) { - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("this qemu doesn't support the rng-egd " - "backend")); - return -1; - } - if (!(charBackendAlias = qemuAliasChardevFromDevAlias(rng->info.alias))) return -1; @@ -5385,13 +5370,6 @@ 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; @@ -5399,9 +5377,7 @@ qemuBuildRNGBackendProps(virDomainRNGDefPtr rng, break; case VIR_DOMAIN_RNG_BACKEND_LAST: - virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", - _("unknown rng-random backend")); - return -1; + break; } return 0; @@ -5478,7 +5454,7 @@ qemuBuildRNGCommandLine(virLogManagerPtr logManager, if (chardev) virCommandAddArgList(cmd, "-chardev", chardev, NULL); - if (qemuBuildRNGBackendProps(rng, qemuCaps, &props) < 0) + if (qemuBuildRNGBackendProps(rng, &props) < 0) return -1; rc = virQEMUBuildObjectCommandlineFromJSON(&buf, props); diff --git a/src/qemu/qemu_command.h b/src/qemu/qemu_command.h index 8a30f2852c..12014b1451 100644 --- a/src/qemu/qemu_command.h +++ b/src/qemu/qemu_command.h @@ -167,7 +167,6 @@ char *qemuBuildRNGDevStr(const virDomainDef *def, virDomainRNGDefPtr dev, virQEMUCapsPtr qemuCaps); int qemuBuildRNGBackendProps(virDomainRNGDefPtr rng, - virQEMUCapsPtr qemuCaps, virJSONValuePtr *props); /* Current, best practice */ diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c index 79fc8baa5c..fdb3801af0 100644 --- a/src/qemu/qemu_hotplug.c +++ b/src/qemu/qemu_hotplug.c @@ -2264,7 +2264,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver, if (!(devstr = qemuBuildRNGDevStr(vm->def, rng, priv->qemuCaps))) goto cleanup; - if (qemuBuildRNGBackendProps(rng, priv->qemuCaps, &props) < 0) + if (qemuBuildRNGBackendProps(rng, &props) < 0) goto cleanup; if (!(charAlias = qemuAliasChardevFromDevAlias(rng->info.alias))) diff --git a/src/qemu/qemu_validate.c b/src/qemu/qemu_validate.c index 1895ad857b..c97b4770b8 100644 --- a/src/qemu/qemu_validate.c +++ b/src/qemu/qemu_validate.c @@ -1646,9 +1646,43 @@ static int qemuValidateDomainRNGDef(const virDomainRNGDef *def, virQEMUCapsPtr qemuCaps) { - if (def->backend == VIR_DOMAIN_RNG_BACKEND_EGD && - qemuValidateDomainChrSourceDef(def->source.chardev, qemuCaps) < 0) + switch ((virDomainRNGBackend) def->backend) { + case VIR_DOMAIN_RNG_BACKEND_RANDOM: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_RANDOM)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("this qemu doesn't support the rng-random " + "backend")); + return -1; + } + break; + + case VIR_DOMAIN_RNG_BACKEND_EGD: + if (!virQEMUCapsGet(qemuCaps, QEMU_CAPS_OBJECT_RNG_EGD)) { + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("this qemu doesn't support the rng-egd " + "backend")); + return -1; + } + + if (qemuValidateDomainChrSourceDef(def->source.chardev, qemuCaps) < 0) + return -1; + + 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; + } + break; + + case VIR_DOMAIN_RNG_BACKEND_LAST: + virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s", + _("unknown rng-random backend")); return -1; + } if (qemuValidateDomainVirtioOptions(def->virtio, qemuCaps) < 0) return -1; diff --git a/tests/qemuxml2xmltest.c b/tests/qemuxml2xmltest.c index a9037101de..2213dc8615 100644 --- a/tests/qemuxml2xmltest.c +++ b/tests/qemuxml2xmltest.c @@ -682,9 +682,11 @@ mymain(void) DO_TEST_CAPS_ARCH_LATEST("disk-arm-virtio-sd", "aarch64"); DO_TEST("virtio-rng-random", - QEMU_CAPS_DEVICE_VIRTIO_RNG); + QEMU_CAPS_DEVICE_VIRTIO_RNG, + QEMU_CAPS_OBJECT_RNG_RANDOM); DO_TEST("virtio-rng-egd", - QEMU_CAPS_DEVICE_VIRTIO_RNG); + QEMU_CAPS_DEVICE_VIRTIO_RNG, + QEMU_CAPS_OBJECT_RNG_EGD); DO_TEST_CAPS_LATEST("virtio-rng-builtin"); DO_TEST("pseries-nvram", @@ -1124,7 +1126,8 @@ mymain(void) DO_TEST_CAPS_LATEST("disk-network-http"); DO_TEST("chardev-label", - QEMU_CAPS_DEVICE_VIRTIO_RNG); + QEMU_CAPS_DEVICE_VIRTIO_RNG, + QEMU_CAPS_OBJECT_RNG_EGD); DO_TEST("cpu-numa1", NONE); DO_TEST("cpu-numa2", NONE); -- 2.26.2