]> xenbits.xensource.com Git - libvirt.git/commitdiff
virDomainRNGDef: Convert 'model' field to proper enum type
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 2 May 2023 10:23:45 +0000 (12:23 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 15 Sep 2023 08:35:09 +0000 (10:35 +0200)
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>
src/conf/domain_conf.c
src/conf/domain_conf.h
src/qemu/qemu_domain_address.c

index 95a71b204fb2db343134b70787b01f9952dc6842..3b24d0218da3161961e919d944fd09505ded90ce 100644 (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"));
-        goto error;
-    }
-
-    if ((def->model = virDomainRNGModelTypeFromString(model)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED, _("unknown RNG model '%1$s'"), model);
+    if (virXMLPropEnum(node, "model",
+                       virDomainRNGModelTypeFromString,
+                       VIR_XML_PROP_REQUIRED,
+                       &def->model) < 0)
         goto error;
-    }
 
     ctxt->node = node;
 
index 9dadda2d1d1c73e47291c3313a39d4308f05884a..f56c04ce360cbd99f661b7f6fc725483854348f1 100644 (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 */
index 2e58930eec8e4132efdc2f8fd8c70de9a738fdcb..0ed70e5b8653cfdcbb17a09cef64c424dd866ba2 100644 (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;