qemu_command.c: move RNG backend validation to qemu_validate.c

Reviewed-by: Michal Privoznik <mprivozn@redhat.com>
Signed-off-by: Daniel Henrique Barboza <danielhb413@gmail.com>
This commit is contained in:
Daniel Henrique Barboza 2020-10-09 15:18:53 -03:00
parent 66f15d17e2
commit f800aa3ee7
5 changed files with 45 additions and 33 deletions

View File

@ -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);

View File

@ -167,7 +167,6 @@ char *qemuBuildRNGDevStr(const virDomainDef *def,
virDomainRNGDefPtr dev,
virQEMUCapsPtr qemuCaps);
int qemuBuildRNGBackendProps(virDomainRNGDefPtr rng,
virQEMUCapsPtr qemuCaps,
virJSONValuePtr *props);
/* Current, best practice */

View File

@ -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)))

View File

@ -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;

View File

@ -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);