mirror of https://gitee.com/openkylin/libvirt.git
qemu: Move <rng> validation out of qemu_command.c
Move the rng->model == VIRTIO check to parse time. This also allows us to remove similar checks throughout the qemu driver Reviewed-by: Andrea Bolognani <abologna@redhat.com> Signed-off-by: Cole Robinson <crobinso@redhat.com>
This commit is contained in:
parent
6427bfc8b3
commit
0ba9786d8a
|
@ -5871,14 +5871,6 @@ qemuBuildRNGDevStr(const virDomainDef *def,
|
||||||
{
|
{
|
||||||
virBuffer buf = VIR_BUFFER_INITIALIZER;
|
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,
|
if (!qemuDomainCheckCCWS390AddressSupport(def, dev->info, qemuCaps,
|
||||||
dev->source.file))
|
dev->source.file))
|
||||||
goto error;
|
goto error;
|
||||||
|
|
|
@ -4536,12 +4536,31 @@ qemuDomainSmartcardDefValidate(const virDomainSmartcardDef *def)
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
qemuDomainRNGDefValidate(const virDomainRNGDef *def)
|
qemuDomainRNGDefValidate(const virDomainRNGDef *def,
|
||||||
|
virQEMUCapsPtr qemuCaps)
|
||||||
{
|
{
|
||||||
|
bool modelIsSupported = false;
|
||||||
|
|
||||||
if (def->backend == VIR_DOMAIN_RNG_BACKEND_EGD &&
|
if (def->backend == VIR_DOMAIN_RNG_BACKEND_EGD &&
|
||||||
qemuDomainChrSourceDefValidate(def->source.chardev) < 0)
|
qemuDomainChrSourceDefValidate(def->source.chardev) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
|
switch ((virDomainRNGModel) def->model) {
|
||||||
|
case VIR_DOMAIN_RNG_MODEL_VIRTIO:
|
||||||
|
modelIsSupported = virQEMUCapsGet(qemuCaps,
|
||||||
|
QEMU_CAPS_DEVICE_VIRTIO_RNG);
|
||||||
|
break;
|
||||||
|
case VIR_DOMAIN_RNG_MODEL_LAST:
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!modelIsSupported) {
|
||||||
|
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
|
||||||
|
_("this qemu doesn't support RNG device type '%s'"),
|
||||||
|
virDomainRNGModelTypeToString(def->model));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -6073,7 +6092,7 @@ qemuDomainDeviceDefValidate(const virDomainDeviceDef *dev,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_DEVICE_RNG:
|
case VIR_DOMAIN_DEVICE_RNG:
|
||||||
ret = qemuDomainRNGDefValidate(dev->data.rng);
|
ret = qemuDomainRNGDefValidate(dev->data.rng, qemuCaps);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case VIR_DOMAIN_DEVICE_REDIRDEV:
|
case VIR_DOMAIN_DEVICE_REDIRDEV:
|
||||||
|
|
|
@ -364,8 +364,8 @@ qemuDomainPrimeVirtioDeviceAddresses(virDomainDefPtr def,
|
||||||
def->memballoon->info.type = type;
|
def->memballoon->info.type = type;
|
||||||
|
|
||||||
for (i = 0; i < def->nrngs; i++) {
|
for (i = 0; i < def->nrngs; i++) {
|
||||||
if (def->rngs[i]->model == VIR_DOMAIN_RNG_MODEL_VIRTIO &&
|
/* All <rng> devices accepted by the qemu driver are virtio */
|
||||||
def->rngs[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
|
if (def->rngs[i]->info.type == VIR_DOMAIN_DEVICE_ADDRESS_TYPE_NONE)
|
||||||
def->rngs[i]->info.type = type;
|
def->rngs[i]->info.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2276,10 +2276,9 @@ qemuDomainAssignDevicePCISlots(virDomainDefPtr def,
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* VirtIO RNG */
|
/* the qemu driver only accepts virtio rng devices */
|
||||||
for (i = 0; i < def->nrngs; i++) {
|
for (i = 0; i < def->nrngs; i++) {
|
||||||
if (def->rngs[i]->model != VIR_DOMAIN_RNG_MODEL_VIRTIO ||
|
if (!virDeviceInfoPCIAddressIsWanted(&def->rngs[i]->info))
|
||||||
!virDeviceInfoPCIAddressIsWanted(&def->rngs[i]->info))
|
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (qemuDomainPCIAddressReserveNextAddr(addrs, &def->rngs[i]->info) < 0)
|
if (qemuDomainPCIAddressReserveNextAddr(addrs, &def->rngs[i]->info) < 0)
|
||||||
|
|
|
@ -585,8 +585,10 @@ mymain(void)
|
||||||
|
|
||||||
DO_TEST("disk-serial", NONE);
|
DO_TEST("disk-serial", NONE);
|
||||||
|
|
||||||
DO_TEST("virtio-rng-random", NONE);
|
DO_TEST("virtio-rng-random",
|
||||||
DO_TEST("virtio-rng-egd", NONE);
|
QEMU_CAPS_DEVICE_VIRTIO_RNG);
|
||||||
|
DO_TEST("virtio-rng-egd",
|
||||||
|
QEMU_CAPS_DEVICE_VIRTIO_RNG);
|
||||||
|
|
||||||
DO_TEST("pseries-nvram",
|
DO_TEST("pseries-nvram",
|
||||||
QEMU_CAPS_DEVICE_SPAPR_PCI_HOST_BRIDGE);
|
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-index", NONE);
|
||||||
DO_TEST("disk-backing-chains-noindex", 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-numa1", NONE);
|
||||||
DO_TEST("cpu-numa2", NONE);
|
DO_TEST("cpu-numa2", NONE);
|
||||||
|
|
Loading…
Reference in New Issue