The qemu driver already does some <rng> model validation, based on
qemuCaps. However, the logic for exposing <rng> model values in domcaps
is basically identical. This drops the qemuCaps checking and compares
against the domCaps data directly.
This approach makes it basically impossible to add a new <rng> model to
the qemu driver without extending domcaps. The validation can also
be shared with other drivers eventually.
Signed-off-by: Cole Robinson <crobinso(a)redhat.com>
---
src/conf/domain_capabilities.c | 35 +++++++++++++++++++++++++++++++---
src/conf/domain_capabilities.h | 1 +
src/qemu/qemu_domain.c | 26 +------------------------
3 files changed, 34 insertions(+), 28 deletions(-)
diff --git a/src/conf/domain_capabilities.c b/src/conf/domain_capabilities.c
index aef5703df6..977f15b9ed 100644
--- a/src/conf/domain_capabilities.c
+++ b/src/conf/domain_capabilities.c
@@ -659,19 +659,48 @@ virDomainCapsFormat(virDomainCapsPtr const caps)
}
+#define ENUM_VALUE_MISSING(capsEnum, value) !(capsEnum.values & (1 << value))
+
+#define ENUM_VALUE_ERROR(valueLabel, valueString) \
+ do { \
+ virReportError(VIR_ERR_CONFIG_UNSUPPORTED, \
+ _("domain configuration does not support '%s' value
'%s'"), \
+ valueLabel, valueString); \
+ } while (0)
+
+
+static int
+virDomainCapsDeviceRNGDefValidate(virDomainCapsPtr const caps,
+ const virDomainRNGDef *dev)
+{
+ if (ENUM_VALUE_MISSING(caps->rng.model, dev->model)) {
+ ENUM_VALUE_ERROR("rng model",
+ virDomainRNGModelTypeToString(dev->model));
+ return -1;
+ }
+
+ return 0;
+}
+
+
int
-virDomainCapsDeviceDefValidate(virDomainCapsPtr const caps ATTRIBUTE_UNUSED,
+virDomainCapsDeviceDefValidate(virDomainCapsPtr const caps,
const virDomainDeviceDef *dev,
const virDomainDef *def ATTRIBUTE_UNUSED)
{
+ int ret = 0;
+
switch ((virDomainDeviceType) dev->type) {
+ case VIR_DOMAIN_DEVICE_RNG:
+ ret = virDomainCapsDeviceRNGDefValidate(caps, dev->data.rng);
+ break;
+
case VIR_DOMAIN_DEVICE_DISK:
case VIR_DOMAIN_DEVICE_REDIRDEV:
case VIR_DOMAIN_DEVICE_NET:
case VIR_DOMAIN_DEVICE_CONTROLLER:
case VIR_DOMAIN_DEVICE_CHR:
case VIR_DOMAIN_DEVICE_SMARTCARD:
- case VIR_DOMAIN_DEVICE_RNG:
case VIR_DOMAIN_DEVICE_HOSTDEV:
case VIR_DOMAIN_DEVICE_VIDEO:
case VIR_DOMAIN_DEVICE_MEMORY:
@@ -694,5 +723,5 @@ virDomainCapsDeviceDefValidate(virDomainCapsPtr const caps
ATTRIBUTE_UNUSED,
break;
}
- return 0;
+ return ret;
}
diff --git a/src/conf/domain_capabilities.h b/src/conf/domain_capabilities.h
index ffce2c2964..997c7d9444 100644
--- a/src/conf/domain_capabilities.h
+++ b/src/conf/domain_capabilities.h
@@ -215,6 +215,7 @@ virDomainCapsCPUModelsGet(virDomainCapsCPUModelsPtr cpuModels,
__nvalues, __values); \
} while (0)
+
int virDomainCapsEnumSet(virDomainCapsEnumPtr capsEnum,
const char *capsEnumName,
size_t nvalues,
diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 6da27a79b0..cad08439b1 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -4523,36 +4523,12 @@ qemuDomainSmartcardDefValidate(const virDomainSmartcardDef *def)
static int
qemuDomainRNGDefValidate(const virDomainRNGDef *def,
- virQEMUCapsPtr qemuCaps)
+ virQEMUCapsPtr qemuCaps ATTRIBUTE_UNUSED)
{
- bool modelIsSupported = 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:
- modelIsSupported = virQEMUCapsGet(qemuCaps,
- QEMU_CAPS_DEVICE_VIRTIO_RNG);
- break;
- case VIR_DOMAIN_RNG_MODEL_VIRTIO_TRANSITIONAL:
- case VIR_DOMAIN_RNG_MODEL_VIRTIO_NON_TRANSITIONAL:
- modelIsSupported = (virQEMUCapsGet(qemuCaps, QEMU_CAPS_DEVICE_VIRTIO_RNG)
&&
- (virQEMUCapsGet(qemuCaps, QEMU_CAPS_VIRTIO_PCI_TRANSITIONAL)
||
- virQEMUCapsGet(qemuCaps,
QEMU_CAPS_VIRTIO_PCI_DISABLE_LEGACY)));
- 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;
}
--
2.21.0