[libvirt] [PATCH v3 1/5] link-state: util: Add equality comparision functions for structures
Daniel Veillard
veillard at redhat.com
Tue Sep 6 07:54:25 UTC 2011
On Mon, Sep 05, 2011 at 05:26:50PM +0200, Peter Krempa wrote:
> This patch adds functions to compare structures containing network
> device configuration for equality. They serve for the purpose of
> disallowing unsupported changes to live network devices.
> ---
> src/util/network.c | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++
> src/util/network.h | 5 ++++
> 2 files changed, 67 insertions(+), 0 deletions(-)
>
> diff --git a/src/util/network.c b/src/util/network.c
> index 6fcdab2..ee69557 100644
> --- a/src/util/network.c
> +++ b/src/util/network.c
> @@ -842,6 +842,43 @@ error:
> return ret;
> }
>
> +bool
> +virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, virVirtualPortProfileParamsPtr b)
> +{
> + /* NULL resistant */
> + if (!a && !b)
> + return true;
> +
> + if (!a || !b)
> + return false;
> +
> + if (a->virtPortType != b->virtPortType)
> + return false;
> +
> + switch (a->virtPortType) {
> + case VIR_VIRTUALPORT_NONE:
> + break;
> +
> + case VIR_VIRTUALPORT_8021QBG:
> + if (a->u.virtPort8021Qbg.managerID != b->u.virtPort8021Qbg.managerID ||
> + a->u.virtPort8021Qbg.typeID != b->u.virtPort8021Qbg.typeID ||
> + a->u.virtPort8021Qbg.typeIDVersion != b->u.virtPort8021Qbg.typeIDVersion ||
> + memcmp(a->u.virtPort8021Qbg.instanceID, b->u.virtPort8021Qbg.instanceID, VIR_UUID_BUFLEN) != 0)
> + return false;
> + break;
> +
> + case VIR_VIRTUALPORT_8021QBH:
> + if (STRNEQ(a->u.virtPort8021Qbh.profileID, b->u.virtPort8021Qbh.profileID))
> + return false;
> + break;
> +
> + default:
> + break;
> + }
> +
> + return true;
> +}
> +
> void
> virVirtualPortProfileFormat(virBufferPtr buf,
> virVirtualPortProfileParamsPtr virtPort,
> @@ -1321,3 +1358,28 @@ cleanup:
> }
> return ret;
> }
> +
> +bool
> +virBandwidthEqual(virBandwidthPtr a,
> + virBandwidthPtr b)
> +{
> + if (!a && !b)
> + return true;
> +
> + if (!a || !b)
> + return false;
The only question I would have here is what if one of the structure
in or out pointer is NULL, since it's an internal API I would try to
harde this a bit in a following patch,
> + /* in */
> + if (a->in->average != b->in->average ||
> + a->in->peak != b->in->peak ||
> + a->in->burst != b->in->burst)
> + return false;
> +
> + /*out*/
> + if (a->out->average != b->out->average ||
> + a->out->peak != b->out->peak ||
> + a->out->burst != b->out->burst)
> + return false;
> +
> + return true;
> +}
> diff --git a/src/util/network.h b/src/util/network.h
> index 6ceaa6d..4d195af 100644
> --- a/src/util/network.h
> +++ b/src/util/network.h
> @@ -150,6 +150,8 @@ virVirtualPortProfileFormat(virBufferPtr buf,
> virVirtualPortProfileParamsPtr virtPort,
> const char *indent);
>
> +bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, virVirtualPortProfileParamsPtr b);
> +
> virBandwidthPtr virBandwidthDefParseNode(xmlNodePtr node);
> void virBandwidthDefFree(virBandwidthPtr def);
> int virBandwidthDefFormat(virBufferPtr buf,
> @@ -160,4 +162,7 @@ int virBandwidthEnable(virBandwidthPtr bandwidth, const char *iface);
> int virBandwidthDisable(const char *iface, bool may_fail);
> int virBandwidthCopy(virBandwidthPtr *dest, const virBandwidthPtr src);
>
> +bool virBandwidthEqual(virBandwidthPtr a, virBandwidthPtr b);
> +
> +
> #endif /* __VIR_NETWORK_H__ */
Otherwise looks just fine, ACK
Daniel
--
Daniel Veillard | libxml Gnome XML XSLT toolkit http://xmlsoft.org/
daniel at veillard.com | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library http://libvirt.org/
More information about the libvir-list
mailing list