mirror of
https://gitlab.com/libvirt/libvirt.git
synced 2024-10-05 22:05:47 +00:00
virNetDevBandwidthParse: Use virXMLNodeGetSubelement instead of looped parser
Extract the 'inbound'/'outbound' subelements using virXMLNodeGetSubelement to simplify the code. Signed-off-by: Peter Krempa <pkrempa@redhat.com> Reviewed-by: Ján Tomko <jtomko@redhat.com>
This commit is contained in:
parent
036e677886
commit
355582e3df
@ -91,8 +91,8 @@ virNetDevBandwidthParse(virNetDevBandwidth **bandwidth,
|
|||||||
bool allowFloor)
|
bool allowFloor)
|
||||||
{
|
{
|
||||||
g_autoptr(virNetDevBandwidth) def = NULL;
|
g_autoptr(virNetDevBandwidth) def = NULL;
|
||||||
xmlNodePtr cur;
|
xmlNodePtr in;
|
||||||
xmlNodePtr in = NULL, out = NULL;
|
xmlNodePtr out;
|
||||||
unsigned int class_id_value;
|
unsigned int class_id_value;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
@ -113,40 +113,14 @@ virNetDevBandwidthParse(virNetDevBandwidth **bandwidth,
|
|||||||
*class_id = class_id_value;
|
*class_id = class_id_value;
|
||||||
}
|
}
|
||||||
|
|
||||||
cur = node->children;
|
if ((in = virXMLNodeGetSubelement(node, "inbound"))) {
|
||||||
|
|
||||||
while (cur) {
|
|
||||||
if (cur->type == XML_ELEMENT_NODE) {
|
|
||||||
if (virXMLNodeNameEqual(cur, "inbound")) {
|
|
||||||
if (in) {
|
|
||||||
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
|
||||||
_("Only one child <inbound> "
|
|
||||||
"element allowed"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
in = cur;
|
|
||||||
} else if (virXMLNodeNameEqual(cur, "outbound")) {
|
|
||||||
if (out) {
|
|
||||||
virReportError(VIR_ERR_XML_DETAIL, "%s",
|
|
||||||
_("Only one child <outbound> "
|
|
||||||
"element allowed"));
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
out = cur;
|
|
||||||
}
|
|
||||||
/* Silently ignore unknown elements */
|
|
||||||
}
|
|
||||||
cur = cur->next;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (in) {
|
|
||||||
def->in = g_new0(virNetDevBandwidthRate, 1);
|
def->in = g_new0(virNetDevBandwidthRate, 1);
|
||||||
|
|
||||||
if (virNetDevBandwidthParseRate(in, def->in, allowFloor) < 0)
|
if (virNetDevBandwidthParseRate(in, def->in, allowFloor) < 0)
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (out) {
|
if ((out = virXMLNodeGetSubelement(node, "outbound"))) {
|
||||||
def->out = g_new0(virNetDevBandwidthRate, 1);
|
def->out = g_new0(virNetDevBandwidthRate, 1);
|
||||||
|
|
||||||
/* floor is not allowed for <outbound> */
|
/* floor is not allowed for <outbound> */
|
||||||
|
Loading…
Reference in New Issue
Block a user