[PATCH] virNodeDevCapMdevParseXML: Use virXMLPropEnum() for ./start/@type
Peter Krempa
pkrempa at redhat.com
Thu May 20 12:33:50 UTC 2021
On Thu, May 20, 2021 at 14:12:56 +0200, Michal Privoznik wrote:
> Signed-off-by: Michal Privoznik <mprivozn at redhat.com>
> ---
>
> Initially, this started as a fix for broken build, but Peter beat me to
> it. I figured it's worth sending anyway.
>
> src/conf/node_device_conf.c | 19 ++++++++-----------
> 1 file changed, 8 insertions(+), 11 deletions(-)
>
> diff --git a/src/conf/node_device_conf.c b/src/conf/node_device_conf.c
> index 5598d420fe..d9b7aff7db 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,14 @@ 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;
This default setting ...
>
> - mdev->start = tmp;
> - } else {
> - mdev->start = VIR_NODE_DEV_MDEV_START_MANUAL;
> + startNode = virXPathNode("./start[1]", ctxt);
... in case when the 'start' element exists ...
> + if (startNode &&
> + virXMLPropEnum(startNode, "type",
.. but 'type' attribute does not ...
> + virNodeDevMdevStartTypeFromString,
> + VIR_XML_PROP_NONE, &mdev->start) < 0) {
... since it's not mandatory will be overwritten by an explicit 0 inside
virXMLPropEnum.
You need to use virXMLPropEnumDefault which allows setting the requested
default value.
> + return -1;
> }
>
> /* 'iommuGroup' is optional, only report an error if the supplied value is
> --
> 2.26.3
>
More information about the libvir-list
mailing list