Re: [PATCH 15/28] conf: single object containing list of IP addresses, list of routes

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



[...]

The second cup of caffeine finally started flowing through the veins...
and of course I'm on patch 19...

use

static int ATTRIBUTE_UNUSED
virDomainxxx()



>>  
>> +
>> +/* fill in a virNetDevIPInfoPtr from the <route> and <ip>
>> + * elements found in the given XML context.
>> + *
>> + * return 0 on success (including none found) and -1 on failure.
>> + */
>> +int
>> +virDomainNetIPInfoParseXML(const char *source,
>> +                           xmlXPathContextPtr ctxt,
>> +                           virNetDevIPInfoPtr def);
> 
> Why?  If it needs to be "higher" to avoid the forward reference for
> future callers, then so be it.
> 
>> +int
> 
> static int
> 
>> +virDomainNetIPInfoParseXML(const char *source,
>> +                           xmlXPathContextPtr ctxt,
>> +                           virNetDevIPInfoPtr def)
>> +
>> +{
>> +    xmlNodePtr *nodes = NULL;
>> +    virNetDevIPAddrPtr ip = NULL;
>> +    virNetDevIPRoutePtr route = NULL;
>> +    int nnodes;
>> +    int ret = -1;
>> +    size_t i;
>> +
>> +    if ((nnodes = virXPathNodeSet("./ip", ctxt, &nodes)) < 0)
>> +        goto cleanup;
>> +
>> +    for (i = 0; i < nnodes; i++) {
>> +        if (!(ip = virDomainNetIPParseXML(nodes[i])) ||
>> +            VIR_APPEND_ELEMENT(def->ips, def->nips, ip) < 0)
>> +            goto cleanup;
>> +    }
>> +    VIR_FREE(nodes);
>> +
>> +    if ((nnodes = virXPathNodeSet("./route", ctxt, &nodes)) < 0)
>> +        goto cleanup;
>> +
>> +    for (i = 0; i < nnodes; i++) {
>> +        if (!(route = virNetDevIPRouteParseXML(source, nodes[i], ctxt)) ||
>> +            VIR_APPEND_ELEMENT(def->routes, def->nroutes, route) < 0)
>> +            goto cleanup;
>> +    }
>> +
>> +    ret = 0;
>> + cleanup:
>> +    if (ret < 0)
>> +        virNetDevIPInfoClear(def);
>> +    VIR_FREE(ip);
> 
> Seeing just VIR_FREE(ip) made me go look at how it was allocated - guess
> I was (now) concerned that something would be allocated into ip that
> wasn't free'd properly (eg. no virNetDevIPFree() API ...
> 
> Anyway, the ip->address is written with the result of a getaddrinfo in
> virSocketAddrParseInternal, which when free'd should be done by
> freeaddrinfo, right?
> 
> I think this is existing, but fixable... at some point in time.
> 
>> +    virNetDevIPRouteFree(route);
>> +    VIR_FREE(nodes);
>> +    return ret;
>> +}
>> +
>>  static int
>>  virDomainHostdevDefParseXMLCaps(xmlNodePtr node ATTRIBUTE_UNUSED,
>>                                  xmlXPathContextPtr ctxt,
>> @@ -20311,6 +20363,22 @@ virDomainNetRoutesFormat(virBufferPtr buf,
>>      return 0;
>>  }
>>  
>> +
>> +int
>> +virDomainNetIPInfoFormat(virBufferPtr buf,
>> +                         virNetDevIPInfoPtr def);
> 
> Same complaint.
> 
>> +int
> 
> static int
> 
> 
> ACK with the forward ref and static int used.  I think you need a "new"
> patch at some point in time to handle the getaddrinfo/freeaddrinfo...
> 
> John
>> +virDomainNetIPInfoFormat(virBufferPtr buf,
>> +                         virNetDevIPInfoPtr def)
>> +{
>> +    if (virDomainNetIPsFormat(buf, def->ips, def->nips) < 0)
>> +        return -1;
>> +    if (virDomainNetRoutesFormat(buf, def->routes, def->nroutes) < 0)
>> +        return -1;
>> +    return 0;
>> +}
>> +
>> +
>>  static int
>>  virDomainHostdevDefFormatSubsys(virBufferPtr buf,
>>                                  virDomainHostdevDefPtr def,
>> diff --git a/src/libvirt_private.syms b/src/libvirt_private.syms
>> index 151cf9f..f6c3d45 100644
>> --- a/src/libvirt_private.syms
>> +++ b/src/libvirt_private.syms
>> @@ -1925,6 +1925,7 @@ virNetDevBridgeSetVlanFiltering;
>>  virNetDevIPAddrAdd;
>>  virNetDevIPAddrDel;
>>  virNetDevIPAddrGet;
>> +virNetDevIPInfoClear;
>>  virNetDevIPRouteAdd;
>>  virNetDevIPRouteFree;
>>  virNetDevIPRouteGetAddress;
>> diff --git a/src/util/virnetdevip.c b/src/util/virnetdevip.c
>> index 619f926..376d4ad 100644
>> --- a/src/util/virnetdevip.c
>> +++ b/src/util/virnetdevip.c
>> @@ -845,3 +845,19 @@ virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def)
>>          return &def->gateway;
>>      return NULL;
>>  }
>> +
>> +/* manipulating the virNetDevIPInfo object */
>> +
>> +void
>> +virNetDevIPInfoClear(virNetDevIPInfoPtr ip)
>> +{
>> +    size_t i;
>> +
>> +    for (i = 0; i < ip->nips; i++)
>> +        VIR_FREE(ip->ips[i]);
>> +    VIR_FREE(ip->ips);
>> +
>> +    for (i = 0; i < ip->nroutes; i++)
>> +        virNetDevIPRouteFree(ip->routes[i]);
>> +    VIR_FREE(ip->routes);
>> +}
>> diff --git a/src/util/virnetdevip.h b/src/util/virnetdevip.h
>> index 7a07b73..be41636 100644
>> --- a/src/util/virnetdevip.h
>> +++ b/src/util/virnetdevip.h
>> @@ -47,6 +47,14 @@ typedef struct {
>>      virSocketAddr gateway;      /* gateway IP address for ip-route */
>>  } virNetDevIPRoute, *virNetDevIPRoutePtr;
>>  
>> +/* A full set of all IP config info for a network device */
>> +typedef struct {
>> +    size_t nips;
>> +    virNetDevIPAddrPtr *ips;
>> +    size_t nroutes;
>> +    virNetDevIPRoutePtr *routes;
>> +} virNetDevIPInfo, *virNetDevIPInfoPtr;
>> +
>>  /* manipulating/querying the netdev */
>>  int virNetDevIPAddrAdd(const char *ifname,
>>                         virSocketAddr *addr,
>> @@ -76,4 +84,7 @@ int virNetDevIPRouteGetPrefix(virNetDevIPRoutePtr def);
>>  unsigned int virNetDevIPRouteGetMetric(virNetDevIPRoutePtr def);
>>  virSocketAddrPtr virNetDevIPRouteGetGateway(virNetDevIPRoutePtr def);
>>  
>> +/* virNetDevIPInfo object */
>> +void virNetDevIPInfoClear(virNetDevIPInfoPtr ip);
>> +
>>  #endif /* __VIR_NETDEVIP_H__ */
>>
> 
> --
> libvir-list mailing list
> libvir-list@xxxxxxxxxx
> https://www.redhat.com/mailman/listinfo/libvir-list
> 

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]