virDomainRNGDef: Convert 'model' field to proper enum type

Convert the field and adjust the XML parser to use
virXMLPropEnum().

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
Michal Privoznik 2023-05-02 12:23:45 +02:00
parent 27a653b893
commit 53edfa23f1
3 changed files with 6 additions and 11 deletions

View File

@ -12116,21 +12116,16 @@ virDomainRNGDefParseXML(virDomainXMLOption *xmlopt,
VIR_XPATH_NODE_AUTORESTORE(ctxt)
int nbackends;
g_autofree xmlNodePtr *backends = NULL;
g_autofree char *model = NULL;
g_autofree char *backend = NULL;
g_autofree char *type = NULL;
def = g_new0(virDomainRNGDef, 1);
if (!(model = virXMLPropString(node, "model"))) {
virReportError(VIR_ERR_XML_ERROR, "%s", _("missing RNG device model"));
if (virXMLPropEnum(node, "model",
virDomainRNGModelTypeFromString,
VIR_XML_PROP_REQUIRED,
&def->model) < 0)
goto error;
}
if ((def->model = virDomainRNGModelTypeFromString(model)) < 0) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown RNG model '%1$s'"), model);
goto error;
}
ctxt->node = node;

View File

@ -2609,7 +2609,7 @@ typedef enum {
} virDomainRNGBackend;
struct _virDomainRNGDef {
int model;
virDomainRNGModel model;
int backend;
unsigned int rate; /* bytes per period */
unsigned int period; /* milliseconds */

View File

@ -912,7 +912,7 @@ qemuDomainDeviceCalculatePCIConnectFlags(virDomainDeviceDef *dev,
break;
case VIR_DOMAIN_DEVICE_RNG:
switch ((virDomainRNGModel) dev->data.rng->model) {
switch (dev->data.rng->model) {
case VIR_DOMAIN_RNG_MODEL_VIRTIO_TRANSITIONAL:
/* Transitional devices only work in conventional PCI slots */
return pciFlags;