On 11/19/2012 11:51 AM, Michal Privoznik wrote:
This will be used whenever a NIC with guaranteed throughput is to
be plugged into a bridge. It will adjust the average throughput of
non guaranteed NICs (classid 1:2) to meet new requirements.
---
src/util/virnetdevbandwidth.c | 49 +++++++++++++++++++++++++++++++++++++++++
src/util/virnetdevbandwidth.h | 6 +++++
2 files changed, 55 insertions(+), 0 deletions(-)
diff --git a/src/util/virnetdevbandwidth.c b/src/util/virnetdevbandwidth.c
index 9597dcd..3abe7e2 100644
--- a/src/util/virnetdevbandwidth.c
+++ b/src/util/virnetdevbandwidth.c
@@ -463,3 +463,52 @@ cleanup:
virCommandFree(cmd);
return ret;
}
+
+/**
+ * virNetDevBandwidthUpdateRate:
+ * @ifname: interface name
+ * @classid: ID of class to update
+ * @new_rate: new rate
+ *
+ * This function updates the 'rate' attribute of HTB class.
+ * It can be used whenever a new interface is plugged to a
+ * bridge to adjust average throughput of non guaranteed
+ * NICs.
So it's changing the "average" for that NIC to something other than what
was configured? Is a record of this kept anywhere? (or maybe it's not
necessary).
+ *
+ * Returns 0 on success, -1 otherwise.
+ */
+int
+virNetDevBandwidthUpdateRate(const char *ifname,
+ const char *class_id,
+ virNetDevBandwidthPtr bandwidth,
+ unsigned long long new_rate)
+{
+ int ret = -1;
+ virCommandPtr cmd = NULL;
+ char *rate = NULL;
+ char *ceil = NULL;
+
+ if (virAsprintf(&rate, "%llukbps", new_rate) < 0 ||
+ virAsprintf(&ceil, "%llukbps", bandwidth->in->peak ?
+ bandwidth->in->peak :
+ bandwidth->in->average) < 0) {
+ virReportOOMError();
+ goto cleanup;
+ }
+
+ cmd = virCommandNew(TC);
+ virCommandAddArgList(cmd, "class", "change", "dev",
ifname,
+ "classid", class_id, "htb",
"rate", rate,
+ "ceil", ceil, NULL);
+
+ if (virCommandRun(cmd, NULL) < 0)
+ goto cleanup;
+
+ ret = 0;
+
+cleanup:
+ virCommandFree(cmd);
+ VIR_FREE(rate);
+ VIR_FREE(ceil);
+ return ret;
+}
diff --git a/src/util/virnetdevbandwidth.h b/src/util/virnetdevbandwidth.h
index 19eb418..a5d595e 100644
--- a/src/util/virnetdevbandwidth.h
+++ b/src/util/virnetdevbandwidth.h
@@ -67,4 +67,10 @@ int virNetDevBandwidthUnplug(const char *brname,
unsigned int id)
ATTRIBUTE_NONNULL(1) ATTRIBUTE_RETURN_CHECK;
+int virNetDevBandwidthUpdateRate(const char *ifname,
+ const char *class_id,
+ virNetDevBandwidthPtr bandwidth,
+ unsigned long long new_rate)
+ ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
+ ATTRIBUTE_RETURN_CHECK;
#endif /* __VIR_NETDEV_BANDWIDTH_H__ */
ACK.