break;
}
- virBandwidthDefFree(def->bandwidth);
+ virNetDevBandwidthFree(def->bandwidth);
VIR_FREE(def);
}
VIR_FREE(def->filter);
virNWFilterHashTableFree(def->filterparams);
- virBandwidthDefFree(def->bandwidth);
+ virNetDevBandwidthFree(def->bandwidth);
VIR_FREE(def);
}
bandwidth_node = virXPathNode("./bandwidth", ctxt);
if (bandwidth_node &&
- !(actual->bandwidth = virBandwidthDefParseNode(bandwidth_node)))
+ !(actual->bandwidth = virNetDevBandwidthParse(bandwidth_node)))
goto error;
*def = actual;
if (virDomainActualNetDefParseXML(cur, ctxt, &actual) < 0)
goto error;
} else if (xmlStrEqual(cur->name, BAD_CAST "bandwidth")) {
- if (!(def->bandwidth = virBandwidthDefParseNode(cur)))
+ if (!(def->bandwidth = virNetDevBandwidthParse(cur)))
goto error;
}
}
}
virBufferAdjustIndent(buf, 8);
- if (virBandwidthDefFormat(buf, def->bandwidth) < 0)
+ if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0)
goto error;
virBufferAdjustIndent(buf, -8);
virDomainNetInterfaceLinkStateTypeToString(def->linkstate));
virBufferAdjustIndent(buf, 6);
- if (virBandwidthDefFormat(buf, def->bandwidth) < 0)
+ if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0)
return -1;
virBufferAdjustIndent(buf, -6);
return iface->data.network.actual->data.direct.virtPortProfile;
}
-virBandwidthPtr
+virNetDevBandwidthPtr
virDomainNetGetActualBandwidth(virDomainNetDefPtr iface)
{
if ((iface->type == VIR_DOMAIN_NET_TYPE_NETWORK) &&
virVirtualPortProfileParamsPtr virtPortProfile;
} direct;
} data;
- virBandwidthPtr bandwidth;
+ virNetDevBandwidthPtr bandwidth;
};
/* Stores the virtual network interface configuration */
virDomainDeviceInfo info;
char *filter;
virNWFilterHashTablePtr filterparams;
- virBandwidthPtr bandwidth;
+ virNetDevBandwidthPtr bandwidth;
int linkstate;
};
int virDomainNetGetActualDirectMode(virDomainNetDefPtr iface);
virVirtualPortProfileParamsPtr
virDomainNetGetActualDirectVirtPortProfile(virDomainNetDefPtr iface);
-virBandwidthPtr
+virNetDevBandwidthPtr
virDomainNetGetActualBandwidth(virDomainNetDefPtr iface);
int virDomainControllerInsert(virDomainDefPtr def,
{
VIR_FREE(def->name);
VIR_FREE(def->virtPortProfile);
- virBandwidthDefFree(def->bandwidth);
+ virNetDevBandwidthFree(def->bandwidth);
def->bandwidth = NULL;
}
VIR_FREE(def->virtPortProfile);
- virBandwidthDefFree(def->bandwidth);
+ virNetDevBandwidthFree(def->bandwidth);
VIR_FREE(def);
}
bandwidth_node = virXPathNode("./bandwidth", ctxt);
if (bandwidth_node &&
- !(def->bandwidth = virBandwidthDefParseNode(bandwidth_node))) {
+ !(def->bandwidth = virNetDevBandwidthParse(bandwidth_node))) {
goto error;
}
def->domain = virXPathString("string(./domain[1]/@name)", ctxt);
if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) != NULL &&
- (def->bandwidth = virBandwidthDefParseNode(bandwidthNode)) == NULL)
+ (def->bandwidth = virNetDevBandwidthParse(bandwidthNode)) == NULL)
goto error;
/* Parse bridge information */
virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 4);
virVirtualPortProfileFormat(buf, def->virtPortProfile);
- virBandwidthDefFormat(buf, def->bandwidth);
+ virNetDevBandwidthFormat(def->bandwidth, buf);
virBufferAdjustIndent(buf, -4);
virBufferAddLit(buf, " </portgroup>\n");
}
goto error;
virBufferAdjustIndent(&buf, 2);
- if (virBandwidthDefFormat(&buf, def->bandwidth) < 0)
+ if (virNetDevBandwidthFormat(def->bandwidth, &buf) < 0)
goto error;
virBufferAdjustIndent(&buf, -2);
char *name;
bool isDefault;
virVirtualPortProfileParamsPtr virtPortProfile;
- virBandwidthPtr bandwidth;
+ virNetDevBandwidthPtr bandwidth;
};
typedef struct _virNetworkDef virNetworkDef;
size_t nPortGroups;
virPortGroupDefPtr portGroups;
- virBandwidthPtr bandwidth;
+ virNetDevBandwidthPtr bandwidth;
};
typedef struct _virNetworkObj virNetworkObj;
# network.h
-virBandwidthCopy;
-virBandwidthDefFormat;
-virBandwidthDefFree;
-virBandwidthDefParseNode;
-virBandwidthDisable;
-virBandwidthEnable;
-virBandwidthEqual;
+virNetDevBandwidthClear;
+virNetDevBandwidthCopy;
+virNetDevBandwidthEqual;
+virNetDevBandwidthFormat;
+virNetDevBandwidthFree;
+virNetDevBandwidthParse;
+virNetDevBandwidthSet;
virSocketAddrBroadcast;
virSocketAddrBroadcastByPrefix;
virSocketAddrCheckNetmask;
if (vethInterfaceUpOrDown(parentVeth, 1) < 0)
goto error_exit;
- if (virBandwidthEnable(virDomainNetGetActualBandwidth(def->nets[i]),
- def->nets[i]->ifname) < 0) {
+ if (virNetDevBandwidthSet(def->nets[i]->ifname,
+ virDomainNetGetActualBandwidth(def->nets[i])) < 0) {
lxcError(VIR_ERR_INTERNAL_ERROR,
_("cannot set bandwidth limits on %s"),
def->nets[i]->ifname);
if (v6present && networkStartRadvd(network) < 0)
goto err4;
- if (virBandwidthEnable(network->def->bandwidth, network->def->bridge) < 0) {
+ if (virNetDevBandwidthSet(network->def->bridge, network->def->bandwidth) < 0) {
networkReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot set bandwidth limits on %s"),
network->def->bridge);
return 0;
err5:
- if (virBandwidthDisable(network->def->bridge, true) < 0) {
- VIR_WARN("Failed to disable QoS on %s",
- network->def->bridge);
- }
+ ignore_value(virNetDevBandwidthClear(network->def->bridge));
err4:
if (!save_err)
static int networkShutdownNetworkVirtual(struct network_driver *driver,
virNetworkObjPtr network)
{
- if (virBandwidthDisable(network->def->bridge, true) < 0) {
- VIR_WARN("Failed to disable QoS on %s",
- network->def->name);
- }
+ ignore_value(virNetDevBandwidthClear(network->def->bridge));
if (network->radvdPid > 0) {
char *radvdpidbase;
goto cleanup;
}
- if (virBandwidthCopy(&iface->data.network.actual->bandwidth,
- portgroup->bandwidth) < 0) {
+ if (virNetDevBandwidthCopy(&iface->data.network.actual->bandwidth,
+ portgroup->bandwidth) < 0)
goto cleanup;
- }
}
if ((netdef->forwardType == VIR_NETWORK_FORWARD_NONE) ||
}
if (tapfd >= 0 &&
- virBandwidthEnable(virDomainNetGetActualBandwidth(net),
- net->ifname) < 0) {
+ virNetDevBandwidthSet(net->ifname,
+ virDomainNetGetActualBandwidth(net)) < 0) {
qemuReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot set bandwidth limits on %s"),
net->ifname);
char **res_ifname,
enum virVMOperationType vmOp,
char *stateDir,
- virBandwidthPtr bandwidth)
+ virNetDevBandwidthPtr bandwidth)
{
const char *type = "macvtap";
int c, rc;
} else
goto disassociate_exit;
- if (virBandwidthEnable(bandwidth, cr_ifname) < 0) {
+ if (virNetDevBandwidthSet(cr_ifname, bandwidth) < 0) {
macvtapError(VIR_ERR_INTERNAL_ERROR,
_("cannot set bandwidth limits on %s"),
cr_ifname);
char **res_ifname,
enum virVMOperationType vmop,
char *stateDir,
- virBandwidthPtr bandwidth);
+ virNetDevBandwidthPtr bandwidth);
void delMacvtap(const char *ifname,
const unsigned char *macaddress,
#include "util.h"
#include "virterror_internal.h"
#include "command.h"
+#include "ignore-value.h"
#define VIR_FROM_THIS VIR_FROM_NONE
#define virSocketError(code, ...) \
}
static int
-virBandwidthParseChildDefNode(xmlNodePtr node, virRatePtr rate)
+virNetDevBandwidthParseRate(xmlNodePtr node, virNetDevBandwidthRatePtr rate)
{
int ret = -1;
char *average = NULL;
}
/**
- * virBandwidthDefParseNode:
+ * virNetDevBandwidthParse:
* @node: XML node
*
* Parse bandwidth XML and return pointer to structure
*
* Returns !NULL on success, NULL on error.
*/
-virBandwidthPtr
-virBandwidthDefParseNode(xmlNodePtr node)
+virNetDevBandwidthPtr
+virNetDevBandwidthParse(xmlNodePtr node)
{
- virBandwidthPtr def = NULL;
+ virNetDevBandwidthPtr def = NULL;
xmlNodePtr cur = node->children;
xmlNodePtr in = NULL, out = NULL;
goto error;
}
- if (virBandwidthParseChildDefNode(in, def->in) < 0) {
+ if (virNetDevBandwidthParseRate(in, def->in) < 0) {
/* helper reported error for us */
goto error;
}
goto error;
}
- if (virBandwidthParseChildDefNode(out, def->out) < 0) {
+ if (virNetDevBandwidthParseRate(out, def->out) < 0) {
/* helper reported error for us */
goto error;
}
return def;
error:
- virBandwidthDefFree(def);
+ virNetDevBandwidthFree(def);
return NULL;
}
void
-virBandwidthDefFree(virBandwidthPtr def)
+virNetDevBandwidthFree(virNetDevBandwidthPtr def)
{
if (!def)
return;
}
static int
-virBandwidthChildDefFormat(virBufferPtr buf,
- virRatePtr def,
- const char *elem_name)
+virNetDevBandwidthRateFormat(virNetDevBandwidthRatePtr def,
+ virBufferPtr buf,
+ const char *elem_name)
{
if (!buf || !elem_name)
return -1;
}
/**
- * virBandwidthDefFormat:
- * @buf: Buffer to print to
+ * virNetDevBandwidthDefFormat:
* @def: Data source
+ * @buf: Buffer to print to
*
* Formats bandwidth and prepend each line with @indent.
* @buf may use auto-indentation.
* Returns 0 on success, else -1.
*/
int
-virBandwidthDefFormat(virBufferPtr buf,
- virBandwidthPtr def)
+virNetDevBandwidthFormat(virNetDevBandwidthPtr def, virBufferPtr buf)
{
int ret = -1;
}
virBufferAddLit(buf, "<bandwidth>\n");
- if (virBandwidthChildDefFormat(buf, def->in, "inbound") < 0 ||
- virBandwidthChildDefFormat(buf, def->out, "outbound") < 0)
+ if (virNetDevBandwidthRateFormat(def->in, buf, "inbound") < 0 ||
+ virNetDevBandwidthRateFormat(def->out, buf, "outbound") < 0)
goto cleanup;
virBufferAddLit(buf, "</bandwidth>\n");
}
/**
- * virBandwidthEnable:
- * @bandwidth: rates to set
- * @iface: on which interface
+ * virNetDevBandwidthSet:
+ * @ifname: on which interface
+ * @bandwidth: rates to set (may be NULL)
*
* This function enables QoS on specified interface
* and set given traffic limits for both, incoming
* Return 0 on success, -1 otherwise.
*/
int
-virBandwidthEnable(virBandwidthPtr bandwidth,
- const char *iface)
+virNetDevBandwidthSet(const char *ifname,
+ virNetDevBandwidthPtr bandwidth)
{
int ret = -1;
virCommandPtr cmd = NULL;
char *peak = NULL;
char *burst = NULL;
- if (!iface)
- return -1;
-
if (!bandwidth) {
/* nothing to be enabled */
ret = 0;
goto cleanup;
}
- if (virBandwidthDisable(iface, true) < 0)
- goto cleanup;
+ ignore_value(virNetDevBandwidthClear(ifname));
if (bandwidth->in) {
if (virAsprintf(&average, "%llukbps", bandwidth->in->average) < 0)
goto cleanup;
cmd = virCommandNew(TC);
- virCommandAddArgList(cmd, "qdisc", "add", "dev", iface, "root",
+ virCommandAddArgList(cmd, "qdisc", "add", "dev", ifname, "root",
"handle", "1:", "htb", "default", "1", NULL);
if (virCommandRun(cmd, NULL) < 0)
goto cleanup;
virCommandFree(cmd);
cmd = virCommandNew(TC);
- virCommandAddArgList(cmd,"class", "add", "dev", iface, "parent",
+ virCommandAddArgList(cmd,"class", "add", "dev", ifname, "parent",
"1:", "classid", "1:1", "htb", NULL);
virCommandAddArgList(cmd, "rate", average, NULL);
virCommandFree(cmd);
cmd = virCommandNew(TC);
- virCommandAddArgList(cmd,"filter", "add", "dev", iface, "parent",
+ virCommandAddArgList(cmd,"filter", "add", "dev", ifname, "parent",
"1:0", "protocol", "ip", "handle", "1", "fw",
"flowid", "1", NULL);
virCommandFree(cmd);
cmd = virCommandNew(TC);
- virCommandAddArgList(cmd, "qdisc", "add", "dev", iface,
+ virCommandAddArgList(cmd, "qdisc", "add", "dev", ifname,
"ingress", NULL);
if (virCommandRun(cmd, NULL) < 0)
virCommandFree(cmd);
cmd = virCommandNew(TC);
- virCommandAddArgList(cmd, "filter", "add", "dev", iface, "parent",
+ virCommandAddArgList(cmd, "filter", "add", "dev", ifname, "parent",
"ffff:", "protocol", "ip", "u32", "match", "ip",
"src", "0.0.0.0/0", "police", "rate", average,
"burst", burst, "mtu", burst, "drop", "flowid",
}
/**
- * virBandwidthDisable:
- * @iface: on which interface
- * @may_fail: should be unsuccessful disable considered fatal?
+ * virNetDevBandwidthClear:
+ * @ifname: on which interface
*
* This function tries to disable QoS on specified interface
* by deleting root and ingress qdisc. However, this may fail
* Return 0 on success, -1 otherwise.
*/
int
-virBandwidthDisable(const char *iface,
- bool may_fail)
+virNetDevBandwidthClear(const char *ifname)
{
- int ret = -1;
- int status;
+ int ret = 0;
virCommandPtr cmd = NULL;
- if (!iface)
- return -1;
-
cmd = virCommandNew(TC);
- virCommandAddArgList(cmd, "qdisc", "del", "dev", iface, "root", NULL);
+ virCommandAddArgList(cmd, "qdisc", "del", "dev", ifname, "root", NULL);
- if ((virCommandRun(cmd, &status) < 0) ||
- (!may_fail && status))
- goto cleanup;
+ if (virCommandRun(cmd, NULL) < 0)
+ ret = -1;
virCommandFree(cmd);
cmd = virCommandNew(TC);
- virCommandAddArgList(cmd, "qdisc", "del", "dev", iface, "ingress", NULL);
-
- if ((virCommandRun(cmd, &status) < 0) ||
- (!may_fail && status))
- goto cleanup;
-
- ret = 0;
+ virCommandAddArgList(cmd, "qdisc", "del", "dev", ifname, "ingress", NULL);
-cleanup:
+ if (virCommandRun(cmd, NULL) < 0)
+ ret = -1;
virCommandFree(cmd);
+
return ret;
}
/*
- * virBandwidthCopy:
+ * virNetDevBandwidthCopy:
* @dest: destination
- * @src: source
+ * @src: source (may be NULL)
*
* Returns -1 on OOM error (which gets reported),
* 0 otherwise.
*/
int
-virBandwidthCopy(virBandwidthPtr *dest,
- const virBandwidthPtr src)
+virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
+ const virNetDevBandwidthPtr src)
{
int ret = -1;
- if (!dest) {
- virSocketError(VIR_ERR_INVALID_ARG, "%s",
- _("invalid argument supplied"));
- return -1;
- }
-
*dest = NULL;
if (!src) {
/* nothing to be copied */
cleanup:
if (ret < 0) {
- virBandwidthDefFree(*dest);
+ virNetDevBandwidthFree(*dest);
*dest = NULL;
}
return ret;
}
bool
-virBandwidthEqual(virBandwidthPtr a,
- virBandwidthPtr b)
+virNetDevBandwidthEqual(virNetDevBandwidthPtr a,
+ virNetDevBandwidthPtr b)
{
if (!a && !b)
return true;
typedef virSocketAddr *virSocketAddrPtr;
-typedef struct {
+typedef struct _virNetDevBandwidthRate virNetDevBandwidthRate;
+typedef virNetDevBandwidthRate *virNetDevBandwidthRatePtr;
+struct _virNetDevBandwidthRate {
unsigned long long average; /* kbytes/s */
unsigned long long peak; /* kbytes/s */
unsigned long long burst; /* kbytes */
-} virRate;
-
-typedef virRate *virRatePtr;
-
-typedef struct {
- virRatePtr in, out;
-} virBandwidth;
+};
-typedef virBandwidth *virBandwidthPtr;
+typedef struct _virNetDevBandwidth virNetDevBandwidth;
+typedef virNetDevBandwidth *virNetDevBandwidthPtr;
+struct _virNetDevBandwidth {
+ virNetDevBandwidthRatePtr in, out;
+};
int virSocketAddrParse(virSocketAddrPtr addr,
const char *val,
bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a,
virVirtualPortProfileParamsPtr b);
-virBandwidthPtr virBandwidthDefParseNode(xmlNodePtr node);
-void virBandwidthDefFree(virBandwidthPtr def);
-int virBandwidthDefFormat(virBufferPtr buf,
- virBandwidthPtr def);
-
-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);
+virNetDevBandwidthPtr virNetDevBandwidthParse(xmlNodePtr node)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+void virNetDevBandwidthFree(virNetDevBandwidthPtr def);
+int virNetDevBandwidthFormat(virNetDevBandwidthPtr def,
+ virBufferPtr buf)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
+
+int virNetDevBandwidthSet(const char *ifname, virNetDevBandwidthPtr bandwidth)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+int virNetDevBandwidthClear(const char *ifname)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+int virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest, const virNetDevBandwidthPtr src)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+
+bool virNetDevBandwidthEqual(virNetDevBandwidthPtr a, virNetDevBandwidthPtr b);
#endif /* __VIR_NETWORK_H__ */
/* parse inbound and outbound which are in the format of
* 'average,peak,burst', in which peak and burst are optional,
* thus 'average,,burst' and 'average,peak' are also legal. */
-static int parseRateStr(const char *rateStr, virRatePtr rate)
+static int parseRateStr(const char *rateStr, virNetDevBandwidthRatePtr rate)
{
const char *average = NULL;
char *peak = NULL, *burst = NULL;
const char *mac = NULL, *target = NULL, *script = NULL,
*type = NULL, *source = NULL, *model = NULL,
*inboundStr = NULL, *outboundStr = NULL;
- virRate inbound, outbound;
+ virNetDevBandwidthRate inbound, outbound;
int typ;
int ret;
bool functionReturn = false;