bandwidth_node = virXPathNode("./bandwidth", ctxt);
if (bandwidth_node &&
- !(actual->bandwidth = virNetDevBandwidthParse(bandwidth_node,
- actual->type)))
+ virNetDevBandwidthParse(&actual->bandwidth,
+ bandwidth_node,
+ actual->type) < 0)
goto error;
vlanNode = virXPathNode("./vlan", ctxt);
goto error;
}
} else if (xmlStrEqual(cur->name, BAD_CAST "bandwidth")) {
- if (!(def->bandwidth = virNetDevBandwidthParse(cur,
- def->type)))
+ if (virNetDevBandwidthParse(&def->bandwidth,
+ cur,
+ def->type) < 0)
goto error;
} else if (xmlStrEqual(cur->name, BAD_CAST "vlan")) {
if (virNetDevVlanParse(cur, ctxt, &def->vlan) < 0)
/**
* virNetDevBandwidthParse:
+ * @bandwidth: parsed bandwidth
* @node: XML node
* @net_type: one of virDomainNetType
*
*
* Returns !NULL on success, NULL on error.
*/
-virNetDevBandwidthPtr
-virNetDevBandwidthParse(xmlNodePtr node,
+int
+virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
+ xmlNodePtr node,
int net_type)
{
+ int ret = -1;
virNetDevBandwidthPtr def = NULL;
xmlNodePtr cur;
xmlNodePtr in = NULL, out = NULL;
if (VIR_ALLOC(def) < 0)
- return NULL;
+ return ret;
if (!node || !xmlStrEqual(node->name, BAD_CAST "bandwidth")) {
virReportError(VIR_ERR_INVALID_ARG, "%s",
_("invalid argument supplied"));
- goto error;
+ goto cleanup;
}
cur = node->children;
virReportError(VIR_ERR_XML_DETAIL, "%s",
_("Only one child <inbound> "
"element allowed"));
- goto error;
+ goto cleanup;
}
in = cur;
} else if (xmlStrEqual(cur->name, BAD_CAST "outbound")) {
virReportError(VIR_ERR_XML_DETAIL, "%s",
_("Only one child <outbound> "
"element allowed"));
- goto error;
+ goto cleanup;
}
out = cur;
}
if (in) {
if (VIR_ALLOC(def->in) < 0)
- goto error;
+ goto cleanup;
if (virNetDevBandwidthParseRate(in, def->in) < 0) {
/* helper reported error for us */
- goto error;
+ goto cleanup;
}
if (def->in->floor && net_type != VIR_DOMAIN_NET_TYPE_NETWORK) {
_("floor attribute is supported only for "
"interfaces of type network"));
}
- goto error;
+ goto cleanup;
}
}
if (out) {
if (VIR_ALLOC(def->out) < 0)
- goto error;
+ goto cleanup;
if (virNetDevBandwidthParseRate(out, def->out) < 0) {
/* helper reported error for us */
- goto error;
+ goto cleanup;
}
if (def->out->floor) {
virReportError(VIR_ERR_CONFIG_UNSUPPORTED, "%s",
_("'floor' attribute allowed "
"only in <inbound> element"));
- goto error;
+ goto cleanup;
}
}
- return def;
+ if (!def->in && !def->out)
+ VIR_FREE(def);
+
+ *bandwidth = def;
+ def = NULL;
+ ret = 0;
- error:
+ cleanup:
virNetDevBandwidthFree(def);
- return NULL;
+ return ret;
}
static int
# include "virxml.h"
# include "domain_conf.h"
-virNetDevBandwidthPtr virNetDevBandwidthParse(xmlNodePtr node,
- int net_type)
- ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+int virNetDevBandwidthParse(virNetDevBandwidthPtr *bandwidth,
+ xmlNodePtr node,
+ int net_type)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2) ATTRIBUTE_RETURN_CHECK;
int virNetDevBandwidthFormat(virNetDevBandwidthPtr def,
virBufferPtr buf)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
bandwidth_node = virXPathNode("./bandwidth", ctxt);
if (bandwidth_node &&
- !(def->bandwidth = virNetDevBandwidthParse(bandwidth_node, -1))) {
+ virNetDevBandwidthParse(&def->bandwidth, bandwidth_node, -1) < 0)
goto cleanup;
- }
vlanNode = virXPathNode("./vlan", ctxt);
if (vlanNode && virNetDevVlanParse(vlanNode, ctxt, &def->vlan) < 0)
/* Parse network domain information */
def->domain = virXPathString("string(./domain[1]/@name)", ctxt);
- if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) != NULL &&
- (def->bandwidth = virNetDevBandwidthParse(bandwidthNode, -1)) == NULL)
+ if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) &&
+ virNetDevBandwidthParse(&def->bandwidth, bandwidthNode, -1) < 0)
goto error;
vlanNode = virXPathNode("./vlan", ctxt);
#define PARSE(xml, var) \
do { \
+ int rc; \
xmlDocPtr doc; \
xmlXPathContextPtr ctxt = NULL; \
\
&ctxt))) \
goto cleanup; \
\
- (var) = virNetDevBandwidthParse(ctxt->node, \
- VIR_DOMAIN_NET_TYPE_NETWORK); \
+ rc = virNetDevBandwidthParse(&(var), \
+ ctxt->node, \
+ VIR_DOMAIN_NET_TYPE_NETWORK); \
xmlFreeDoc(doc); \
xmlXPathFreeContext(ctxt); \
- if (!(var)) \
+ if (rc < 0) \
goto cleanup; \
} while (0)
DO_TEST_SET(NULL, NULL);
- DO_TEST_SET(("<bandwidth/>"),
- (TC " qdisc del dev eth0 root\n"
- TC " qdisc del dev eth0 ingress\n"));
+ DO_TEST_SET("<bandwidth/>", NULL);
DO_TEST_SET(("<bandwidth>"
" <inbound average='1024'/>"