[libvirt PATCH 04/10] virDomainNumaDefNodeDistanceParseXML: Use virXMLProp*

Tim Wiederhake twiederh at redhat.com
Thu May 13 15:32:45 UTC 2021


On Tue, 2021-05-11 at 12:15 -0400, Laine Stump wrote:
> On 5/11/21 11:01 AM, Tim Wiederhake wrote:
> > Signed-off-by: Tim Wiederhake <twiederh at redhat.com>
> > ---
> >   src/conf/numa_conf.c | 42 ++++-----------------------------------
> > ---
> >   1 file changed, 4 insertions(+), 38 deletions(-)
> > 
> > diff --git a/src/conf/numa_conf.c b/src/conf/numa_conf.c
> > index 531bdc6eba..e631bfa341 100644
> > --- a/src/conf/numa_conf.c
> > +++ b/src/conf/numa_conf.c
> > @@ -743,7 +743,6 @@
> > virDomainNumaDefNodeDistanceParseXML(virDomainNuma *def,
> >   {
> >       int ret = -1;
> >       int sibling;
> > -    char *tmp = NULL;
> >       xmlNodePtr *nodes = NULL;
> 
> (Not about *this* patch, but rather the absence of a related patch)
> The 
> other "Use virXMLProp*" patches have a companion patch that makes 
> "nodes" a g_autofree, but you haven't included that patch for this
> function.

g-autofree-ing this function is not trivial (see label "cleanup"), like
it was with other function. The topic of this series-of-series is
replacing virXMLPropString + virStrTo* combos with
virXMLProp{enum,int,tristate,etc}, which is why at this time, this
function stays un-g-autofree-d. I will propably have a look at it at
some point in the future though.

Cheers,
Tim

> >       size_t i, ndistances = def->nmem_nodes;
> >   
> > @@ -765,24 +764,9 @@
> > virDomainNumaDefNodeDistanceParseXML(virDomainNuma *def,
> >           virDomainNumaDistance *rdist;
> >           unsigned int sibling_id, sibling_value;
> >   
> > -        /* siblings are in order of parsing or explicitly numbered
> > */
> > -        if (!(tmp = virXMLPropString(nodes[i], "id"))) {
> > -            virReportError(VIR_ERR_XML_ERROR,
> > -                           _("Missing 'id' attribute in NUMA "
> > -                             "distances under 'cell id %d'"),
> > -                           cur_cell);
> > -            goto cleanup;
> > -        }
> > -
> > -        /* The "id" needs to be applicable */
> > -        if (virStrToLong_uip(tmp, NULL, 10, &sibling_id) < 0) {
> > -            virReportError(VIR_ERR_XML_ERROR,
> > -                           _("Invalid 'id' attribute in NUMA "
> > -                             "distances for sibling: '%s'"),
> > -                           tmp);
> > +        if (virXMLPropUInt(nodes[i], "id", 10,
> > VIR_XML_PROP_REQUIRED,
> > +                           &sibling_id) < 0)
> >               goto cleanup;
> > -        }
> > -        VIR_FREE(tmp);
> >   
> >           /* The "id" needs to be within numa/cell range */
> >           if (sibling_id >= ndistances) {
> > @@ -793,26 +777,9 @@
> > virDomainNumaDefNodeDistanceParseXML(virDomainNuma *def,
> >               goto cleanup;
> >           }
> >   
> > -        /* We need a locality value. Check and correct
> > -         * distance to local and distance to remote node.
> > -         */
> > -        if (!(tmp = virXMLPropString(nodes[i], "value"))) {
> > -            virReportError(VIR_ERR_XML_ERROR,
> > -                           _("Missing 'value' attribute in NUMA
> > distances "
> > -                             "under 'cell id %d' for 'sibling id
> > %d'"),
> > -                           cur_cell, sibling_id);
> > -            goto cleanup;
> > -        }
> > -
> > -        /* The "value" needs to be applicable */
> > -        if (virStrToLong_uip(tmp, NULL, 10, &sibling_value) < 0) {
> > -            virReportError(VIR_ERR_XML_ERROR,
> > -                           _("'value %s' is invalid for "
> > -                             "'sibling id %d' under NUMA 'cell id
> > %d'"),
> > -                           tmp, sibling_id, cur_cell);
> > +        if (virXMLPropUInt(nodes[i], "value", 10,
> > VIR_XML_PROP_REQUIRED,
> > +                           &sibling_value) < 0)
> >               goto cleanup;
> > -        }
> > -        VIR_FREE(tmp);
> >   
> >           /* Assure LOCAL_DISTANCE <= "value" <= UNREACHABLE
> >            * and correct LOCAL_DISTANCE setting if such applies.
> > @@ -867,7 +834,6 @@
> > virDomainNumaDefNodeDistanceParseXML(virDomainNuma *def,
> >           def->mem_nodes[i].ndistances = 0;
> >       }
> >       VIR_FREE(nodes);
> > -    VIR_FREE(tmp);
> >   
> >       return ret;
> >   }
> > 




More information about the libvir-list mailing list