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; + + /* 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__ */ -- 1.7.3.4 -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list