From c246b0258645d3781362ce880d2cb435ab96835d Mon Sep 17 00:00:00 2001 From: Peter Krempa Date: Tue, 6 Sep 2011 16:05:53 +0800 Subject: [PATCH] link-state: util: Add equality comparison functions for structures 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(+) diff --git a/src/util/network.c b/src/util/network.c index 6fcdab2bba..ee695575a9 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; + + /* 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 6ceaa6d5b9..4d195af90f 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__ */