[libvirt] [PATCHv2 2/4] util: add virNetDevVlanType

Eric Blake eblake at redhat.com
Tue Aug 14 22:55:13 UTC 2012


On 08/14/2012 01:15 AM, Laine Stump wrote:
> To allow for the possibility of vlan "trunks", which have more than
> one vlan tag associated with them, we need a vlan struct. Since it
> will be used by multiple files in src/util, src/conf, src/network, and
> src/qemu, it must be defined in src/util. Unfortunately there isn't
> currently a common file for simple netdev data definitions, so I
> created a new file.

> +int
> +virNetDevVlanEqual(const virNetDevVlanPtr a, const virNetDevVlanPtr b)
> +{
> +    int ii;
> +
> +    if (!(a || b))
> +        return true;
> +    if (!a || !b)
> +        return false;
> +
> +    if (a->trunk != b->trunk ||
> +        a->nTags != b->nTags) {
> +        return false;
> +    }
> +
> +    for (ii = 0; ii < a->nTags; ii++) {
> +        if (a->tag[ii] != b->tag[ii])
> +            return false;

I think this requires the user to list tags in identical order.  Should
two virNetDevVlanPtr be considered equal if the only difference is the
order in which tags are listed, or is there some other reason why an
unsorted list would lose significance if sorted?

> +int
> +virNetDevVlanCopy(virNetDevVlanPtr dst, const virNetDevVlanPtr src)
> +{
> +    if (!src || src->nTags == 0)
> +        return 0;
> +
> +    if (VIR_ALLOC_N(dst->tag, src->nTags) < 0) {
> +        virReportOOMError();
> +        return -1;
> +    }
> +
> +    dst->trunk = src->trunk;
> +    dst->nTags = src->nTags;
> +    memmove(dst->tag, src->tag, src->nTags * sizeof(*src->tag));

src and dst better not overlap; therefore, memcpy() is a better fit.

-- 
Eric Blake   eblake at redhat.com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 620 bytes
Desc: OpenPGP digital signature
URL: <http://listman.redhat.com/archives/libvir-list/attachments/20120814/b025460e/attachment-0001.sig>


More information about the libvir-list mailing list