Adjust naming of network device bandwidth management APIs

Rename virBandwidth to virNetDevBandwidth, and virRate to
virNetDevBandwidthRate.

* src/util/network.c, src/util/network.h: Rename bandwidth
  structs and APIs
* src/conf/domain_conf.c, src/conf/domain_conf.h,
  src/conf/network_conf.c, src/conf/network_conf.h,
  src/lxc/lxc_driver.c, src/network/bridge_driver.c,
  src/qemu/qemu_command.c, src/util/macvtap.c,
  src/util/macvtap.h, tools/virsh.c: Update for API changes.
This commit is contained in:
Daniel P. Berrange 2011-11-02 14:29:05 +00:00
parent 4c544e6c61
commit 0eee075dc7
13 changed files with 108 additions and 131 deletions

View File

@ -862,7 +862,7 @@ virDomainActualNetDefFree(virDomainActualNetDefPtr def)
break; break;
} }
virBandwidthDefFree(def->bandwidth); virNetDevBandwidthFree(def->bandwidth);
VIR_FREE(def); VIR_FREE(def);
} }
@ -921,7 +921,7 @@ void virDomainNetDefFree(virDomainNetDefPtr def)
VIR_FREE(def->filter); VIR_FREE(def->filter);
virNWFilterHashTableFree(def->filterparams); virNWFilterHashTableFree(def->filterparams);
virBandwidthDefFree(def->bandwidth); virNetDevBandwidthFree(def->bandwidth);
VIR_FREE(def); VIR_FREE(def);
} }
@ -3120,7 +3120,7 @@ virDomainActualNetDefParseXML(xmlNodePtr node,
bandwidth_node = virXPathNode("./bandwidth", ctxt); bandwidth_node = virXPathNode("./bandwidth", ctxt);
if (bandwidth_node && if (bandwidth_node &&
!(actual->bandwidth = virBandwidthDefParseNode(bandwidth_node))) !(actual->bandwidth = virNetDevBandwidthParse(bandwidth_node)))
goto error; goto error;
*def = actual; *def = actual;
@ -3278,7 +3278,7 @@ virDomainNetDefParseXML(virCapsPtr caps,
if (virDomainActualNetDefParseXML(cur, ctxt, &actual) < 0) if (virDomainActualNetDefParseXML(cur, ctxt, &actual) < 0)
goto error; goto error;
} else if (xmlStrEqual(cur->name, BAD_CAST "bandwidth")) { } else if (xmlStrEqual(cur->name, BAD_CAST "bandwidth")) {
if (!(def->bandwidth = virBandwidthDefParseNode(cur))) if (!(def->bandwidth = virNetDevBandwidthParse(cur)))
goto error; goto error;
} }
} }
@ -9730,7 +9730,7 @@ virDomainActualNetDefFormat(virBufferPtr buf,
} }
virBufferAdjustIndent(buf, 8); virBufferAdjustIndent(buf, 8);
if (virBandwidthDefFormat(buf, def->bandwidth) < 0) if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0)
goto error; goto error;
virBufferAdjustIndent(buf, -8); virBufferAdjustIndent(buf, -8);
@ -9883,7 +9883,7 @@ virDomainNetDefFormat(virBufferPtr buf,
virDomainNetInterfaceLinkStateTypeToString(def->linkstate)); virDomainNetInterfaceLinkStateTypeToString(def->linkstate));
virBufferAdjustIndent(buf, 6); virBufferAdjustIndent(buf, 6);
if (virBandwidthDefFormat(buf, def->bandwidth) < 0) if (virNetDevBandwidthFormat(def->bandwidth, buf) < 0)
return -1; return -1;
virBufferAdjustIndent(buf, -6); virBufferAdjustIndent(buf, -6);
@ -13091,7 +13091,7 @@ virDomainNetGetActualDirectVirtPortProfile(virDomainNetDefPtr iface)
return iface->data.network.actual->data.direct.virtPortProfile; return iface->data.network.actual->data.direct.virtPortProfile;
} }
virBandwidthPtr virNetDevBandwidthPtr
virDomainNetGetActualBandwidth(virDomainNetDefPtr iface) virDomainNetGetActualBandwidth(virDomainNetDefPtr iface)
{ {
if ((iface->type == VIR_DOMAIN_NET_TYPE_NETWORK) && if ((iface->type == VIR_DOMAIN_NET_TYPE_NETWORK) &&

View File

@ -511,7 +511,7 @@ struct _virDomainActualNetDef {
virVirtualPortProfileParamsPtr virtPortProfile; virVirtualPortProfileParamsPtr virtPortProfile;
} direct; } direct;
} data; } data;
virBandwidthPtr bandwidth; virNetDevBandwidthPtr bandwidth;
}; };
/* Stores the virtual network interface configuration */ /* Stores the virtual network interface configuration */
@ -576,7 +576,7 @@ struct _virDomainNetDef {
virDomainDeviceInfo info; virDomainDeviceInfo info;
char *filter; char *filter;
virNWFilterHashTablePtr filterparams; virNWFilterHashTablePtr filterparams;
virBandwidthPtr bandwidth; virNetDevBandwidthPtr bandwidth;
int linkstate; int linkstate;
}; };
@ -1797,7 +1797,7 @@ char *virDomainNetGetActualDirectDev(virDomainNetDefPtr iface);
int virDomainNetGetActualDirectMode(virDomainNetDefPtr iface); int virDomainNetGetActualDirectMode(virDomainNetDefPtr iface);
virVirtualPortProfileParamsPtr virVirtualPortProfileParamsPtr
virDomainNetGetActualDirectVirtPortProfile(virDomainNetDefPtr iface); virDomainNetGetActualDirectVirtPortProfile(virDomainNetDefPtr iface);
virBandwidthPtr virNetDevBandwidthPtr
virDomainNetGetActualBandwidth(virDomainNetDefPtr iface); virDomainNetGetActualBandwidth(virDomainNetDefPtr iface);
int virDomainControllerInsert(virDomainDefPtr def, int virDomainControllerInsert(virDomainDefPtr def,

View File

@ -92,7 +92,7 @@ virPortGroupDefClear(virPortGroupDefPtr def)
{ {
VIR_FREE(def->name); VIR_FREE(def->name);
VIR_FREE(def->virtPortProfile); VIR_FREE(def->virtPortProfile);
virBandwidthDefFree(def->bandwidth); virNetDevBandwidthFree(def->bandwidth);
def->bandwidth = NULL; def->bandwidth = NULL;
} }
@ -171,7 +171,7 @@ void virNetworkDefFree(virNetworkDefPtr def)
VIR_FREE(def->virtPortProfile); VIR_FREE(def->virtPortProfile);
virBandwidthDefFree(def->bandwidth); virNetDevBandwidthFree(def->bandwidth);
VIR_FREE(def); VIR_FREE(def);
} }
@ -797,7 +797,7 @@ virNetworkPortGroupParseXML(virPortGroupDefPtr def,
bandwidth_node = virXPathNode("./bandwidth", ctxt); bandwidth_node = virXPathNode("./bandwidth", ctxt);
if (bandwidth_node && if (bandwidth_node &&
!(def->bandwidth = virBandwidthDefParseNode(bandwidth_node))) { !(def->bandwidth = virNetDevBandwidthParse(bandwidth_node))) {
goto error; goto error;
} }
@ -863,7 +863,7 @@ virNetworkDefParseXML(xmlXPathContextPtr ctxt)
def->domain = virXPathString("string(./domain[1]/@name)", ctxt); def->domain = virXPathString("string(./domain[1]/@name)", ctxt);
if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) != NULL && if ((bandwidthNode = virXPathNode("./bandwidth", ctxt)) != NULL &&
(def->bandwidth = virBandwidthDefParseNode(bandwidthNode)) == NULL) (def->bandwidth = virNetDevBandwidthParse(bandwidthNode)) == NULL)
goto error; goto error;
/* Parse bridge information */ /* Parse bridge information */
@ -1269,7 +1269,7 @@ virPortGroupDefFormat(virBufferPtr buf,
virBufferAddLit(buf, ">\n"); virBufferAddLit(buf, ">\n");
virBufferAdjustIndent(buf, 4); virBufferAdjustIndent(buf, 4);
virVirtualPortProfileFormat(buf, def->virtPortProfile); virVirtualPortProfileFormat(buf, def->virtPortProfile);
virBandwidthDefFormat(buf, def->bandwidth); virNetDevBandwidthFormat(def->bandwidth, buf);
virBufferAdjustIndent(buf, -4); virBufferAdjustIndent(buf, -4);
virBufferAddLit(buf, " </portgroup>\n"); virBufferAddLit(buf, " </portgroup>\n");
} }
@ -1344,7 +1344,7 @@ char *virNetworkDefFormat(const virNetworkDefPtr def)
goto error; goto error;
virBufferAdjustIndent(&buf, 2); virBufferAdjustIndent(&buf, 2);
if (virBandwidthDefFormat(&buf, def->bandwidth) < 0) if (virNetDevBandwidthFormat(def->bandwidth, &buf) < 0)
goto error; goto error;
virBufferAdjustIndent(&buf, -2); virBufferAdjustIndent(&buf, -2);

View File

@ -123,7 +123,7 @@ struct _virPortGroupDef {
char *name; char *name;
bool isDefault; bool isDefault;
virVirtualPortProfileParamsPtr virtPortProfile; virVirtualPortProfileParamsPtr virtPortProfile;
virBandwidthPtr bandwidth; virNetDevBandwidthPtr bandwidth;
}; };
typedef struct _virNetworkDef virNetworkDef; typedef struct _virNetworkDef virNetworkDef;
@ -155,7 +155,7 @@ struct _virNetworkDef {
size_t nPortGroups; size_t nPortGroups;
virPortGroupDefPtr portGroups; virPortGroupDefPtr portGroups;
virBandwidthPtr bandwidth; virNetDevBandwidthPtr bandwidth;
}; };
typedef struct _virNetworkObj virNetworkObj; typedef struct _virNetworkObj virNetworkObj;

View File

@ -764,13 +764,13 @@ nlComm;
# network.h # network.h
virBandwidthCopy; virNetDevBandwidthClear;
virBandwidthDefFormat; virNetDevBandwidthCopy;
virBandwidthDefFree; virNetDevBandwidthEqual;
virBandwidthDefParseNode; virNetDevBandwidthFormat;
virBandwidthDisable; virNetDevBandwidthFree;
virBandwidthEnable; virNetDevBandwidthParse;
virBandwidthEqual; virNetDevBandwidthSet;
virSocketAddrBroadcast; virSocketAddrBroadcast;
virSocketAddrBroadcastByPrefix; virSocketAddrBroadcastByPrefix;
virSocketAddrCheckNetmask; virSocketAddrCheckNetmask;

View File

@ -1275,8 +1275,8 @@ static int lxcSetupInterfaces(virConnectPtr conn,
if (vethInterfaceUpOrDown(parentVeth, 1) < 0) if (vethInterfaceUpOrDown(parentVeth, 1) < 0)
goto error_exit; goto error_exit;
if (virBandwidthEnable(virDomainNetGetActualBandwidth(def->nets[i]), if (virNetDevBandwidthSet(def->nets[i]->ifname,
def->nets[i]->ifname) < 0) { virDomainNetGetActualBandwidth(def->nets[i])) < 0) {
lxcError(VIR_ERR_INTERNAL_ERROR, lxcError(VIR_ERR_INTERNAL_ERROR,
_("cannot set bandwidth limits on %s"), _("cannot set bandwidth limits on %s"),
def->nets[i]->ifname); def->nets[i]->ifname);

View File

@ -1778,7 +1778,7 @@ networkStartNetworkVirtual(struct network_driver *driver,
if (v6present && networkStartRadvd(network) < 0) if (v6present && networkStartRadvd(network) < 0)
goto err4; 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, networkReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot set bandwidth limits on %s"), _("cannot set bandwidth limits on %s"),
network->def->bridge); network->def->bridge);
@ -1790,10 +1790,7 @@ networkStartNetworkVirtual(struct network_driver *driver,
return 0; return 0;
err5: err5:
if (virBandwidthDisable(network->def->bridge, true) < 0) { ignore_value(virNetDevBandwidthClear(network->def->bridge));
VIR_WARN("Failed to disable QoS on %s",
network->def->bridge);
}
err4: err4:
if (!save_err) if (!save_err)
@ -1836,10 +1833,7 @@ networkStartNetworkVirtual(struct network_driver *driver,
static int networkShutdownNetworkVirtual(struct network_driver *driver, static int networkShutdownNetworkVirtual(struct network_driver *driver,
virNetworkObjPtr network) virNetworkObjPtr network)
{ {
if (virBandwidthDisable(network->def->bridge, true) < 0) { ignore_value(virNetDevBandwidthClear(network->def->bridge));
VIR_WARN("Failed to disable QoS on %s",
network->def->name);
}
if (network->radvdPid > 0) { if (network->radvdPid > 0) {
char *radvdpidbase; char *radvdpidbase;
@ -2733,10 +2727,9 @@ networkAllocateActualDevice(virDomainNetDefPtr iface)
goto cleanup; goto cleanup;
} }
if (virBandwidthCopy(&iface->data.network.actual->bandwidth, if (virNetDevBandwidthCopy(&iface->data.network.actual->bandwidth,
portgroup->bandwidth) < 0) { portgroup->bandwidth) < 0)
goto cleanup; goto cleanup;
}
} }
if ((netdef->forwardType == VIR_NETWORK_FORWARD_NONE) || if ((netdef->forwardType == VIR_NETWORK_FORWARD_NONE) ||

View File

@ -298,8 +298,8 @@ qemuNetworkIfaceConnect(virDomainDefPtr def,
} }
if (tapfd >= 0 && if (tapfd >= 0 &&
virBandwidthEnable(virDomainNetGetActualBandwidth(net), virNetDevBandwidthSet(net->ifname,
net->ifname) < 0) { virDomainNetGetActualBandwidth(net)) < 0) {
qemuReportError(VIR_ERR_INTERNAL_ERROR, qemuReportError(VIR_ERR_INTERNAL_ERROR,
_("cannot set bandwidth limits on %s"), _("cannot set bandwidth limits on %s"),
net->ifname); net->ifname);

View File

@ -271,7 +271,7 @@ openMacvtapTap(const char *tgifname,
char **res_ifname, char **res_ifname,
enum virVMOperationType vmOp, enum virVMOperationType vmOp,
char *stateDir, char *stateDir,
virBandwidthPtr bandwidth) virNetDevBandwidthPtr bandwidth)
{ {
const char *type = "macvtap"; const char *type = "macvtap";
int c, rc; int c, rc;
@ -364,7 +364,7 @@ create_name:
} else } else
goto disassociate_exit; goto disassociate_exit;
if (virBandwidthEnable(bandwidth, cr_ifname) < 0) { if (virNetDevBandwidthSet(cr_ifname, bandwidth) < 0) {
macvtapError(VIR_ERR_INTERNAL_ERROR, macvtapError(VIR_ERR_INTERNAL_ERROR,
_("cannot set bandwidth limits on %s"), _("cannot set bandwidth limits on %s"),
cr_ifname); cr_ifname);

View File

@ -63,7 +63,7 @@ int openMacvtapTap(const char *ifname,
char **res_ifname, char **res_ifname,
enum virVMOperationType vmop, enum virVMOperationType vmop,
char *stateDir, char *stateDir,
virBandwidthPtr bandwidth); virNetDevBandwidthPtr bandwidth);
void delMacvtap(const char *ifname, void delMacvtap(const char *ifname,
const unsigned char *macaddress, const unsigned char *macaddress,

View File

@ -17,6 +17,7 @@
#include "util.h" #include "util.h"
#include "virterror_internal.h" #include "virterror_internal.h"
#include "command.h" #include "command.h"
#include "ignore-value.h"
#define VIR_FROM_THIS VIR_FROM_NONE #define VIR_FROM_THIS VIR_FROM_NONE
#define virSocketError(code, ...) \ #define virSocketError(code, ...) \
@ -918,7 +919,7 @@ virVirtualPortProfileFormat(virBufferPtr buf,
} }
static int static int
virBandwidthParseChildDefNode(xmlNodePtr node, virRatePtr rate) virNetDevBandwidthParseRate(xmlNodePtr node, virNetDevBandwidthRatePtr rate)
{ {
int ret = -1; int ret = -1;
char *average = NULL; char *average = NULL;
@ -973,17 +974,17 @@ cleanup:
} }
/** /**
* virBandwidthDefParseNode: * virNetDevBandwidthParse:
* @node: XML node * @node: XML node
* *
* Parse bandwidth XML and return pointer to structure * Parse bandwidth XML and return pointer to structure
* *
* Returns !NULL on success, NULL on error. * Returns !NULL on success, NULL on error.
*/ */
virBandwidthPtr virNetDevBandwidthPtr
virBandwidthDefParseNode(xmlNodePtr node) virNetDevBandwidthParse(xmlNodePtr node)
{ {
virBandwidthPtr def = NULL; virNetDevBandwidthPtr def = NULL;
xmlNodePtr cur = node->children; xmlNodePtr cur = node->children;
xmlNodePtr in = NULL, out = NULL; xmlNodePtr in = NULL, out = NULL;
@ -1028,7 +1029,7 @@ virBandwidthDefParseNode(xmlNodePtr node)
goto error; goto error;
} }
if (virBandwidthParseChildDefNode(in, def->in) < 0) { if (virNetDevBandwidthParseRate(in, def->in) < 0) {
/* helper reported error for us */ /* helper reported error for us */
goto error; goto error;
} }
@ -1040,7 +1041,7 @@ virBandwidthDefParseNode(xmlNodePtr node)
goto error; goto error;
} }
if (virBandwidthParseChildDefNode(out, def->out) < 0) { if (virNetDevBandwidthParseRate(out, def->out) < 0) {
/* helper reported error for us */ /* helper reported error for us */
goto error; goto error;
} }
@ -1049,12 +1050,12 @@ virBandwidthDefParseNode(xmlNodePtr node)
return def; return def;
error: error:
virBandwidthDefFree(def); virNetDevBandwidthFree(def);
return NULL; return NULL;
} }
void void
virBandwidthDefFree(virBandwidthPtr def) virNetDevBandwidthFree(virNetDevBandwidthPtr def)
{ {
if (!def) if (!def)
return; return;
@ -1065,9 +1066,9 @@ virBandwidthDefFree(virBandwidthPtr def)
} }
static int static int
virBandwidthChildDefFormat(virBufferPtr buf, virNetDevBandwidthRateFormat(virNetDevBandwidthRatePtr def,
virRatePtr def, virBufferPtr buf,
const char *elem_name) const char *elem_name)
{ {
if (!buf || !elem_name) if (!buf || !elem_name)
return -1; return -1;
@ -1090,9 +1091,9 @@ virBandwidthChildDefFormat(virBufferPtr buf,
} }
/** /**
* virBandwidthDefFormat: * virNetDevBandwidthDefFormat:
* @buf: Buffer to print to
* @def: Data source * @def: Data source
* @buf: Buffer to print to
* *
* Formats bandwidth and prepend each line with @indent. * Formats bandwidth and prepend each line with @indent.
* @buf may use auto-indentation. * @buf may use auto-indentation.
@ -1100,8 +1101,7 @@ virBandwidthChildDefFormat(virBufferPtr buf,
* Returns 0 on success, else -1. * Returns 0 on success, else -1.
*/ */
int int
virBandwidthDefFormat(virBufferPtr buf, virNetDevBandwidthFormat(virNetDevBandwidthPtr def, virBufferPtr buf)
virBandwidthPtr def)
{ {
int ret = -1; int ret = -1;
@ -1114,8 +1114,8 @@ virBandwidthDefFormat(virBufferPtr buf,
} }
virBufferAddLit(buf, "<bandwidth>\n"); virBufferAddLit(buf, "<bandwidth>\n");
if (virBandwidthChildDefFormat(buf, def->in, "inbound") < 0 || if (virNetDevBandwidthRateFormat(def->in, buf, "inbound") < 0 ||
virBandwidthChildDefFormat(buf, def->out, "outbound") < 0) virNetDevBandwidthRateFormat(def->out, buf, "outbound") < 0)
goto cleanup; goto cleanup;
virBufferAddLit(buf, "</bandwidth>\n"); virBufferAddLit(buf, "</bandwidth>\n");
@ -1126,9 +1126,9 @@ cleanup:
} }
/** /**
* virBandwidthEnable: * virNetDevBandwidthSet:
* @bandwidth: rates to set * @ifname: on which interface
* @iface: on which interface * @bandwidth: rates to set (may be NULL)
* *
* This function enables QoS on specified interface * This function enables QoS on specified interface
* and set given traffic limits for both, incoming * and set given traffic limits for both, incoming
@ -1138,8 +1138,8 @@ cleanup:
* Return 0 on success, -1 otherwise. * Return 0 on success, -1 otherwise.
*/ */
int int
virBandwidthEnable(virBandwidthPtr bandwidth, virNetDevBandwidthSet(const char *ifname,
const char *iface) virNetDevBandwidthPtr bandwidth)
{ {
int ret = -1; int ret = -1;
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
@ -1147,17 +1147,13 @@ virBandwidthEnable(virBandwidthPtr bandwidth,
char *peak = NULL; char *peak = NULL;
char *burst = NULL; char *burst = NULL;
if (!iface)
return -1;
if (!bandwidth) { if (!bandwidth) {
/* nothing to be enabled */ /* nothing to be enabled */
ret = 0; ret = 0;
goto cleanup; goto cleanup;
} }
if (virBandwidthDisable(iface, true) < 0) ignore_value(virNetDevBandwidthClear(ifname));
goto cleanup;
if (bandwidth->in) { if (bandwidth->in) {
if (virAsprintf(&average, "%llukbps", bandwidth->in->average) < 0) if (virAsprintf(&average, "%llukbps", bandwidth->in->average) < 0)
@ -1170,14 +1166,14 @@ virBandwidthEnable(virBandwidthPtr bandwidth,
goto cleanup; goto cleanup;
cmd = virCommandNew(TC); cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "qdisc", "add", "dev", iface, "root", virCommandAddArgList(cmd, "qdisc", "add", "dev", ifname, "root",
"handle", "1:", "htb", "default", "1", NULL); "handle", "1:", "htb", "default", "1", NULL);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
goto cleanup; goto cleanup;
virCommandFree(cmd); virCommandFree(cmd);
cmd = virCommandNew(TC); cmd = virCommandNew(TC);
virCommandAddArgList(cmd,"class", "add", "dev", iface, "parent", virCommandAddArgList(cmd,"class", "add", "dev", ifname, "parent",
"1:", "classid", "1:1", "htb", NULL); "1:", "classid", "1:1", "htb", NULL);
virCommandAddArgList(cmd, "rate", average, NULL); virCommandAddArgList(cmd, "rate", average, NULL);
@ -1191,7 +1187,7 @@ virBandwidthEnable(virBandwidthPtr bandwidth,
virCommandFree(cmd); virCommandFree(cmd);
cmd = virCommandNew(TC); cmd = virCommandNew(TC);
virCommandAddArgList(cmd,"filter", "add", "dev", iface, "parent", virCommandAddArgList(cmd,"filter", "add", "dev", ifname, "parent",
"1:0", "protocol", "ip", "handle", "1", "fw", "1:0", "protocol", "ip", "handle", "1", "fw",
"flowid", "1", NULL); "flowid", "1", NULL);
@ -1212,7 +1208,7 @@ virBandwidthEnable(virBandwidthPtr bandwidth,
virCommandFree(cmd); virCommandFree(cmd);
cmd = virCommandNew(TC); cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "qdisc", "add", "dev", iface, virCommandAddArgList(cmd, "qdisc", "add", "dev", ifname,
"ingress", NULL); "ingress", NULL);
if (virCommandRun(cmd, NULL) < 0) if (virCommandRun(cmd, NULL) < 0)
@ -1220,7 +1216,7 @@ virBandwidthEnable(virBandwidthPtr bandwidth,
virCommandFree(cmd); virCommandFree(cmd);
cmd = virCommandNew(TC); cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "filter", "add", "dev", iface, "parent", virCommandAddArgList(cmd, "filter", "add", "dev", ifname, "parent",
"ffff:", "protocol", "ip", "u32", "match", "ip", "ffff:", "protocol", "ip", "u32", "match", "ip",
"src", "0.0.0.0/0", "police", "rate", average, "src", "0.0.0.0/0", "police", "rate", average,
"burst", burst, "mtu", burst, "drop", "flowid", "burst", burst, "mtu", burst, "drop", "flowid",
@ -1241,9 +1237,8 @@ cleanup:
} }
/** /**
* virBandwidthDisable: * virNetDevBandwidthClear:
* @iface: on which interface * @ifname: on which interface
* @may_fail: should be unsuccessful disable considered fatal?
* *
* This function tries to disable QoS on specified interface * This function tries to disable QoS on specified interface
* by deleting root and ingress qdisc. However, this may fail * by deleting root and ingress qdisc. However, this may fail
@ -1252,59 +1247,43 @@ cleanup:
* Return 0 on success, -1 otherwise. * Return 0 on success, -1 otherwise.
*/ */
int int
virBandwidthDisable(const char *iface, virNetDevBandwidthClear(const char *ifname)
bool may_fail)
{ {
int ret = -1; int ret = 0;
int status;
virCommandPtr cmd = NULL; virCommandPtr cmd = NULL;
if (!iface)
return -1;
cmd = virCommandNew(TC); cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "qdisc", "del", "dev", iface, "root", NULL); virCommandAddArgList(cmd, "qdisc", "del", "dev", ifname, "root", NULL);
if ((virCommandRun(cmd, &status) < 0) || if (virCommandRun(cmd, NULL) < 0)
(!may_fail && status)) ret = -1;
goto cleanup;
virCommandFree(cmd); virCommandFree(cmd);
cmd = virCommandNew(TC); cmd = virCommandNew(TC);
virCommandAddArgList(cmd, "qdisc", "del", "dev", iface, "ingress", NULL); virCommandAddArgList(cmd, "qdisc", "del", "dev", ifname, "ingress", NULL);
if ((virCommandRun(cmd, &status) < 0) || if (virCommandRun(cmd, NULL) < 0)
(!may_fail && status)) ret = -1;
goto cleanup;
ret = 0;
cleanup:
virCommandFree(cmd); virCommandFree(cmd);
return ret; return ret;
} }
/* /*
* virBandwidthCopy: * virNetDevBandwidthCopy:
* @dest: destination * @dest: destination
* @src: source * @src: source (may be NULL)
* *
* Returns -1 on OOM error (which gets reported), * Returns -1 on OOM error (which gets reported),
* 0 otherwise. * 0 otherwise.
*/ */
int int
virBandwidthCopy(virBandwidthPtr *dest, virNetDevBandwidthCopy(virNetDevBandwidthPtr *dest,
const virBandwidthPtr src) const virNetDevBandwidthPtr src)
{ {
int ret = -1; int ret = -1;
if (!dest) {
virSocketError(VIR_ERR_INVALID_ARG, "%s",
_("invalid argument supplied"));
return -1;
}
*dest = NULL; *dest = NULL;
if (!src) { if (!src) {
/* nothing to be copied */ /* nothing to be copied */
@ -1337,15 +1316,15 @@ virBandwidthCopy(virBandwidthPtr *dest,
cleanup: cleanup:
if (ret < 0) { if (ret < 0) {
virBandwidthDefFree(*dest); virNetDevBandwidthFree(*dest);
*dest = NULL; *dest = NULL;
} }
return ret; return ret;
} }
bool bool
virBandwidthEqual(virBandwidthPtr a, virNetDevBandwidthEqual(virNetDevBandwidthPtr a,
virBandwidthPtr b) virNetDevBandwidthPtr b)
{ {
if (!a && !b) if (!a && !b)
return true; return true;

View File

@ -48,19 +48,19 @@ typedef struct {
typedef virSocketAddr *virSocketAddrPtr; typedef virSocketAddr *virSocketAddrPtr;
typedef struct { typedef struct _virNetDevBandwidthRate virNetDevBandwidthRate;
typedef virNetDevBandwidthRate *virNetDevBandwidthRatePtr;
struct _virNetDevBandwidthRate {
unsigned long long average; /* kbytes/s */ unsigned long long average; /* kbytes/s */
unsigned long long peak; /* kbytes/s */ unsigned long long peak; /* kbytes/s */
unsigned long long burst; /* kbytes */ unsigned long long burst; /* kbytes */
} virRate; };
typedef virRate *virRatePtr; typedef struct _virNetDevBandwidth virNetDevBandwidth;
typedef virNetDevBandwidth *virNetDevBandwidthPtr;
typedef struct { struct _virNetDevBandwidth {
virRatePtr in, out; virNetDevBandwidthRatePtr in, out;
} virBandwidth; };
typedef virBandwidth *virBandwidthPtr;
int virSocketAddrParse(virSocketAddrPtr addr, int virSocketAddrParse(virSocketAddrPtr addr,
const char *val, const char *val,
@ -152,16 +152,21 @@ virVirtualPortProfileFormat(virBufferPtr buf,
bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a, bool virVirtualPortProfileEqual(virVirtualPortProfileParamsPtr a,
virVirtualPortProfileParamsPtr b); virVirtualPortProfileParamsPtr b);
virBandwidthPtr virBandwidthDefParseNode(xmlNodePtr node); virNetDevBandwidthPtr virNetDevBandwidthParse(xmlNodePtr node)
void virBandwidthDefFree(virBandwidthPtr def); ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virBandwidthDefFormat(virBufferPtr buf, void virNetDevBandwidthFree(virNetDevBandwidthPtr def);
virBandwidthPtr def); int virNetDevBandwidthFormat(virNetDevBandwidthPtr def,
virBufferPtr buf)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2);
int virBandwidthEnable(virBandwidthPtr bandwidth, const char *iface); int virNetDevBandwidthSet(const char *ifname, virNetDevBandwidthPtr bandwidth)
int virBandwidthDisable(const char *iface, bool may_fail); ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
int virBandwidthCopy(virBandwidthPtr *dest, const virBandwidthPtr src); 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 virBandwidthEqual(virBandwidthPtr a, virBandwidthPtr b); bool virNetDevBandwidthEqual(virNetDevBandwidthPtr a, virNetDevBandwidthPtr b);
#endif /* __VIR_NETWORK_H__ */ #endif /* __VIR_NETWORK_H__ */

View File

@ -11250,7 +11250,7 @@ static const vshCmdOptDef opts_attach_interface[] = {
/* parse inbound and outbound which are in the format of /* parse inbound and outbound which are in the format of
* 'average,peak,burst', in which peak and burst are optional, * 'average,peak,burst', in which peak and burst are optional,
* thus 'average,,burst' and 'average,peak' are also legal. */ * 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; const char *average = NULL;
char *peak = NULL, *burst = NULL; char *peak = NULL, *burst = NULL;
@ -11289,7 +11289,7 @@ cmdAttachInterface(vshControl *ctl, const vshCmd *cmd)
const char *mac = NULL, *target = NULL, *script = NULL, const char *mac = NULL, *target = NULL, *script = NULL,
*type = NULL, *source = NULL, *model = NULL, *type = NULL, *source = NULL, *model = NULL,
*inboundStr = NULL, *outboundStr = NULL; *inboundStr = NULL, *outboundStr = NULL;
virRate inbound, outbound; virNetDevBandwidthRate inbound, outbound;
int typ; int typ;
int ret; int ret;
bool functionReturn = false; bool functionReturn = false;