[libvirt PATCH 09/10] virDomainVsockDefParseXML: Use virXMLProp*
Peter Krempa
pkrempa at redhat.com
Wed Apr 21 14:31:48 UTC 2021
On Wed, Apr 21, 2021 at 15:33:31 +0200, Tim Wiederhake wrote:
> Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
> ---
> src/conf/domain_conf.c | 48 ++++++++++++------------------------------
> 1 file changed, 13 insertions(+), 35 deletions(-)
>
> diff --git a/src/conf/domain_conf.c b/src/conf/domain_conf.c
> index 9e968c087d..1878d9ed9d 100644
> --- a/src/conf/domain_conf.c
> +++ b/src/conf/domain_conf.c
> @@ -15855,8 +15855,6 @@ virDomainVsockDefParseXML(virDomainXMLOption *xmlopt,
> {
> VIR_XPATH_NODE_AUTORESTORE(ctxt)
> xmlNodePtr cid;
> - int val;
> - g_autofree char *tmp = NULL;
> g_autoptr(virDomainVsockDef) vsock = NULL;
>
> ctxt->node = node;
> @@ -15864,49 +15862,29 @@ virDomainVsockDefParseXML(virDomainXMLOption *xmlopt,
> if (!(vsock = virDomainVsockDefNew(xmlopt)))
> return NULL;
>
> - if ((tmp = virXMLPropString(node, "model"))) {
> - if ((val = virDomainVsockModelTypeFromString(tmp)) < 0) {
> - virReportError(VIR_ERR_XML_ERROR, _("unknown vsock model: %s"), tmp);
> - return NULL;
> - }
> - vsock->model = val;
> - }
> -
> - cid = virXPathNode("./cid", ctxt);
> + if (virXMLPropEnum(node, "model", virDomainVsockModelTypeFromString,
> + VIR_XML_PROP_NONE, &vsock->model) < 0)
> + return NULL;
>
> - VIR_FREE(tmp);
> - if (cid) {
> - if ((tmp = virXMLPropString(cid, "address"))) {
> - if (virStrToLong_uip(tmp, NULL, 10, &vsock->guest_cid) < 0 ||
> - vsock->guest_cid == 0) {
> - virReportError(VIR_ERR_XML_DETAIL,
> - _("'cid' attribute must be a positive number: %s"),
> - tmp);
> - return NULL;
> - }
> - }
> + if ((cid = virXPathNode("./cid", ctxt))) {
> + if (virXMLPropUInt(cid, "address", 10,
> + VIR_XML_PROP_NONE | VIR_XML_PROP_NONZERO,
'or'-ing something to VIR_XML_PROP_NONE doesn't make sense.
> + &vsock->guest_cid) < 0)
> + return NULL;
>
> - VIR_FREE(tmp);
> - if ((tmp = virXMLPropString(cid, "auto"))) {
> - val = virTristateBoolTypeFromString(tmp);
> - if (val <= 0) {
> - virReportError(VIR_ERR_XML_DETAIL,
> - _("'auto' attribute can be 'yes' or 'no': %s"),
> - tmp);
> - return NULL;
> - }
> - vsock->auto_cid = val;
> - }
> + if (virXMLPropTristateBool(cid, "auto", VIR_XML_PROP_NONE,
> + &vsock->auto_cid) < 0)
> + return NULL;
> }
>
> - if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &vsock->info, flags) < 0)
> + if (virDomainDeviceInfoParseXML(xmlopt, node, ctxt, &vsock->info,
> + flags) < 0)
This is an unrelated change.
> return NULL;
I'll fix both before pushing.
More information about the libvir-list
mailing list