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.
This commit is contained in:
Peter Krempa 2011-09-06 16:05:53 +08:00 committed by Daniel Veillard
parent 9fd3bb7a88
commit c246b02586
2 changed files with 67 additions and 0 deletions

View File

@ -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;
}

View File

@ -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__ */