conf: allow bandwidth parsing / formatting to include class ID

The domain conf actual network def stores a <class id='3'/> element
separately from the <bandwidth>. The class ID should really just be
an attribute on the <bandwidth> element. We can't change existing
XML, and this isn't visible to users since it is internal XML only.
When we expose the new network port XML to users though, we should
get the design right.

Reviewed-by: Laine Stump <laine@laine.org>
Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
This commit is contained in:
Daniel P. Berrangé 2019-05-14 15:44:55 +01:00
parent f8a53a0795
commit c0c37de2d6
5 changed files with 39 additions and 8 deletions

View File

@ -11280,6 +11280,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
bandwidth_node = virXPathNode("./bandwidth", ctxt); bandwidth_node = virXPathNode("./bandwidth", ctxt);
if (bandwidth_node && if (bandwidth_node &&
virNetDevBandwidthParse(&actual->bandwidth, virNetDevBandwidthParse(&actual->bandwidth,
NULL,
bandwidth_node, bandwidth_node,
actual->type == VIR_DOMAIN_NET_TYPE_NETWORK) < 0) actual->type == VIR_DOMAIN_NET_TYPE_NETWORK) < 0)
goto error; goto error;
@ -11619,6 +11620,7 @@ virDomainNetDefParseXML(virDomainXMLOptionPtr xmlopt,
} }
} else if (virXMLNodeNameEqual(cur, "bandwidth")) { } else if (virXMLNodeNameEqual(cur, "bandwidth")) {
if (virNetDevBandwidthParse(&def->bandwidth, if (virNetDevBandwidthParse(&def->bandwidth,
NULL,
cur, cur,
def->type == VIR_DOMAIN_NET_TYPE_NETWORK) < 0) def->type == VIR_DOMAIN_NET_TYPE_NETWORK) < 0)
goto error; goto error;
@ -25016,7 +25018,7 @@ virDomainActualNetDefContentsFormat(virBufferPtr buf,
return -1; return -1;
if (virNetDevVPortProfileFormat(virDomainNetGetActualVirtPortProfile(def), buf) < 0) if (virNetDevVPortProfileFormat(virDomainNetGetActualVirtPortProfile(def), buf) < 0)
return -1; return -1;
if (virNetDevBandwidthFormat(virDomainNetGetActualBandwidth(def), buf) < 0) if (virNetDevBandwidthFormat(virDomainNetGetActualBandwidth(def), 0, buf) < 0)
return -1; return -1;
return 0; return 0;
} }
@ -25393,7 +25395,7 @@ virDomainNetDefFormat(virBufferPtr buf,
return -1; return -1;
if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0) if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0)
return -1; return -1;
if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0) if (virNetDevBandwidthFormat(def->bandwidth, 0, buf) < 0)
return -1; return -1;
/* ONLY for internal status storage - format the ActualNetDef /* ONLY for internal status storage - format the ActualNetDef

View File

@ -99,6 +99,7 @@ virNetDevBandwidthParseRate(xmlNodePtr node, virNetDevBandwidthRatePtr rate)
/** /**
* virNetDevBandwidthParse: * virNetDevBandwidthParse:
* @bandwidth: parsed bandwidth * @bandwidth: parsed bandwidth
* @class_id: parsed class ID
* @node: XML node * @node: XML node
* @allowFloor: whether "floor" setting is supported * @allowFloor: whether "floor" setting is supported
* *
@ -110,6 +111,7 @@ virNetDevBandwidthParseRate(xmlNodePtr node, virNetDevBandwidthRatePtr rate)
*/ */
int int
virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
unsigned int *class_id,
xmlNodePtr node, xmlNodePtr node,
bool allowFloor) bool allowFloor)
{ {
@ -117,6 +119,7 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
virNetDevBandwidthPtr def = NULL; virNetDevBandwidthPtr def = NULL;
xmlNodePtr cur; xmlNodePtr cur;
xmlNodePtr in = NULL, out = NULL; xmlNodePtr in = NULL, out = NULL;
char *class_id_prop = NULL;
if (VIR_ALLOC(def) < 0) if (VIR_ALLOC(def) < 0)
return ret; return ret;
@ -127,6 +130,22 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
goto cleanup; goto cleanup;
} }
class_id_prop = virXMLPropString(node, "classID");
if (class_id_prop) {
if (!class_id) {
virReportError(VIR_ERR_XML_DETAIL, "%s",
_("classID attribute not supported on <bandwidth> "
"in this usage context"));
goto cleanup;
}
if (virStrToLong_ui(class_id_prop, NULL, 10, class_id) < 0) {
virReportError(VIR_ERR_INTERNAL_ERROR,
_("Unable to parse class id '%s'"),
class_id_prop);
goto cleanup;
}
}
cur = node->children; cur = node->children;
while (cur) { while (cur) {
@ -194,6 +213,7 @@ virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
ret = 0; ret = 0;
cleanup: cleanup:
VIR_FREE(class_id_prop);
virNetDevBandwidthFree(def); virNetDevBandwidthFree(def);
return ret; return ret;
} }
@ -231,6 +251,7 @@ virNetDevBandwidthRateFormat(virNetDevBandwidthRatePtr def,
/** /**
* virNetDevBandwidthFormat: * virNetDevBandwidthFormat:
* @def: Data source * @def: Data source
* @class_id: the class ID to format, 0 to skip
* @buf: Buffer to print to * @buf: Buffer to print to
* *
* Formats bandwidth and prepend each line with @indent. * Formats bandwidth and prepend each line with @indent.
@ -239,7 +260,9 @@ virNetDevBandwidthRateFormat(virNetDevBandwidthRatePtr def,
* Returns 0 on success, else -1. * Returns 0 on success, else -1.
*/ */
int int
virNetDevBandwidthFormat(virNetDevBandwidthPtr def, virBufferPtr buf) virNetDevBandwidthFormat(virNetDevBandwidthPtr def,
unsigned int class_id,
virBufferPtr buf)
{ {
int ret = -1; int ret = -1;
@ -251,7 +274,10 @@ virNetDevBandwidthFormat(virNetDevBandwidthPtr def, virBufferPtr buf)
goto cleanup; goto cleanup;
} }
virBufferAddLit(buf, "<bandwidth>\n"); virBufferAddLit(buf, "<bandwidth");
if (class_id)
virBufferAsprintf(buf, " classID='%u'", class_id);
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 2); virBufferAdjustIndent(buf, 2);
if (virNetDevBandwidthRateFormat(def->in, buf, "inbound") < 0 || if (virNetDevBandwidthRateFormat(def->in, buf, "inbound") < 0 ||
virNetDevBandwidthRateFormat(def->out, buf, "outbound") < 0) virNetDevBandwidthRateFormat(def->out, buf, "outbound") < 0)

View File

@ -25,10 +25,12 @@
#include "domain_conf.h" #include "domain_conf.h"
int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth, int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
unsigned int *class_id,
xmlNodePtr node, xmlNodePtr node,
bool allowFloor) bool allowFloor)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK; ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virNetDevBandwidthFormat(virNetDevBandwidthPtr def, int virNetDevBandwidthFormat(virNetDevBandwidthPtr def,
unsigned int class_id,
virBufferPtr buf); virBufferPtr buf);
void virDomainClearNetBandwidth(virDomainObjPtr vm) void virDomainClearNetBandwidth(virDomainObjPtr vm)

View File

@ -1188,7 +1188,7 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def,
bandwidth_node = virXPathNode("./bandwidth", ctxt); bandwidth_node = virXPathNode("./bandwidth", ctxt);
if (bandwidth_node && if (bandwidth_node &&
virNetDevBandwidthParse(&def->bandwidth, bandwidth_node, false) < 0) virNetDevBandwidthParse(&def->bandwidth, NULL, bandwidth_node, false) < 0)
goto cleanup; goto cleanup;
vlanNode = virXPathNode("./vlan", ctxt); vlanNode = virXPathNode("./vlan", ctxt);
@ -1682,7 +1682,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
} }
if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) && if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) &&
virNetDevBandwidthParse(&def->bandwidth, bandwidthNode, false) < 0) virNetDevBandwidthParse(&def->bandwidth, NULL, bandwidthNode, false) < 0)
goto error; goto error;
vlanNode = virXPathNode("./vlan", ctxt); vlanNode = virXPathNode("./vlan", ctxt);
@ -2311,7 +2311,7 @@ virPortGroupDefFormat(virBufferPtr buf,
return -1; return -1;
if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0) if (virNetDevVPortProfileFormat(def->virtPortProfile, buf) < 0)
return -1; return -1;
virNetDevBandwidthFormat(def->bandwidth, buf); virNetDevBandwidthFormat(def->bandwidth, 0, buf);
virBufferAdjustIndent(buf, -2); virBufferAdjustIndent(buf, -2);
virBufferAddLit(buf, "</portgroup>\n"); virBufferAddLit(buf, "</portgroup>\n");
return 0; return 0;
@ -2566,7 +2566,7 @@ virNetworkDefFormatBuf(virBufferPtr buf,
if (virNetDevVlanFormat(&def->vlan, buf) < 0) if (virNetDevVlanFormat(&def->vlan, buf) < 0)
goto error; goto error;
if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0) if (virNetDevBandwidthFormat(def->bandwidth, 0, buf) < 0)
goto error; goto error;
for (i = 0; i < def->nips; i++) { for (i = 0; i < def->nips; i++) {

View File

@ -54,6 +54,7 @@ struct testSetStruct {
goto cleanup; \ goto cleanup; \
\ \
rc = virNetDevBandwidthParse(&(var), \ rc = virNetDevBandwidthParse(&(var), \
NULL, \
ctxt->node, \ ctxt->node, \
true); \ true); \
xmlFreeDoc(doc); \ xmlFreeDoc(doc); \