]> xenbits.xensource.com Git - libvirt.git/commitdiff
Introduce virNetDevBandwidthUpdateFilter
authorMichal Privoznik <mprivozn@redhat.com>
Tue, 14 Apr 2015 16:04:30 +0000 (18:04 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Fri, 17 Apr 2015 08:49:03 +0000 (10:49 +0200)
This is a simple wrapper around virNetDevBandwidthManipulateFilter() that
will update the desired filter on an interface (usually a network bridge)
with a new MAC address. Although, the MAC address in question usually
refers to some other interface - the one that the filter is constructed
for. Yeah, hard to parse. Thing is, our NATed network has a bridge where
some part of QoS takes place. And vNICs from guests are plugged into
the bridge. However, if a guest decides to change the MAC of its vNIC,
the corresponding qemu process emits an event which we can use to
update the QoS configuration based on the new MAC address.. However,
our QoS hierarchy is currently not notified, therefore it falls apart.
This function (when called in response to the aforementioned event)
will update our QoS hierarchy and duct tape it together again.

Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
src/libvirt_private.syms
src/util/virnetdevbandwidth.c
src/util/virnetdevbandwidth.h

index aafc3851c403c61da944403317070ad3c805b865..8c3730399b995dfcdb67bb2e2c64f4fcc885a1da 100644 (file)
@@ -1758,6 +1758,7 @@ virNetDevBandwidthFree;
 virNetDevBandwidthPlug;
 virNetDevBandwidthSet;
 virNetDevBandwidthUnplug;
+virNetDevBandwidthUpdateFilter;
 virNetDevBandwidthUpdateRate;
 
 
index 7d3c486eb0ac64fc8a42275a66fd4f785d3e9521..6ae08775a44d54e3f2d4a5acdc455ead4add104f 100644 (file)
@@ -681,3 +681,41 @@ virNetDevBandwidthUpdateRate(const char *ifname,
     VIR_FREE(ceil);
     return ret;
 }
+
+/**
+ * virNetDevBandwidthUpdateFilter:
+ * @ifname: interface to operate on
+ * @ifmac_ptr: new MAC to update the filter with
+ * @id: filter ID
+ *
+ * Sometimes the host environment is so dynamic, that even a
+ * guest's MAC addresses change on the fly. When that happens we
+ * must update our QoS hierarchy so that the guest's traffic is
+ * placed into the correct QDiscs.  This function updates the
+ * filter for the interface @ifname with the unique identifier
+ * @id so that it uses the new MAC address of the guest interface
+ * @ifmac_ptr.
+ *
+ * Returns: 0 on success,
+ *         -1 on failure (with error reported).
+ */
+int
+virNetDevBandwidthUpdateFilter(const char *ifname,
+                               const virMacAddr *ifmac_ptr,
+                               unsigned int id)
+{
+    int ret = -1;
+    char *class_id = NULL;
+
+    if (virAsprintf(&class_id, "1:%x", id) < 0)
+        goto cleanup;
+
+    if (virNetDevBandwidthManipulateFilter(ifname, ifmac_ptr, id,
+                                           class_id, true, true) < 0)
+        goto cleanup;
+
+    ret = 0;
+ cleanup:
+    VIR_FREE(class_id);
+    return ret;
+}
index efcf95af51bf3ee15bf02c134cd209f1de994675..9b1d2a63644ff857300ce8df9b9e801154480749 100644 (file)
@@ -73,4 +73,10 @@ int virNetDevBandwidthUpdateRate(const char *ifname,
                                  unsigned long long new_rate)
     ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
     ATTRIBUTE_RETURN_CHECK;
+
+int virNetDevBandwidthUpdateFilter(const char *ifname,
+                                   const virMacAddr *ifmac_ptr,
+                                   unsigned int id)
+    ATTRIBUTE_NONNULL(1) ATTRIBUTE_NONNULL(2)
+    ATTRIBUTE_RETURN_CHECK;
 #endif /* __VIR_NETDEV_BANDWIDTH_H__ */