[PATCH 32/43] virDomainTimerDef: Convert 'name' field to proper enum type

Peter Krempa posted 43 patches 3 years, 3 months ago
[PATCH 32/43] virDomainTimerDef: Convert 'name' field to proper enum type
Posted by Peter Krempa 3 years, 3 months ago
Adjust the type and the corresponding parser to use virXMLPropEnum.

Signed-off-by: Peter Krempa <pkrempa@redhat.com>
---
 src/conf/domain_conf.c | 13 ++-----------
 src/conf/domain_conf.h |  2 +-
 2 files changed, 3 insertions(+), 12 deletions(-)

diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
index 7c718ce799..aa949766e1 100644
--- a/src/conf/domain_conf.c
+++ b/src/conf/domain_conf.c
@@ -10546,24 +10546,15 @@ virDomainTimerDefParseXML(xmlNodePtr node,
     VIR_XPATH_NODE_AUTORESTORE(ctxt)
     xmlNodePtr catchup;
     int ret;
-    g_autofree char *name = NULL;
     g_autofree char *tickpolicy = NULL;
     g_autofree char *track = NULL;
     g_autofree char *mode = NULL;

     ctxt->node = node;

-    name = virXMLPropString(node, "name");
-    if (name == NULL) {
-        virReportError(VIR_ERR_INTERNAL_ERROR,
-                       "%s", _("missing timer name"));
+    if (virXMLPropEnum(node, "name", virDomainTimerNameTypeFromString,
+                       VIR_XML_PROP_REQUIRED, &def->name) < 0)
         return NULL;
-    }
-    if ((def->name = virDomainTimerNameTypeFromString(name)) < 0) {
-        virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                       _("unknown timer name '%s'"), name);
-        return NULL;
-    }

     if (virXMLPropTristateBool(node, "present",
                                VIR_XML_PROP_NONE,
diff --git a/src/conf/domain_conf.h b/src/conf/domain_conf.h
index ba411bfa02..de6aefed2d 100644
--- a/src/conf/domain_conf.h
+++ b/src/conf/domain_conf.h
@@ -2472,7 +2472,7 @@ struct _virDomainTimerCatchupDef {
 };

 struct _virDomainTimerDef {
-    int name;
+    virDomainTimerNameType name;
     virTristateBool present;
     int tickpolicy; /* enum virDomainTimerTickpolicyType */

-- 
2.37.3
Re: [PATCH 32/43] virDomainTimerDef: Convert 'name' field to proper enum type
Posted by Ján Tomko 3 years, 3 months ago
On a Monday in 2022, Peter Krempa wrote:
>Adjust the type and the corresponding parser to use virXMLPropEnum.
>
>Signed-off-by: Peter Krempa <pkrempa@redhat.com>
>---
> src/conf/domain_conf.c | 13 ++-----------
> src/conf/domain_conf.h |  2 +-
> 2 files changed, 3 insertions(+), 12 deletions(-)
>

Reviewed-by: Ján Tomko <jtomko@redhat.com>

Jano