[PATCH v2] virNodeDevCapMdevParseXML: Use virXMLPropEnum() for ./start/@type

Michal Privoznik posted 1 patch 2 years, 11 months ago
Test syntax-check failed
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/27e7ae5b83c6e53f93507f89e4bdc095dfb7e041.1621514713.git.mprivozn@redhat.com
src/conf/node_device_conf.c | 20 +++++++++-----------
1 file changed, 9 insertions(+), 11 deletions(-)
[PATCH v2] virNodeDevCapMdevParseXML: Use virXMLPropEnum() for ./start/@type
Posted by Michal Privoznik 2 years, 11 months ago
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
---

v2 of:

https://listman.redhat.com/archives/libvir-list/2021-May/msg00604.html

diff to v1:
- Switch from virXMLPropEnum() to virXMLPropEnumDefault() per Peter's
review

 src/conf/node_device_conf.c | 20 +++++++++-----------
 1 file changed, 9 insertions(+), 11 deletions(-)

diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
index 5598d420fe..af72e160a5 100644
--- a/src/conf/node_device_conf.c
+++ b/src/conf/node_device_conf.c
@@ -1919,7 +1919,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
     g_autofree xmlNodePtr *attrs = NULL;
     size_t i;
     g_autofree char *uuidstr = NULL;
-    g_autofree char *starttype = NULL;
+    xmlNodePtr startNode = NULL;
 
     ctxt->node = node;
 
@@ -1941,17 +1941,15 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
         virUUIDFormat(uuidbuf, mdev->uuid);
     }
 
-    if ((starttype = virXPathString("string(./start[1]/@type)", ctxt))) {
-        int tmp;
-        if ((tmp = virNodeDevMdevStartTypeFromString(starttype)) < 0) {
-            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
-                           _("unknown mdev start type '%s' for '%s'"), starttype, def->name);
-            return -1;
-        }
+    mdev->start = VIR_NODE_DEV_MDEV_START_MANUAL;
 
-        mdev->start = tmp;
-    } else {
-        mdev->start = VIR_NODE_DEV_MDEV_START_MANUAL;
+    startNode = virXPathNode("./start[1]", ctxt);
+    if (startNode &&
+        virXMLPropEnumDefault(startNode, "type",
+                              virNodeDevMdevStartTypeFromString,
+                              VIR_XML_PROP_NONE, &mdev->start,
+                              VIR_NODE_DEV_MDEV_START_MANUAL) < 0) {
+        return -1;
     }
 
     /* 'iommuGroup' is optional, only report an error if the supplied value is
-- 
2.26.3

Re: [PATCH v2] virNodeDevCapMdevParseXML: Use virXMLPropEnum() for ./start/@type
Posted by Peter Krempa 2 years, 11 months ago
On Thu, May 20, 2021 at 14:46:02 +0200, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
> 
> v2 of:
> 
> https://listman.redhat.com/archives/libvir-list/2021-May/msg00604.html
> 
> diff to v1:
> - Switch from virXMLPropEnum() to virXMLPropEnumDefault() per Peter's
> review

Reviewed-by: Peter Krempa <pkrempa@redhat.com>

Re: [PATCH v2] virNodeDevCapMdevParseXML: Use virXMLPropEnum() for ./start/@type
Posted by Boris Fiuczynski 2 years, 11 months ago
Looks good as well as works for me.

Reviewed-by: Boris Fiuczynski <fiuczy@linux.ibm.com>

On 5/20/21 2:46 PM, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
> ---
> 
> v2 of:
> 
> https://listman.redhat.com/archives/libvir-list/2021-May/msg00604.html
> 
> diff to v1:
> - Switch from virXMLPropEnum() to virXMLPropEnumDefault() per Peter's
> review
> 
>   src/conf/node_device_conf.c | 20 +++++++++-----------
>   1 file changed, 9 insertions(+), 11 deletions(-)
> 
> diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
> index 5598d420fe..af72e160a5 100644
> --- a/src/conf/node_device_conf.c
> +++ b/src/conf/node_device_conf.c
> @@ -1919,7 +1919,7 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
>       g_autofree xmlNodePtr *attrs = NULL;
>       size_t i;
>       g_autofree char *uuidstr = NULL;
> -    g_autofree char *starttype = NULL;
> +    xmlNodePtr startNode = NULL;
>   
>       ctxt->node = node;
>   
> @@ -1941,17 +1941,15 @@ virNodeDevCapMdevParseXML(xmlXPathContextPtr ctxt,
>           virUUIDFormat(uuidbuf, mdev->uuid);
>       }
>   
> -    if ((starttype = virXPathString("string(./start[1]/@type)", ctxt))) {
> -        int tmp;
> -        if ((tmp = virNodeDevMdevStartTypeFromString(starttype)) < 0) {
> -            virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
> -                           _("unknown mdev start type '%s' for '%s'"), starttype, def->name);
> -            return -1;
> -        }
> +    mdev->start = VIR_NODE_DEV_MDEV_START_MANUAL;
>   
> -        mdev->start = tmp;
> -    } else {
> -        mdev->start = VIR_NODE_DEV_MDEV_START_MANUAL;
> +    startNode = virXPathNode("./start[1]", ctxt);
> +    if (startNode &&
> +        virXMLPropEnumDefault(startNode, "type",
> +                              virNodeDevMdevStartTypeFromString,
> +                              VIR_XML_PROP_NONE, &mdev->start,
> +                              VIR_NODE_DEV_MDEV_START_MANUAL) < 0) {
> +        return -1;
>       }
>   
>       /* 'iommuGroup' is optional, only report an error if the supplied value is
> 


-- 
Mit freundlichen Grüßen/Kind regards
    Boris Fiuczynski

IBM Deutschland Research & Development GmbH
Vorsitzender des Aufsichtsrats: Gregor Pillen
Geschäftsführung: Dirk Wittkopp
Sitz der Gesellschaft: Böblingen
Registergericht: Amtsgericht Stuttgart, HRB 243294