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 f6f2a86..19c00b6 100644
--- a/src/util/virnetdevbandwidth.c
+++ b/src/util/virnetdevbandwidth.c
@@ -534,3 +534,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.
+ *
+ * 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 5c9bce3..01a2ba5 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__ */
--
1.7.8.6